mirror of
https://github.com/golang/sys.git
synced 2026-02-07 19:26:03 +03:00
unix: lock the thread for TestPrctlRetInt
The prctl system calls used in this test modify and examine the properties of the current thread. For the test to work correctly (and to avoid interfering with other tests), the thread must be locked for those calls and should not be reused when the test completes. Fixes golang/go#50607 Change-Id: I2b14e6c0440155f4287d97f0bb72099af291ba0d Reviewed-on: https://go-review.googlesource.com/c/sys/+/378555 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Bryan Mills
parent
5a964db013
commit
da31bd327a
@@ -815,16 +815,35 @@ func TestEpoll(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrctlRetInt(t *testing.T) {
|
||||
err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)
|
||||
if err != nil {
|
||||
t.Skipf("Prctl: %v, skipping test", err)
|
||||
skipc := make(chan bool, 1)
|
||||
skip := func() {
|
||||
skipc <- true
|
||||
runtime.Goexit()
|
||||
}
|
||||
v, err := unix.PrctlRetInt(unix.PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to perform prctl: %v", err)
|
||||
}
|
||||
if v != 1 {
|
||||
t.Fatalf("unexpected return from prctl; got %v, expected %v", v, 1)
|
||||
|
||||
go func() {
|
||||
// This test uses prctl to modify the calling thread, so run it on its own
|
||||
// throwaway thread and do not unlock it when the goroutine exits.
|
||||
runtime.LockOSThread()
|
||||
defer close(skipc)
|
||||
|
||||
err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)
|
||||
if err != nil {
|
||||
t.Logf("Prctl: %v, skipping test", err)
|
||||
skip()
|
||||
}
|
||||
|
||||
v, err := unix.PrctlRetInt(unix.PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0)
|
||||
if err != nil {
|
||||
t.Errorf("failed to perform prctl: %v", err)
|
||||
}
|
||||
if v != 1 {
|
||||
t.Errorf("unexpected return from prctl; got %v, expected %v", v, 1)
|
||||
}
|
||||
}()
|
||||
|
||||
if <-skipc {
|
||||
t.SkipNow()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user