modules-load.c revision 4b462d1a28461b302586b117736ef288fba1012f
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt This file is part of systemd.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Copyright 2010 Lennart Poettering
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is free software; you can redistribute it and/or modify it
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt under the terms of the GNU Lesser General Public License as published by
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt the Free Software Foundation; either version 2.1 of the License, or
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt (at your option) any later version.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is distributed in the hope that it will be useful, but
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt WITHOUT ANY WARRANTY; without even the implied warranty of
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Lesser General Public License for more details.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt You should have received a copy of the GNU Lesser General Public License
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt along with systemd; If not, see <http://www.gnu.org/licenses/>.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic char **arg_proc_cmdline_modules = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic const char conf_file_dirs[] =
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#pragma GCC diagnostic ignored "-Wformat-nonliteral"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void systemd_kmod_log(void *data, int priority, const char *file, int line,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt const char *fn, const char *format, va_list args) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_metav(priority, file, line, fn, format, args);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int add_modules(const char *p) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (strv_extend_strv(&arg_proc_cmdline_modules, k) < 0)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int parse_proc_cmdline_word(const char *word) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt } else if (startswith(word, "rd.modules-load=")) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int load_module(struct kmod_ctx *ctx, const char *m) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = kmod_module_new_from_lookup(ctx, m, &modlist);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to lookup alias '%s': %s", m, strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_info("Module '%s' is builtin", kmod_module_get_name(mod));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("Module '%s' is already loaded", kmod_module_get_name(mod));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt err = kmod_module_probe_insert_module(mod, probe_flags,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_info("Inserted module '%s'", kmod_module_get_name(mod));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to insert '%s': %s", kmod_module_get_name(mod),
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_error("Failed to open %s, ignoring: %s", path, strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_error("Failed to read file '%s', ignoring: %m", path);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (k < 0 && r == 0)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int help(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt "Loads statically configured kernel modules.\n\n"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt " -h --help Show this help\n"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt " --version Show package version\n",
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int parse_argv(int argc, char *argv[]) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt { "version", no_argument, NULL, ARG_VERSION },
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (parse_proc_cmdline(parse_proc_cmdline_word) < 0)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_error("Failed to allocate memory for kmod.");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt kmod_set_log_fn(ctx, systemd_kmod_log, NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (k < 0 && r == 0)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char **fn, **i;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (k < 0 && r == 0)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt k = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_error("Failed to enumerate modules-load.d files: %s", strerror(-k));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (k < 0 && r == 0)