Skip to content

Commit e6f88e2

Browse files
Zoe Leeabcqqoo
authored andcommitted
fix(cmd/start): use absolute executable path for child process
1 parent b5626b2 commit e6f88e2

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

cmd/start.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ func start() {
3131
return
3232
}
3333
}
34-
args := os.Args
35-
args[1] = "server"
36-
args = append(args, "--force-bin-dir")
37-
cmd := &exec.Cmd{
38-
Path: args[0],
39-
Args: args,
40-
Env: os.Environ(),
34+
exe, err := os.Executable()
35+
if err != nil {
36+
log.Fatal("failed to resolve executable path: ", err)
37+
}
38+
childArgs := append([]string{"server"}, os.Args[2:]...)
39+
hasForceBinDir := false
40+
for _, arg := range childArgs {
41+
if arg == "--force-bin-dir" {
42+
hasForceBinDir = true
43+
break
44+
}
45+
}
46+
if !hasForceBinDir {
47+
childArgs = append(childArgs, "--force-bin-dir")
4148
}
49+
cmd := exec.Command(exe, childArgs...)
50+
cmd.Env = os.Environ()
4251
stdout, err := os.OpenFile(filepath.Join(filepath.Dir(pidFile), "start.log"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
4352
if err != nil {
4453
log.Fatal(os.Getpid(), ": failed to open start log file:", err)

0 commit comments

Comments
 (0)