From 8ee8ae0f4697827ab9b8901896ef125a53d7e58b Mon Sep 17 00:00:00 2001 From: Ricardo Branco Date: Mon, 30 Dec 2024 11:59:31 +0100 Subject: [PATCH] Minor refactor --- restartable.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/restartable.go b/restartable.go index d877ac1..c3a580b 100644 --- a/restartable.go +++ b/restartable.go @@ -295,8 +295,6 @@ func main() { } sort.Ints(pids) - services := make(map[string]bool) - if opts.short < 3 { fmt.Printf("%s\t%s\t%s\t%-20s\t%20s\t%s\n", "PID", "PPID", "UID", "User", "Service", "Command") } @@ -309,24 +307,22 @@ func main() { go func() { for _, pid := range pids { go func(pid int) { - if info, err := getInfo(pid); info != nil && err == nil { - channel[pid] <- info - } else { - if err != nil { - log.Print(err) - } - close(channel[pid]) + info, err := getInfo(pid) + if err != nil { + log.Print(err) } + channel[pid] <- info }(pid) } }() + services := make(map[string]bool) for _, pid := range pids { proc := <-channel[pid] if proc == nil { continue } - //close(channel[pid]) + close(channel[pid]) if opts.short < 3 { fmt.Printf("%d\t%s\t%d\t%-20s\t%20s\t%s\n", pid, proc.ppid, proc.uid, getUser(proc.uid), proc.service, proc.command) } else if proc.service != "-" {