fix(cmd/start): use absolute executable path for child process (#2125)

* fix(cmd/start): use absolute executable path for child process

* fix(cmd/start): detect force-bin-dir flag variants

---------

Co-authored-by: Zoe Lee <zoelee@gmail.com>
This commit is contained in:
abcqqoo
2026-09-01 18:15:06 +08:00
committed by GitHub
parent 4031b31837
commit ce87b45d2d
+17 -7
View File
@@ -8,6 +8,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -31,14 +32,23 @@ func start() {
return return
} }
} }
args := os.Args exe, err := os.Executable()
args[1] = "server" if err != nil {
args = append(args, "--force-bin-dir") log.Fatal("failed to resolve executable path: ", err)
cmd := &exec.Cmd{
Path: args[0],
Args: args,
Env: os.Environ(),
} }
childArgs := append([]string{"server"}, os.Args[2:]...)
hasForceBinDir := false
for _, arg := range childArgs {
if arg == "--force-bin-dir" || strings.HasPrefix(arg, "--force-bin-dir=") {
hasForceBinDir = true
break
}
}
if !hasForceBinDir {
childArgs = append(childArgs, "--force-bin-dir")
}
cmd := exec.Command(exe, childArgs...)
cmd.Env = os.Environ()
stdout, err := os.OpenFile(filepath.Join(filepath.Dir(pidFile), "start.log"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) stdout, err := os.OpenFile(filepath.Join(filepath.Dir(pidFile), "start.log"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil { if err != nil {
log.Fatal(os.Getpid(), ": failed to open start log file:", err) log.Fatal(os.Getpid(), ": failed to open start log file:", err)