fix: tolerate setsid EPERM in subcontainer pre_exec

In TTY mode, pty_process already calls setsid() on the child before
our pre_exec runs. The second setsid() fails with EPERM since the
process is already a session leader. This is harmless — ignore it.
This commit is contained in:
Aiden McClelland
2026-03-25 10:31:29 -06:00
parent 2bb1463f4f
commit 4bebcafdde

View File

@@ -283,10 +283,16 @@ impl ExecParams {
let set_gid = gid.ok();
unsafe {
cmd.pre_exec(move || {
// Create a new process group so entrypoint scripts that do
// Create a new session so entrypoint scripts that do
// kill(0, SIGTERM) don't cascade to other subcontainers.
nix::unistd::setsid()
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
// EPERM means we're already a session leader (e.g. pty_process
// called setsid() for us), which is fine.
match nix::unistd::setsid() {
Ok(_) | Err(Errno::EPERM) => {}
Err(e) => {
return Err(std::io::Error::from_raw_os_error(e as i32));
}
}
if !groups.is_empty() {
nix::unistd::setgroups(&groups)
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;