diff options
| author | Michael MacInnis <michael.p.macinnis@gmail.com> | 2015-02-17 22:23:16 -0500 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-03-23 15:35:53 +0000 |
| commit | f7befa43a3e5110379a85cabbbc999cf3b5fb9f6 (patch) | |
| tree | 41a53d28077f9ff4f1ef94762d90dbcc273d5db9 /src/syscall/exec_bsd.go | |
| parent | 5bf9249edafa26eb2b4d7768a48e5ace8656a01a (diff) | |
| download | go-f7befa43a3e5110379a85cabbbc999cf3b5fb9f6.tar.xz | |
syscall: Add Foreground and Pgid to SysProcAttr
On Unix, when placing a child in a new process group, allow that group
to become the foreground process group. Also, allow a child process to
join a specific process group.
When setting the foreground process group, Ctty is used as the file
descriptor of the controlling terminal. Ctty has been added to the BSD
and Solaris SysProcAttr structures and the handling of Setctty changed
to match Linux.
Change-Id: I18d169a6c5ab8a6a90708c4ff52eb4aded50bc8c
Reviewed-on: https://go-review.googlesource.com/5130
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/syscall/exec_bsd.go')
| -rw-r--r-- | src/syscall/exec_bsd.go | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/syscall/exec_bsd.go b/src/syscall/exec_bsd.go index ff78f197f1..4b5774b492 100644 --- a/src/syscall/exec_bsd.go +++ b/src/syscall/exec_bsd.go @@ -16,9 +16,12 @@ type SysProcAttr struct { Credential *Credential // Credential. 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 + Setpgid bool // Set process group ID to Pgid, or, if Pgid == 0, to new pid. + Setctty bool // Set controlling terminal to fd Ctty Noctty bool // Detach fd 0 from controlling terminal + Ctty int // Controlling TTY fd + Foreground bool // Place child's process group in foreground. (Implies Setpgid. Uses Ctty as fd of controlling TTY) + Pgid int // Child's process group ID if Setpgid. } // Implemented in runtime package. @@ -101,8 +104,27 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } // Set process group - if sys.Setpgid { - _, _, err1 = RawSyscall(SYS_SETPGID, 0, 0, 0) + if sys.Setpgid || sys.Foreground { + // Place child in process group. + _, _, err1 = RawSyscall(SYS_SETPGID, 0, uintptr(sys.Pgid), 0) + if err1 != 0 { + goto childerror + } + } + + if sys.Foreground { + pgrp := sys.Pgid + if pgrp == 0 { + r1, _, err1 = RawSyscall(SYS_GETPID, 0, 0, 0) + if err1 != 0 { + goto childerror + } + + pgrp = int(r1) + } + + // Place process group in foreground. + _, _, err1 = RawSyscall(SYS_IOCTL, uintptr(sys.Ctty), uintptr(TIOCSPGRP), uintptr(unsafe.Pointer(&pgrp))) if err1 != 0 { goto childerror } @@ -210,9 +232,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 { - _, _, err1 = RawSyscall(SYS_IOCTL, 0, uintptr(TIOCSCTTY), 0) + _, _, err1 = RawSyscall(SYS_IOCTL, uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0) if err1 != 0 { goto childerror } |
