Skip to content

Commit

Permalink
fixup! Enable run_hooks to be passed cwd
Browse files Browse the repository at this point in the history
Signed-off-by: utam0k <k0ma@utam0k.jp>
  • Loading branch information
utam0k committed May 14, 2024
1 parent b536591 commit 73cffe3
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions crates/libcontainer/src/hooks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
collections::HashMap,
env,
io::{ErrorKind, Write},
os::unix::prelude::CommandExt,
path::Path,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73cffe3

Please sign in to comment.