]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-kmod: support to run without arguments
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 14 Oct 2022 07:18:35 +0000 (16:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 14 Oct 2022 12:32:24 +0000 (21:32 +0900)
If no module name is provided, then try to load modules based on the
device modealias.

Previously, MODALIAS property is passed as an argument, but it may
contain quotation. Hence, unfortunately the modalias may be modified
and cannot load expected modules.

Fixes #24715.

rules.d/80-drivers.rules
src/udev/udev-builtin-kmod.c

index 57d69b8232bd234d461a9708ddb0a6ca00254e19..4bf942f3d70e03149af53f366bcddb0cc9320afb 100644 (file)
@@ -2,7 +2,7 @@
 
 ACTION!="add", GOTO="drivers_end"
 
-ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load '$env{MODALIAS}'"
+ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load"
 SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="SD", RUN{builtin}+="kmod load tifm_sd"
 SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="MS", RUN{builtin}+="kmod load tifm_ms"
 SUBSYSTEM=="memstick", RUN{builtin}+="kmod load ms_block mspro_block"
index 0ba2d2bd13d125db5ffa053e8cf28108d495779b..eade042f3514f692f9ee7d02cb88516eb801fa01 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "device-util.h"
 #include "module-util.h"
 #include "string-util.h"
+#include "strv.h"
 #include "udev-builtin.h"
 
 static struct kmod_ctx *ctx = NULL;
@@ -21,15 +23,29 @@ _printf_(6,0) static void udev_kmod_log(void *data, int priority, const char *fi
 }
 
 static int builtin_kmod(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+        int r;
+
+        assert(dev);
+
         if (!ctx)
                 return 0;
 
-        if (argc < 3 || !streq(argv[1], "load"))
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                       "%s: expected: load <module>…", argv[0]);
+        if (argc < 2 || !streq(argv[1], "load"))
+                return log_device_warning_errno(dev, SYNTHETIC_ERRNO(EINVAL),
+                                                "%s: expected: load [module…]", argv[0]);
+
+        char **modules = strv_skip(argv, 2);
+        if (strv_isempty(modules)) {
+                const char *modalias;
+
+                r = sd_device_get_property_value(dev, "MODALIAS", &modalias);
+                if (r < 0)
+                        return log_device_warning_errno(dev, r, "Failed to read property \"MODALIAS\".");
 
-        for (int i = 2; argv[i]; i++)
-                (void) module_load_and_warn(ctx, argv[i], false);
+                (void) module_load_and_warn(ctx, modalias, /* verbose = */ false);
+        } else
+                STRV_FOREACH(module, modules)
+                        (void) module_load_and_warn(ctx, *module, /* verbose = */ false);
 
         return 0;
 }