rmmod -a removed modules recursively
authorTim Riker <tim@rikers.org>
Sat, 14 Dec 2002 01:58:59 +0000 (01:58 -0000)
committerTim Riker <tim@rikers.org>
Sat, 14 Dec 2002 01:58:59 +0000 (01:58 -0000)
docs/busybox.sgml
include/libbb.h
include/usage.h
libbb/Makefile.in
libbb/qmodule.c [new file with mode: 0644]
modutils/lsmod.c
modutils/rmmod.c

index aa3c376927936ef7d55cb6e2819c585c2bc17f96..dacc13249f2305bd084839c293ce30e58b8646e8 100644 (file)
 
                <para>
                <screen>
-                       -a      Try to remove all unused kernel modules
+                       -a      Remove all unused modules (recursively)
                </screen>
                </para>
 
index 5f437a95f277eeaedd9088d5ed6b25777f457cfc..3523cc41020f6015fe22af03753d5288a63f221d 100644 (file)
@@ -357,6 +357,8 @@ typedef struct {
 extern procps_status_t * procps_scan(int save_user_arg0);
 extern unsigned short compare_string_array(const char *string_array[], const char *key);
 
+extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret);
+
 typedef struct llist_s {
        char *data;
        struct llist_s *link;
index 3b519e65d6a06c8cfae5b218f4944a5701bd0479..16dd6fd78048019bc2b70459a2c8c3c113f98184 100644 (file)
 #define rmmod_full_usage \
        "Unloads the specified kernel modules from the kernel.\n\n" \
        "Options:\n" \
-       "\t-a\tTry to remove all unused kernel modules."
+       "\t-a\tRemove all unused modules (recursively)"
 #define rmmod_example_usage \
        "$ rmmod tulip\n"
 
index 3f4e77314573d4d14a6a9a5f759069485c83ed63..c97f7d2b30eecdbebc6adf237cbfaad5cab2b06f 100644 (file)
@@ -38,7 +38,7 @@ LIBBB_SRC:= \
        my_getpwnam.c my_getpwnamegid.c my_getpwuid.c obscure.c parse_mode.c \
        parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \
        process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c \
-       read_package_field.c recursive_action.c remove_file.c \
+       qmodule.c read_package_field.c recursive_action.c remove_file.c \
        restricted_shell.c run_parts.c run_shell.c safe_read.c safe_strncpy.c \
        setup_environment.c simplify_path.c syscalls.c syslog_msg_with_name.c \
        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 (file)
index 0000000..fd14d10
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+   Copyright (C) 2002 Tim Riker <Tim@Rikers.org>
+   everyone seems to claim it someplace. ;-)
+*/
+
+#include <errno.h>
+
+#include "libbb.h"
+
+int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret);
+
+int my_query_module(const char *name, int which, void **buf,
+               size_t *bufsize, size_t *ret)
+{
+       int my_ret;
+
+       my_ret = query_module(name, which, *buf, *bufsize, ret);
+
+       if (my_ret == -1 && errno == ENOSPC) {
+               *buf = xrealloc(*buf, *ret);
+               *bufsize = *ret;
+
+               my_ret = query_module(name, which, *buf, *bufsize, ret);
+       }
+
+       return my_ret;
+}
+
+
index d51da2d1699a4f26de7e739c38b4d740b52f8321..0d5ac756b650f3d53441b08c23b8a300aba4c72e 100644 (file)
@@ -98,23 +98,6 @@ static const int NEW_MOD_VISITED = 8;
 static const int NEW_MOD_USED_ONCE = 16;
 static const int NEW_MOD_INITIALIZING = 64;
 
-static int my_query_module(const char *name, int which, void **buf,
-               size_t *bufsize, size_t *ret)
-{
-       int my_ret;
-
-       my_ret = query_module(name, which, *buf, *bufsize, ret);
-
-       if (my_ret == -1 && errno == ENOSPC) {
-               *buf = xrealloc(*buf, *ret);
-               *bufsize = *ret;
-
-               my_ret = query_module(name, which, *buf, *bufsize, ret);
-       }
-
-       return my_ret;
-}
-
 extern int lsmod_main(int argc, char **argv)
 {
        struct module_info info;
index affe975fa22bbe1d21e460822a8ed783c0a6e08b..0103d91458277784322c3af971913f811ae070a2 100644 (file)
@@ -34,14 +34,30 @@ extern int delete_module(const char * name);
 extern int rmmod_main(int argc, char **argv)
 {
        int n, ret = EXIT_SUCCESS;
+       size_t nmod = 0; /* number of modules */
+       size_t pnmod = -1; /* previous number of modules */
+       void *buf; /* hold the module names which we ignore but must get */
+       size_t bufsize = 0;
 
        /* Parse command line. */
        while ((n = getopt(argc, argv, "a")) != EOF) {
                switch (n) {
                        case 'a':
                                /* Unload _all_ unused modules via NULL delete_module() call */
-                               if (delete_module(NULL))
-                                       perror_msg_and_die("rmmod");
+                               /* until the number of modules does not change */
+                               buf = xmalloc(bufsize = 256);
+                               while (nmod != pnmod) {
+                                       if (delete_module(NULL))
+                                               perror_msg_and_die("rmmod");
+                                       pnmod = nmod;
+                                       /* 1 == QM_MODULES */
+                                       if (my_query_module(NULL, 1, &buf, &bufsize, &nmod)) {
+                                               perror_msg_and_die("QM_MODULES");
+                                       }
+                               }
+#ifdef CONFIG_FEATURE_CLEAN_UP
+                               free(buf);
+#endif
                                return EXIT_SUCCESS;
                        default:
                                show_usage();