Skip to main content

setup_console

Function setup_console 

Source
pub fn setup_console(
    syscall: &dyn Syscall,
    console_fd: RawFd,
    mount: bool,
) -> Result<(), TTYError>
Expand description

Setup console AFTER pivot_root.

This function should be called AFTER pivot_root. This follows runc’s approach: setupConsole is called after pivotRoot in prepareRootfs.

The process:

  1. Create PTY pair from /dev/pts/ptmx (we’re already in the container)
  2. Optionally mount PTY slave on /dev/console (bind mount) - only for init
  3. Send PTY master to console socket
  4. Set controlling terminal
  5. Connect stdio to PTY slave

§Arguments

  • console_fd - The console socket file descriptor
  • mount - Whether to mount PTY slave on /dev/console (true for init, false for exec)

By creating PTY from container’s devpts, the PTY belongs to a mount that exists within the container’s namespace, which is required for CRIU checkpoint.

See: https://github.com/opencontainers/runc/blob/v1.4.0/libcontainer/rootfs_linux.go