helper: embed context on creation
All checks were successful
Test / Create distribution (push) Successful in 24s
Test / Fortify (push) Successful in 2m34s
Test / Fpkg (push) Successful in 3m22s
Test / Data race detector (push) Successful in 3m44s
Test / Flake checks (push) Successful in 49s

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-03-14 18:30:22 +09:00
parent 4bb5d9780f
commit 7c60a4d8e8
8 changed files with 76 additions and 75 deletions

View File

@@ -124,7 +124,11 @@ func Main() {
if fmsg.Load() {
seccomp.CPrintln = log.Println
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop() // unreachable
if b, err := helper.NewBwrap(
ctx,
conf, path.Join(fst.Tmp, "sbin/init0"), false,
nil, func(int, int) []string { return make([]string, 0) },
extraFiles,
@@ -132,12 +136,10 @@ func Main() {
); err != nil {
log.Fatalf("malformed sandbox config: %v", err)
} else {
b.Stdin(os.Stdin).Stdout(os.Stdout).Stderr(os.Stderr)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop() // unreachable
b.SetStdin(os.Stdin).SetStdout(os.Stdout).SetStderr(os.Stderr)
// run and pass through exit code
if err = b.Start(ctx, false); err != nil {
if err = b.Start(false); err != nil {
log.Fatalf("cannot start target process: %v", err)
} else if err = b.Wait(); err != nil {
var exitError *exec.ExitError