diff options
Diffstat (limited to 'src/core/kmod-setup.c')
-rw-r--r-- | src/core/kmod-setup.c | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index b8e3f7a..c39b136 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -9,28 +9,13 @@ #include "fileio.h" #include "kmod-setup.h" #include "macro.h" +#include "module-util.h" #include "recurse-dir.h" #include "string-util.h" #include "strv.h" #include "virt.h" #if HAVE_KMOD -#include "module-util.h" - -static void systemd_kmod_log( - void *data, - int priority, - const char *file, int line, - const char *fn, - const char *format, - va_list args) { - - /* library logging is enabled at debug only */ - DISABLE_WARNING_FORMAT_NONLITERAL; - log_internalv(LOG_DEBUG, 0, file, line, fn, format, args); - REENABLE_WARNING; -} - static int match_modalias_recurse_dir_cb( RecurseDirEvent event, const char *path, @@ -113,12 +98,11 @@ static bool in_qemu(void) { int kmod_setup(void) { #if HAVE_KMOD - static const struct { const char *module; const char *path; - bool warn_if_unavailable:1; - bool warn_if_module:1; + bool warn_if_unavailable; + bool warn_if_module; bool (*condition_fn)(void); } kmod_table[] = { /* This one we need to load explicitly, since auto-loading on use doesn't work @@ -166,34 +150,32 @@ int kmod_setup(void) { { "tpm", "/sys/class/tpmrm", false, false, efi_has_tpm2 }, #endif }; - _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL; - unsigned i; + + int r; if (have_effective_cap(CAP_SYS_MODULE) <= 0) return 0; - for (i = 0; i < ELEMENTSOF(kmod_table); i++) { - if (kmod_table[i].path && access(kmod_table[i].path, F_OK) >= 0) + _cleanup_(sym_kmod_unrefp) struct kmod_ctx *ctx = NULL; + FOREACH_ELEMENT(kmod, kmod_table) { + if (kmod->path && access(kmod->path, F_OK) >= 0) continue; - if (kmod_table[i].condition_fn && !kmod_table[i].condition_fn()) + if (kmod->condition_fn && !kmod->condition_fn()) continue; - if (kmod_table[i].warn_if_module) + if (kmod->warn_if_module) log_debug("Your kernel apparently lacks built-in %s support. Might be " "a good idea to compile it in. We'll now try to work around " - "this by loading the module...", kmod_table[i].module); + "this by loading the module...", kmod->module); if (!ctx) { - ctx = kmod_new(NULL, NULL); - if (!ctx) - return log_oom(); - - kmod_set_log_fn(ctx, systemd_kmod_log, NULL); - kmod_load_resources(ctx); + r = module_setup_context(&ctx); + if (r < 0) + return log_error_errno(r, "Failed to initialize kmod context: %m"); } - (void) module_load_and_warn(ctx, kmod_table[i].module, kmod_table[i].warn_if_unavailable); + (void) module_load_and_warn(ctx, kmod->module, kmod->warn_if_unavailable); } #endif |