From fanf@dotat.at  Wed Sep 12 17:02:07 2001
Return-Path: <fanf@dotat.at>
Received: from hand.dotat.at (host217-35-41-52.in-addr.btopenworld.com [217.35.41.52])
	by hub.freebsd.org (Postfix) with ESMTP id 90AC237B405
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Sep 2001 17:02:06 -0700 (PDT)
Received: from fanf by hand.dotat.at with local (Exim 3.33 #16)
	id 15hKt4-0001d7-00
	for FreeBSD-gnats-submit@freebsd.org; Thu, 13 Sep 2001 01:01:50 +0000
Message-Id: <E15hKt4-0001d7-00@hand.dotat.at>
Date: Thu, 13 Sep 2001 01:01:50 +0000
From: Tony Finch <dot@dotat.at>
Reply-To: Tony Finch <dot@dotat.at>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] add -q option to shut up killall
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30542
>Category:       bin
>Synopsis:       [patch] add -q option to shut up killall(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mjg
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 12 17:10:00 PDT 2001
>Closed-Date:    
>Last-Modified:  Sun Jun 30 20:30:00 UTC 2013
>Originator:     Tony Finch
>Release:        FreeBSD 4.4-RC i386
>Organization:
dotat labs
>Environment:
System: FreeBSD hand.dotat.at 4.4-RC FreeBSD 4.4-RC #4: Sat Sep 1 19:06:27 GMT 2001 fanf@hand.dotat.at:/FreeBSD/obj/FreeBSD/releng4/sys/SHARP i386
>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.

This patch also happens to have some strlcpy pedantry in it.
>How-To-Repeat:
>Fix:

Index: usr.bin/killall/killall.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/killall/killall.1,v
retrieving revision 1.11.2.7
diff -u -r1.11.2.7 killall.1
--- usr.bin/killall/killall.1	2001/08/16 13:16:53	1.11.2.7
+++ usr.bin/killall/killall.1	2001/08/28 22:23:14
@@ -33,6 +33,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl d | v
+.Op Fl q
 .Op Fl h | ?\&
 .Op Fl help
 .Op Fl l
@@ -59,6 +60,8 @@
 .Pp
 The options are as follows:
 .Bl -tag -width 10n -offset indent
+.It Fl q
+Do not print an error message if no matching processes are found.
 .It Fl d | v
 Be more verbose about what will be done.  For a single
 .Fl d
Index: usr.bin/killall/killall.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/killall/killall.c,v
retrieving revision 1.5.2.4
diff -u -r1.5.2.4 killall.c
--- usr.bin/killall/killall.c	2001/05/19 19:22:49	1.5.2.4
+++ usr.bin/killall/killall.c	2001/08/28 22:23:14
@@ -62,8 +62,7 @@
 	static char buf[80];
 	char *s;
 
-	strncpy(buf, str, sizeof(buf));
-	buf[sizeof(buf) - 1] = '\0';
+	strlcpy(buf, str, sizeof(buf));
 	for (s = buf; *s; s++)
 		*s = toupper(*s);
 	return buf;
@@ -109,6 +108,7 @@
 	char		*user = NULL;
 	char		*tty = NULL;
 	char		*cmd = NULL;
+	int		qflag = 0;
 	int		vflag = 0;
 	int		sflag = 0;
 	int		dflag = 0;
@@ -168,6 +168,9 @@
 			case 'v':
 				vflag++;
 				break;
+			case 'q':
+				qflag++;
+				break;
 			case 's':
 				sflag++;
 				break;
@@ -362,7 +365,7 @@
 			}
 		}
 	}
-	if (killed == 0) {
+	if (!qflag && killed == 0) {
 		fprintf(stderr, "No matching processes %swere found\n",
 		    getuid() != 0 ? "belonging to you " : "");
 		errors = 1;
>Release-Note:
>Audit-Trail:

From: Dima Dorfman <dima@unixfreak.org>
To: Tony Finch <dot@dotat.at>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/30542: [PATCH] add -q option to shut up killall 
Date: Thu, 13 Sep 2001 04:19:13 -0700

 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?

From: Dima Dorfman <dima@unixfreak.org>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/30542: [PATCH] add -q option to shut up killall 
Date: Sat, 15 Sep 2001 09:01:21 -0700

 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?

From: "Garrett Cooper" <yanefbsd@gmail.com>
To: bug-followup@FreeBSD.org, dot@dotat.at
Cc:  
Subject: Re: bin/30542: [patch] add -q option to shut up killall(1)
Date: Fri, 20 Jun 2008 19:11:04 -0700

 Not finding any processes seems more legitimate as an error to send to
 stderr than stdout.
 -Garrett
Responsible-Changed-From-To: freebsd-bugs->mjg 
Responsible-Changed-By: mjg 
Responsible-Changed-When: Sun Jun 30 20:27:56 UTC 2013 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30542 
State-Changed-From-To: open->patched 
State-Changed-By: mjg 
State-Changed-When: Sun Jun 30 20:28:39 UTC 2013 
State-Changed-Why:  
Committed as r252428 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30542 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/30542: commit references a PR
Date: Sun, 30 Jun 2013 20:27:46 +0000 (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"
 
>Unformatted:
