Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/pkill Don't use p_comm since it is only 16 character...



details:   https://anonhg.NetBSD.org/src/rev/42a7b17a42bc
branches:  trunk
changeset: 782805:42a7b17a42bc
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Nov 20 22:52:01 2012 +0000

description:
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.

diffstat:

 usr.bin/pkill/pkill.c |  24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)

diffs (78 lines):

diff -r 4e06aea4c996 -r 42a7b17a42bc usr.bin/pkill/pkill.c
--- a/usr.bin/pkill/pkill.c     Tue Nov 20 22:02:46 2012 +0000
+++ b/usr.bin/pkill/pkill.c     Tue Nov 20 22:52:01 2012 +0000
@@ -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 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 @@
        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 @@
                        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 @@
                                            pargv[0]);
                                        pargv++;
                                }
+                       } else
+                               strlcpy(buf, pargv[0], sizeof(buf));
 
-                               mstr = buf;
-                       } else
-                               mstr = kp->p_comm;
-
-                       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 @@
                        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;



Home | Main Index | Thread Index | Old Index