svn commit: r330324 - stable/11/bin/pkill

Eitan Adler eadler at FreeBSD.org
Sat Mar 3 10:43:42 UTC 2018


Author: eadler
Date: Sat Mar  3 10:43:41 2018
New Revision: 330324
URL: https://svnweb.freebsd.org/changeset/base/330324

Log:
  MFC r322210,r322613,r322831:
  
  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.
  
  The r322210 change to pgrep's PID delimiting behaviour causes pgrep's default
  output to not include a trailing new line, which is a potential POLA violation
  for existing consumers. Change pgrep to always emit a trailing new line on
  completion of its output, regardless of the delimeter in use (which technically
  is also a potential POLA violation for existing consumers that rely on the
  pre-r322210 buggy behaviour, but a line has to be drawn somewhere).
  
  Only emit the trailing new line added in r322613 when not operating in quiet
  mode.
  
  PR:	221534 (r322613)

Modified:
  stable/11/bin/pkill/pkill.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/pkill/pkill.c
==============================================================================
--- stable/11/bin/pkill/pkill.c	Sat Mar  3 10:37:53 2018	(r330323)
+++ stable/11/bin/pkill/pkill.c	Sat Mar  3 10:43:41 2018	(r330324)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/user.h>
 
 #include <assert.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -567,6 +568,8 @@ main(int argc, char **argv)
 			continue;
 		rv |= (*action)(kp);
 	}
+	if (rv && pgrep && !quiet)
+		putchar('\n');
 	if (!did_action && !pgrep && longfmt)
 		fprintf(stderr,
 		    "No matching processes belonging to you were found\n");
@@ -656,10 +659,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);
 }
 


More information about the svn-src-stable-11 mailing list