helper/args: simplify argument parsing and eliminate excess memory copies

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-09-25 14:00:30 +09:00
parent a8b4b3634b
commit 8492239cba
3 changed files with 33 additions and 75 deletions

View File

@@ -19,7 +19,6 @@ var (
// Helper wraps *exec.Cmd and manages status and args fd.
// Args is always 3 and status if set is always 4.
type Helper struct {
lock sync.RWMutex
args io.WriterTo
statP [2]*os.File
@@ -32,6 +31,7 @@ type Helper struct {
// standard error. If non-nil, entry i becomes file descriptor 5+i.
ExtraFiles []*os.File
lock sync.RWMutex
*exec.Cmd
}
@@ -177,7 +177,7 @@ func (h *Helper) Start() error {
func New(wt io.WriterTo, name string, arg ...string) *Helper {
if wt == nil {
panic("attempted to create helper with nil argument writer")
panic("attempted to create helper with invalid argument writer")
}
return &Helper{args: wt, Cmd: exec.Command(name, arg...)}