From a816712fb320dac0690b2a243b8ef94cb936ee09 Mon Sep 17 00:00:00 2001 From: utam0k Date: Tue, 14 May 2024 21:43:03 +0900 Subject: [PATCH] fixup! Enable run_hooks to be passed cwd Signed-off-by: utam0k --- crates/libcontainer/src/hooks.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/crates/libcontainer/src/hooks.rs b/crates/libcontainer/src/hooks.rs index 05dd4f98b..432b4990d 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,12 @@ 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 = process::Command::new(hook.path()); + + if let Some(cwd) = cwd { + 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