Skip to content

Commit

Permalink
fix: delegate the SIGINT signal of processes with orphan=true to …
Browse files Browse the repository at this point in the history
…their parent
  • Loading branch information
sxyazi committed Oct 20, 2023
1 parent bed8172 commit 8962cbf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/external/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ShellOpt {

pub fn shell(opt: ShellOpt) -> Result<Child> {
#[cfg(unix)]
return Ok(
return Ok(unsafe {
Command::new("sh")
.arg("-c")
.stdin(opt.stdio())
Expand All @@ -40,8 +40,14 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
.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)]
{
Expand Down

0 comments on commit 8962cbf

Please sign in to comment.