rmmod -a removed modules recursively
This commit was genuinely broken at the time (not related to our build system): sysdeps/linux/Config.in "fileutils/Config.in" dosyasini kaynak gosteriyor ama bu dosya repoda hic var olmadi (2002-12-05 - 2003-02-15 arasi orijinal yazar hatasi, 3238ea167 ile duzeltildi)
No binary (build failed)
—
(log yok)
| @@ -2788,7 +2788,7 @@ | |
| <para> | |
| <screen> | |
| - | -a Try to remove all unused kernel modules |
| + | -a Remove all unused modules (recursively) |
| </screen> | |
| </para> | |
| @@ -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; | |
| @@ -1722,7 +1722,7 @@ | |
| #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" | |
| @@ -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 \ | |
| @@ -0,0 +1,29 @@ | |
| + | /* |
| + | Copyright (C) 2002 Tim Riker <[email protected]> |
| + | 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; |
| + | } |
| + | |
| + | |
| @@ -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; | |
| @@ -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(); | |