From ee108603572101ad3c285830e04ee248916b6c5d Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 17 Mar 2025 01:09:12 +0900 Subject: seccomp: install output atomically Signed-off-by: Ophestra --- seccomp/output.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 seccomp/output.go (limited to 'seccomp/output.go') diff --git a/seccomp/output.go b/seccomp/output.go new file mode 100644 index 00000000..d583c9ee --- /dev/null +++ b/seccomp/output.go @@ -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)) + } +} -- cgit v1.3.1