http://perforce.freebsd.org/chv.cgi?CH=72919 Change 72919 by pjd@pjd_anger on 2005/03/11 18:48:57 Add '-j' flag which allows to match processes based on their jail ID. Affected files ... .. //depot/user/pjd/pkill/usr.bin/pkill/pkill.1#5 edit .. //depot/user/pjd/pkill/usr.bin/pkill/pkill.c#6 edit Differences ... ==== //depot/user/pjd/pkill/usr.bin/pkill/pkill.1#5 (text+ko) ==== @@ -53,6 +53,7 @@ .Op Fl U Ar uid .Op Fl d Ar delim .Op Fl g Ar pgrp +.Op Fl j Ar jid .Op Fl s Ar sid .Op Fl t Ar tty .Op Fl u Ar euid @@ -67,6 +68,7 @@ .Op Fl P Ar ppid .Op Fl U Ar uid .Op Fl g Ar pgrp +.Op Fl j Ar jid .Op Fl s Ar sid .Op Fl t Ar tty .Op Fl u Ar euid @@ -127,6 +129,11 @@ command. .It Fl i Ignore case distinctions in both the process table and the supplied pattern. +.It Fl j Ar jid +Restrict matches to processes inside jails with a jail ID in the comma-separated +list +.Ar jid . +The value zero is taken to mean any jail ID. .It Fl l Long output. Print the process name in addition to the process ID for each matching ==== //depot/user/pjd/pkill/usr.bin/pkill/pkill.c#6 (text+ko) ==== @@ -113,6 +113,7 @@ struct listhead ppidlist = SLIST_HEAD_INITIALIZER(list); struct listhead tdevlist = SLIST_HEAD_INITIALIZER(list); struct listhead sidlist = SLIST_HEAD_INITIALIZER(list); +struct listhead jidlist = SLIST_HEAD_INITIALIZER(list); int main(int, char **); void usage(void); @@ -174,7 +175,7 @@ pidfromfile = -1; execf = coref = _PATH_DEVNULL; - while ((ch = getopt(argc, argv, "DF:G:M:N:P:U:d:fg:ilns:t:u:vx")) != -1) + while ((ch = getopt(argc, argv, "DF:G:M:N:P:U:d:fg:ij:lns:t:u:vx")) != -1) switch (ch) { case 'D': debug_opt++; @@ -216,6 +217,10 @@ case 'i': cflags |= REG_ICASE; break; + case 'j': + makelist(&jidlist, LT_GENERIC, optarg); + criteria = 1; + break; case 'l': if (!pgrep) usage(); @@ -408,6 +413,19 @@ continue; } + SLIST_FOREACH(li, &jidlist, li_chain) { + if (kp->ki_jid > 0) { + if (li->li_number == 0) + break; + if (kp->ki_jid == (int)li->li_number) + break; + } + } + if (SLIST_FIRST(&jidlist) != NULL && li == NULL) { + selected[i] = 0; + continue; + } + if (argc == 0) selected[i] = 1; } @@ -469,8 +487,9 @@ fprintf(stderr, "usage: %s %s [-F pidfile] [-G gid] [-M core] [-N system]\n" - " [-P ppid] [-U uid] [-g pgrp] [-s sid] [-t tty]\n" - " [-u euid] pattern ...\n", getprogname(), ustr); + " [-P ppid] [-U uid] [-g pgrp] [-j jid] [-s sid]\n" + " [-t tty] [-u euid] pattern ...\n", getprogname(), + ustr); exit(STATUS_ERROR); }