mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-29 13:26:45 -04:00
unix: implement Waitid on Linux
waitid(2) can be used to wait on pidfds. Update TestPidfd to test this new functionality as well. Change-Id: I5f26140b9afd5a6ec3f04217fb1c91542936a2c3 Reviewed-on: https://go-review.googlesource.com/c/sys/+/395936 Trust: Matt Layher <mdlayher@gmail.com> Run-TryBot: Matt Layher <mdlayher@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
@@ -238,6 +238,11 @@ func TestPidfd(t *testing.T) {
|
||||
}
|
||||
defer unix.Close(fd)
|
||||
|
||||
// Child is running but not terminated.
|
||||
if err := unix.Waitid(unix.P_PIDFD, fd, nil, unix.WEXITED|unix.WNOHANG, nil); err != nil {
|
||||
t.Fatalf("failed to check for child exit: %v", err)
|
||||
}
|
||||
|
||||
const want = unix.SIGHUP
|
||||
if err := unix.PidfdSendSignal(fd, want, nil, 0); err != nil {
|
||||
t.Fatalf("failed to signal child process: %v", err)
|
||||
@@ -249,6 +254,10 @@ func TestPidfd(t *testing.T) {
|
||||
t.Fatalf("child process terminated but did not return an exit error: %v", err)
|
||||
}
|
||||
|
||||
if err := unix.Waitid(unix.P_PIDFD, fd, nil, unix.WEXITED, nil); !errors.Is(err, unix.ECHILD) {
|
||||
t.Fatalf("expected ECHILD for final waitid, but got: %v", err)
|
||||
}
|
||||
|
||||
ws, ok := eerr.Sys().(syscall.WaitStatus)
|
||||
if !ok {
|
||||
t.Fatalf("expected syscall.WaitStatus value, but got: %#T", eerr.Sys())
|
||||
|
||||
Reference in New Issue
Block a user