]> Cypherpunks repositories - gostls13.git/commitdiff
syscall/exec_linux: enable changing controlling tty
authorPeter Waller <peter.waller@gmail.com>
Wed, 31 Oct 2012 00:36:18 +0000 (17:36 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 31 Oct 2012 00:36:18 +0000 (17:36 -0700)
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

index 70f3e6217b9cd44d22ee504d5a1d2f02187423d5..adb6a06ba8d0bf6d98cd12e8656affc50d63959e 100644 (file)
@@ -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
                }