1// Program psx-signals validates that the psx mechanism can coexist 2// with Go use of signals. This is an unprivilaged program derived 3// from the sample code provided in this bug report: 4// 5// https://bugzilla.kernel.org/show_bug.cgi?id=210533 6package main 7 8import ( 9 "fmt" 10 "log" 11 "os" 12 "os/signal" 13 "syscall" 14 "time" 15 16 "kernel.org/pub/linux/libs/security/libcap/psx" 17) 18 19const maxSig = 10 20const prSetKeepCaps = 8 21 22func main() { 23 sig := make(chan os.Signal, maxSig) 24 signal.Notify(sig, os.Interrupt) 25 26 fmt.Print("Toggling KEEP_CAPS ") 27 for i := 0; i < maxSig; i++ { 28 fmt.Print(".") 29 _, _, err := psx.Syscall3(syscall.SYS_PRCTL, prSetKeepCaps, uintptr(i&1), 0) 30 if err != 0 { 31 log.Fatalf("[%d] attempt to set KEEPCAPS (to %d) failed: %v", i, i%2, err) 32 } 33 } 34 35 fmt.Println(" done") 36 fmt.Print("Wait 1 second to see if unwanted signals arrive...") 37 // Confirm no signals are delivered. 38 select { 39 case <-time.After(1 * time.Second): 40 break 41 case info := <-sig: 42 log.Fatalf("signal received: %v", info) 43 } 44 fmt.Println(" none arrived") 45 fmt.Println("PASSED") 46} 47