diff options
author | Tim Riker <tim@rikers.org> | 2002-12-14 01:58:59 +0000 |
---|---|---|
committer | Tim Riker <tim@rikers.org> | 2002-12-14 01:58:59 +0000 |
commit | cf93274663877cb4d722a23d8c418470eb90332a (patch) | |
tree | a056983d1162502b58e2aca4c2ebf3c9c7b9c6be | |
parent | 6fe1960ff5e4c7c993a8bc3add5361ee55323afe (diff) | |
download | busybox-w32-cf93274663877cb4d722a23d8c418470eb90332a.tar.gz busybox-w32-cf93274663877cb4d722a23d8c418470eb90332a.tar.bz2 busybox-w32-cf93274663877cb4d722a23d8c418470eb90332a.zip |
rmmod -a removed modules recursively
-rw-r--r-- | docs/busybox.sgml | 2 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | include/usage.h | 2 | ||||
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/qmodule.c | 29 | ||||
-rw-r--r-- | modutils/lsmod.c | 17 | ||||
-rw-r--r-- | modutils/rmmod.c | 20 |
7 files changed, 52 insertions, 22 deletions
diff --git a/docs/busybox.sgml b/docs/busybox.sgml index aa3c37692..dacc13249 100644 --- a/docs/busybox.sgml +++ b/docs/busybox.sgml | |||
@@ -2788,7 +2788,7 @@ | |||
2788 | 2788 | ||
2789 | <para> | 2789 | <para> |
2790 | <screen> | 2790 | <screen> |
2791 | -a Try to remove all unused kernel modules | 2791 | -a Remove all unused modules (recursively) |
2792 | </screen> | 2792 | </screen> |
2793 | </para> | 2793 | </para> |
2794 | 2794 | ||
diff --git a/include/libbb.h b/include/libbb.h index 5f437a95f..3523cc410 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -357,6 +357,8 @@ typedef struct { | |||
357 | extern procps_status_t * procps_scan(int save_user_arg0); | 357 | extern procps_status_t * procps_scan(int save_user_arg0); |
358 | extern unsigned short compare_string_array(const char *string_array[], const char *key); | 358 | extern unsigned short compare_string_array(const char *string_array[], const char *key); |
359 | 359 | ||
360 | extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret); | ||
361 | |||
360 | typedef struct llist_s { | 362 | typedef struct llist_s { |
361 | char *data; | 363 | char *data; |
362 | struct llist_s *link; | 364 | struct llist_s *link; |
diff --git a/include/usage.h b/include/usage.h index 3b519e65d..16dd6fd78 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1722,7 +1722,7 @@ | |||
1722 | #define rmmod_full_usage \ | 1722 | #define rmmod_full_usage \ |
1723 | "Unloads the specified kernel modules from the kernel.\n\n" \ | 1723 | "Unloads the specified kernel modules from the kernel.\n\n" \ |
1724 | "Options:\n" \ | 1724 | "Options:\n" \ |
1725 | "\t-a\tTry to remove all unused kernel modules." | 1725 | "\t-a\tRemove all unused modules (recursively)" |
1726 | #define rmmod_example_usage \ | 1726 | #define rmmod_example_usage \ |
1727 | "$ rmmod tulip\n" | 1727 | "$ rmmod tulip\n" |
1728 | 1728 | ||
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 3f4e77314..c97f7d2b3 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -38,7 +38,7 @@ LIBBB_SRC:= \ | |||
38 | my_getpwnam.c my_getpwnamegid.c my_getpwuid.c obscure.c parse_mode.c \ | 38 | my_getpwnam.c my_getpwnamegid.c my_getpwuid.c obscure.c parse_mode.c \ |
39 | parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \ | 39 | parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \ |
40 | process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c \ | 40 | process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c \ |
41 | read_package_field.c recursive_action.c remove_file.c \ | 41 | qmodule.c read_package_field.c recursive_action.c remove_file.c \ |
42 | restricted_shell.c run_parts.c run_shell.c safe_read.c safe_strncpy.c \ | 42 | restricted_shell.c run_parts.c run_shell.c safe_read.c safe_strncpy.c \ |
43 | setup_environment.c simplify_path.c syscalls.c syslog_msg_with_name.c \ | 43 | setup_environment.c simplify_path.c syscalls.c syslog_msg_with_name.c \ |
44 | time_string.c trim.c u_signal_names.c vdprintf.c verror_msg.c \ | 44 | time_string.c trim.c u_signal_names.c vdprintf.c verror_msg.c \ |
diff --git a/libbb/qmodule.c b/libbb/qmodule.c new file mode 100644 index 000000000..fd14d10fa --- /dev/null +++ b/libbb/qmodule.c | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | Copyright (C) 2002 Tim Riker <Tim@Rikers.org> | ||
3 | everyone seems to claim it someplace. ;-) | ||
4 | */ | ||
5 | |||
6 | #include <errno.h> | ||
7 | |||
8 | #include "libbb.h" | ||
9 | |||
10 | int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret); | ||
11 | |||
12 | int my_query_module(const char *name, int which, void **buf, | ||
13 | size_t *bufsize, size_t *ret) | ||
14 | { | ||
15 | int my_ret; | ||
16 | |||
17 | my_ret = query_module(name, which, *buf, *bufsize, ret); | ||
18 | |||
19 | if (my_ret == -1 && errno == ENOSPC) { | ||
20 | *buf = xrealloc(*buf, *ret); | ||
21 | *bufsize = *ret; | ||
22 | |||
23 | my_ret = query_module(name, which, *buf, *bufsize, ret); | ||
24 | } | ||
25 | |||
26 | return my_ret; | ||
27 | } | ||
28 | |||
29 | |||
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index d51da2d16..0d5ac756b 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
@@ -98,23 +98,6 @@ static const int NEW_MOD_VISITED = 8; | |||
98 | static const int NEW_MOD_USED_ONCE = 16; | 98 | static const int NEW_MOD_USED_ONCE = 16; |
99 | static const int NEW_MOD_INITIALIZING = 64; | 99 | static const int NEW_MOD_INITIALIZING = 64; |
100 | 100 | ||
101 | static int my_query_module(const char *name, int which, void **buf, | ||
102 | size_t *bufsize, size_t *ret) | ||
103 | { | ||
104 | int my_ret; | ||
105 | |||
106 | my_ret = query_module(name, which, *buf, *bufsize, ret); | ||
107 | |||
108 | if (my_ret == -1 && errno == ENOSPC) { | ||
109 | *buf = xrealloc(*buf, *ret); | ||
110 | *bufsize = *ret; | ||
111 | |||
112 | my_ret = query_module(name, which, *buf, *bufsize, ret); | ||
113 | } | ||
114 | |||
115 | return my_ret; | ||
116 | } | ||
117 | |||
118 | extern int lsmod_main(int argc, char **argv) | 101 | extern int lsmod_main(int argc, char **argv) |
119 | { | 102 | { |
120 | struct module_info info; | 103 | struct module_info info; |
diff --git a/modutils/rmmod.c b/modutils/rmmod.c index affe975fa..0103d9145 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c | |||
@@ -34,14 +34,30 @@ extern int delete_module(const char * name); | |||
34 | extern int rmmod_main(int argc, char **argv) | 34 | extern int rmmod_main(int argc, char **argv) |
35 | { | 35 | { |
36 | int n, ret = EXIT_SUCCESS; | 36 | int n, ret = EXIT_SUCCESS; |
37 | size_t nmod = 0; /* number of modules */ | ||
38 | size_t pnmod = -1; /* previous number of modules */ | ||
39 | void *buf; /* hold the module names which we ignore but must get */ | ||
40 | size_t bufsize = 0; | ||
37 | 41 | ||
38 | /* Parse command line. */ | 42 | /* Parse command line. */ |
39 | while ((n = getopt(argc, argv, "a")) != EOF) { | 43 | while ((n = getopt(argc, argv, "a")) != EOF) { |
40 | switch (n) { | 44 | switch (n) { |
41 | case 'a': | 45 | case 'a': |
42 | /* Unload _all_ unused modules via NULL delete_module() call */ | 46 | /* Unload _all_ unused modules via NULL delete_module() call */ |
43 | if (delete_module(NULL)) | 47 | /* until the number of modules does not change */ |
44 | perror_msg_and_die("rmmod"); | 48 | buf = xmalloc(bufsize = 256); |
49 | while (nmod != pnmod) { | ||
50 | if (delete_module(NULL)) | ||
51 | perror_msg_and_die("rmmod"); | ||
52 | pnmod = nmod; | ||
53 | /* 1 == QM_MODULES */ | ||
54 | if (my_query_module(NULL, 1, &buf, &bufsize, &nmod)) { | ||
55 | perror_msg_and_die("QM_MODULES"); | ||
56 | } | ||
57 | } | ||
58 | #ifdef CONFIG_FEATURE_CLEAN_UP | ||
59 | free(buf); | ||
60 | #endif | ||
45 | return EXIT_SUCCESS; | 61 | return EXIT_SUCCESS; |
46 | default: | 62 | default: |
47 | show_usage(); | 63 | show_usage(); |