diff --git a/pkg/program/shell.go b/pkg/program/shell.go index 34a79aeb..058c8c69 100644 --- a/pkg/program/shell.go +++ b/pkg/program/shell.go @@ -17,8 +17,8 @@ type shellProgram struct { } func (sh *shellProgram) Main(fds [3]*os.File, args []string) int { - p := shell.MakePathsWithDefaults(fds[2], - &shell.Paths{Bin: sh.BinPath, Sock: sh.SockPath, Db: sh.DbPath}) + p := shell.MakePaths(fds[2], + shell.Paths{Bin: sh.BinPath, Sock: sh.SockPath, Db: sh.DbPath}) if sh.NoRc { p.Rc = "" } diff --git a/pkg/program/shell/paths.go b/pkg/program/shell/paths.go index 1484d793..44ba7fca 100644 --- a/pkg/program/shell/paths.go +++ b/pkg/program/shell/paths.go @@ -23,9 +23,9 @@ type Paths struct { Bin string } -// MakePathsWithDefaults tries to populate empty fileds with default values. -func MakePathsWithDefaults(stderr io.Writer, p0 *Paths) *Paths { - p := *p0 +// MakePaths makes a populated Paths, using the given overrides. +func MakePaths(stderr io.Writer, overrides Paths) Paths { + p := overrides setDir(&p.RunDir, "secure run directory", getSecureRunDir, stderr) if p.RunDir != "" { setChild(&p.Sock, p.RunDir, "sock") @@ -47,7 +47,7 @@ func MakePathsWithDefaults(stderr io.Writer, p0 *Paths) *Paths { fmt.Fprintln(stderr, "warning: cannot get executable path:", err) } } - return &p + return p } func setDir(p *string, what string, f func() (string, error), stderr io.Writer) { diff --git a/pkg/program/web/web.go b/pkg/program/web/web.go index f09f48bd..f594dae4 100644 --- a/pkg/program/web/web.go +++ b/pkg/program/web/web.go @@ -34,8 +34,8 @@ type ExecuteResponse struct { } func (web *Web) Main(fds [3]*os.File, _ []string) int { - p := shell.MakePathsWithDefaults(fds[2], - &shell.Paths{Bin: web.BinPath, Sock: web.SockPath, Db: web.DbPath}) + p := shell.MakePaths(fds[2], + shell.Paths{Bin: web.BinPath, Sock: web.SockPath, Db: web.DbPath}) ev := shell.InitRuntime(fds[2], p, true) defer shell.CleanupRuntime(fds[2], ev)