]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: move TestForegroundSignal create call out of goroutine
authorIan Lance Taylor <iant@golang.org>
Tue, 27 Apr 2021 18:28:40 +0000 (11:28 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 27 Apr 2021 19:12:41 +0000 (19:12 +0000)
That way the skip takes effect.

Also ignore the result of calling TIOCSPGRP when cleaing up TestForeground.
It has started to fail for some reason, and the result doesn't matter.

Also call TIOCSPGRP to clean up in TestForegroundSignal.

For #37217

Change-Id: I2e4282d7d91ad9a198eeb12cef01c2214c2a98c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/314271
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/syscall/exec_unix_test.go

index 643c2e978911ac412ff17653ec597a04e337e859..866671ba2aca759a4c959f8695c775acdc5c71e8 100644 (file)
@@ -214,10 +214,9 @@ func TestForeground(t *testing.T) {
 
        cmd.Stop()
 
-       errno = syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
-       if errno != 0 {
-               t.Fatalf("TIOCSPGRP failed with error code: %s", errno)
-       }
+       // This call fails on darwin/arm64. The failure doesn't matter, though.
+       // This is just best effort.
+       syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
 }
 
 func TestForegroundSignal(t *testing.T) {
@@ -227,14 +226,34 @@ func TestForegroundSignal(t *testing.T) {
        }
        defer tty.Close()
 
+       // This should really be pid_t, however _C_int (aka int32) is generally
+       // equivalent.
+       fpgrp := int32(0)
+
+       errno := syscall.Ioctl(tty.Fd(), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&fpgrp)))
+       if errno != 0 {
+               t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
+       }
+
+       if fpgrp == 0 {
+               t.Fatalf("Foreground process group is zero")
+       }
+
+       defer func() {
+               signal.Ignore(syscall.SIGTTIN, syscall.SIGTTOU)
+               syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
+               signal.Reset()
+       }()
+
        ch1 := make(chan os.Signal, 1)
        ch2 := make(chan bool)
 
        signal.Notify(ch1, syscall.SIGTTIN, syscall.SIGTTOU)
        defer signal.Stop(ch1)
 
+       cmd := create(t)
+
        go func() {
-               cmd := create(t)
                cmd.proc.SysProcAttr = &syscall.SysProcAttr{
                        Ctty:       int(tty.Fd()),
                        Foreground: true,