helper: clean up interface
All checks were successful
Test / Create distribution (push) Successful in 26s
Test / Fortify (push) Successful in 2m37s
Test / Fpkg (push) Successful in 3m40s
Test / Data race detector (push) Successful in 3m54s
Test / Flake checks (push) Successful in 59s

The helper interface was messy due to odd context acquisition order. That has changed, so this cleans it up.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-03-15 00:27:44 +09:00
parent 9e18d1de77
commit f443d315ad
8 changed files with 95 additions and 87 deletions

View File

@@ -39,9 +39,14 @@ func (p *Proxy) Start(ctx context.Context, output io.Writer, sandbox bool) error
c, cancel := context.WithCancelCause(ctx)
if !sandbox {
h = helper.New(c, p.seal, p.name, argF)
// xdg-dbus-proxy does not need to inherit the environment
h.SetEnv(make([]string, 0))
h = helper.NewDirect(c, p.seal, p.name, argF, func(cmd *exec.Cmd) {
if output != nil {
cmd.Stdout, cmd.Stderr = output, output
}
// xdg-dbus-proxy does not need to inherit the environment
cmd.Env = make([]string, 0)
}, true)
} else {
// look up absolute path if name is just a file name
toolPath := p.name
@@ -111,14 +116,15 @@ func (p *Proxy) Start(ctx context.Context, output io.Writer, sandbox bool) error
bc.Bind(k, k)
}
h = helper.MustNewBwrap(c, bc, toolPath, true, p.seal, argF, nil, nil)
h = helper.MustNewBwrap(c, bc, toolPath, true, p.seal, argF, func(cmd *exec.Cmd) {
if output != nil {
cmd.Stdout, cmd.Stderr = output, output
}
}, nil, nil, true)
p.bwrap = bc
}
if output != nil {
h.SetStdout(output).SetStderr(output)
}
if err := h.Start(true); err != nil {
if err := h.Start(); err != nil {
cancel(err)
return err
}