From 3afe8d7c1da6592e46a09abb426d6b2ac66077a7 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sat, 24 Feb 2024 13:04:18 +0300 Subject: [PATCH] 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. --- internal/app/app.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/app/app.go b/internal/app/app.go index c242ae33..7b0de1a6 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -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)