From e81749a3ad32021c29b9c1fb35cc2c1ba24be517 Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Fri, 25 Nov 2022 11:32:17 +0100 Subject: [PATCH 1/2] Chdir to chroot if no working dir is given. --- src/process.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/process.rs b/src/process.rs index cca43b94..7ce15f0e 100644 --- a/src/process.rs +++ b/src/process.rs @@ -405,7 +405,17 @@ mod unix { if detach { self.perform_fork()? } - if let Some(path) = config.working_dir.as_ref() { + + let path = if let Some(path) = config.working_dir.as_ref() { + Some(path) + } + else if let Some(path) = config.chroot.as_ref() { + Some(path) + } + else { + None + }; + if let Some(path) = path { if let Err(err) = set_current_dir(path) { error!("Fatal: failed to set working directory {}: {}", path.display(), err @@ -413,6 +423,7 @@ mod unix { return Err(Failed) } } + // set_sid // umask if detach { From 1b163f92c4be691272df40779ba9d633a96803e4 Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Fri, 25 Nov 2022 11:59:32 +0100 Subject: [PATCH 2/2] Make it better. --- src/process.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/process.rs b/src/process.rs index 7ce15f0e..2cb2c4d9 100644 --- a/src/process.rs +++ b/src/process.rs @@ -406,16 +406,9 @@ mod unix { self.perform_fork()? } - let path = if let Some(path) = config.working_dir.as_ref() { - Some(path) - } - else if let Some(path) = config.chroot.as_ref() { - Some(path) - } - else { - None - }; - if let Some(path) = path { + if let Some(path) = config.working_dir.as_ref().or( + config.chroot.as_ref() + ) { if let Err(err) = set_current_dir(path) { error!("Fatal: failed to set working directory {}: {}", path.display(), err