1
0
mirror of https://github.com/golang/go synced 2024-11-20 06:14:53 -07:00

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
This commit is contained in:
Peter Waller 2012-10-30 17:36:18 -07:00 committed by Ian Lance Taylor
parent 9b0f4be2fb
commit 3494010f7d

View File

@ -16,8 +16,9 @@ type SysProcAttr struct {
Ptrace bool // Enable tracing. Ptrace bool // Enable tracing.
Setsid bool // Create session. Setsid bool // Create session.
Setpgid bool // Set process group ID to new pid (SYSV setpgrp) 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 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) 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 // Set the controlling TTY to Ctty
if sys.Setctty { if sys.Setctty && sys.Ctty >= 0 {
_, _, err1 = RawSyscall(SYS_IOCTL, 0, uintptr(TIOCSCTTY), 0) _, _, err1 = RawSyscall(SYS_IOCTL, uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0)
if err1 != 0 { if err1 != 0 {
goto childerror goto childerror
} }