From fe7d208cf76fa6f24bb9d12ba29b5ed61d837ce3 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 13 Feb 2025 23:15:34 +0900 Subject: helper: use generic extra files interface This replaces the pipes object and integrates context into helper process lifecycle. Signed-off-by: Ophestra --- internal/system/op.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'internal/system/op.go') 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)) -- cgit v1.3.1