aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-13 22:49:16 +0900
committerOphestra <cat@gensokyo.uk>2025-02-13 22:49:16 +0900
commitd1d20c06fb0c3ed5aaff15f284921a5e61c291e1 (patch)
tree2b52ec349fab79a67ce16025fd8c784485b9d355
parent1e6a0596687ee772fd53317727f5724dd119668c (diff)
helper/seccomp: use sync.Once for closeWrite
This makes the code much cleaner, and eliminates the intermittent ErrInvalid errors. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--helper/seccomp/export.go25
1 files changed, 11 insertions, 14 deletions
diff --git a/helper/seccomp/export.go b/helper/seccomp/export.go
index dd1aedad..52ec4144 100644
--- a/helper/seccomp/export.go
+++ b/helper/seccomp/export.go
@@ -1,11 +1,9 @@
package seccomp
import (
- "io/fs"
"os"
"runtime"
"sync"
- "sync/atomic"
)
type exporter struct {
@@ -14,7 +12,8 @@ type exporter struct {
prepareOnce sync.Once
prepareErr error
- closeErr atomic.Pointer[error]
+ closeOnce sync.Once
+ closeErr error
exportErr <-chan error
}
@@ -36,19 +35,17 @@ func (e *exporter) prepare() error {
}
func (e *exporter) closeWrite() error {
- if !e.closeErr.CompareAndSwap(nil, &fs.ErrInvalid) {
- return *e.closeErr.Load()
- }
- if e.w == nil {
- panic("closeWrite called on invalid exporter")
- }
- err := e.w.Close()
- e.closeErr.Store(&err)
+ e.closeOnce.Do(func() {
+ if e.w == nil {
+ panic("closeWrite called on invalid exporter")
+ }
+ e.closeErr = e.w.Close()
- // no need for a finalizer anymore
- runtime.SetFinalizer(e, nil)
+ // no need for a finalizer anymore
+ runtime.SetFinalizer(e, nil)
+ })
- return err
+ return e.closeErr
}
func newExporter(opts SyscallOpts) *exporter {