Bug 30542

Summary: [patch] add -q option to shut up killall(1)
Product: Base System Reporter: Tony Finch <dot>
Component: binAssignee: Mateusz Guzik <mjg>
Status: Closed FIXED    
Severity: Affects Only Me CC: ngie
Priority: Normal Flags: bugmeister: mfc-stable10?
bugmeister: mfc-stable9?
bugmeister: mfc-stable8?
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Tony Finch 2001-09-13 01:10:00 UTC
Somewhere (can't remember where) I saw some code that did a
`killall >/dev/null 2>&1` which made me think there should be
a -q option.

This patch also happens to have some strlcpy pedantry in it.
Comment 1 dima 2001-09-13 12:19:13 UTC
Tony Finch <dot@dotat.at> wrote:
> >Description:
> Somewhere (can't remember where) I saw some code that did a
> `killall >/dev/null 2>&1` which made me think there should be
> a -q option.

Why?  That's what redirects are for.  I don't see anything wrong with
the above construct.  It seems silly to add a "shut up" option to
every program; if we wanted to do that, why did we have redirects and
/dev/null in the first place?
Comment 2 dima 2001-09-15 17:01:21 UTC
Garrett Wollman <wollman@khavrinen.lcs.mit.edu> wrote:
> <<On Thu, 13 Sep 2001 04:20:02 -0700 (PDT), Dima Dorfman <dima@unixfreak.org>
>  said:
> 
> >  Why?  That's what redirects are for.
> 
> Redirects are not content-sensitive.  In the case of `killall', it is
> entirely legitimate to want to suppress the ``no matching processes
> found'' while still displaying any other error messages which might be
> generated.

Okay, agreed.  How about just changing the output stream for that
message to stdout instead of stderr?
Comment 3 Garrett Cooper 2008-06-21 03:11:04 UTC
Not finding any processes seems more legitimate as an error to send to
stderr than stdout.
-Garrett
Comment 4 dfilter service freebsd_committer freebsd_triage 2013-06-30 21:27:46 UTC
Author: mjg
Date: Sun Jun 30 20:27:31 2013
New Revision: 252428
URL: http://svnweb.freebsd.org/changeset/base/252428

Log:
  killall: add -q flag to suppress error message when no processes are matched
  
  Man-page text provided by wblock.
  
  PR:		bin/30542
  Submitted by:	Tony Finch <dot@dotat.at> (original version)
  MFC after:	1 week

Modified:
  head/usr.bin/killall/killall.1
  head/usr.bin/killall/killall.c

Modified: head/usr.bin/killall/killall.1
==============================================================================
--- head/usr.bin/killall/killall.1	Sun Jun 30 19:53:52 2013	(r252427)
+++ head/usr.bin/killall/killall.1	Sun Jun 30 20:27:31 2013	(r252428)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 27, 2012
+.Dd June 30, 2013
 .Dt KILLALL 1
 .Os
 .Sh NAME
@@ -110,6 +110,8 @@ the specified
 Limit potentially matching processes to those matching
 the specified
 .Ar procname .
+.It Fl q
+Suppress error message if no processes are matched.
 .It Fl z
 Do not skip zombies.
 This should not have any effect except to print a few error messages

Modified: head/usr.bin/killall/killall.c
==============================================================================
--- head/usr.bin/killall/killall.c	Sun Jun 30 19:53:52 2013	(r252427)
+++ head/usr.bin/killall/killall.c	Sun Jun 30 20:27:31 2013	(r252428)
@@ -53,7 +53,7 @@ static void __dead2
 usage(void)
 {
 
-	fprintf(stderr, "usage: killall [-delmsvz] [-help] [-I] [-j jail]\n");
+	fprintf(stderr, "usage: killall [-delmsqvz] [-help] [-I] [-j jail]\n");
 	fprintf(stderr,
 	    "               [-u user] [-t tty] [-c cmd] [-SIGNAL] [cmd]...\n");
 	fprintf(stderr, "At least one option or argument to specify processes must be given.\n");
@@ -101,6 +101,7 @@ main(int ac, char **av)
 	char		*user = NULL;
 	char		*tty = NULL;
 	char		*cmd = NULL;
+	int		qflag = 0;
 	int		vflag = 0;
 	int		sflag = 0;
 	int		dflag = 0;
@@ -191,6 +192,9 @@ main(int ac, char **av)
 				    	errx(1, "must specify procname");
 				cmd = *av;
 				break;
+			case 'q':
+				qflag++;
+				break;
 			case 'v':
 				vflag++;
 				break;
@@ -417,8 +421,9 @@ main(int ac, char **av)
 		}
 	}
 	if (killed == 0) {
-		fprintf(stderr, "No matching processes %swere found\n",
-		    getuid() != 0 ? "belonging to you " : "");
+		if (!qflag)
+			fprintf(stderr, "No matching processes %swere found\n",
+			    getuid() != 0 ? "belonging to you " : "");
 		errors = 1;
 	}
 	exit(errors);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 5 Mateusz Guzik freebsd_committer freebsd_triage 2013-06-30 21:27:56 UTC
Responsible Changed
From-To: freebsd-bugs->mjg

I'll take it.
Comment 6 Mateusz Guzik freebsd_committer freebsd_triage 2013-06-30 21:28:39 UTC
State Changed
From-To: open->patched

Committed as r252428
Comment 7 Enji Cooper freebsd_committer freebsd_triage 2015-10-15 20:23:28 UTC
Mateusz: is this bug in need of an MFC still?