Skip to content

Commit

Permalink
Properly set the controlling console
Browse files Browse the repository at this point in the history
For FreeBSD it's required to become session leader of the process group
before a console can be set as controlling, furthermore it's required
to call TIOCSTTY on the console FD to actually set it as controlling.
  • Loading branch information
gizahNL committed Jun 2, 2021
1 parent 496b8ad commit 572ced0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/runj-entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"fmt"
"os"
"strconv"
"syscall"

"github.com/containerd/console"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -121,6 +122,14 @@ func dupStdio(slavePath string) error {
Err: err,
}
}

if _, err := syscall.Setsid(); err != nil {
return err
}

if ret, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), unix.TIOCSCTTY, uintptr(0)); ret != 0 || err != 0 {
return fmt.Errorf("Unable to set controlling tty")
}
for _, i := range []int{0, 1, 2} {
if err := unix.Dup2(fd, i); err != nil {
return err
Expand Down

0 comments on commit 572ced0

Please sign in to comment.