libcap/go/psx-fd.go
Andrew G. Morgan bbabfb4cf4 Add a test case for a deadlock.
The CGO_ENABLED=0 failure mode is discussed in:

  https://github.com/golang/go/issues/50113

At the present time, this only passes when the psx package is compiled
CGO_ENABLED=1. The problem being that a blocking read cannot be
interrupted by the CGO_ENABLED=0 build of package "psx". It does not
deadlock when compiled CGO_ENABLED=1 because the psx signal wakes the
reading thread up back into user space.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-01-23 16:35:23 -08:00

26 lines
401 B
Go

package main
import (
"log"
"os"
"syscall"
"time"
"kernel.org/pub/linux/libs/security/libcap/psx"
)
const prSetKeepCaps = 8
func main() {
r, w, err := os.Pipe()
if err != nil {
log.Fatalf("failed to obtain pipe: %v", err)
}
data := make([]byte, 2+r.Fd())
go r.Read(data)
time.Sleep(500 * time.Millisecond)
psx.Syscall3(syscall.SYS_PRCTL, prSetKeepCaps, 1, 0)
w.Close()
r.Close()
}