diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-04-27 11:28:40 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-04-27 19:12:41 +0000 |
commit | 0c3557e6adbc4892afbef65d76ec5bce3d84a964 (patch) | |
tree | 74e62fb18f1183a167ac9fad32257c1be8d94d15 /src/syscall | |
parent | 291eb0178f143b373a9bc4fbc4edaf3420175660 (diff) | |
download | go-0c3557e6adbc4892afbef65d76ec5bce3d84a964.tar.gz go-0c3557e6adbc4892afbef65d76ec5bce3d84a964.zip |
syscall: move TestForegroundSignal create call out of goroutine
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>
Diffstat (limited to 'src/syscall')
-rw-r--r-- | src/syscall/exec_unix_test.go | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/syscall/exec_unix_test.go b/src/syscall/exec_unix_test.go index 643c2e9789..866671ba2a 100644 --- a/src/syscall/exec_unix_test.go +++ b/src/syscall/exec_unix_test.go @@ -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, |