diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2012-02-09 20:04:36 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2012-02-09 20:04:36 +0000 |
commit | 79eb7a428273715b4a82c35102dde9996b46940f (patch) | |
tree | d59be6c79a4809a86723a922bccde4f6f544df91 /usr.bin/pkill | |
parent | 96bec6bae636b6e834007da99291880fd54fc498 (diff) |
restrict pkill/pgrep to the routing domain specified by -T; ok henning@, mpf@
Diffstat (limited to 'usr.bin/pkill')
-rw-r--r-- | usr.bin/pkill/pkill.1 | 10 | ||||
-rw-r--r-- | usr.bin/pkill/pkill.c | 32 |
2 files changed, 35 insertions, 7 deletions
diff --git a/usr.bin/pkill/pkill.1 b/usr.bin/pkill/pkill.1 index ec3bcd5be9f..83f5c95e717 100644 --- a/usr.bin/pkill/pkill.1 +++ b/usr.bin/pkill/pkill.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pkill.1,v 1.17 2012/01/17 04:27:20 lum Exp $ +.\" $OpenBSD: pkill.1,v 1.18 2012/02/09 20:04:35 markus Exp $ .\" $NetBSD: pkill.1,v 1.8 2003/02/14 15:59:18 grant Exp $ .\" .\" Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: January 17 2012 $ +.Dd $Mdocdate: February 9 2012 $ .Dt PKILL 1 .Os .Sh NAME @@ -42,6 +42,7 @@ .Op Fl g Ar pgrp .Op Fl P Ar ppid .Op Fl s Ar sid +.Op Fl T Ar rtable .Op Fl t Ar tty .Op Fl U Ar uid .Op Fl u Ar euid @@ -53,6 +54,7 @@ .Op Fl g Ar pgrp .Op Fl P Ar ppid .Op Fl s Ar sid +.Op Fl T Ar rtable .Op Fl t Ar tty .Op Fl U Ar uid .Op Fl u Ar euid @@ -123,6 +125,10 @@ The value zero is taken to mean the session ID of the running or .Nm pkill command. +.It Fl T Ar rtable +Restrict matches to processes associated with the specified routing tables +in the comma-separated list +.Ar rtable . .It Fl t Ar tty Restrict matches to processes associated with a terminal in the comma-separated list diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c index 89f67223eff..aace2e0ad48 100644 --- a/usr.bin/pkill/pkill.c +++ b/usr.bin/pkill/pkill.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pkill.c,v 1.20 2012/01/17 04:27:20 lum Exp $ */ +/* $OpenBSD: pkill.c,v 1.21 2012/02/09 20:04:35 markus Exp $ */ /* $NetBSD: pkill.c,v 1.5 2002/10/27 11:49:34 kleink Exp $ */ /*- @@ -36,6 +36,7 @@ #include <sys/proc.h> #include <sys/queue.h> #include <sys/stat.h> +#include <sys/socket.h> #include <stdio.h> #include <stdlib.h> @@ -63,7 +64,8 @@ enum listtype { LT_GROUP, LT_TTY, LT_PGRP, - LT_SID + LT_SID, + LT_RTABLE }; struct list { @@ -95,6 +97,7 @@ struct listhead pgrplist = SLIST_HEAD_INITIALIZER(list); struct listhead ppidlist = SLIST_HEAD_INITIALIZER(list); struct listhead tdevlist = SLIST_HEAD_INITIALIZER(list); struct listhead sidlist = SLIST_HEAD_INITIALIZER(list); +struct listhead rtablist = SLIST_HEAD_INITIALIZER(list); int main(int, char **); void usage(void); @@ -150,7 +153,7 @@ main(int argc, char **argv) criteria = 0; - while ((ch = getopt(argc, argv, "G:P:U:d:fg:lnos:t:u:vx")) != -1) + while ((ch = getopt(argc, argv, "G:P:T:U:d:fg:lnos:t:u:vx")) != -1) switch (ch) { case 'G': makelist(&rgidlist, LT_GROUP, optarg); @@ -160,6 +163,10 @@ main(int argc, char **argv) makelist(&ppidlist, LT_GENERIC, optarg); criteria = 1; break; + case 'T': + makelist(&rtablist, LT_RTABLE, optarg); + criteria = 1; + break; case 'U': makelist(&ruidlist, LT_USER, optarg); criteria = 1; @@ -354,6 +361,14 @@ main(int argc, char **argv) continue; } + SLIST_FOREACH(li, &rtablist, li_chain) + if (kp->p_rtableid == (u_int32_t)li->li_number) + break; + if (SLIST_FIRST(&rtablist) != NULL && li == NULL) { + selected[i] = 0; + continue; + } + if (argc == 0) selected[i] = 1; } @@ -428,7 +443,8 @@ usage(void) ustr = "[-signal] [-flnovx]"; fprintf(stderr, "usage: %s %s [-G gid] [-g pgrp] [-P ppid] [-s sid] " - "[-t tty]\n\t[-U uid] [-u euid] [pattern ...]\n", __progname, ustr); + "[-T rtable]\n\t[-t tty] [-U uid] [-u euid] [pattern ...]\n", + __progname, ustr); exit(STATUS_ERROR); } @@ -490,7 +506,7 @@ makelist(struct listhead *head, enum listtype type, char *src) SLIST_INSERT_HEAD(head, li, li_chain); empty = 0; - li->li_number = (uid_t)strtol(sp, &p, 0); + li->li_number = strtol(sp, &p, 0); if (*p == '\0') { switch (type) { case LT_PGRP: @@ -501,6 +517,12 @@ makelist(struct listhead *head, enum listtype type, char *src) if (li->li_number == 0) li->li_number = getsid(mypid); break; + case LT_RTABLE: + if (li->li_number < 0 || + li->li_number > RT_TABLEID_MAX) + errx(STATUS_BADUSAGE, + "rtable out of range"); + break; case LT_TTY: usage(); default: |