diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-07-30 14:28:58 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-08-12 20:23:07 -0700 |
commit | c5b21c3f4c17b0649155035d2f9aa97b2da8a813 (patch) | |
tree | c6d3a68b503ba5b16182acbb958e3e5dbc95a43b /libgo/go/syscall/exec_unix_test.go | |
parent | 72be20e20299ec57b4bc9ba03d5b7d6bf10e97cc (diff) | |
download | gcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.zip gcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.tar.gz gcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.tar.bz2 |
libgo: update to Go1.17rc2
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/341629
Diffstat (limited to 'libgo/go/syscall/exec_unix_test.go')
-rw-r--r-- | libgo/go/syscall/exec_unix_test.go | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/libgo/go/syscall/exec_unix_test.go b/libgo/go/syscall/exec_unix_test.go index 1399149..8595722 100644 --- a/libgo/go/syscall/exec_unix_test.go +++ b/libgo/go/syscall/exec_unix_test.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris // +build aix darwin dragonfly freebsd hurd linux netbsd openbsd solaris package syscall_test @@ -169,11 +170,13 @@ func TestForeground(t *testing.T) { t.Skip("skipping; TestForeground: fails on GNU/Hurd") } signal.Ignore(syscall.SIGTTIN, syscall.SIGTTOU) + defer signal.Reset() tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0) if err != nil { t.Skipf("Can't test Foreground. Couldn't open /dev/tty: %s", err) } + defer tty.Close() fpgrp := syscall.Pid_t(0) @@ -212,12 +215,68 @@ func TestForeground(t *testing.T) { cmd.Stop() - errno = syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp))) + // 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) { + tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0) + if err != nil { + t.Skipf("couldn't open /dev/tty: %s", err) + } + 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("TIOCSPGRP failed with error code: %s", errno) + t.Fatalf("TIOCGPGRP failed with error code: %s", errno) } - signal.Reset() + 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.proc.SysProcAttr = &syscall.SysProcAttr{ + Ctty: int(tty.Fd()), + Foreground: true, + } + cmd.Start() + cmd.Stop() + close(ch2) + }() + + timer := time.NewTimer(30 * time.Second) + defer timer.Stop() + for { + select { + case sig := <-ch1: + t.Errorf("unexpected signal %v", sig) + case <-ch2: + // Success. + return + case <-timer.C: + t.Fatal("timed out waiting for child process") + } + } } // Test a couple of cases that SysProcAttr can't handle. Issue 29458. |