mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
cmd/syncthing: Use os.executable in monitor, only fallback to PATH (#8502)
This commit is contained in:
parent
b10d106a55
commit
6dedffe3f7
@ -83,15 +83,11 @@ func monitorMain(options serveOptions) {
|
||||
}
|
||||
|
||||
args := os.Args
|
||||
binary := args[0]
|
||||
if build.IsWindows {
|
||||
var err error
|
||||
binary, err = expandExecutableInCurrentDirectory(binary)
|
||||
binary, err := getBinary(args[0])
|
||||
if err != nil {
|
||||
l.Warnln("Error starting the main Syncthing process:", err)
|
||||
panic("Error starting the main Syncthing process")
|
||||
}
|
||||
}
|
||||
var restarts [restartCounts]time.Time
|
||||
|
||||
stopSign := make(chan os.Signal, 1)
|
||||
@ -212,19 +208,17 @@ func monitorMain(options serveOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
func expandExecutableInCurrentDirectory(args0 string) (string, error) {
|
||||
// Works around a restriction added in go1.19 that executables in the
|
||||
// current directory are not resolved when specifying just an executable
|
||||
// name (like e.g. "syncthing")
|
||||
if !strings.ContainsRune(args0, os.PathSeparator) {
|
||||
// Check if it's in PATH
|
||||
_, err := exec.LookPath(args0)
|
||||
if err != nil {
|
||||
// Try to get the path to the current executable
|
||||
return os.Executable()
|
||||
func getBinary(args0 string) (string, error) {
|
||||
e, err := os.Executable()
|
||||
if err == nil {
|
||||
return e, nil
|
||||
}
|
||||
// Check if args0 cuts it
|
||||
e, lerr := exec.LookPath(args0)
|
||||
if lerr == nil {
|
||||
return e, nil
|
||||
}
|
||||
return args0, nil
|
||||
return "", err
|
||||
}
|
||||
|
||||
func copyStderr(stderr io.Reader, dst io.Writer) {
|
||||
@ -352,17 +346,6 @@ func restartMonitor(binary string, args []string) error {
|
||||
}
|
||||
|
||||
func restartMonitorUnix(binary string, args []string) error {
|
||||
if !strings.ContainsRune(binary, os.PathSeparator) {
|
||||
// The path to the binary doesn't contain a slash, so it should be
|
||||
// found in $PATH.
|
||||
var err error
|
||||
binary, err = exec.LookPath(binary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args[0] = binary
|
||||
}
|
||||
|
||||
return syscall.Exec(args[0], args, os.Environ())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user