My original intent was to just get rid of the meaningless O_EXCL, which isn't used by the kernel, after noticing that it's passed here but not in modprobe's module removal code.
But then I noticed that other rmmod implementations allow you to pass a list of modules, not just one (whereas we were ignoring all but the first). And that the help syntax was wrong. And that strend() lets us write the code to remove the ".ko" suffix a bit nicer. And of course, switch to the FLAG() macro. --- toys/other/rmmod.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
From cec39802e781a28718aaf537a5f3c3db92d41198 Mon Sep 17 00:00:00 2001 From: Elliott Hughes <[email protected]> Date: Fri, 10 Sep 2021 16:05:29 -0700 Subject: [PATCH] rmmod: various fixes. My original intent was to just get rid of the meaningless O_EXCL, which isn't used by the kernel, after noticing that it's passed here but not in modprobe's module removal code. But then I noticed that other rmmod implementations allow you to pass a list of modules, not just one (whereas we were ignoring all but the first). And that the help syntax was wrong. And that strend() lets us write the code to remove the ".ko" suffix a bit nicer. And of course, switch to the FLAG() macro. --- toys/other/rmmod.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/toys/other/rmmod.c b/toys/other/rmmod.c index d9f0a15a..b1fd2057 100644 --- a/toys/other/rmmod.c +++ b/toys/other/rmmod.c @@ -8,12 +8,12 @@ config RMMOD bool "rmmod" default y help - usage: rmmod [-wf] [MODULE] + usage: rmmod [-wf] MODULE... + + Unload the given kernel modules. - Unload the module named MODULE from the Linux kernel. -f Force unload of a module -w Wait until the module is no longer used - */ #define FOR_rmmod @@ -24,20 +24,17 @@ config RMMOD void rmmod_main(void) { - unsigned int flags = O_NONBLOCK|O_EXCL; - char * mod_name; - int len; - - // Basename - mod_name = basename(*toys.optargs); - - // Remove .ko if present - len = strlen(mod_name); - if (len > 3 && !strcmp(&mod_name[len-3], ".ko" )) mod_name[len-3] = 0; - - if (toys.optflags & FLAG_f) flags |= O_TRUNC; - if (toys.optflags & FLAG_w) flags &= ~O_NONBLOCK; - - if (delete_module(mod_name, flags)) - perror_exit("failed to unload %s", mod_name); + char **args, *module, *s; + unsigned flags; + + for (args = toys.optargs; *args; args++) { + module = basename(*args); + // Remove .ko if present + if ((s = strend(module, ".ko"))) *s = 0; + + flags = O_NONBLOCK; + if (FLAG(f)) flags |= O_TRUNC; + if (FLAG(w)) flags &= ~O_NONBLOCK; + if (delete_module(module, flags)) perror_msg("failed to unload %s", module); + } } -- 2.33.0.309.g3052b89438-goog
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
