diff options
author | Mark Whitley <markw@lineo.com> | 2001-03-09 21:49:12 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2001-03-09 21:49:12 +0000 |
commit | f90c28dd1ee28c29dc0f7bb4d3681f5606843793 (patch) | |
tree | 715983a318456d8391565e25607a023263c230df | |
parent | 8d4c397d9d551a9a91f0855e1ca48a5ed4130e7d (diff) | |
download | busybox-w32-f90c28dd1ee28c29dc0f7bb4d3681f5606843793.tar.gz busybox-w32-f90c28dd1ee28c29dc0f7bb4d3681f5606843793.tar.bz2 busybox-w32-f90c28dd1ee28c29dc0f7bb4d3681f5606843793.zip |
Applied patch from Jeff Garzik to getopt-ify rmmod.
-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 | } |