diff options
author | Eric Jackson <ericj@cvs.openbsd.org> | 2002-01-09 22:22:57 +0000 |
---|---|---|
committer | Eric Jackson <ericj@cvs.openbsd.org> | 2002-01-09 22:22:57 +0000 |
commit | aa6e74cc9daeb40b2324a5fb491fd524eefa9318 (patch) | |
tree | f000b302dd02cf93b82f65c58ddc3f5ffc3def01 /sbin/modunload | |
parent | aadd4e09390bf75642aa8b4620b3370753a14d31 (diff) |
add ability to execute script or program after a module is
unloaded.. similar to modload.
millert@ ok
Diffstat (limited to 'sbin/modunload')
-rw-r--r-- | sbin/modunload/modunload.8 | 5 | ||||
-rw-r--r-- | sbin/modunload/modunload.c | 46 |
2 files changed, 31 insertions, 20 deletions
diff --git a/sbin/modunload/modunload.8 b/sbin/modunload/modunload.8 index 600fe1e2935..5f147c9ed61 100644 --- a/sbin/modunload/modunload.8 +++ b/sbin/modunload/modunload.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: modunload.8,v 1.9 2001/08/02 18:37:34 mpech Exp $ +.\" $OpenBSD: modunload.8,v 1.10 2002/01/09 22:22:56 ericj Exp $ .\" $NetBSD: modunload.8,v 1.3 1995/03/18 14:56:49 cgd Exp $ .\" .\" Copyright (c) 1993 Christopher G. Demetriou @@ -55,6 +55,9 @@ Unload the module with the ID .It Fl n Ar name Unload the module with the name .Ar name . +.It Fl p Ar postunload +Specify the name of a shell script or program that will be executed if the +module is successfully unloaded. This program is passed no arguments. .El .Sh DIAGNOSTICS The diff --git a/sbin/modunload/modunload.c b/sbin/modunload/modunload.c index 26f1e3d8827..a9e65a7c888 100644 --- a/sbin/modunload/modunload.c +++ b/sbin/modunload/modunload.c @@ -1,4 +1,4 @@ -/* $OpenBSD: modunload.c,v 1.9 2001/07/07 00:15:14 millert Exp $ */ +/* $OpenBSD: modunload.c,v 1.10 2002/01/09 22:22:56 ericj Exp $ */ /* $NetBSD: modunload.c,v 1.9 1995/05/28 05:23:05 jtc Exp $ */ /* @@ -48,22 +48,22 @@ #include <unistd.h> #include "pathnames.h" -void +static int devfd; + +static void usage() { + extern char *__progname; - fprintf(stderr, - "usage: modunload [-i <module id>] [-n <module name>]\n"); + (void)fprintf(stderr, "usage: %s [-i id] [-n name] [-p postunload]\n", + __progname); exit(1); } -int devfd; - void cleanup() { - - close(devfd); + (void)close(devfd); } int @@ -74,23 +74,24 @@ main(argc, argv) int c; long modnum = -1; char *modname = NULL; - char *endptr; + char *endptr, *post = NULL; struct lmc_unload ulbuf; - while ((c = getopt(argc, argv, "i:n:")) != -1) { + while ((c = getopt(argc, argv, "i:n:p:")) != -1) { switch (c) { case 'i': modnum = strtol(optarg, &endptr, 0); if (modnum < 0 || modnum > INT_MAX || *endptr != '\0') errx(1, "not a valid number"); - break; /* number */ + break; case 'n': modname = optarg; - break; /* name */ - case '?': - usage(); + break; + case 'p': + post = optarg; + break; default: - printf("default!\n"); + usage(); break; } } @@ -118,14 +119,21 @@ main(argc, argv) if (ioctl(devfd, LMUNLOAD, &ulbuf) == -1) { switch (errno) { - case EINVAL: /* out of range */ + case EINVAL: errx(3, "id out of range"); - case ENOENT: /* no such entry */ + case ENOENT: errx(3, "no such module"); - default: /* other error (EFAULT, etc) */ + default: err(5, "LMUNLOAD"); } } - return 0; + /* + * Execute the post-unload program. + */ + if (post) { + execl(post, post, (char *)NULL); + err(16, "can't exec `%s'", post); + } + exit(0); } |