From b2d9167b9576cb4953f728699019c564181e4a7a Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 21 May 2025 00:08:53 +0200 Subject: [PATCH] feat: improve daemon check by logging existing PIDs to prevent duplicate instances --- src/commands/cmd_watch.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/cmd_watch.go b/src/commands/cmd_watch.go index efa4972..7c78587 100644 --- a/src/commands/cmd_watch.go +++ b/src/commands/cmd_watch.go @@ -28,13 +28,17 @@ func NewWatchCmd(history *models.History) *cobra.Command { if err == nil { pids := strings.Fields(string(out)) myPid := os.Getpid() + otherPids := []string{} for _, pidStr := range pids { pid, err := strconv.Atoi(pidStr) if err == nil && pid != myPid { - log.Warn().Msg("kcm daemon is already running. Exiting to avoid duplicate daemons.") - os.Exit(1) + otherPids = append(otherPids, pidStr) } } + if len(otherPids) > 0 { + log.Warn().Strs("pids", otherPids).Msg("kcm daemon is already running. Exiting to avoid duplicate daemons.") + os.Exit(1) + } } // Set log file path since we are daemonizing