summaryrefslogtreecommitdiffstats
path: root/src/udev/udev-builtin-kmod.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-10-14 09:18:35 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-10-14 14:32:24 +0200
commit2ce39d78b8a6c01a0750f648a615606cb186ba43 (patch)
treef2543b3e6f2abda62f7e80323d0bf993b91a75e0 /src/udev/udev-builtin-kmod.c
parentupdate TODO (diff)
downloadsystemd-2ce39d78b8a6c01a0750f648a615606cb186ba43.tar.xz
systemd-2ce39d78b8a6c01a0750f648a615606cb186ba43.zip
udev-builtin-kmod: support to run without arguments
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.
Diffstat (limited to 'src/udev/udev-builtin-kmod.c')
-rw-r--r--src/udev/udev-builtin-kmod.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c
index 0ba2d2bd13..eade042f35 100644
--- a/src/udev/udev-builtin-kmod.c
+++ b/src/udev/udev-builtin-kmod.c
@@ -10,8 +10,10 @@
#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;
}