X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=modutils%2Frmmod.c;h=5129b34958adb0da37bf13849da2a0d84f278f51;hb=b2dc913527f2cb9a4590fe5e553bcc2c456007e0;hp=ce239a21fd6ffbf728f95ebee75c01149970e2f3;hpb=67b23e6043d8e2b30b0bf3bc105b8583c2a26db5;p=oweals%2Fbusybox.git diff --git a/modutils/rmmod.c b/modutils/rmmod.c index ce239a21f..5129b3495 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c @@ -7,11 +7,17 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include "busybox.h" -#include +#include "libbb.h" -#ifdef CONFIG_FEATURE_2_6_MODULES -static inline void filename2modname(char *modname, const char *afterslash) +#ifdef __UCLIBC__ +extern int delete_module(const char *module, unsigned int flags); +#else +# include +# define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) +#endif + +#if ENABLE_FEATURE_2_6_MODULES +static void filename2modname(char *modname, const char *afterslash) { unsigned int i; int kr_chk = 1; @@ -38,33 +44,36 @@ void filename2modname(char *modname, const char *afterslash); int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret); +int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int rmmod_main(int argc, char **argv) { int n, ret = EXIT_SUCCESS; unsigned int flags = O_NONBLOCK|O_EXCL; +#define misc_buf bb_common_bufsiz1 + /* Parse command line. */ - n = getopt32(argc, argv, "wfa"); - if((n & 1)) // --wait + n = getopt32(argv, "wfa"); + if (n & 1) // --wait flags &= ~O_NONBLOCK; - if((n & 2)) // --force + if (n & 2) // --force flags |= O_TRUNC; - if((n & 4)) { + if (n & 4) { /* Unload _all_ unused modules via NULL delete_module() call */ /* until the number of modules does not change */ size_t nmod = 0; /* number of modules */ size_t pnmod = -1; /* previous number of modules */ while (nmod != pnmod) { - if (syscall(__NR_delete_module, NULL, flags) != 0) { - if (errno==EFAULT) - return(ret); + if (delete_module(NULL, flags) != 0) { + if (errno == EFAULT) + return ret; bb_perror_msg_and_die("rmmod"); } pnmod = nmod; // the 1 here is QM_MODULES. if (ENABLE_FEATURE_QUERY_MODULE_INTERFACE && query_module(NULL, - 1, bb_common_bufsiz1, sizeof(bb_common_bufsiz1), + 1, misc_buf, sizeof(misc_buf), &nmod)) { bb_perror_msg_and_die("QM_MODULES"); @@ -78,19 +87,14 @@ int rmmod_main(int argc, char **argv) for (n = optind; n < argc; n++) { if (ENABLE_FEATURE_2_6_MODULES) { - const char *afterslash; - - afterslash = strrchr(argv[n], '/'); - if (!afterslash) afterslash = argv[n]; - else afterslash++; - filename2modname(bb_common_bufsiz1, afterslash); + filename2modname(misc_buf, bb_basename(argv[n])); } - if (syscall(__NR_delete_module, ENABLE_FEATURE_2_6_MODULES ? bb_common_bufsiz1 : argv[n], flags)) { - bb_perror_msg("%s", argv[n]); + if (delete_module(ENABLE_FEATURE_2_6_MODULES ? misc_buf : argv[n], flags)) { + bb_simple_perror_msg(argv[n]); ret = EXIT_FAILURE; } } - return(ret); + return ret; }