package containment import ( "fmt" "os" "syscall" "golang.org/x/sys/unix" ) // The Linux system calls the containment needs; sys_darwin.go stands in // so the runner builds for a Mac, where bubblewrap never runs. const oPath = unix.O_PATH func pidfdOpen(pid int) (int, error) { return unix.PidfdOpen(pid, 0) } func pidfdSignal(fd int, sig unix.Signal) error { return unix.PidfdSendSignal(fd, sig, nil, 0) } func parentDeathKill() *syscall.SysProcAttr { return &syscall.SysProcAttr{Pdeathsig: syscall.SIGKILL} } func pathNoLinks(path string) (int, error) { return unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: unix.O_PATH | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) } // OpenTerminal opens a pseudo-terminal pair for a launch that needs a // terminal (StartTerminal), wide enough that the CLI never wraps a line. func OpenTerminal() (master, tty *os.File, err error) { master, err = os.OpenFile("/dev/ptmx", os.O_RDWR|unix.O_NOCTTY|unix.O_CLOEXEC, 0) if err != nil { return nil, nil, err } fd := int(master.Fd()) if err = unix.IoctlSetPointerInt(fd, unix.TIOCSPTLCK, 0); err != nil { master.Close() return nil, nil, err } n, err := unix.IoctlGetInt(fd, unix.TIOCGPTN) if err != nil { master.Close() return nil, nil, err } tty, err = os.OpenFile(fmt.Sprintf("/dev/pts/%d", n), os.O_RDWR|unix.O_NOCTTY|unix.O_CLOEXEC, 0) if err != nil { master.Close() return nil, nil, err } ws := unix.Winsize{Row: 50, Col: 1000} _ = unix.IoctlSetWinsize(int(tty.Fd()), unix.TIOCSWINSZ, &ws) return master, tty, nil }