Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/modutils/rmmod.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/modutils/rmmod.c
r1765 r2725 4 4 * 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi> 6 7 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 9 */ 9 10 11 //applet:IF_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_DROP)) 12 13 //usage:#if !ENABLE_MODPROBE_SMALL 14 //usage:#define rmmod_trivial_usage 15 //usage: "[-wfa] [MODULE]..." 16 //usage:#define rmmod_full_usage "\n\n" 17 //usage: "Unload kernel modules\n" 18 //usage: "\nOptions:" 19 //usage: "\n -w Wait until the module is no longer used" 20 //usage: "\n -f Force unload" 21 //usage: "\n -a Remove all unused modules (recursively)" 22 //usage:#define rmmod_example_usage 23 //usage: "$ rmmod tulip\n" 24 //usage:#endif 25 10 26 #include "libbb.h" 11 #include <sys/syscall.h>27 #include "modutils.h" 12 28 13 #if ENABLE_FEATURE_2_6_MODULES 14 static inline void filename2modname(char *modname, const char *afterslash)29 int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 30 int rmmod_main(int argc UNUSED_PARAM, char **argv) 15 31 { 16 unsigned int i; 17 int kr_chk = 1; 18 19 if (ENABLE_FEATURE_2_4_MODULES 20 && get_linux_version_code() <= KERNEL_VERSION(2,6,0)) 21 kr_chk = 0; 22 23 /* Convert to underscores, stop at first . */ 24 for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) { 25 if (kr_chk && (afterslash[i] == '-')) 26 modname[i] = '_'; 27 else 28 modname[i] = afterslash[i]; 29 } 30 modname[i] = '\0'; 31 } 32 #else 33 void filename2modname(char *modname, const char *afterslash); 34 #endif 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 41 int rmmod_main(int argc, char **argv); 42 int rmmod_main(int argc, char **argv) 43 { 44 int n, ret = EXIT_SUCCESS; 45 unsigned int flags = O_NONBLOCK|O_EXCL; 46 47 #define misc_buf bb_common_bufsiz1 32 int n; 33 unsigned flags = O_NONBLOCK | O_EXCL; 48 34 49 35 /* Parse command line. */ 50 n = getopt32(argv, "wfa"); 51 if (n & 1) // --wait 36 n = getopt32(argv, "wfas"); // -s ignored 37 argv += optind; 38 if (n & 1) // --wait 52 39 flags &= ~O_NONBLOCK; 53 if (n & 2) 40 if (n & 2) // --force 54 41 flags |= O_TRUNC; 55 42 if (n & 4) { 56 43 /* Unload _all_ unused modules via NULL delete_module() call */ 57 /* until the number of modules does not change */ 58 size_t nmod = 0; /* number of modules */ 59 size_t pnmod = -1; /* previous number of modules */ 60 61 while (nmod != pnmod) { 62 if (syscall(__NR_delete_module, NULL, flags) != 0) { 63 if (errno == EFAULT) 64 return ret; 65 bb_perror_msg_and_die("rmmod"); 66 } 67 pnmod = nmod; 68 // the 1 here is QM_MODULES. 69 if (ENABLE_FEATURE_QUERY_MODULE_INTERFACE && query_module(NULL, 70 1, misc_buf, sizeof(misc_buf), 71 &nmod)) 72 { 73 bb_perror_msg_and_die("QM_MODULES"); 74 } 75 } 44 if (bb_delete_module(NULL, flags) != 0 && errno != EFAULT) 45 bb_perror_msg_and_die("rmmod"); 76 46 return EXIT_SUCCESS; 77 47 } 78 48 79 if ( optind == argc)49 if (!*argv) 80 50 bb_show_usage(); 81 51 82 for (n = optind; n < argc; n++) {83 if (ENABLE_FEATURE_2_6_MODULES) {84 filename2modname(misc_buf, bb_basename(argv[n]));85 }52 n = ENABLE_FEATURE_2_4_MODULES && get_linux_version_code() < KERNEL_VERSION(2,6,0); 53 while (*argv) { 54 char modname[MODULE_NAME_LEN]; 55 const char *bname; 86 56 87 if (syscall(__NR_delete_module, ENABLE_FEATURE_2_6_MODULES ? misc_buf : argv[n], flags)) { 88 bb_perror_msg("%s", argv[n]); 89 ret = EXIT_FAILURE; 90 } 57 bname = bb_basename(*argv++); 58 if (n) 59 safe_strncpy(modname, bname, MODULE_NAME_LEN); 60 else 61 filename2modname(bname, modname); 62 if (bb_delete_module(modname, flags)) 63 bb_error_msg_and_die("can't unload '%s': %s", 64 modname, moderror(errno)); 91 65 } 92 66 93 return ret;67 return EXIT_SUCCESS; 94 68 }
Note:
See TracChangeset
for help on using the changeset viewer.