]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/kmod-setup.c
core: add transient units
[thirdparty/systemd.git] / src / core / kmod-setup.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
11c3a4ee
LP
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11c3a4ee
LP
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
11c3a4ee 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
11c3a4ee
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <sys/wait.h>
23#include <unistd.h>
24#include <string.h>
25#include <errno.h>
728beb28 26#include <libkmod.h>
11c3a4ee
LP
27
28#include "macro.h"
29#include "execute.h"
30
31#include "kmod-setup.h"
32
cdb454f2
LP
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wformat-nonliteral"
b4b87964
LP
35
36static void systemd_kmod_log(
37 void *data,
38 int priority,
39 const char *file, int line,
40 const char *fn,
41 const char *format,
42 va_list args) {
43
10223732
KS
44 /* library logging is enabled at debug only */
45 log_metav(LOG_DEBUG, file, line, fn, format, args);
728beb28 46}
b4b87964 47
cdb454f2 48#pragma GCC diagnostic pop
728beb28 49
11c3a4ee 50int kmod_setup(void) {
b4b87964
LP
51
52 static const char kmod_table[] =
53 /* This one we need to load explicitly, since
54 * auto-loading on use doesn't work before udev
55 * created the ghost device nodes, and we need it
56 * earlier than that. */
57 "autofs4\0" "/sys/class/misc/autofs\0"
58
59 /* This one we need to load explicitly, since
60 * auto-loading of IPv6 is not done when we try to
61 * configure ::1 on the loopback device. */
62 "ipv6\0" "/sys/module/ipv6\0"
63
64 "unix\0" "/proc/net/unix\0";
65
728beb28 66 struct kmod_ctx *ctx = NULL;
b4b87964
LP
67 const char *name, *path;
68 int r;
11c3a4ee 69
b4b87964
LP
70 NULSTR_FOREACH_PAIR(name, path, kmod_table) {
71 struct kmod_module *mod;
11c3a4ee 72
b4b87964 73 if (access(path, F_OK) >= 0)
11c3a4ee
LP
74 continue;
75
be11c12e 76 log_debug("Your kernel apparently lacks built-in %s support. Might be a good idea to compile it in. "
728beb28 77 "We'll now try to work around this by loading the module...",
b4b87964 78 name);
11c3a4ee 79
728beb28
TG
80 if (!ctx) {
81 ctx = kmod_new(NULL, NULL);
b4b87964
LP
82 if (!ctx)
83 return log_oom();
11c3a4ee 84
728beb28 85 kmod_set_log_fn(ctx, systemd_kmod_log, NULL);
728beb28
TG
86 kmod_load_resources(ctx);
87 }
11c3a4ee 88
b4b87964
LP
89 r = kmod_module_new_from_name(ctx, name, &mod);
90 if (r < 0) {
91 log_error("Failed to lookup module '%s'", name);
728beb28
TG
92 continue;
93 }
11c3a4ee 94
b4b87964
LP
95 r = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
96 if (r == 0)
728beb28 97 log_info("Inserted module '%s'", kmod_module_get_name(mod));
b4b87964 98 else if (r == KMOD_PROBE_APPLY_BLACKLIST)
728beb28
TG
99 log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
100 else
10223732 101 log_error("Failed to insert module '%s'", kmod_module_get_name(mod));
11c3a4ee 102
728beb28 103 kmod_module_unref(mod);
11c3a4ee
LP
104 }
105
728beb28 106 if (ctx)
34a35ece 107 kmod_unref(ctx);
728beb28
TG
108
109 return 0;
11c3a4ee 110}