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

This commit is contained in:
三咲雅 · Misaki Masa 2025-05-05 16:11:25 +08:00 committed by GitHub
parent ca96c5bd98
commit db60951783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,7 +38,7 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
.current_dir(opt.cwd)
.kill_on_drop(!opt.orphan)
.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());
}
Ok(())