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 /helper/bwrap/trivial.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 'helper/bwrap/trivial.go')
| -rw-r--r-- | helper/bwrap/trivial.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/helper/bwrap/trivial.go b/helper/bwrap/trivial.go new file mode 100644 index 00000000..5aa8a1eb --- /dev/null +++ b/helper/bwrap/trivial.go @@ -0,0 +1,52 @@ +package bwrap + +import ( + "context" + "encoding/gob" + "os" + "strconv" + + "git.gensokyo.uk/security/fortify/helper/proc" +) + +func init() { + gob.Register(new(pairF)) + gob.Register(new(stringF)) +} + +type pairF [3]string + +func (p *pairF) Path() string { return p[2] } +func (p *pairF) Len() int { return len(p) } +func (p *pairF) Append(args *[]string) { *args = append(*args, p[0], p[1], p[2]) } + +type stringF [2]string + +func (s stringF) Path() string { return s[1] } +func (s stringF) Len() int { return len(s) /* compiler replaces this with 2 */ } +func (s stringF) Append(args *[]string) { *args = append(*args, s[0], s[1]) } + +func newFile(name string, f *os.File) FDBuilder { return &fileF{name: name, file: f} } + +type fileF struct { + name string + file *os.File + proc.BaseFile +} + +func (f *fileF) ErrCount() int { return 0 } +func (f *fileF) Fulfill(_ context.Context, _ func(error)) error { f.Set(f.file); return nil } + +func (f *fileF) Len() int { + if f.file == nil { + return 0 + } + return 2 +} + +func (f *fileF) Append(args *[]string) { + if f.file == nil { + return + } + *args = append(*args, f.name, strconv.Itoa(int(f.Fd()))) +} |
