From: Peter Waller Date: Wed, 31 Oct 2012 00:36:18 +0000 (-0700) Subject: syscall/exec_linux: enable changing controlling tty X-Git-Tag: go1.1rc2~2023 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3494010f7dc1705d6317c82bfe458f61cf2bca66;p=gostls13.git syscall/exec_linux: enable changing controlling tty As discussed in the following thread: https://groups.google.com/forum/?fromgroups=#!topic/golang-dev/emeJffxWhVo This is required to enable applications such as `less` to use something other than stdin as the controlling terminal. R=dave, iant CC=bradfitz, golang-dev https://golang.org/cl/6785057 --- diff --git a/src/pkg/syscall/exec_linux.go b/src/pkg/syscall/exec_linux.go index 70f3e6217b..adb6a06ba8 100644 --- a/src/pkg/syscall/exec_linux.go +++ b/src/pkg/syscall/exec_linux.go @@ -16,8 +16,9 @@ type SysProcAttr struct { Ptrace bool // Enable tracing. Setsid bool // Create session. Setpgid bool // Set process group ID to new pid (SYSV setpgrp) - Setctty bool // Set controlling terminal to fd 0 + Setctty bool // Set controlling terminal to fd Ctty (only meaningful if Setsid is set) Noctty bool // Detach fd 0 from controlling terminal + Ctty int // Controlling TTY fd (Linux only) Pdeathsig Signal // Signal that the process will get when its parent dies (Linux only) } @@ -206,9 +207,9 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } } - // Make fd 0 the tty - if sys.Setctty { - _, _, err1 = RawSyscall(SYS_IOCTL, 0, uintptr(TIOCSCTTY), 0) + // Set the controlling TTY to Ctty + if sys.Setctty && sys.Ctty >= 0 { + _, _, err1 = RawSyscall(SYS_IOCTL, uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0) if err1 != 0 { goto childerror }