]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't use waitid on Darwin
authorIan Lance Taylor <iant@golang.org>
Tue, 28 Feb 2017 23:01:38 +0000 (15:01 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 1 Mar 2017 02:02:40 +0000 (02:02 +0000)
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 <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/os/exec/exec_posix_test.go
src/os/exec/exec_test.go
src/os/wait_unimp.go
src/os/wait_waitid.go

index b1f24d6c4e3d54153e927b0074059b8f251924c5..865b6c3ced28915da50af7cfa89e62d3ab91ec6d 100644 (file)
@@ -11,6 +11,7 @@ import (
        "strconv"
        "syscall"
        "testing"
+       "time"
 )
 
 func TestCredentialNoSetGroups(t *testing.T) {
@@ -43,3 +44,40 @@ func TestCredentialNoSetGroups(t *testing.T) {
                t.Errorf("Failed to run command: %v", err)
        }
 }
+
+// For issue #19314: make sure that SIGSTOP does not cause the process
+// to appear done.
+func TestWaitid(t *testing.T) {
+       t.Parallel()
+
+       cmd := helperCommand(t, "sleep")
+       if err := cmd.Start(); err != nil {
+               t.Fatal(err)
+       }
+
+       // The sleeps here are unnecessary in the sense that the test
+       // should still pass, but they are useful to make it more
+       // likely that we are testing the expected state of the child.
+       time.Sleep(100 * time.Millisecond)
+
+       if err := cmd.Process.Signal(syscall.SIGSTOP); err != nil {
+               cmd.Process.Kill()
+               t.Fatal(err)
+       }
+
+       ch := make(chan error)
+       go func() {
+               ch <- cmd.Wait()
+       }()
+
+       time.Sleep(100 * time.Millisecond)
+
+       if err := cmd.Process.Signal(syscall.SIGCONT); err != nil {
+               t.Error(err)
+               syscall.Kill(cmd.Process.Pid, syscall.SIGCONT)
+       }
+
+       cmd.Process.Kill()
+
+       <-ch
+}
index 7b69db7c76723f3064f529f5fadef078d55812e5..95af597f1546a793dc783166275f8e0884bb008d 100644 (file)
@@ -868,6 +868,9 @@ func TestHelperProcess(*testing.T) {
        case "stderrfail":
                fmt.Fprintf(os.Stderr, "some stderr text\n")
                os.Exit(1)
+       case "sleep":
+               time.Sleep(3 * time.Second)
+               os.Exit(0)
        default:
                fmt.Fprintf(os.Stderr, "Unknown command %q\n", cmd)
                os.Exit(2)
index 7059e59ab240556c3e6b2f78a02c5ed66d3c4f4b..b71e93f104a87a55c6c01705a09861ba1d3809bf 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build dragonfly nacl netbsd openbsd solaris
+// +build darwin dragonfly nacl netbsd openbsd solaris
 
 package os
 
index 653fce92532508151053c4875d49ca8241e9746c..a6c5c729d2ea1df5a0657c693bb0f8f8fba25421 100644 (file)
@@ -2,7 +2,10 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin linux
+// We used to used this code for Darwin, but according to issue #19314
+// waitid returns if the process is stopped, even when using WEXITED.
+
+// +build linux
 
 package os