]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/kmod-setup.c
systemctl: fix parsing of LoadError property for systemctl show
[thirdparty/systemd.git] / src / 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
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
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
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
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>
26
27#include "macro.h"
28#include "execute.h"
29
30#include "kmod-setup.h"
31
32static const char * const kmod_table[] = {
33 "autofs4", "/sys/class/misc/autofs",
17586c16
LP
34 "ipv6", "/sys/module/ipv6",
35 "unix", "/proc/net/unix"
11c3a4ee
LP
36};
37
38int kmod_setup(void) {
39 unsigned i, n = 0;
40 const char * cmdline[3 + ELEMENTSOF(kmod_table) + 1];
41 ExecCommand command;
42 ExecContext context;
43 pid_t pid;
8e12a6ae 44 int r;
11c3a4ee
LP
45
46 for (i = 0; i < ELEMENTSOF(kmod_table); i += 2) {
47
48 if (access(kmod_table[i+1], F_OK) >= 0)
49 continue;
50
be11c12e
LP
51 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]);
11c3a4ee
LP
54
55 cmdline[3 + n++] = kmod_table[i];
56 }
57
58 if (n <= 0)
59 return 0;
60
61 cmdline[0] = "/sbin/modprobe";
62 cmdline[1] = "-qab";
63 cmdline[2] = "--";
64 cmdline[3 + n] = NULL;
65
66 zero(command);
67 zero(context);
68
69 command.path = (char*) cmdline[0];
70 command.argv = (char**) cmdline;
71
72 exec_context_init(&context);
1e3ad081 73 r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, false, NULL, &pid);
11c3a4ee
LP
74 exec_context_done(&context);
75
97c4a07d
LP
76 if (r < 0) {
77 log_error("Failed to spawn %s: %s", cmdline[0], strerror(-r));
11c3a4ee 78 return r;
11c3a4ee
LP
79 }
80
97c4a07d 81 return wait_for_terminate_and_warn(cmdline[0], pid);
11c3a4ee 82}