diff options
| author | Rob Landley <rob@landley.net> | 2006-08-28 19:40:08 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2006-08-28 19:40:08 +0000 |
| commit | abfe107f7899145720741dd9051f9fe06fcd7030 (patch) | |
| tree | c330a3b93c62f67b2099d030b6d8c016d902c01a /modutils | |
| parent | 82ac9ecfe59e25606d6e4163ba182a547f9d7180 (diff) | |
| download | busybox-w32-abfe107f7899145720741dd9051f9fe06fcd7030.tar.gz busybox-w32-abfe107f7899145720741dd9051f9fe06fcd7030.tar.bz2 busybox-w32-abfe107f7899145720741dd9051f9fe06fcd7030.zip | |
No real need for my_query_module() and this eliminates some type-punned
pointer warning on certain gcc versions (and saves 38 bytes).
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/lsmod.c | 19 | ||||
| -rw-r--r-- | modutils/rmmod.c | 63 |
2 files changed, 36 insertions, 46 deletions
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index ed194edd6..2bc1ae6b1 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | #ifndef CONFIG_FEATURE_CHECK_TAINTED_MODULE | 17 | #ifndef CONFIG_FEATURE_CHECK_TAINTED_MODULE |
| 18 | static inline void check_tainted(void) { printf("\n"); } | 18 | static void check_tainted(void) { printf("\n"); } |
| 19 | #else | 19 | #else |
| 20 | #define TAINT_FILENAME "/proc/sys/kernel/tainted" | 20 | #define TAINT_FILENAME "/proc/sys/kernel/tainted" |
| 21 | #define TAINT_PROPRIETORY_MODULE (1<<0) | 21 | #define TAINT_PROPRIETORY_MODULE (1<<0) |
| @@ -80,13 +80,15 @@ int lsmod_main(int argc, char **argv) | |||
| 80 | char *module_names, *mn, *deps, *dn; | 80 | char *module_names, *mn, *deps, *dn; |
| 81 | size_t bufsize, depsize, nmod, count, i, j; | 81 | size_t bufsize, depsize, nmod, count, i, j; |
| 82 | 82 | ||
| 83 | module_names = xmalloc(bufsize = 256); | 83 | module_names = deps = NULL; |
| 84 | if (my_query_module(NULL, QM_MODULES, &module_names, &bufsize, &nmod)) { | 84 | bufsize = depsize = 0; |
| 85 | bb_perror_msg_and_die("QM_MODULES"); | 85 | while(query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) { |
| 86 | if (errno != ENOSPC) bb_perror_msg_and_die("QM_MODULES"); | ||
| 87 | module_names = xmalloc(bufsize = nmod); | ||
| 86 | } | 88 | } |
| 87 | 89 | ||
| 88 | deps = xmalloc(depsize = 256); | 90 | deps = xmalloc(depsize = 256); |
| 89 | printf("Module Size Used by"); | 91 | printf("Module\t\t\tSize Used by"); |
| 90 | check_tainted(); | 92 | check_tainted(); |
| 91 | 93 | ||
| 92 | for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) { | 94 | for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) { |
| @@ -98,12 +100,13 @@ int lsmod_main(int argc, char **argv) | |||
| 98 | /* else choke */ | 100 | /* else choke */ |
| 99 | bb_perror_msg_and_die("module %s: QM_INFO", mn); | 101 | bb_perror_msg_and_die("module %s: QM_INFO", mn); |
| 100 | } | 102 | } |
| 101 | if (my_query_module(mn, QM_REFS, &deps, &depsize, &count)) { | 103 | while (query_module(mn, QM_REFS, deps, depsize, &count)) { |
| 102 | if (errno == ENOENT) { | 104 | if (errno == ENOENT) { |
| 103 | /* The module was removed out from underneath us. */ | 105 | /* The module was removed out from underneath us. */ |
| 104 | continue; | 106 | continue; |
| 105 | } | 107 | } else if (errno != ENOSPC) |
| 106 | bb_perror_msg_and_die("module %s: QM_REFS", mn); | 108 | bb_perror_msg_and_die("module %s: QM_REFS", mn); |
| 109 | deps = xrealloc(deps, count); | ||
| 107 | } | 110 | } |
| 108 | printf("%-20s%8lu%4ld", mn, info.size, info.usecount); | 111 | printf("%-20s%8lu%4ld", mn, info.size, info.usecount); |
| 109 | if (info.flags & NEW_MOD_DELETED) | 112 | if (info.flags & NEW_MOD_DELETED) |
diff --git a/modutils/rmmod.c b/modutils/rmmod.c index 97650a4b2..8f210310d 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c | |||
| @@ -8,28 +8,17 @@ | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include "busybox.h" | 10 | #include "busybox.h" |
| 11 | #include <stdio.h> | ||
| 12 | #include <errno.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <getopt.h> | ||
| 16 | #include <fcntl.h> | ||
| 17 | #include <string.h> | ||
| 18 | #include <sys/utsname.h> | ||
| 19 | #include <sys/syscall.h> | 11 | #include <sys/syscall.h> |
| 20 | 12 | ||
| 21 | #ifdef CONFIG_FEATURE_2_6_MODULES | 13 | #ifdef CONFIG_FEATURE_2_6_MODULES |
| 22 | static inline void filename2modname(char *modname, const char *afterslash) | 14 | static inline void filename2modname(char *modname, const char *afterslash) |
| 23 | { | 15 | { |
| 24 | unsigned int i; | 16 | unsigned int i; |
| 25 | |||
| 26 | #if ENABLE_FEATURE_2_4_MODULES | ||
| 27 | int kr_chk = 1; | 17 | int kr_chk = 1; |
| 28 | if (get_linux_version_code() <= KERNEL_VERSION(2,6,0)) | 18 | |
| 29 | kr_chk = 0; | 19 | if (ENABLE_FEATURE_2_4_MODULES |
| 30 | #else | 20 | && get_linux_version_code() <= KERNEL_VERSION(2,6,0)) |
| 31 | #define kr_chk 1 | 21 | kr_chk = 0; |
| 32 | #endif | ||
| 33 | 22 | ||
| 34 | /* Convert to underscores, stop at first . */ | 23 | /* Convert to underscores, stop at first . */ |
| 35 | for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) { | 24 | for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) { |
| @@ -40,17 +29,19 @@ static inline void filename2modname(char *modname, const char *afterslash) | |||
| 40 | } | 29 | } |
| 41 | modname[i] = '\0'; | 30 | modname[i] = '\0'; |
| 42 | } | 31 | } |
| 32 | #else | ||
| 33 | void filename2modname(char *modname, const char *afterslash); | ||
| 43 | #endif | 34 | #endif |
| 44 | 35 | ||
| 36 | // There really should be a header file for this... | ||
| 37 | |||
| 38 | int query_module(const char *name, int which, void *buf, | ||
| 39 | size_t bufsize, size_t *ret); | ||
| 40 | |||
| 45 | int rmmod_main(int argc, char **argv) | 41 | int rmmod_main(int argc, char **argv) |
| 46 | { | 42 | { |
| 47 | int n, ret = EXIT_SUCCESS; | 43 | int n, ret = EXIT_SUCCESS; |
| 48 | unsigned int flags = O_NONBLOCK|O_EXCL; | 44 | unsigned int flags = O_NONBLOCK|O_EXCL; |
| 49 | #ifdef CONFIG_FEATURE_QUERY_MODULE_INTERFACE | ||
| 50 | /* bb_common_bufsiz1 hold the module names which we ignore | ||
| 51 | but must get */ | ||
| 52 | size_t bufsize = sizeof(bb_common_bufsiz1); | ||
| 53 | #endif | ||
| 54 | 45 | ||
| 55 | /* Parse command line. */ | 46 | /* Parse command line. */ |
| 56 | n = bb_getopt_ulflags(argc, argv, "wfa"); | 47 | n = bb_getopt_ulflags(argc, argv, "wfa"); |
| @@ -71,12 +62,13 @@ int rmmod_main(int argc, char **argv) | |||
| 71 | bb_perror_msg_and_die("rmmod"); | 62 | bb_perror_msg_and_die("rmmod"); |
| 72 | } | 63 | } |
| 73 | pnmod = nmod; | 64 | pnmod = nmod; |
| 74 | #ifdef CONFIG_FEATURE_QUERY_MODULE_INTERFACE | 65 | // the 1 here is QM_MODULES. |
| 75 | /* 1 == QM_MODULES */ | 66 | if (ENABLE_FEATURE_QUERY_MODULE_INTERFACE && query_module(NULL, |
| 76 | if (my_query_module(NULL, 1, &bb_common_bufsiz1, &bufsize, &nmod)) { | 67 | 1, bb_common_bufsiz1, sizeof(bb_common_bufsiz1), |
| 68 | &nmod)) | ||
| 69 | { | ||
| 77 | bb_perror_msg_and_die("QM_MODULES"); | 70 | bb_perror_msg_and_die("QM_MODULES"); |
| 78 | } | 71 | } |
| 79 | #endif | ||
| 80 | } | 72 | } |
| 81 | return EXIT_SUCCESS; | 73 | return EXIT_SUCCESS; |
| 82 | } | 74 | } |
| @@ -85,21 +77,16 @@ int rmmod_main(int argc, char **argv) | |||
| 85 | bb_show_usage(); | 77 | bb_show_usage(); |
| 86 | 78 | ||
| 87 | for (n = optind; n < argc; n++) { | 79 | for (n = optind; n < argc; n++) { |
| 88 | #ifdef CONFIG_FEATURE_2_6_MODULES | 80 | if (ENABLE_FEATURE_2_6_MODULES) { |
| 89 | const char *afterslash; | 81 | const char *afterslash; |
| 90 | char *module_name; | ||
| 91 | 82 | ||
| 92 | afterslash = strrchr(argv[n], '/'); | 83 | afterslash = strrchr(argv[n], '/'); |
| 93 | if (!afterslash) | 84 | if (!afterslash) afterslash = argv[n]; |
| 94 | afterslash = argv[n]; | 85 | else afterslash++; |
| 95 | else | 86 | filename2modname(bb_common_bufsiz1, afterslash); |
| 96 | afterslash++; | 87 | } |
| 97 | module_name = alloca(strlen(afterslash) + 1); | 88 | |
| 98 | filename2modname(module_name, afterslash); | 89 | if (syscall(__NR_delete_module, ENABLE_FEATURE_2_6_MODULES ? bb_common_bufsiz1 : argv[n], flags)) { |
| 99 | #else | ||
| 100 | #define module_name argv[n] | ||
| 101 | #endif | ||
| 102 | if (syscall(__NR_delete_module, module_name, flags) != 0) { | ||
| 103 | bb_perror_msg("%s", argv[n]); | 90 | bb_perror_msg("%s", argv[n]); |
| 104 | ret = EXIT_FAILURE; | 91 | ret = EXIT_FAILURE; |
| 105 | } | 92 | } |
