Skip to content

Commit 1544217

Browse files
os: don't use waitid on Darwin
According to issue #19314 waitid on Darwin returns if the process is stopped, even though we specify WEXITED. Fixes #19314. Change-Id: I95faf196c11e43b7741efff79351bab45c811bc2 Reviewed-on: https://go-review.googlesource.com/37610 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent d945b28 commit 1544217

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

src/os/exec/exec_posix_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strconv"
1212
"syscall"
1313
"testing"
14+
"time"
1415
)
1516

1617
func TestCredentialNoSetGroups(t *testing.T) {
@@ -43,3 +44,40 @@ func TestCredentialNoSetGroups(t *testing.T) {
4344
t.Errorf("Failed to run command: %v", err)
4445
}
4546
}
47+
48+
// For issue #19314: make sure that SIGSTOP does not cause the process
49+
// to appear done.
50+
func TestWaitid(t *testing.T) {
51+
t.Parallel()
52+
53+
cmd := helperCommand(t, "sleep")
54+
if err := cmd.Start(); err != nil {
55+
t.Fatal(err)
56+
}
57+
58+
// The sleeps here are unnecessary in the sense that the test
59+
// should still pass, but they are useful to make it more
60+
// likely that we are testing the expected state of the child.
61+
time.Sleep(100 * time.Millisecond)
62+
63+
if err := cmd.Process.Signal(syscall.SIGSTOP); err != nil {
64+
cmd.Process.Kill()
65+
t.Fatal(err)
66+
}
67+
68+
ch := make(chan error)
69+
go func() {
70+
ch <- cmd.Wait()
71+
}()
72+
73+
time.Sleep(100 * time.Millisecond)
74+
75+
if err := cmd.Process.Signal(syscall.SIGCONT); err != nil {
76+
t.Error(err)
77+
syscall.Kill(cmd.Process.Pid, syscall.SIGCONT)
78+
}
79+
80+
cmd.Process.Kill()
81+
82+
<-ch
83+
}

src/os/exec/exec_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ func TestHelperProcess(*testing.T) {
868868
case "stderrfail":
869869
fmt.Fprintf(os.Stderr, "some stderr text\n")
870870
os.Exit(1)
871+
case "sleep":
872+
time.Sleep(3 * time.Second)
873+
os.Exit(0)
871874
default:
872875
fmt.Fprintf(os.Stderr, "Unknown command %q\n", cmd)
873876
os.Exit(2)

src/os/wait_unimp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build dragonfly nacl netbsd openbsd solaris
5+
// +build darwin dragonfly nacl netbsd openbsd solaris
66

77
package os
88

src/os/wait_waitid.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build darwin linux
5+
// We used to used this code for Darwin, but according to issue #19314
6+
// waitid returns if the process is stopped, even when using WEXITED.
7+
8+
// +build linux
69

710
package os
811

0 commit comments

Comments
 (0)