diff options
author | gad <gad@FreeBSD.org> | 2004-03-25 23:19:16 +0000 |
---|---|---|
committer | gad <gad@FreeBSD.org> | 2004-03-25 23:19:16 +0000 |
commit | a932a157f4b39354c248578d0423ad0c06a1319a (patch) | |
tree | 578bf6c4ef12d501a9f442fe2d8bbd1bdb1835c5 /usr.bin/pkill | |
parent | 6db55881ec0f728295a337eaeeefa21d2caa7092 (diff) | |
download | FreeBSD-src-a932a157f4b39354c248578d0423ad0c06a1319a.zip FreeBSD-src-a932a157f4b39354c248578d0423ad0c06a1319a.tar.gz |
Add `-M' and `-N' options to `pkill' and `pgrep', similar to
what are supported in `ps':
-M Extract values associated with the name list from the
specified core instead of the default /dev/kmem.
-N Extract the name list from the specified system instead
of the default /kernel.
Written by: Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org>
Obtained from: the sysutils/pkill port
Diffstat (limited to 'usr.bin/pkill')
-rw-r--r-- | usr.bin/pkill/pkill.1 | 13 | ||||
-rw-r--r-- | usr.bin/pkill/pkill.c | 28 |
2 files changed, 35 insertions, 6 deletions
diff --git a/usr.bin/pkill/pkill.1 b/usr.bin/pkill/pkill.1 index 39c507e..1989daa 100644 --- a/usr.bin/pkill/pkill.1 +++ b/usr.bin/pkill/pkill.1 @@ -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 March 1, 2002 +.Dd March 25, 2004 .Dt PKILL 1 .Os .Sh NAME @@ -46,6 +46,8 @@ .Nm pgrep .Op Fl flnvx .Op Fl G Ar gid +.Op Fl M Ar core +.Op Fl N Ar system .Op Fl P Ar ppid .Op Fl U Ar uid .Op Fl d Ar delim @@ -58,6 +60,8 @@ .Op Fl signal .Op Fl fnvx .Op Fl G Ar gid +.Op Fl M Ar core +.Op Fl N Ar system .Op Fl P Ar ppid .Op Fl U Ar uid .Op Fl g Ar pgrp @@ -87,6 +91,13 @@ list Restrict matches to processes with a parent process ID in the comma-separated list .Ar ppid . +.It Fl M +Extract values associated with the name list from the specified core +instead of the default +.Pa /dev/kmem . +.It Fl N +Extract the name list from the specified system instead of the default +.Pa /kernel . .It Fl U Ar uid Restrict matches to processes with a real user ID in the comma-separated list diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c index 45087ad..6a83cce 100644 --- a/usr.bin/pkill/pkill.c +++ b/usr.bin/pkill/pkill.c @@ -125,7 +125,7 @@ main(int argc, char **argv) extern int optind; char buf[_POSIX2_LINE_MAX], *mstr, **pargv, *p, *q; char *execf, *coref, *swapf; - int i, j, ch, bestidx, rv, criteria; + int i, j, ch, bestidx, rv, criteria, drop_privs; void (*action)(struct kinfo_proc *); struct kinfo_proc *kp; struct list *li; @@ -169,13 +169,22 @@ main(int argc, char **argv) #endif criteria = 0; + drop_privs = 0; - while ((ch = getopt(argc, argv, "G:P:U:d:fg:lns:t:u:vx")) != -1) + while ((ch = getopt(argc, argv, "G:M:N:P:U:d:fg:lns:t:u:vx")) != -1) switch (ch) { case 'G': makelist(&rgidlist, LT_GROUP, optarg); criteria = 1; break; + case 'M': + coref = optarg; + drop_privs = 1; + break; + case 'N': + execf = optarg; + drop_privs = 1; + break; case 'P': makelist(&ppidlist, LT_GENERIC, optarg); criteria = 1; @@ -235,6 +244,15 @@ main(int argc, char **argv) if (!criteria) usage(); + /* + * Discard privileges if not the running kernel so that bad + * guys can't print interesting stuff from kernel memory. + */ + if (drop_privs) { + setgid(getgid()); + setuid(getuid()); + } + mypid = getpid(); /* @@ -426,9 +444,9 @@ usage(void) ustr = "[-signal] [-fnvx]"; fprintf(stderr, - "usage: %s %s [-G gid] [-P ppid] [-U uid] [-g pgrp] [-s sid]\n" - " [-t tty] [-u euid] pattern ...\n", getprogname(), - ustr); + "usage: %s %s [-G gid] [-M core] [-N system]\n" + " [-P ppid] [-U uid] [-g pgrp] [-s sid] [-t tty]\n" + " [-u euid] pattern ...\n", getprogname(), ustr); exit(STATUS_ERROR); } |