Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2012 00:50:25 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r237618 - head/usr.bin/killall
Message-ID:  <201206270050.q5R0oPas071965@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Wed Jun 27 00:50:25 2012
New Revision: 237618
URL: http://svn.freebsd.org/changeset/base/237618

Log:
  Add a -I flag which requests confirmation before action, like what is done
  in pkill(1).
  
  MFC after:	2 weeks

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	Wed Jun 27 00:37:22 2012	(r237617)
+++ head/usr.bin/killall/killall.1	Wed Jun 27 00:50:25 2012	(r237618)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd December 25, 2009
+.Dd June 27, 2012
 .Dt KILLALL 1
 .Os
 .Sh NAME
@@ -34,6 +34,7 @@
 .Nm
 .Op Fl delmsvz
 .Op Fl help
+.Op Fl I
 .Op Fl j Ar jail
 .Op Fl u Ar user
 .Op Fl t Ar tty
@@ -71,6 +72,9 @@ processes specified with the
 option.
 .It Fl help
 Give a help on the command usage and exit.
+.It Fl I
+Request confirmation before attempting to signal each
+process.
 .It Fl l
 List the names of the available signals and exit, like in
 .Xr kill 1 .

Modified: head/usr.bin/killall/killall.c
==============================================================================
--- head/usr.bin/killall/killall.c	Wed Jun 27 00:37:22 2012	(r237617)
+++ head/usr.bin/killall/killall.c	Wed Jun 27 00:50:25 2012	(r237618)
@@ -53,7 +53,7 @@ static void __dead2
 usage(void)
 {
 
-	fprintf(stderr, "usage: killall [-delmsvz] [-help] [-j jail]\n");
+	fprintf(stderr, "usage: killall [-delmsvz] [-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");
@@ -95,8 +95,9 @@ main(int ac, char **av)
 	struct passwd	*pw;
 	regex_t		rgx;
 	regmatch_t	pmatch;
-	int		i, j;
+	int		i, j, ch;
 	char		buf[256];
+	char		first;
 	char		*user = NULL;
 	char		*tty = NULL;
 	char		*cmd = NULL;
@@ -104,6 +105,7 @@ main(int ac, char **av)
 	int		sflag = 0;
 	int		dflag = 0;
 	int		eflag = 0;
+	int		Iflag = 0;
 	int		jflag = 0;
 	int		mflag = 0;
 	int		zflag = 0;
@@ -141,6 +143,9 @@ main(int ac, char **av)
 		if (**av == '-') {
 			++*av;
 			switch (**av) {
+			case 'I':
+				Iflag = 1;
+				break;
 			case 'j':
 				++*av;
 				if (**av == '\0') {
@@ -382,6 +387,16 @@ main(int ac, char **av)
 			if (matched)
 				break;
 		}
+		if (matched != 0 && Iflag) {
+			printf("Send signal %d to %s (pid %d uid %d)? ",
+				sig, thiscmd, thispid, thisuid);
+			fflush(stdout);
+			first = ch = getchar();
+			while (ch != '\n' && ch != EOF)
+				ch = getchar();
+			if (first != 'y' && first != 'Y')
+				matched = 0;
+		}
 		if (matched == 0)
 			continue;
 		if (dflag)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206270050.q5R0oPas071965>