Merge pull request #31131 from poettering/dlopen-kmod

turn libkmod into a dlopen() dependency, too
This commit is contained in:
Luca Boccassi
2024-04-06 13:19:27 +01:00
committed by GitHub
16 changed files with 202 additions and 92 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ libudevd_core = static_library(
include_directories : includes + include_directories('net'),
link_with : udev_link_with,
dependencies : [libblkid,
libkmod,
libkmod_cflags,
userspace],
build_by_default : false)
+14 -13
View File
@@ -18,10 +18,6 @@
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[]) {
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
int r;
@@ -44,7 +40,7 @@ static int builtin_kmod(UdevEvent *event, int argc, char *argv[]) {
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
@@ -56,23 +52,28 @@ static int builtin_kmod(UdevEvent *event, int argc, char *argv[]) {
/* 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 */
@@ -80,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;
}