From 8962cbfe3ed78518abea442a41d0042e38ba4f87 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 20 Oct 2023 08:27:39 +0800 Subject: [PATCH] fix: delegate the `SIGINT` signal of processes with `orphan=true` to their parent --- core/src/external/shell.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/external/shell.rs b/core/src/external/shell.rs index 5011b707..fa4cc948 100644 --- a/core/src/external/shell.rs +++ b/core/src/external/shell.rs @@ -30,7 +30,7 @@ impl ShellOpt { pub fn shell(opt: ShellOpt) -> Result { #[cfg(unix)] - return Ok( + return Ok(unsafe { Command::new("sh") .arg("-c") .stdin(opt.stdio()) @@ -40,8 +40,14 @@ pub fn shell(opt: ShellOpt) -> Result { .arg("") // $0 is the command name .args(opt.args) .kill_on_drop(!opt.orphan) - .spawn()?, - ); + .pre_exec(move || { + if opt.orphan && libc::setpgid(0i32, 0i32) < 0 { + libc::perror(std::ptr::null()); + } + Ok(()) + }) + .spawn()? + }); #[cfg(windows)] {