diff options
| author | David Crawshaw <crawshaw@golang.org> | 2014-12-11 10:25:32 -0500 |
|---|---|---|
| committer | David Crawshaw <crawshaw@golang.org> | 2014-12-22 21:21:10 +0000 |
| commit | 401b20234cc56ac771a0daeec53c200f752500a7 (patch) | |
| tree | 93c4f26495fa62e69cc2edacaf67c89276705849 /src/syscall/exec_linux.go | |
| parent | 2a617d46f3ed39a71d8af8fb004fdfe8711160c2 (diff) | |
| download | go-401b20234cc56ac771a0daeec53c200f752500a7.tar.xz | |
syscall: check recorded version of ppid instead of 1
Handles the case where the parent is pid 1 (common in docker
containers).
Attempted and failed to write a test for this.
Fixes #9263.
Change-Id: I5c6036446c99e66259a4fab1660b6a594f875020
Reviewed-on: https://go-review.googlesource.com/1372
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/syscall/exec_linux.go')
| -rw-r--r-- | src/syscall/exec_linux.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index 042c20a468..03dd5c53c4 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -58,6 +58,9 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr p [2]int ) + // Record parent PID so child can test if it has died. + ppid, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) + // Guard against side effects of shuffling fds below. // Make sure that nextfd is beyond any currently open files so // that we can't run the risk of overwriting any of them. @@ -138,7 +141,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // duplicate signal in rare cases, but it won't matter when // using SIGKILL. r1, _, _ = RawSyscall(SYS_GETPPID, 0, 0, 0) - if r1 == 1 { + if r1 != ppid { pid, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) _, _, err1 := RawSyscall(SYS_KILL, pid, uintptr(sys.Pdeathsig), 0) if err1 != 0 { |
