diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/syscall/exec_linux.go | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-04b08da9af0c450d645ab7389d1467308cfc2db8.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/syscall/exec_linux.go')
-rw-r--r-- | src/pkg/syscall/exec_linux.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/pkg/syscall/exec_linux.go b/src/pkg/syscall/exec_linux.go index 70f3e6217..a8dc672b8 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 } @@ -232,3 +233,20 @@ childerror: // and this shuts up the compiler. panic("unreached") } + +// Try to open a pipe with O_CLOEXEC set on both file descriptors. +func forkExecPipe(p []int) (err error) { + err = Pipe2(p, O_CLOEXEC) + // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it + // might not be implemented. + if err == ENOSYS { + if err = Pipe(p); err != nil { + return + } + if _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != nil { + return + } + _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC) + } + return +} |