diff options
Diffstat (limited to 'src/udev/udev-builtin-kmod.c')
-rw-r--r-- | src/udev/udev-builtin-kmod.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index 3ab5c48..f4aa480 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -18,14 +18,15 @@ static struct kmod_ctx *ctx = NULL; -_printf_(6,0) static void udev_kmod_log(void *data, int priority, const char *file, int line, const char *fn, const char *format, va_list args) { - log_internalv(priority, 0, file, line, fn, format, args); -} - -static int builtin_kmod(UdevEvent *event, int argc, char *argv[], bool test) { +static int builtin_kmod(UdevEvent *event, int argc, char *argv[]) { sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev); int r; + if (event->event_mode != EVENT_UDEV_WORKER) { + log_device_debug(dev, "Running in test mode, skipping execution of 'kmod' builtin command."); + return 0; + } + if (!ctx) return 0; @@ -39,7 +40,7 @@ static int builtin_kmod(UdevEvent *event, int argc, char *argv[], bool test) { r = sd_device_get_property_value(dev, "MODALIAS", &modalias); if (r < 0) - return log_device_warning_errno(dev, r, "Failed to read property \"MODALIAS\"."); + return log_device_warning_errno(dev, r, "Failed to read property \"MODALIAS\": %m"); (void) module_load_and_warn(ctx, modalias, /* verbose = */ false); } else @@ -51,23 +52,28 @@ static int builtin_kmod(UdevEvent *event, int argc, char *argv[], bool test) { /* called at udev startup and reload */ static int builtin_kmod_init(void) { + int r; + if (ctx) return 0; - ctx = kmod_new(NULL, NULL); - if (!ctx) - return -ENOMEM; - log_debug("Loading kernel module index."); - kmod_set_log_fn(ctx, udev_kmod_log, NULL); - kmod_load_resources(ctx); + + r = module_setup_context(&ctx); + if (r < 0) + return log_error_errno(r, "Failed to initialize libkmod context: %m"); + return 0; } /* called on udev shutdown and reload request */ static void builtin_kmod_exit(void) { log_debug("Unload kernel module index."); - ctx = kmod_unref(ctx); + + if (!ctx) + return; + + ctx = sym_kmod_unref(ctx); } /* called every couple of seconds during event activity; 'true' if config has changed */ @@ -75,7 +81,7 @@ static bool builtin_kmod_should_reload(void) { if (!ctx) return false; - if (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK) { + if (sym_kmod_validate_resources(ctx) != KMOD_RESOURCES_OK) { log_debug("Kernel module index needs reloading."); return true; } |