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
This commit is contained in:
Garance A Drosehn 2004-03-25 23:19:16 +00:00
parent 69fd9fbfbc
commit 998c10ebd9
2 changed files with 35 additions and 6 deletions

View File

@ -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

View File

@ -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);
}