filename2modname needs to do dir-stripping, or I get:
modprobe: remove 'kernel/drivers/usb/class/usblp': No such file or directory

While we're here, replace the guts with functionally equivalent code
from pathname_matches_modname(), and make that call filename2modname().

Unbreaks modprobe-small for me.

function                                             old     new   delta
find_alias                                           666     708     +42
process_module                                       781     745     -36
pathname_matches_modname                             125       -    -125
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 42/-161)          Total: -119 bytes
   text    data     bss     dec     hex filename
 843355    8004    1792  853151   d049f busybox_old
 843354    8004    1792  853150   d049e busybox_unstripped
---
 modutils/modprobe-small.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index dafe91e..57a04d3 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -148,18 +148,13 @@ static void replace(char *s, char what, char with)
 
 static char *filename2modname(const char *filename, char *modname)
 {
-       int i;
-       const char *from;
-
-       // Disabled since otherwise "modprobe dir/name" would work
-       // as if it is "modprobe name". It is unclear why
-       // 'basenamization' was here in the first place.
-       //from = bb_get_last_path_component_nostrip(filename);
-       from = filename;
-       for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != 
'.'; i++)
-               modname[i] = (from[i] == '-') ? '_' : from[i];
-       modname[i] = '\0';
+       // Make sure that modname does not include the path.
+       // Otherwise rmmod/modprobe -r will fail.
+       const char *fname = bb_get_last_path_component_nostrip(filename);
+       const char *suffix = strrstr(fname, ".ko");
 
+       safe_strncpy(modname, fname, suffix - fname + 1);
+       replace(modname, '-', '_');
        return modname;
 }
 
@@ -299,10 +294,7 @@ static int pathname_matches_modname(const char *pathname, 
const char *modname)
 {
        int r;
        char name[MODULE_NAME_LEN];
-       const char *fname = bb_get_last_path_component_nostrip(pathname);
-       const char *suffix = strrstr(fname, ".ko");
-       safe_strncpy(name, fname, suffix - fname + 1);
-       replace(name, '-', '_');
+       filename2modname(pathname, name);
        r = (strcmp(name, modname) == 0);
        return r;
 }
-- 
2.2.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to