summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/meson.build1
-rw-r--r--src/shared/meson.build3
-rw-r--r--src/shared/module-util.c64
3 files changed, 67 insertions, 1 deletions
diff --git a/src/basic/meson.build b/src/basic/meson.build
index c199e78c8..af146b574 100644
--- a/src/basic/meson.build
+++ b/src/basic/meson.build
@@ -122,7 +122,6 @@
# mkdir-label.c
# mkdir.c
# mkdir.h
-# module-util.h
# mount-util.c
# mount-util.h
# nss-util.h
diff --git a/src/shared/meson.build b/src/shared/meson.build
index b215e267d..9f4615091 100644
--- a/src/shared/meson.build
+++ b/src/shared/meson.build
@@ -64,6 +64,8 @@
# machine-image.h
# machine-pool.c
# machine-pool.h
+# module-util.h
+# module-util.c
# nsflags.c
# nsflags.h
# output-mode.c
@@ -157,6 +159,7 @@ libshared_name = 'elogind-shared-@0@'.format(meson.project_version())
# libcryptsetup,
# libgcrypt,
# libiptc,
+# libkmod,
# libseccomp,
# libselinux,
# libidn,
diff --git a/src/shared/module-util.c b/src/shared/module-util.c
new file mode 100644
index 000000000..b203239b3
--- /dev/null
+++ b/src/shared/module-util.c
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+//#include <errno.h>
+
+//#include "module-util.h"
+
+int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
+ const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
+ struct kmod_list *itr;
+ _cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
+ int r = 0;
+
+ log_debug("Loading module: %s", module);
+
+ r = kmod_module_new_from_lookup(ctx, module, &modlist);
+ if (r < 0)
+ return log_error_errno(r, "Failed to lookup module alias '%s': %m", module);
+
+ if (!modlist) {
+ log_error("Failed to find module '%s'", module);
+ return -ENOENT;
+ }
+
+ kmod_list_foreach(itr, modlist) {
+ _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
+ int state, err;
+
+ mod = kmod_module_get_module(itr);
+ state = kmod_module_get_initstate(mod);
+
+ switch (state) {
+ case KMOD_MODULE_BUILTIN:
+ log_info("Module '%s' is builtin", kmod_module_get_name(mod));
+ break;
+
+ case KMOD_MODULE_LIVE:
+ log_debug("Module '%s' is already loaded", kmod_module_get_name(mod));
+ break;
+
+ default:
+ err = kmod_module_probe_insert_module(mod, probe_flags,
+ NULL, NULL, NULL, NULL);
+
+ if (err == 0)
+ log_info("Inserted module '%s'", kmod_module_get_name(mod));
+ else if (err == KMOD_PROBE_APPLY_BLACKLIST)
+ log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
+ else {
+ assert(err < 0);
+
+ log_full_errno(err == ENODEV ? LOG_NOTICE :
+ err == ENOENT ? LOG_WARNING :
+ LOG_ERR,
+ err,
+ "Failed to insert module '%s': %m",
+ kmod_module_get_name(mod));
+ if (!IN_SET(err, ENODEV, ENOENT))
+ r = err;
+ }
+ }
+ }
+
+ return r;
+}