diff options
| author | markw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-03-09 21:49:12 +0000 |
|---|---|---|
| committer | markw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-03-09 21:49:12 +0000 |
| commit | fb74ba18032d79f02be135a63d11b111e2f56dc1 (patch) | |
| tree | 715983a318456d8391565e25607a023263c230df | |
| parent | 49efa6409a6796771c60dd1c2e2ac30ad6f0e1c2 (diff) | |
| download | busybox-w32-fb74ba18032d79f02be135a63d11b111e2f56dc1.tar.gz busybox-w32-fb74ba18032d79f02be135a63d11b111e2f56dc1.tar.bz2 busybox-w32-fb74ba18032d79f02be135a63d11b111e2f56dc1.zip | |
Applied patch from Jeff Garzik to getopt-ify rmmod.
git-svn-id: svn://busybox.net/trunk/busybox@2030 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | modutils/rmmod.c | 25 | ||||
| -rw-r--r-- | rmmod.c | 25 |
2 files changed, 24 insertions, 26 deletions
diff --git a/modutils/rmmod.c b/modutils/rmmod.c index aab326123..36857e02c 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <errno.h> | 25 | #include <errno.h> |
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| 27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
| 28 | #include <getopt.h> | ||
| 28 | #include <sys/syscall.h> | 29 | #include <sys/syscall.h> |
| 29 | #include <linux/unistd.h> | 30 | #include <linux/unistd.h> |
| 30 | #include "busybox.h" | 31 | #include "busybox.h" |
| @@ -37,15 +38,11 @@ _syscall1(int, delete_module, const char *, name) | |||
| 37 | 38 | ||
| 38 | extern int rmmod_main(int argc, char **argv) | 39 | extern int rmmod_main(int argc, char **argv) |
| 39 | { | 40 | { |
| 40 | int ret = EXIT_SUCCESS; | 41 | int n, ret = EXIT_SUCCESS; |
| 41 | if (argc <= 1) { | ||
| 42 | show_usage(); | ||
| 43 | } | ||
| 44 | 42 | ||
| 45 | /* Parse any options */ | 43 | /* Parse command line. */ |
| 46 | while (--argc > 0 && **(++argv) == '-') { | 44 | while ((n = getopt(argc, argv, "a")) != EOF) { |
| 47 | while (*(++(*argv))) { | 45 | switch (n) { |
| 48 | switch (**argv) { | ||
| 49 | case 'a': | 46 | case 'a': |
| 50 | /* Unload _all_ unused modules via NULL delete_module() call */ | 47 | /* Unload _all_ unused modules via NULL delete_module() call */ |
| 51 | if (delete_module(NULL)) | 48 | if (delete_module(NULL)) |
| @@ -53,16 +50,18 @@ extern int rmmod_main(int argc, char **argv) | |||
| 53 | return EXIT_SUCCESS; | 50 | return EXIT_SUCCESS; |
| 54 | default: | 51 | default: |
| 55 | show_usage(); | 52 | show_usage(); |
| 56 | } | ||
| 57 | } | 53 | } |
| 58 | } | 54 | } |
| 59 | 55 | ||
| 60 | while (argc-- > 0) { | 56 | if (optind == argc) |
| 61 | if (delete_module(*argv) < 0) { | 57 | show_usage(); |
| 62 | perror_msg("%s", *argv); | 58 | |
| 59 | for (n = optind; n < argc; n++) { | ||
| 60 | if (delete_module(argv[n]) < 0) { | ||
| 61 | perror_msg("%s", argv[n]); | ||
| 63 | ret = EXIT_FAILURE; | 62 | ret = EXIT_FAILURE; |
| 64 | } | 63 | } |
| 65 | argv++; | ||
| 66 | } | 64 | } |
| 65 | |||
| 67 | return(ret); | 66 | return(ret); |
| 68 | } | 67 | } |
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <errno.h> | 25 | #include <errno.h> |
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| 27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
| 28 | #include <getopt.h> | ||
| 28 | #include <sys/syscall.h> | 29 | #include <sys/syscall.h> |
| 29 | #include <linux/unistd.h> | 30 | #include <linux/unistd.h> |
| 30 | #include "busybox.h" | 31 | #include "busybox.h" |
| @@ -37,15 +38,11 @@ _syscall1(int, delete_module, const char *, name) | |||
| 37 | 38 | ||
| 38 | extern int rmmod_main(int argc, char **argv) | 39 | extern int rmmod_main(int argc, char **argv) |
| 39 | { | 40 | { |
| 40 | int ret = EXIT_SUCCESS; | 41 | int n, ret = EXIT_SUCCESS; |
| 41 | if (argc <= 1) { | ||
| 42 | show_usage(); | ||
| 43 | } | ||
| 44 | 42 | ||
| 45 | /* Parse any options */ | 43 | /* Parse command line. */ |
| 46 | while (--argc > 0 && **(++argv) == '-') { | 44 | while ((n = getopt(argc, argv, "a")) != EOF) { |
| 47 | while (*(++(*argv))) { | 45 | switch (n) { |
| 48 | switch (**argv) { | ||
| 49 | case 'a': | 46 | case 'a': |
| 50 | /* Unload _all_ unused modules via NULL delete_module() call */ | 47 | /* Unload _all_ unused modules via NULL delete_module() call */ |
| 51 | if (delete_module(NULL)) | 48 | if (delete_module(NULL)) |
| @@ -53,16 +50,18 @@ extern int rmmod_main(int argc, char **argv) | |||
| 53 | return EXIT_SUCCESS; | 50 | return EXIT_SUCCESS; |
| 54 | default: | 51 | default: |
| 55 | show_usage(); | 52 | show_usage(); |
| 56 | } | ||
| 57 | } | 53 | } |
| 58 | } | 54 | } |
| 59 | 55 | ||
| 60 | while (argc-- > 0) { | 56 | if (optind == argc) |
| 61 | if (delete_module(*argv) < 0) { | 57 | show_usage(); |
| 62 | perror_msg("%s", *argv); | 58 | |
| 59 | for (n = optind; n < argc; n++) { | ||
| 60 | if (delete_module(argv[n]) < 0) { | ||
| 61 | perror_msg("%s", argv[n]); | ||
| 63 | ret = EXIT_FAILURE; | 62 | ret = EXIT_FAILURE; |
| 64 | } | 63 | } |
| 65 | argv++; | ||
| 66 | } | 64 | } |
| 65 | |||
| 67 | return(ret); | 66 | return(ret); |
| 68 | } | 67 | } |
