X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fkmod-setup.c;h=debf87130db4c1a877797944292a120b6d2cff9d;hp=44d843db12ad0774a580019853ae31a3e961940c;hb=b47ffcfdfd46de119e0fe8d1c48105bd7c21ddd4;hpb=8e12a6aed3d99ac8c140cd56b560f5efeb1c4e1a diff --git a/src/kmod-setup.c b/src/kmod-setup.c index 44d843db1..debf87130 100644 --- a/src/kmod-setup.c +++ b/src/kmod-setup.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "macro.h" #include "execute.h" @@ -35,14 +36,20 @@ static const char * const kmod_table[] = { "unix", "/proc/net/unix" }; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +static void systemd_kmod_log(void *data, int priority, const char *file, int line, + const char *fn, const char *format, va_list args) +{ + log_meta(priority, file, line, fn, format, args); +} +#pragma GCC diagnostic pop + int kmod_setup(void) { - unsigned i, n = 0; - const char * cmdline[3 + ELEMENTSOF(kmod_table) + 1]; - ExecCommand command; - ExecContext context; - pid_t pid; - int r; - siginfo_t status; + unsigned i; + struct kmod_ctx *ctx = NULL; + struct kmod_module *mod; + int err; for (i = 0; i < ELEMENTSOF(kmod_table); i += 2) { @@ -50,52 +57,40 @@ int kmod_setup(void) { continue; 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 calling '/sbin/modprobe %s'...", - kmod_table[i], kmod_table[i]); - - cmdline[3 + n++] = kmod_table[i]; - } - - if (n <= 0) - return 0; - - cmdline[0] = "/sbin/modprobe"; - cmdline[1] = "-qab"; - cmdline[2] = "--"; - cmdline[3 + n] = NULL; + "We'll now try to work around this by loading the module...", + kmod_table[i]); - zero(command); - zero(context); + if (!ctx) { + ctx = kmod_new(NULL, NULL); + if (!ctx) { + log_error("Failed to allocate memory for kmod"); + return -ENOMEM; + } - command.path = (char*) cmdline[0]; - command.argv = (char**) cmdline; + kmod_set_log_fn(ctx, systemd_kmod_log, NULL); - exec_context_init(&context); - r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, false, NULL, &pid); - exec_context_done(&context); - - if (r < 0) - return r; - - if ((r = wait_for_terminate(pid, &status)) < 0) - return -errno; - - if (status.si_code == CLD_EXITED) { - if (status.si_status != 0) { - log_warning("/sbin/modprobe failed with error code %i.", status.si_status); - return -EPROTO; + kmod_load_resources(ctx); } - log_debug("/sbin/modprobe succeeded."); - return 0; + err = kmod_module_new_from_name(ctx, kmod_table[i], &mod); + if (err < 0) { + log_error("Failed to load module '%s'", kmod_table[i]); + continue; + } - } else if (status.si_code == CLD_KILLED || - status.si_code == CLD_DUMPED) { + err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, 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 + log_error("Failed to insert '%s'", kmod_module_get_name(mod)); - log_warning("/sbin/modprobe terminated by signal %s.", signal_to_string(status.si_status)); - return -EPROTO; + kmod_module_unref(mod); } - log_warning("/sbin/modprobe failed due to unknown reason."); - return -EPROTO; + if (ctx) + kmod_unref(ctx); + + return 0; }