mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
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:
@@ -283,10 +283,16 @@ impl ExecParams {
|
|||||||
let set_gid = gid.ok();
|
let set_gid = gid.ok();
|
||||||
unsafe {
|
unsafe {
|
||||||
cmd.pre_exec(move || {
|
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.
|
// kill(0, SIGTERM) don't cascade to other subcontainers.
|
||||||
nix::unistd::setsid()
|
// EPERM means we're already a session leader (e.g. pty_process
|
||||||
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
|
// 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() {
|
if !groups.is_empty() {
|
||||||
nix::unistd::setgroups(&groups)
|
nix::unistd::setgroups(&groups)
|
||||||
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
|
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user