From 062edb3487c1cc116cae78bf77420b65c43517d1 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 7 Apr 2026 15:50:59 +0900 Subject: container: remove setup pipe helper The API forces use of finalizer to close the read end of the setup pipe, which is no longer considered acceptable. Exporting this as part of package container also imposes unnecessary maintenance burden. Signed-off-by: Ophestra --- internal/outcome/process.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'internal') diff --git a/internal/outcome/process.go b/internal/outcome/process.go index 9b8fc537..44a62463 100644 --- a/internal/outcome/process.go +++ b/internal/outcome/process.go @@ -13,7 +13,6 @@ import ( "time" "hakurei.app/check" - "hakurei.app/container" "hakurei.app/fhs" "hakurei.app/hst" "hakurei.app/internal/info" @@ -372,17 +371,18 @@ func (k *outcome) start(ctx context.Context, msg message.Msg, // shim runs in the same session as monitor; see shim.go for behaviour cmd.Cancel = func() error { return cmd.Process.Signal(syscall.SIGCONT) } - var shimPipe *os.File - if fd, w, err := container.Setup(&cmd.ExtraFiles); err != nil { + var shimPipe [2]*os.File + if r, w, err := os.Pipe(); err != nil { return cmd, nil, &hst.AppError{Step: "create shim setup pipe", Err: err} } else { - shimPipe = w cmd.Env = []string{ // passed through to shim by hsu - shimEnv + "=" + strconv.Itoa(fd), + shimEnv + "=" + strconv.Itoa(3+len(cmd.ExtraFiles)), // interpreted by hsu "HAKUREI_IDENTITY=" + k.state.identity.String(), } + cmd.ExtraFiles = append(cmd.ExtraFiles, r) + shimPipe[0], shimPipe[1] = r, w } if len(k.supp) > 0 { @@ -393,12 +393,16 @@ func (k *outcome) start(ctx context.Context, msg message.Msg, msg.Verbosef("setuid helper at %s", hsuPath) if err := cmd.Start(); err != nil { + _, _ = shimPipe[0].Close(), shimPipe[1].Close() msg.Resume() - return cmd, shimPipe, &hst.AppError{Step: "start setuid wrapper", Err: err} + return cmd, nil, &hst.AppError{Step: "start setuid wrapper", Err: err} + } + if err := shimPipe[0].Close(); err != nil { + msg.Verbose(err) } *startTime = time.Now().UTC() - return cmd, shimPipe, nil + return cmd, shimPipe[1], nil } // serveShim serves outcomeState through the shim setup pipe. @@ -411,11 +415,11 @@ func serveShim(msg message.Msg, shimPipe *os.File, state *outcomeState) error { msg.Verbose(err.Error()) } if err := gob.NewEncoder(shimPipe).Encode(state); err != nil { + _ = shimPipe.Close() msg.Resume() return &hst.AppError{Step: "transmit shim config", Err: err} } - _ = shimPipe.Close() - return nil + return shimPipe.Close() } // printMessageError prints the error message according to [message.GetMessage], -- cgit v1.3.1