From 27181846bbdd2a8825c1099e692423fae17c5600 Mon Sep 17 00:00:00 2001 From: Lawrence Stewart Date: Tue, 8 Aug 2017 00:31:10 +0000 Subject: [PATCH] pgrep naively appends the delimiter to all PIDs including the last e.g. "pgrep -d, getty" outputs "1399,1386,1309,1308,1307,1306,1305,1302," Ensure the list is correctly delimited by suppressing the emission of the delimiter after the final PID. Reviewed by: imp, kib MFC after: 1 week Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D8537 --- bin/pkill/pkill.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/pkill/pkill.c b/bin/pkill/pkill.c index abdc4502d36..f65767a8f38 100644 --- a/bin/pkill/pkill.c +++ b/bin/pkill/pkill.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -656,10 +657,12 @@ killact(const struct kinfo_proc *kp) static int grepact(const struct kinfo_proc *kp) { + static bool first = true; - show_process(kp); - if (!quiet) + if (!quiet && !first) printf("%s", delim); + show_process(kp); + first = false; return (1); }