summaryrefslogtreecommitdiffstats
path: root/sbin/kldunload/kldunload.c
diff options
context:
space:
mode:
authorwkoszek <wkoszek@FreeBSD.org>2006-02-27 22:20:57 +0000
committerwkoszek <wkoszek@FreeBSD.org>2006-02-27 22:20:57 +0000
commit69303cd40f3b48bb66cc6700d6dc1ebdc0e1d8f1 (patch)
tree8fd3af2f2e7c57506f53e13dc44532e332fc079c /sbin/kldunload/kldunload.c
parent97af57388060392fb35871f19f1206393d0f76bd (diff)
downloadFreeBSD-src-69303cd40f3b48bb66cc6700d6dc1ebdc0e1d8f1.zip
FreeBSD-src-69303cd40f3b48bb66cc6700d6dc1ebdc0e1d8f1.tar.gz
Extend kldunload(8) functionality and fix minor problems:
o multiple modules can be unloaded at once (specified either by id or be module name) o exit with EX_USAGE after usage() is called. o remove unused variables, since we keep command line flags as bitmask, in 'opt'. o 'kldload -n ...' does nothing. Add comment to this options. Additionally: o Update manual page to conform new functionality. o Increace WARNS to 6. Because we can. Approved by: cognet (mentor) MFC after: 1 week
Diffstat (limited to 'sbin/kldunload/kldunload.c')
-rw-r--r--sbin/kldunload/kldunload.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/sbin/kldunload/kldunload.c b/sbin/kldunload/kldunload.c
index cafc7ea..8a3ea61 100644
--- a/sbin/kldunload/kldunload.c
+++ b/sbin/kldunload/kldunload.c
@@ -33,41 +33,48 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sysexits.h>
#include <unistd.h>
static void
usage(void)
{
- fprintf(stderr, "usage: kldunload [-fv] -i id\n");
- fprintf(stderr, " kldunload [-fv] [-n] name\n");
- exit(1);
+ fprintf(stderr, "usage: kldunload [-fv] -i id ...\n");
+ fprintf(stderr, " kldunload [-fv] [-n] name ...\n");
+ exit(EX_USAGE);
}
+#define OPT_NULL 0x00
+#define OPT_ID 0x01
+#define OPT_VERBOSE 0x02
+#define OPT_FORCE 0x04
+
int
main(int argc, char** argv)
{
struct kld_file_stat stat;
- int c;
- int verbose = 0;
- int fileid = 0;
- int force = LINKER_UNLOAD_NORMAL;
- char *filename = NULL;
+ int c, fileid, force, opt;
+ char *filename;
+
+ filename = NULL;
+ opt = OPT_NULL;
- while ((c = getopt(argc, argv, "fi:n:v")) != -1) {
+ while ((c = getopt(argc, argv, "finv")) != -1) {
switch (c) {
case 'f':
- force = LINKER_UNLOAD_FORCE;
+ opt |= OPT_FORCE;
break;
case 'i':
- fileid = atoi(optarg);
- if (!fileid)
- errx(1, "Invalid ID %s", optarg);
+ opt |= OPT_ID;
break;
case 'n':
- filename = optarg;
+ /*
+ * XXX: For backward compatibility. Currently does
+ * nothing
+ */
break;
case 'v':
- verbose = 1;
+ opt |= OPT_VERBOSE;
break;
default:
usage();
@@ -77,31 +84,34 @@ main(int argc, char** argv)
argc -= optind;
argv += optind;
- if (fileid == 0 && filename == NULL && (argc == 1)) {
- filename = *argv;
- argc--;
- }
-
- if (argc != 0 || (fileid != 0 && filename != NULL))
- usage();
-
- if (fileid == 0 && filename == NULL)
+ if (argc == 0)
usage();
- if (filename != NULL) {
- if ((fileid = kldfind(filename)) < 0)
- err(1, "can't find file %s", filename);
- }
+ while ((filename = *argv++) != NULL) {
+ if (opt & OPT_ID) {
+ fileid = atoi(filename);
+ if (fileid < 0)
+ errx(EXIT_FAILURE, "Invalid ID %s", optarg);
+ } else {
+ if ((fileid = kldfind(filename)) < 0)
+ errx(EXIT_FAILURE, "can't find file %s",
+ filename);
+ }
+ if (opt & OPT_VERBOSE) {
+ stat.version = sizeof(stat);
+ if (kldstat(fileid, &stat) < 0)
+ err(EXIT_FAILURE, "can't stat file");
+ (void) printf("Unloading %s, id=%d\n", stat.name,
+ fileid);
+ }
+ if (opt & OPT_FORCE)
+ force = LINKER_UNLOAD_FORCE;
+ else
+ force = LINKER_UNLOAD_NORMAL;
- if (verbose) {
- stat.version = sizeof stat;
- if (kldstat(fileid, &stat) < 0)
- err(1, "can't stat file");
- printf("Unloading %s, id=%d\n", stat.name, fileid);
+ if (kldunloadf(fileid, force) < 0)
+ err(EXIT_FAILURE, "can't unload file");
}
- if (kldunloadf(fileid, force) < 0)
- err(1, "can't unload file");
-
- return 0;
+ return (EXIT_SUCCESS);
}
OpenPOWER on IntegriCloud