From stacey_@starwhack.net  Sun Dec  8 11:01:40 2002
Return-Path: <stacey_@starwhack.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 244F537B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Dec 2002 11:01:40 -0800 (PST)
Received: from starwhack.net (056.a.008.mel.iprimus.net.au [210.50.86.56])
	by mx1.FreeBSD.org (Postfix) with ESMTP id BB7A043EB2
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Dec 2002 11:01:37 -0800 (PST)
	(envelope-from stacey_@starwhack.net)
Received: from starwhack.net (localhost [127.0.0.1])
	by starwhack.net (8.12.6/8.12.6) with ESMTP id gB8J1OEL021595
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 9 Dec 2002 06:01:26 +1100 (EST)
	(envelope-from stacey_@starwhack.net)
Received: (from stacey_@localhost)
	by starwhack.net (8.12.6/8.12.6/Submit) id gB8J1MIn021594;
	Mon, 9 Dec 2002 06:01:23 +1100 (EST)
	(envelope-from stacey_)
Message-Id: <200212081901.gB8J1MIn021594@starwhack.net>
Date: Mon, 9 Dec 2002 06:01:23 +1100 (EST)
From: stacey <duqz@starwhack.net>
Reply-To: stacey <duqz@starwhack.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: killall(1) can prematurely kill itself
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         46107
>Category:       bin
>Synopsis:       killall(1) can prematurely kill itself
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 08 11:10:01 PST 2002
>Closed-Date:    Thu Jan 22 13:04:34 PST 2004
>Last-Modified:  Thu Jan 22 13:04:34 PST 2004
>Originator:     stacey <duqz@starwhack.net>
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
>Environment:
System: FreeBSD starwhack.net 4.7-STABLE FreeBSD 4.7-STABLE #5: Sun Dec 1 18:37:27 EST 2002 root@starwhack.net:/usr/obj/usr/src/sys/STARWHACK i386


>Description:
	killall(1) suicides, which makes it die before killing other matching procs.

>How-To-Repeat:
	$ ps | grep killall
	21470  p1  T      0:00.07 killall ducks
	21473  p1  T      0:00.05 killall go
	21475  p1  T      0:00.04 killall wak wak
	21483  p1  R+     0:00.06 grep killall

	$ killall -KILL -v killall
	kill -KILL 21551
	Killed

>Fix:

Index: killall.c
===================================================================
RCS file: /home/stacey_/src/freebsd/src/usr.bin/killall/killall.c,v
retrieving revision 1.19
diff -u -r1.19 killall.c
--- killall.c   30 Jun 2002 05:25:01 -0000      1.19
+++ killall.c   8 Dec 2002 18:03:18 -0000
@@ -117,6 +117,7 @@
        int             zflag = 0;
        uid_t           uid = 0;
        dev_t           tdev = 0;
+       pid_t           mypid;
        char            thiscmd[MAXCOMLEN + 1];
        pid_t           thispid;
        uid_t           thisuid;
@@ -289,6 +290,7 @@
        nprocs = size / sizeof(struct kinfo_proc);
        if (dflag)
                printf("nprocs %d\n", nprocs);
+       mypid = getpid();
 
        for (i = 0; i < nprocs; i++) {
                if ((procs[i].ki_stat & SZOMB) == SZOMB && !zflag)
@@ -365,7 +367,7 @@
                            thispid);
 
                killed++;
-               if (!dflag && !sflag) {
+               if (!dflag && !sflag && thispid != mypid) {
                        if (kill(thispid, sig) < 0 /* && errno != ESRCH */ ) {
                                warn("warning: kill -%s %d",
                                    upper(sys_signame[sig]), thispid);
>Release-Note:
>Audit-Trail:

From: stacey <stacey_@starwhack.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/46107: killall(1) can prematurely kill itself
Date: Mon, 9 Dec 2002 19:29:42 +1100

 previous diff has inconsistencies with verbosity options
 and is just poor in general. :\
 
 Index: killall.c
 ===================================================================
 RCS file: /home/stacey_/src/freebsd/src/usr.bin/killall/killall.c,v
 retrieving revision 1.19
 diff -u -r1.19 killall.c
 --- killall.c   30 Jun 2002 05:25:01 -0000      1.19
 +++ killall.c   9 Dec 2002 08:18:47 -0000
 @@ -117,6 +117,7 @@
         int             zflag = 0;
         uid_t           uid = 0;
         dev_t           tdev = 0;
 +       pid_t           mypid;
         char            thiscmd[MAXCOMLEN + 1];
         pid_t           thispid;
         uid_t           thisuid;
 @@ -289,6 +290,7 @@
         nprocs = size / sizeof(struct kinfo_proc);
         if (dflag)
                 printf("nprocs %d\n", nprocs);
 +       mypid = getpid();
  
         for (i = 0; i < nprocs; i++) {
                 if ((procs[i].ki_stat & SZOMB) == SZOMB && !zflag)
 @@ -299,6 +301,8 @@
                 thistdev = procs[i].ki_tdev;
                 thisuid = procs[i].ki_ruid;     /* real uid */
  
 +               if (thispid == mypid)
 +                       continue;
                 matched = 1;
                 if (user) {
                         if (thisuid != uid)
State-Changed-From-To: open->closed 
State-Changed-By: cperciva 
State-Changed-When: Thu Jan 22 13:03:53 PST 2004 
State-Changed-Why:  
Committed, thanks! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=46107 
>Unformatted:
