From 3494010f7dc1705d6317c82bfe458f61cf2bca66 Mon Sep 17 00:00:00 2001 From: Peter Waller Date: Tue, 30 Oct 2012 17:36:18 -0700 Subject: [PATCH] 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 --- src/pkg/syscall/exec_linux.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 } -- 2.48.1