modprobe was failing if you `modprobe a.ko`, then `modprobe b.ko` where b.ko
depends on a.ko --- b.ko will fail to load because a.ko is already loaded.
The code to handle this was incorrectly checking `rc` rather than `errno`
against EEXIST.

(We should pull the insmod.c equivalent of `ins_mod` out into lib/
and reuse it in modprobe.c, but I didn't want to get bogged down.)

Bug: https://issuetracker.google.com/112069618
Reported-by: Wen Xie <xiew...@motorola.com>
---
 toys/pending/modprobe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
From 9f6707702cffca4d608371d7aa9618d417ddd709 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Wed, 1 Aug 2018 12:14:23 -0700
Subject: [PATCH] Fix modprobe error handling.

modprobe was failing if you `modprobe a.ko`, then `modprobe b.ko` where b.ko
depends on a.ko --- b.ko will fail to load because a.ko is already loaded.
The code to handle this was incorrectly checking `rc` rather than `errno`
against EEXIST.

(We should pull the insmod.c equivalent of `ins_mod` out into lib/
and reuse it in modprobe.c, but I didn't want to get bogged down.)

Bug: https://issuetracker.google.com/112069618
Reported-by: Wen Xie <xiew...@motorola.com>
---
 toys/pending/modprobe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c
index 33a2a31..0c0cbc8 100644
--- a/toys/pending/modprobe.c
+++ b/toys/pending/modprobe.c
@@ -482,9 +482,9 @@ static int go_probe(struct module_s *m)
     // none of above is true insert the module.
     rc = ins_mod(fn, options);
     if (toys.optflags&FLAG_v)
-      printf("loaded %s '%s', rc:%d\n", fn, options, rc);
-    if (rc == EEXIST) rc = 0;
-    if (options) free(options);
+      printf("loaded %s '%s': %s\n", fn, options, strerror(errno));
+    if (errno == EEXIST) rc = 0;
+    free(options);
     if (rc) {
       perror_msg("can't load module %s (%s)", m2->name, fn);
       break;
-- 
2.18.0.597.ga71716f1ad-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to