From 0c3557e6adbc4892afbef65d76ec5bce3d84a964 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 27 Apr 2021 11:28:40 -0700 Subject: [PATCH] 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 Run-TryBot: Ian Lance Taylor Reviewed-by: Cherry Zhang --- src/syscall/exec_unix_test.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/syscall/exec_unix_test.go b/src/syscall/exec_unix_test.go index 643c2e97891..866671ba2ac 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,