Source-Changes-HG archive

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

[src/netbsd-3]: src/usr.bin/pkill Pull up following revision(s) (requested by...



details:   https://anonhg.NetBSD.org/src/rev/f972e1b71881
branches:  netbsd-3
changeset: 577355:f972e1b71881
user:      riz <riz%NetBSD.org@localhost>
date:      Sat Oct 15 16:31:50 2005 +0000

description:
Pull up following revision(s) (requested by kleink in ticket #890):
        usr.bin/pkill/pkill.c: revision 1.10
>From David Sainty: If a process dissappears while we are signalling it, don't
count it as a match/error.

diffstat:

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

diffs (100 lines):

diff -r 080829cbab44 -r f972e1b71881 usr.bin/pkill/pkill.c
--- a/usr.bin/pkill/pkill.c     Sat Oct 15 16:15:54 2005 +0000
+++ b/usr.bin/pkill/pkill.c     Sat Oct 15 16:31:50 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pkill.c,v 1.9 2005/03/16 08:52:20 sketch Exp $ */
+/*     $NetBSD: pkill.c,v 1.9.2.1 2005/10/15 16:31:50 riz Exp $        */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: pkill.c,v 1.9 2005/03/16 08:52:20 sketch Exp $");
+__RCSID("$NetBSD: pkill.c,v 1.9.2.1 2005/10/15 16:31:50 riz Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -108,8 +108,8 @@
 
 int    main(int, char **);
 void   usage(void);
-void   killact(struct kinfo_proc2 *);
-void   grepact(struct kinfo_proc2 *);
+int    killact(struct kinfo_proc2 *);
+int    grepact(struct kinfo_proc2 *);
 void   makelist(struct listhead *, enum listtype, char *);
 
 int
@@ -119,7 +119,7 @@
        extern int optind;
        char buf[_POSIX2_LINE_MAX], *mstr, **pargv, *p, *q;
        int i, j, ch, bestidx, rv, criteria;
-       void (*action)(struct kinfo_proc2 *);
+       int (*action)(struct kinfo_proc2 *);
        struct kinfo_proc2 *kp;
        struct list *li;
        u_int32_t bestsec, bestusec;
@@ -398,8 +398,7 @@
                if ((kp->p_flag & P_SYSTEM) != 0)
                        continue;
 
-               rv = 1;
-               (*action)(kp);
+               rv |= (*action)(kp);
        }
 
        exit(rv ? STATUS_MATCH : STATUS_NOMATCH);
@@ -423,22 +422,38 @@
        exit(STATUS_ERROR);
 }
 
-void
+int
 killact(struct kinfo_proc2 *kp)
 {
+       if (kill(kp->p_pid, signum) == -1) {
+               if (errno == ESRCH)
+                       /*
+                        * The process disappeared between us matching
+                        * it and us signalling it.  Return 0 to
+                        * indicate that the process should not be
+                        * considered a match.
+                        */
+                       return 0;
 
-       if (kill(kp->p_pid, signum) == -1)
                err(STATUS_ERROR, "signalling pid %d", (int)kp->p_pid);
+       }
+
+       return 1;
 }
 
-void
+int
 grepact(struct kinfo_proc2 *kp)
 {
        char **argv;
 
        if (longfmt && matchargs) {
                if ((argv = kvm_getargv2(kd, kp, 0)) == NULL)
-                       return;
+                       /*
+                        * The process disappeared?  Return 0 to
+                        * indicate that the process should not be
+                        * considered a match.
+                        */
+                       return 0;
 
                printf("%d ", (int)kp->p_pid);
                for (; *argv != NULL; argv++) {
@@ -452,6 +467,8 @@
                printf("%d", (int)kp->p_pid);
 
        printf("%s", delim);
+
+       return 1;
 }
 
 void



Home | Main Index | Thread Index | Old Index