aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/exec_unix_test.go
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2024-03-17 01:02:16 +1100
committerJoel Sing <joel@sing.id.au>2024-03-22 04:41:27 +0000
commitac0b2f95a5f25e9e331352c93e38f9b29bee9ccc (patch)
treef07e5dd85b8ba3c7e7379acf8b74c12eaabd9204 /src/syscall/exec_unix_test.go
parent4f0408a3a205a88624dced4b188e11dd429bc3ad (diff)
downloadgo-ac0b2f95a5f25e9e331352c93e38f9b29bee9ccc.tar.xz
syscall: export Tc{get,set}pgrp for testing
Provide appropriate implementations of Tc{get,set}pgrp and export these for use in the TestForeground* tests in exec_unix_test.go. This avoids calling ioctl via syscall.Syscall on BSDs. Fixes #59667 Updates #63900 Change-Id: Ice4dcedae1f0931c026bddf33043d3864a52d44e Reviewed-on: https://go-review.googlesource.com/c/go/+/572155 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joel Sing <joel@sing.id.au>
Diffstat (limited to 'src/syscall/exec_unix_test.go')
-rw-r--r--src/syscall/exec_unix_test.go31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/syscall/exec_unix_test.go b/src/syscall/exec_unix_test.go
index 5584f7d444..bb0b3e7037 100644
--- a/src/syscall/exec_unix_test.go
+++ b/src/syscall/exec_unix_test.go
@@ -19,7 +19,6 @@ import (
"syscall"
"testing"
"time"
- "unsafe"
)
type command struct {
@@ -176,15 +175,12 @@ func TestForeground(t *testing.T) {
}
defer tty.Close()
- // This should really be pid_t, however _C_int (aka int32) is generally
- // equivalent.
- fpgrp := int32(0)
+ ttyFD := int(tty.Fd())
- errno := syscall.IoctlPtr(tty.Fd(), syscall.TIOCGPGRP, unsafe.Pointer(&fpgrp))
- if errno != 0 {
- t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
+ fpgrp, err := syscall.Tcgetpgrp(ttyFD)
+ if err != nil {
+ t.Fatalf("Tcgetpgrp failed: %v", err)
}
-
if fpgrp == 0 {
t.Fatalf("Foreground process group is zero")
}
@@ -194,7 +190,7 @@ func TestForeground(t *testing.T) {
cmd := create(t)
cmd.proc.SysProcAttr = &syscall.SysProcAttr{
- Ctty: int(tty.Fd()),
+ Ctty: ttyFD,
Foreground: true,
}
cmd.Start()
@@ -217,7 +213,7 @@ func TestForeground(t *testing.T) {
// This call fails on darwin/arm64. The failure doesn't matter, though.
// This is just best effort.
- syscall.IoctlPtr(tty.Fd(), syscall.TIOCSPGRP, unsafe.Pointer(&fpgrp))
+ syscall.Tcsetpgrp(ttyFD, fpgrp)
}
func TestForegroundSignal(t *testing.T) {
@@ -227,22 +223,19 @@ 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)
+ ttyFD := int(tty.Fd())
- errno := syscall.IoctlPtr(tty.Fd(), syscall.TIOCGPGRP, unsafe.Pointer(&fpgrp))
- if errno != 0 {
- t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
+ fpgrp, err := syscall.Tcgetpgrp(ttyFD)
+ if err != nil {
+ t.Fatalf("Tcgetpgrp failed: %v", err)
}
-
if fpgrp == 0 {
t.Fatalf("Foreground process group is zero")
}
defer func() {
signal.Ignore(syscall.SIGTTIN, syscall.SIGTTOU)
- syscall.IoctlPtr(tty.Fd(), syscall.TIOCSPGRP, unsafe.Pointer(&fpgrp))
+ syscall.Tcsetpgrp(ttyFD, fpgrp)
signal.Reset()
}()
@@ -256,7 +249,7 @@ func TestForegroundSignal(t *testing.T) {
go func() {
cmd.proc.SysProcAttr = &syscall.SysProcAttr{
- Ctty: int(tty.Fd()),
+ Ctty: ttyFD,
Foreground: true,
}
cmd.Start()