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_linux.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_linux.go')
| -rw-r--r-- | src/syscall/exec_linux.go | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index 2e0577cecc..02474fc459 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -23,10 +23,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) + Setpgid bool // Set process group ID to Pgid, or, if Pgid == 0, to new pid. 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) + 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. Pdeathsig Signal // Signal that the process will get when its parent dies (Linux only) Cloneflags uintptr // Flags for clone calls (Linux only) UidMappings []SysProcIDMap // User ID mappings for user namespaces. @@ -167,8 +169,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 } @@ -277,7 +298,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } // Set the controlling TTY to Ctty - if sys.Setctty && sys.Ctty >= 0 { + if sys.Setctty { _, _, err1 = RawSyscall(SYS_IOCTL, uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0) if err1 != 0 { goto childerror |
