fix: delegate the SIGINT signal of processes with orphan=true to their parent

This commit is contained in:
sxyazi 2023-10-20 08:27:39 +08:00
parent bed8172347
commit 8962cbfe3e
No known key found for this signature in database

View file

@ -30,7 +30,7 @@ impl ShellOpt {
pub fn shell(opt: ShellOpt) -> Result<Child> { pub fn shell(opt: ShellOpt) -> Result<Child> {
#[cfg(unix)] #[cfg(unix)]
return Ok( return Ok(unsafe {
Command::new("sh") Command::new("sh")
.arg("-c") .arg("-c")
.stdin(opt.stdio()) .stdin(opt.stdio())
@ -40,8 +40,14 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
.arg("") // $0 is the command name .arg("") // $0 is the command name
.args(opt.args) .args(opt.args)
.kill_on_drop(!opt.orphan) .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)] #[cfg(windows)]
{ {