From 5f2ac17129ed836e4c2f13aaf7efaf42dacd8bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=98=B3?= Date: Sat, 4 Apr 2026 21:37:40 +0800 Subject: [PATCH] fix(cli): preserve daemon pid before releasing child process --- server/cmd/multica/cmd_daemon.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/cmd/multica/cmd_daemon.go b/server/cmd/multica/cmd_daemon.go index fc57703a..e9bddb77 100644 --- a/server/cmd/multica/cmd_daemon.go +++ b/server/cmd/multica/cmd_daemon.go @@ -163,13 +163,14 @@ func runDaemonBackground(cmd *cobra.Command) error { return fmt.Errorf("start daemon: %w", err) } logFile.Close() + pid := child.Process.Pid // Detach: we don't Wait() on the child — it runs independently. child.Process.Release() // Write PID file. pidPath := daemonPIDPathForProfile(profile) - if err := os.WriteFile(pidPath, []byte(strconv.Itoa(child.Process.Pid)), 0o644); err != nil { + if err := os.WriteFile(pidPath, []byte(strconv.Itoa(pid)), 0o644); err != nil { fmt.Fprintf(os.Stderr, "Warning: could not write PID file: %v\n", err) } @@ -184,9 +185,9 @@ func runDaemonBackground(cmd *cobra.Command) error { } if profile != "" { - fmt.Fprintf(os.Stderr, "Daemon [%s] started (pid %d, version %s)\n", profile, child.Process.Pid, version) + fmt.Fprintf(os.Stderr, "Daemon [%s] started (pid %d, version %s)\n", profile, pid, version) } else { - fmt.Fprintf(os.Stderr, "Daemon started (pid %d, version %s)\n", child.Process.Pid, version) + fmt.Fprintf(os.Stderr, "Daemon started (pid %d, version %s)\n", pid, version) } fmt.Fprintf(os.Stderr, "Logs: %s\n", logPath) return nil