1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
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.
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.
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/>.
34 int main(int argc, char *argv[]) {
36 char **arguments = NULL;
37 unsigned n_arguments = 0, n_allocated = 0;
41 log_error("This program takes no argument.");
45 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
46 log_parse_environment();
49 if (!(arguments = strv_new("/sbin/modprobe", "-sab", "--", NULL))) {
50 log_error("Failed to allocate string array");
54 n_arguments = n_allocated = 3;
56 files = conf_files_list(".conf",
57 "/run/modules-load.d",
58 "/etc/modules-load.d",
59 "/usr/lib/modules-load.d",
62 log_error("Failed to enumerate modules-load.d files: %m");
68 STRV_FOREACH(fn, files) {
76 log_error("Failed to open %s: %m", *fn);
82 log_debug("apply: %s\n", *fn);
84 char line[LINE_MAX], *l, *t;
86 if (!(fgets(line, sizeof(line), f)))
90 if (*l == '#' || *l == 0)
93 if (!(t = strdup(l))) {
94 log_error("Failed to allocate module name.");
98 if (n_arguments >= n_allocated) {
102 m = MAX(16U, n_arguments*2);
104 if (!(a = realloc(arguments, sizeof(char*) * (m+1)))) {
105 log_error("Failed to increase module array size.");
115 arguments[n_arguments++] = t;
120 log_error("Failed to read from file: %m");
129 if (n_arguments > 3) {
130 arguments[n_arguments] = NULL;
131 execv("/sbin/modprobe", arguments);
133 log_error("Failed to execute /sbin/modprobe: %m");
137 strv_free(arguments);