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:
- Create PTY pair from /dev/pts/ptmx (we’re already in the container)
- Optionally mount PTY slave on /dev/console (bind mount) - only for init
- Send PTY master to console socket
- Set controlling terminal
- Connect stdio to PTY slave
§Arguments
console_fd- The console socket file descriptormount- 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