From owner-svn-src-stable@FreeBSD.ORG Sun Jun 7 08:21:06 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AED81106566B; Sun, 7 Jun 2009 08:21:06 +0000 (UTC) (envelope-from brian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 938F98FC1B; Sun, 7 Jun 2009 08:21:06 +0000 (UTC) (envelope-from brian@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n578L6XJ086940; Sun, 7 Jun 2009 08:21:06 GMT (envelope-from brian@svn.freebsd.org) Received: (from brian@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n578L66a086938; Sun, 7 Jun 2009 08:21:06 GMT (envelope-from brian@svn.freebsd.org) Message-Id: <200906070821.n578L66a086938@svn.freebsd.org> From: Brian Somers Date: Sun, 7 Jun 2009 08:21:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r193627 - stable/7/usr.bin/pkill X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2009 08:21:07 -0000 Author: brian Date: Sun Jun 7 08:21:06 2009 New Revision: 193627 URL: http://svn.freebsd.org/changeset/base/193627 Log: MFC: r192242: Don't kill ancestors unless -a is given. Modified: stable/7/usr.bin/pkill/ (props changed) stable/7/usr.bin/pkill/pkill.1 stable/7/usr.bin/pkill/pkill.c Modified: stable/7/usr.bin/pkill/pkill.1 ============================================================================== --- stable/7/usr.bin/pkill/pkill.1 Sun Jun 7 08:11:25 2009 (r193626) +++ stable/7/usr.bin/pkill/pkill.1 Sun Jun 7 08:21:06 2009 (r193627) @@ -36,7 +36,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 23, 2006 +.Dd May 16, 2009 .Dt PKILL 1 .Os .Sh NAME @@ -44,7 +44,7 @@ .Nd find or signal processes by name .Sh SYNOPSIS .Nm pgrep -.Op Fl LSfilnovx +.Op Fl LSafilnovx .Op Fl F Ar pidfile .Op Fl G Ar gid .Op Fl M Ar core @@ -60,7 +60,7 @@ .Ar pattern ... .Nm pkill .Op Fl Ar signal -.Op Fl ILfinovx +.Op Fl ILafinovx .Op Fl F Ar pidfile .Op Fl G Ar gid .Op Fl M Ar core @@ -128,6 +128,15 @@ The default is a newline. This option can only be used with the .Nm pgrep command. +.It Fl a +Include process ancestors in the match list. +By default, the current +.Nm pgrep +or +.Nm pkill +process and all of its ancestors are excluded (unless +.Fl v +is used). .It Fl f Match against full argument lists. The default is to match against process names. Modified: stable/7/usr.bin/pkill/pkill.c ============================================================================== --- stable/7/usr.bin/pkill/pkill.c Sun Jun 7 08:11:25 2009 (r193626) +++ stable/7/usr.bin/pkill/pkill.c Sun Jun 7 08:21:06 2009 (r193627) @@ -133,7 +133,7 @@ main(int argc, char **argv) { char buf[_POSIX2_LINE_MAX], *mstr, **pargv, *p, *q, *pidfile; const char *execf, *coref; - int debug_opt; + int ancestors, debug_opt; int i, ch, bestidx, rv, criteria, pidfromfile, pidfilelock; size_t jsz; int (*action)(const struct kinfo_proc *); @@ -142,6 +142,7 @@ main(int argc, char **argv) struct timeval best_tval; regex_t reg; regmatch_t regmatch; + pid_t pid; setlocale(LC_ALL, ""); @@ -174,13 +175,14 @@ main(int argc, char **argv) } } + ancestors = 0; criteria = 0; debug_opt = 0; pidfile = NULL; pidfilelock = 0; execf = coref = _PATH_DEVNULL; - while ((ch = getopt(argc, argv, "DF:G:ILM:N:P:SU:d:fg:ij:lnos:t:u:vx")) != -1) + while ((ch = getopt(argc, argv, "DF:G:ILM:N:P:SU:ad:fg:ij:lnos:t:u:vx")) != -1) switch (ch) { case 'D': debug_opt++; @@ -220,6 +222,9 @@ main(int argc, char **argv) makelist(&ruidlist, LT_USER, optarg); criteria = 1; break; + case 'a': + ancestors++; + break; case 'd': if (!pgrep) usage(); @@ -468,6 +473,27 @@ main(int argc, char **argv) selected[i] = 1; } + if (!ancestors) { + pid = mypid; + while (pid) { + for (i = 0, kp = plist; i < nproc; i++, kp++) { + if (PSKIP(kp)) + continue; + if (kp->ki_pid == pid) { + selected[i] = 0; + pid = kp->ki_ppid; + break; + } + } + if (i == nproc) { + if (pid == mypid) + pid = getppid(); + else + break; /* Maybe we're in a jail ? */ + } + } + } + if (newest || oldest) { best_tval.tv_sec = 0; best_tval.tv_usec = 0;