fix: detach background and orphan processes from the controlling terminal with setsid()

This commit is contained in:
sxyazi 2025-05-05 16:09:12 +08:00
parent ca96c5bd98
commit eab5148a75
No known key found for this signature in database

View file

@ -38,7 +38,7 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
.current_dir(opt.cwd) .current_dir(opt.cwd)
.kill_on_drop(!opt.orphan) .kill_on_drop(!opt.orphan)
.pre_exec(move || { .pre_exec(move || {
if opt.orphan && libc::setpgid(0, 0) < 0 { if (opt.piped || opt.orphan) && libc::setsid() < 0 {
return Err(std::io::Error::last_os_error()); return Err(std::io::Error::last_os_error());
} }
Ok(()) Ok(())