aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-28 19:40:08 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-28 19:40:08 +0000
commit680deb07073f10d09509e43bbe68753b4abaa726 (patch)
treec330a3b93c62f67b2099d030b6d8c016d902c01a
parent91e9e31ac059a4f9c08c6c0759591b569f320a3d (diff)
downloadbusybox-w32-680deb07073f10d09509e43bbe68753b4abaa726.tar.gz
busybox-w32-680deb07073f10d09509e43bbe68753b4abaa726.tar.bz2
busybox-w32-680deb07073f10d09509e43bbe68753b4abaa726.zip
No real need for my_query_module() and this eliminates some type-punned
pointer warning on certain gcc versions (and saves 38 bytes). git-svn-id: svn://busybox.net/trunk/busybox@16003 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/qmodule.c30
-rw-r--r--modutils/lsmod.c19
-rw-r--r--modutils/rmmod.c63
5 files changed, 37 insertions, 79 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 67d4eb170..3c563a96f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -521,8 +521,6 @@ typedef struct {
521extern procps_status_t * procps_scan(int save_user_arg0); 521extern procps_status_t * procps_scan(int save_user_arg0);
522extern int compare_string_array(const char * const string_array[], const char *key); 522extern int compare_string_array(const char * const string_array[], const char *key);
523 523
524extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret);
525
526extern void print_login_issue(const char *issue_file, const char *tty); 524extern void print_login_issue(const char *issue_file, const char *tty);
527extern void print_login_prompt(void); 525extern void print_login_prompt(void);
528 526
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index 4f688e77a..ae9c9f0db 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -23,7 +23,7 @@ LIBBB-y:= \
23 make_directory.c md5.c mode_string.c mtab_file.c \ 23 make_directory.c md5.c mode_string.c mtab_file.c \
24 obscure.c parse_mode.c parse_number.c perror_msg.c \ 24 obscure.c parse_mode.c parse_number.c perror_msg.c \
25 perror_msg_and_die.c get_console.c \ 25 perror_msg_and_die.c get_console.c \
26 process_escape_sequence.c procps.c qmodule.c \ 26 process_escape_sequence.c procps.c \
27 recursive_action.c remove_file.c \ 27 recursive_action.c remove_file.c \
28 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \ 28 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
29 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \ 29 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
diff --git a/libbb/qmodule.c b/libbb/qmodule.c
deleted file mode 100644
index 4e4e79d38..000000000
--- a/libbb/qmodule.c
+++ /dev/null
@@ -1,30 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 Copyright (C) 2002 Tim Riker <Tim@Rikers.org>
4 everyone seems to claim it someplace. ;-)
5*/
6
7#include <errno.h>
8
9#include "libbb.h"
10
11int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret);
12
13int my_query_module(const char *name, int which, void **buf,
14 size_t *bufsize, size_t *ret)
15{
16 int my_ret;
17
18 my_ret = query_module(name, which, *buf, *bufsize, ret);
19
20 if (my_ret == -1 && errno == ENOSPC) {
21 *buf = xrealloc(*buf, *ret);
22 *bufsize = *ret;
23
24 my_ret = query_module(name, which, *buf, *bufsize, ret);
25 }
26
27 return my_ret;
28}
29
30
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
18static inline void check_tainted(void) { printf("\n"); } 18static 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
22static inline void filename2modname(char *modname, const char *afterslash) 14static 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
33void filename2modname(char *modname, const char *afterslash);
43#endif 34#endif
44 35
36// There really should be a header file for this...
37
38int query_module(const char *name, int which, void *buf,
39 size_t bufsize, size_t *ret);
40
45int rmmod_main(int argc, char **argv) 41int 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 }