diff --git a/crates/libcontainer/src/hooks.rs b/crates/libcontainer/src/hooks.rs index 05dd4f98b..c5a0785ad 100644 --- a/crates/libcontainer/src/hooks.rs +++ b/crates/libcontainer/src/hooks.rs @@ -1,6 +1,5 @@ use std::{ collections::HashMap, - env, io::{ErrorKind, Write}, os::unix::prelude::CommandExt, path::Path, @@ -43,20 +42,13 @@ pub fn run_hooks( if let Some(hooks) = hooks { for hook in hooks { - let mut cmd = process::Command::new(hook.path()); + let mut hook_command = &mut process::Command::new(hook.path()); + + if let Some(cwd) = cwd { + // This is error. please fix it + hook_command = hook_command.current_dir(cwd); + } - let hook_command = if let Some(cwd) = cwd { - cmd.current_dir(cwd) - } else { - cmd.current_dir( - env::current_dir() - .map_err(|err| { - tracing::error!("failed to get current directory: {}", err); - HookError::OtherIO(err) - })? - .as_path(), - ) - }; // Based on OCI spec, the first argument of the args vector is the // arg0, which can be different from the path. For example, path // may be "/usr/bin/true" and arg0 is set to "true". However, rust