summaryrefslogtreecommitdiffstats
path: root/src/udev
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-01-30 14:50:35 +0100
committerLennart Poettering <lennart@poettering.net>2024-04-04 18:16:45 +0200
commit1d98716ef7fef3abc078a2cee3156985b8562383 (patch)
treed1279d06b095778fade9923e370a4bc070a9a151 /src/udev
parentwatchdog: clarify that we set the *watchdog* timeout (diff)
downloadsystemd-1d98716ef7fef3abc078a2cee3156985b8562383.tar.xz
systemd-1d98716ef7fef3abc078a2cee3156985b8562383.zip
libkmod: turn into dlopen() dependency
As it turns out libkmod has quite a bunch of deps, including various compressing libs and similar. By turning this into a dlopen() dependency, we can make our depchain during install time quite a bit smaller. In particular as inside of containers kmod doesn't help anyway as CAP_SYS_MODULE is not available anyway. While we are at it, also share the code that sets up logging/kmod context. After: $ lddtree ./build/systemd systemd => ./build/systemd (interpreter => /lib64/ld-linux-x86-64.so.2) libsystemd-core-255.so => ./build/src/core/libsystemd-core-255.so libaudit.so.1 => /lib64/libaudit.so.1 libcap-ng.so.0 => /lib64/libcap-ng.so.0 ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 libm.so.6 => /lib64/libm.so.6 libmount.so.1 => /lib64/libmount.so.1 libblkid.so.1 => /lib64/libblkid.so.1 libseccomp.so.2 => /lib64/libseccomp.so.2 libselinux.so.1 => /lib64/libselinux.so.1 libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 libsystemd-shared-255.so => /home/lennart/projects/systemd/build/src/shared/libsystemd-shared-255.so libacl.so.1 => /lib64/libacl.so.1 libattr.so.1 => /lib64/libattr.so.1 libcap.so.2 => /lib64/libcap.so.2 libcrypt.so.2 => /lib64/libcrypt.so.2 libgcrypt.so.20 => /lib64/libgcrypt.so.20 libgpg-error.so.0 => /lib64/libgpg-error.so.0 liblz4.so.1 => /lib64/liblz4.so.1 libcrypto.so.3 => /lib64/libcrypto.so.3 libz.so.1 => /lib64/libz.so.1 libpam.so.0 => /lib64/libpam.so.0 libeconf.so.0 => /lib64/libeconf.so.0 liblzma.so.5 => /lib64/liblzma.so.5 libzstd.so.1 => /lib64/libzstd.so.1 libc.so.6 => /lib64/libc.so.6 Before: $ lddtree ./build/systemd systemd => ./build/systemd (interpreter => /lib64/ld-linux-x86-64.so.2) libsystemd-core-255.so => ./build/src/core/libsystemd-core-255.so libaudit.so.1 => /lib64/libaudit.so.1 libcap-ng.so.0 => /lib64/libcap-ng.so.0 ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 libkmod.so.2 => /lib64/libkmod.so.2 libzstd.so.1 => /lib64/libzstd.so.1 liblzma.so.5 => /lib64/liblzma.so.5 libz.so.1 => /lib64/libz.so.1 libcrypto.so.3 => /lib64/libcrypto.so.3 libgcc_s.so.1 => /lib64/libgcc_s.so.1 libm.so.6 => /lib64/libm.so.6 libmount.so.1 => /lib64/libmount.so.1 libblkid.so.1 => /lib64/libblkid.so.1 libseccomp.so.2 => /lib64/libseccomp.so.2 libselinux.so.1 => /lib64/libselinux.so.1 libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 libsystemd-shared-255.so => /home/lennart/projects/systemd/build/src/shared/libsystemd-shared-255.so libacl.so.1 => /lib64/libacl.so.1 libattr.so.1 => /lib64/libattr.so.1 libcap.so.2 => /lib64/libcap.so.2 libcrypt.so.2 => /lib64/libcrypt.so.2 libgcrypt.so.20 => /lib64/libgcrypt.so.20 libgpg-error.so.0 => /lib64/libgpg-error.so.0 liblz4.so.1 => /lib64/liblz4.so.1 libpam.so.0 => /lib64/libpam.so.0 libeconf.so.0 => /lib64/libeconf.so.0 libc.so.6 => /lib64/libc.so.6
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/meson.build2
-rw-r--r--src/udev/udev-builtin-kmod.c27
2 files changed, 15 insertions, 14 deletions
diff --git a/src/udev/meson.build b/src/udev/meson.build
index e5b52ab642..3535551e74 100644
--- a/src/udev/meson.build
+++ b/src/udev/meson.build
@@ -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)
diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c
index 6d37af88a3..f4aa4802c9 100644
--- a/src/udev/udev-builtin-kmod.c
+++ b/src/udev/udev-builtin-kmod.c
@@ -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;
}