seccomp: install output atomically
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
30
seccomp/output.go
Normal file
30
seccomp/output.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package seccomp
|
||||
|
||||
import "C"
|
||||
import "sync/atomic"
|
||||
|
||||
var printlnP atomic.Pointer[func(v ...any)]
|
||||
|
||||
func SetOutput(f func(v ...any)) {
|
||||
if f == nil {
|
||||
// avoid storing nil function
|
||||
printlnP.Store(nil)
|
||||
} else {
|
||||
printlnP.Store(&f)
|
||||
}
|
||||
}
|
||||
|
||||
func GetOutput() func(v ...any) {
|
||||
if fp := printlnP.Load(); fp == nil {
|
||||
return nil
|
||||
} else {
|
||||
return *fp
|
||||
}
|
||||
}
|
||||
|
||||
//export F_println
|
||||
func F_println(v *C.char) {
|
||||
if fp := printlnP.Load(); fp != nil {
|
||||
(*fp)(C.GoString(v))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user