fortify/helper/seccomp/api.go
Ophestra 106f9f4450
Some checks failed
Test / Create distribution (push) Has been cancelled
Test / Run NixOS test (push) Has been cancelled
helper/seccomp: implement reader interface via pipe
This also does not require the libc tmpfile call.

BPF programs emitted by libseccomp seems to be deterministic. The tests would catch regressions as it verifies the program against known good output backed by manual testing.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-02-03 19:39:34 +09:00

38 lines
627 B
Go

package seccomp
import (
"errors"
"syscall"
)
/*
An Encoder writes a BPF program to an output stream.
Methods of Encoder are not safe for concurrent use.
An Encoder must not be copied after first use.
*/
type Encoder struct {
*exporter
}
func (e *Encoder) Read(p []byte) (n int, err error) {
if err = e.prepare(); err != nil {
return
}
return e.r.Read(p)
}
func (e *Encoder) Close() error {
if e.r == nil {
return syscall.EINVAL
}
// this hangs if the cgo thread fails to exit
return errors.Join(e.closeWrite(), <-e.exportErr)
}
func New(opts SyscallOpts) *Encoder {
return &Encoder{newExporter(opts)}
}