35
36
"unix", "/proc/net/unix"
39
#pragma GCC diagnostic push
40
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
41
static void systemd_kmod_log(void *data, int priority, const char *file, int line,
42
const char *fn, const char *format, va_list args)
44
log_meta(priority, file, line, fn, format, args);
46
#pragma GCC diagnostic pop
38
48
int kmod_setup(void) {
40
const char * cmdline[3 + ELEMENTSOF(kmod_table) + 1];
50
struct kmod_ctx *ctx = NULL;
51
struct kmod_module *mod;
46
54
for (i = 0; i < ELEMENTSOF(kmod_table); i += 2) {
51
59
log_debug("Your kernel apparently lacks built-in %s support. Might be a good idea to compile it in. "
52
"We'll now try to work around this by calling '/sbin/modprobe %s'...",
53
kmod_table[i], kmod_table[i]);
55
cmdline[3 + n++] = kmod_table[i];
61
cmdline[0] = "/sbin/modprobe";
64
cmdline[3 + n] = NULL;
69
command.path = (char*) cmdline[0];
70
command.argv = (char**) cmdline;
72
exec_context_init(&context);
73
r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, false, NULL, NULL, &pid);
74
exec_context_done(&context);
77
log_error("Failed to spawn %s: %s", cmdline[0], strerror(-r));
81
return wait_for_terminate_and_warn(cmdline[0], pid);
60
"We'll now try to work around this by loading the module...",
64
ctx = kmod_new(NULL, NULL);
66
log_error("Failed to allocate memory for kmod");
70
kmod_set_log_fn(ctx, systemd_kmod_log, NULL);
72
kmod_load_resources(ctx);
75
err = kmod_module_new_from_name(ctx, kmod_table[i], &mod);
77
log_error("Failed to load module '%s'", kmod_table[i]);
81
err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
83
log_info("Inserted module '%s'", kmod_module_get_name(mod));
84
else if (err == KMOD_PROBE_APPLY_BLACKLIST)
85
log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
87
log_error("Failed to insert '%s'", kmod_module_get_name(mod));
89
kmod_module_unref(mod);