diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-02-13 23:15:34 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-02-13 23:34:15 +0900 |
| commit | fe7d208cf76fa6f24bb9d12ba29b5ed61d837ce3 (patch) | |
| tree | cac02af50a13b2078739a8f5a74d219f3b60833d /internal/system/op.go | |
| parent | 60c287375048b21eab2bd82f1e7d43e36dcfb3a2 (diff) | |
helper: use generic extra files interface
This replaces the pipes object and integrates context into helper process lifecycle.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/system/op.go')
| -rw-r--r-- | internal/system/op.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/internal/system/op.go b/internal/system/op.go index d8479c7c..8a98fa78 100644 --- a/internal/system/op.go +++ b/internal/system/op.go @@ -1,6 +1,7 @@ package system import ( + "context" "errors" "os" "sync" @@ -57,10 +58,14 @@ func TypeString(e Enablement) string { type I struct { uid int ops []Op - sp *os.File + ctx context.Context + // sync fd passed to bwrap + sp *os.File - state [2]bool - lock sync.Mutex + // whether sys has been reverted + state bool + + lock sync.Mutex } func (sys *I) UID() int { @@ -85,14 +90,14 @@ func (sys *I) Equal(v *I) bool { return true } -func (sys *I) Commit() error { +func (sys *I) Commit(ctx context.Context) error { sys.lock.Lock() defer sys.lock.Unlock() - if sys.state[0] { + if sys.ctx != nil { panic("sys instance committed twice") } - sys.state[0] = true + sys.ctx = ctx sp := New(sys.uid) sp.ops = make([]Op, 0, len(sys.ops)) // prevent copies during commits @@ -125,10 +130,10 @@ func (sys *I) Revert(ec *Criteria) error { sys.lock.Lock() defer sys.lock.Unlock() - if sys.state[1] { + if sys.state { panic("sys instance reverted twice") } - sys.state[1] = true + sys.state = true // collect errors errs := make([]error, len(sys.ops)) |
