From: Liam J. Foy Date: Mon, 6 Dec 2004 21:13:51 +0000 (+0000) Subject: - Remove signal.h X-Git-Url: https://gitweb.dragonflybsd.org/~lentferj/dragonfly.git/commitdiff_plain/9f2c9b06b8be96655dcf51ee5eaf05cd8f71af6a - Remove signal.h - Add usage - Static functions - Add verbose option (nice to know what failed etc) - Use getopt for consistency - Make size of buf MAXPATHLEN - Make WARNS 6 clean - Add WARNS?= 6 to Makefile - Update procctl man page accordingly OK'ed by: Joerg@ --- diff --git a/usr.sbin/procctl/Makefile b/usr.sbin/procctl/Makefile index ca15c67d5d..e6c97a261e 100644 --- a/usr.sbin/procctl/Makefile +++ b/usr.sbin/procctl/Makefile @@ -1,7 +1,8 @@ # $FreeBSD: src/usr.sbin/procctl/Makefile,v 1.4.2.1 2001/04/25 12:10:38 ru Exp $ -# $DragonFly: src/usr.sbin/procctl/Makefile,v 1.2 2003/06/17 04:30:01 dillon Exp $ +# $DragonFly: src/usr.sbin/procctl/Makefile,v 1.3 2004/12/06 21:13:51 liamfoy Exp $ PROG= procctl MAN= procctl.8 +WARNS?= 6 .include diff --git a/usr.sbin/procctl/procctl.8 b/usr.sbin/procctl/procctl.8 index 0a165a4ebb..01f12ea37b 100644 --- a/usr.sbin/procctl/procctl.8 +++ b/usr.sbin/procctl/procctl.8 @@ -1,6 +1,6 @@ .\" $FreeBSD: src/usr.sbin/procctl/procctl.8,v 1.7.2.3 2003/03/11 22:31:31 trhodes Exp $ -.\" $DragonFly: src/usr.sbin/procctl/procctl.8,v 1.2 2003/06/17 04:30:01 dillon Exp $ -.Dd November 23, 1997 +.\" $DragonFly: src/usr.sbin/procctl/procctl.8,v 1.3 2004/12/06 21:13:51 liamfoy Exp $ +.Dd December 6, 2004 .Dt PROCCTL 8 .Os .Sh NAME @@ -8,6 +8,7 @@ .Nd clear procfs event flags .Sh SYNOPSIS .Nm +.Op Fl v .Ar pid ... .Sh DESCRIPTION The @@ -23,6 +24,12 @@ events result in a non-killable process. The arguments are a list of process IDs; .Nm goes through the list and clears the event masks for each specified process. +.Pp +The options are as follows: +.Bl -tag -width Ds +.Bl -tag -width Ds +.It Fl v +Verbose mode. .Sh SEE ALSO .Xr truss 1 , .Xr procfs 5 @@ -33,3 +40,6 @@ utility was written by .An Sean Eric Fagan for .Fx . +.Pp +Some contributions made by +.An Liam J. Foy Aq liamfoy@sepulcrum.org diff --git a/usr.sbin/procctl/procctl.c b/usr.sbin/procctl/procctl.c index 5a986b95cc..984769676f 100644 --- a/usr.sbin/procctl/procctl.c +++ b/usr.sbin/procctl/procctl.c @@ -1,5 +1,6 @@ /* * Copyright 1997 Sean Eric Fagan + * Copyright (c) 2004 Liam J. Foy * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.sbin/procctl/procctl.c,v 1.6 2000/02/21 10:22:39 ru Exp $ - * $DragonFly: src/usr.sbin/procctl/procctl.c,v 1.2 2003/06/17 04:30:01 dillon Exp $ + * $DragonFly: src/usr.sbin/procctl/procctl.c,v 1.3 2004/12/06 21:13:51 liamfoy Exp $ */ /* @@ -44,35 +45,68 @@ #include #include #include -#include #include #include #include #include #include +#include #include +static void usage(void); + int -main(int ac, char **av) { - int fd; - int i; +main(int argc, char **argv) +{ + int c, vflag, fd; + + vflag = 0; + while ((c = getopt(argc, argv, "v")) != -1) { + switch (c) { + case 'v': + vflag = 1; + break; + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (argc == 0) + usage(); + + for (; *argv; ++argv) { + char buf[MAXPATHLEN]; + + snprintf(buf, sizeof(buf), "/proc/%s/mem", *argv); + fd = open(buf, O_RDWR); + if (fd == -1) { + if (!vflag && errno == ENOENT) + continue; + warn("cannot open pid %s", *argv); + continue; + } + + if (ioctl(fd, PIOCBIC, ~0) == -1) + warn("cannot clear process %s's event mask", *argv); + else if (vflag) + printf("successfully cleared process %s\n", *argv); + + if (ioctl(fd, PIOCCONT, 0) == -1 && errno != EINVAL) + warn("cannot continue process %s", *argv); + else if (vflag) + printf("process %s continued\n", *argv); + close(fd); + } + return 0; +} - for (i = 1; i < ac; i++) { - char buf[32]; +static void +usage(void) +{ - snprintf(buf, sizeof(buf), "/proc/%s/mem", av[i]); - fd = open(buf, O_RDWR); - if (fd == -1) { - if (errno == ENOENT) - continue; - warn("cannot open pid %s", av[i]); - continue; - } - if (ioctl(fd, PIOCBIC, ~0) == -1) - warn("cannot clear process %s's event mask", av[i]); - if (ioctl(fd, PIOCCONT, 0) == -1 && errno != EINVAL) - warn("cannot continue process %s", av[i]); - close(fd); - } - return 0; + fprintf(stderr, "usage: procctl [-v] pid...\n"); + exit(EXIT_FAILURE); }