modprobe: properly handle errors from init_module
authorDave Reisner <dreisner@archlinux.org>
Tue, 31 Jan 2012 01:57:36 +0000 (20:57 -0500)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 31 Jan 2012 16:08:57 +0000 (14:08 -0200)
Effectively catch and the zero and non-zero cases and error out
appropriately. Note that -EEXIST will only ever be returned when
KMOD_PROBE_STOP_ON_ALREADY_LOADED is set as a probe_insert_module flag.

tools/kmod-modprobe.c

index 764b8bf..94500cf 100644 (file)
@@ -590,10 +590,21 @@ static int insmod(struct kmod_ctx *ctx, const char *alias,
                                        extra_options, NULL, NULL, show);
                }
 
-               if (err == KMOD_PROBE_STOP_ON_ALREADY_LOADED) {
-                       ERR("Module %s already in kernel.\n",
-                                               kmod_module_get_name(mod));
-                       err = -EEXIST;
+               if (err >= 0)
+                       /* ignore flag return values such as a mod being blacklisted */
+                       err = 0;
+               else {
+                       switch (err) {
+                       case -EEXIST:
+                               ERR("could not insert '%s': Module already in kernel\n",
+                                                       kmod_module_get_name(mod));
+                               break;
+                       default:
+                               ERR("could not insert '%s': %s\n",
+                                               kmod_module_get_name(mod),
+                                               strerror(-err));
+                               break;
+                       }
                }
 
                kmod_module_unref(mod);