--- /usr/src/sbin/kldunload/kldunload.c Sun Jan 30 14:23:04 2005 +++ kldunload.c Sun Feb 26 19:32:04 2006 @@ -27,78 +27,81 @@ #include __FBSDID("$FreeBSD: src/sbin/kldunload/kldunload.c,v 1.15 2005/01/30 13:23:04 ru Exp $"); +#include +#include + #include #include #include #include -#include -#include 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(1); } int main(int argc, char** argv) { - int c; - int verbose = 0; - int fileid = 0; - int force = LINKER_UNLOAD_NORMAL; - char* filename = NULL; - - while ((c = getopt(argc, argv, "fi:n:v")) != -1) - switch (c) { - case 'f': - force = LINKER_UNLOAD_FORCE; - break; - case 'i': - fileid = atoi(optarg); - if (!fileid) - errx(1, "Invalid ID %s", optarg); - break; - case 'n': - filename = optarg; - break; - case 'v': - verbose = 1; - break; - default: - usage(); + struct kld_file_stat stat; + int c; + int verbose = 0; + int fileid = 0; + int force = LINKER_UNLOAD_NORMAL; + char *filename = NULL; + + while ((c = getopt(argc, argv, "fi:n:v")) != -1) { + switch (c) { + case 'f': + force = LINKER_UNLOAD_FORCE; + break; + case 'i': + fileid = atoi(optarg); + if (!fileid) + errx(1, "Invalid ID %s", optarg); + break; + case 'n': + filename = optarg; + break; + case 'v': + verbose = 1; + break; + default: + usage(); + } } - 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) - usage(); - - if (filename != NULL) { - if ((fileid = kldfind(filename)) < 0) - err(1, "can't find file %s", filename); - } + argc -= optind; + argv += optind; - if (verbose) { - struct kld_file_stat stat; - 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 (fileid == 0 && filename == NULL && (argc == 1)) { + filename = *argv; + argc--; + } + + if (argc != 0 || (fileid != 0 && filename != NULL)) + usage(); + + if (fileid == 0 && filename == NULL) + usage(); + + if (filename != NULL) { + if ((fileid = kldfind(filename)) < 0) + err(1, "can't find file %s", filename); + } + + 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(1, "can't unload file"); + if (kldunloadf(fileid, force) < 0) + err(1, "can't unload file"); - return 0; + return 0; }