Skip to content

Commit

Permalink
Always call setsid
Browse files Browse the repository at this point in the history
Signed-off-by: Furisto <[email protected]>
  • Loading branch information
Furisto authored and adrianreber committed Jan 24, 2022
1 parent 1b810d4 commit 03bbfd8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/libcontainer/src/process/container_init_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use anyhow::{bail, Context, Result};
use nix::mount::MsFlags;
use nix::sched::CloneFlags;
use nix::unistd::setsid;
use nix::{
fcntl,
unistd::{self, Gid, Uid},
Expand Down Expand Up @@ -222,9 +223,10 @@ pub fn container_init_process(
let container = args.container.as_ref();
let namespaces = Namespaces::from(linux.namespaces().as_ref());

setsid().context("failed to create session")?;
// set up tty if specified
if let Some(csocketfd) = args.console_socket {
tty::setup_console(&csocketfd).with_context(|| "Failed to set up tty")?;
tty::setup_console(&csocketfd).with_context(|| "failed to set up tty")?;
}

apply_rest_namespaces(&namespaces, spec, syscall)?;
Expand Down
3 changes: 1 addition & 2 deletions crates/libcontainer/src/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use anyhow::{bail, Result};
use nix::errno::Errno;
use nix::sys::socket;
use nix::sys::uio;
use nix::unistd::close;
use nix::unistd::dup2;
use nix::unistd::{close, setsid};

const STDIN: i32 = 0;
const STDOUT: i32 = 1;
Expand Down Expand Up @@ -65,7 +65,6 @@ pub fn setup_console(console_fd: &RawFd) -> Result<()> {
)
.context("failed to send pty master")?;

setsid()?;
if unsafe { libc::ioctl(openpty_result.slave, libc::TIOCSCTTY) } < 0 {
log::warn!("could not TIOCSCTTY");
};
Expand Down

0 comments on commit 03bbfd8

Please sign in to comment.