Module Name:    src
Committed By:   christos
Date:           Tue Nov 20 22:52:02 UTC 2012

Modified Files:
        src/usr.bin/pkill: pkill.c

Log Message:
Don't use p_comm since it is only 16 characters long and you can find the
full argv[0]. It is just confusing to have a long command name, that ps
shows as the long command name, and then when you try to kill it using
the full command name as displayed you don't get a match. While there
fix a format nit, and remove the main() declaration.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/pkill/pkill.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/pkill/pkill.c
diff -u src/usr.bin/pkill/pkill.c:1.27 src/usr.bin/pkill/pkill.c:1.28
--- src/usr.bin/pkill/pkill.c:1.27	Tue Dec  7 02:39:15 2010
+++ src/usr.bin/pkill/pkill.c	Tue Nov 20 17:52:01 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pkill.c,v 1.27 2010/12/07 07:39:15 mrg Exp $	*/
+/*	$NetBSD: pkill.c,v 1.28 2012/11/20 22:52:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: pkill.c,v 1.27 2010/12/07 07:39:15 mrg Exp $");
+__RCSID("$NetBSD: pkill.c,v 1.28 2012/11/20 22:52:01 christos Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -102,7 +102,6 @@ static struct listhead ppidlist = SLIST_
 static struct listhead tdevlist = SLIST_HEAD_INITIALIZER(list);
 static struct listhead sidlist = SLIST_HEAD_INITIALIZER(list);
 
-int	main(int, char **);
 static void	usage(void) __dead;
 static int	killact(const struct kinfo_proc2 *);
 static int	reniceact(const struct kinfo_proc2 *);
@@ -117,7 +116,7 @@ main(int argc, char **argv)
 	int (*action)(const struct kinfo_proc2 *);
 	const struct kinfo_proc2 *kp;
 	struct list *li;
-	const char *mstr, *p;
+	const char *p;
 	u_int32_t bestsec, bestusec;
 	regex_t reg;
 	regmatch_t regmatch;
@@ -286,9 +285,9 @@ main(int argc, char **argv)
 			if ((kp->p_flag & P_SYSTEM) != 0 || kp->p_pid == mypid)
 				continue;
 
+			if ((pargv = kvm_getargv2(kd, kp, 0)) == NULL)
+				continue;
 			if (matchargs) {
-				if ((pargv = kvm_getargv2(kd, kp, 0)) == NULL)
-					continue;
 
 				j = 0;
 				while (j < (int)sizeof(buf) && *pargv != NULL) {
@@ -297,16 +296,15 @@ main(int argc, char **argv)
 					    pargv[0]);
 					pargv++;
 				}
-
-				mstr = buf;
 			} else
-				mstr = kp->p_comm;
+				strlcpy(buf, pargv[0], sizeof(buf));
 
-			rv = regexec(&reg, mstr, 1, &regmatch, 0);
+			rv = regexec(&reg, buf, 1, &regmatch, 0);
 			if (rv == 0) {
 				if (fullmatch) {
 					if (regmatch.rm_so == 0 &&
-					    regmatch.rm_eo == (regoff_t)strlen(mstr))
+					    regmatch.rm_eo == 
+					    (regoff_t)strlen(buf))
 						selected[i] = 1;
 				} else
 					selected[i] = 1;
@@ -560,7 +558,7 @@ makelist(struct listhead *head, enum lis
 			usage();
 
 		if ((li = malloc(sizeof(*li))) == NULL)
-			err(STATUS_ERROR, "Cannot allocate %zd bytes",
+			err(STATUS_ERROR, "Cannot allocate %zu bytes",
 			    sizeof(*li));
 		SLIST_INSERT_HEAD(head, li, li_chain);
 		empty = 0;

Reply via email to