fix(daemon-mode): handle '-daemon' argument correctly for background execution
This commit fixes the issue where the '-daemon' argument was not being properly handled when re-executing the program in daemon mode. The loop removes the '-daemon' flag from the arguments slice before the program is re-run in the background, ensuring that subsequent executions do not attempt to enter daemon mode again. The change will prevent potential errors or unexpected behavior due to the presence of the '-daemon' argument in recursive calls, making the daemon mode feature more robust and reliable.
This commit is contained in:
+6
-1
@@ -43,8 +43,13 @@ func Init() {
|
||||
}
|
||||
|
||||
if daemon {
|
||||
for i, arg := range os.Args[1:] {
|
||||
if arg == "-daemon" {
|
||||
os.Args[i+1] = ""
|
||||
}
|
||||
}
|
||||
// Re-run the program in background and exit
|
||||
cmd := exec.Command(os.Args[0], os.Args[2:]...)
|
||||
cmd := exec.Command(os.Args[0], os.Args[1:]...)
|
||||
cmd.Start()
|
||||
fmt.Println("Running in daemon mode with PID:", cmd.Process.Pid)
|
||||
os.Exit(0)
|
||||
|
||||
Reference in New Issue
Block a user