aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/direct.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-15 00:27:44 +0900
committerOphestra <cat@gensokyo.uk>2025-03-15 00:27:44 +0900
commitf443d315ad60d761c06135569abb0adb183ac8c1 (patch)
treee22b866dc239cd888ef7f3d2ffadaf6a14bd51aa /helper/direct.go
parent9e18d1de77b2c9bb24a51c2e99b060c6d06818ee (diff)
helper: clean up interface
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>
Diffstat (limited to 'helper/direct.go')
-rw-r--r--helper/direct.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/helper/direct.go b/helper/direct.go
index 9e279130..93eae227 100644
--- a/helper/direct.go
+++ b/helper/direct.go
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"io"
+ "os/exec"
"sync"
"git.gensokyo.uk/security/fortify/helper/proc"
@@ -15,7 +16,7 @@ type direct struct {
*helperCmd
}
-func (h *direct) Start(stat bool) error {
+func (h *direct) Start() error {
h.lock.Lock()
defer h.lock.Unlock()
@@ -25,15 +26,25 @@ func (h *direct) Start(stat bool) error {
return errors.New("exec: already started")
}
- args := h.finalise(stat)
+ args := h.finalise()
h.Cmd.Args = append(h.Cmd.Args, args...)
return proc.Fulfill(h.ctx, &h.ExtraFiles, h.Cmd.Start, h.files, h.extraFiles)
}
-// New initialises a new direct Helper instance with wt as the null-terminated argument writer.
+// NewDirect initialises a new direct Helper instance with wt as the null-terminated argument writer.
// Function argF returns an array of arguments passed directly to the child process.
-func New(ctx context.Context, wt io.WriterTo, name string, argF func(argsFd, statFd int) []string) Helper {
+func NewDirect(
+ ctx context.Context,
+ wt io.WriterTo,
+ name string,
+ argF func(argsFd, statFd int) []string,
+ cmdF func(cmd *exec.Cmd),
+ stat bool,
+) Helper {
d := new(direct)
- d.helperCmd = newHelperCmd(d, ctx, name, wt, argF, nil)
+ d.helperCmd = newHelperCmd(ctx, name, wt, argF, nil, stat)
+ if cmdF != nil {
+ cmdF(d.helperCmd.Cmd)
+ }
return d
}