]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/modules-load/modules-load.c
tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
[thirdparty/systemd.git] / src / modules-load / modules-load.c
index 1fd01adbe443862143eba0700b00ed79eda13edf..0901fea8dc35e5f97be5d5f5baeb282222bde766 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
-#include <fcntl.h>
 #include <errno.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <dirent.h>
 #include <getopt.h>
 #include <libkmod.h>
+#include <limits.h>
+#include <string.h>
+#include <sys/stat.h>
 
-#include "log.h"
-#include "util.h"
-#include "strv.h"
 #include "conf-files.h"
+#include "def.h"
+#include "fd-util.h"
 #include "fileio.h"
-#include "build.h"
+#include "log.h"
+#include "proc-cmdline.h"
+#include "string-util.h"
+#include "strv.h"
+#include "util.h"
 
 static char **arg_proc_cmdline_modules = NULL;
 
-static const char conf_file_dirs[] = CONF_DIRS_NULSTR("modules-load");
+static const char conf_file_dirs[] = CONF_PATHS_NULSTR("modules-load.d");
 
 static void systemd_kmod_log(void *data, int priority, const char *file, int line,
                              const char *fn, const char *format, va_list args) {
@@ -55,16 +53,16 @@ static int add_modules(const char *p) {
         if (!k)
                 return log_oom();
 
-        if (strv_extend_strv(&arg_proc_cmdline_modules, k) < 0)
+        if (strv_extend_strv(&arg_proc_cmdline_modules, k, true) < 0)
                 return log_oom();
 
         return 0;
 }
 
-static int parse_proc_cmdline_item(const char *key, const char *value) {
+static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
         int r;
 
-        if (STR_IN_SET(key, "modules-load", "rd.modules-load") && value) {
+        if (streq(key, "modules-load") && value) {
                 r = add_modules(value);
                 if (r < 0)
                         return r;
@@ -139,8 +137,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
 
-                log_error_errno(r, "Failed to open %s, ignoring: %m", path);
-                return r;
+                return log_error_errno(r, "Failed to open %s, ignoring: %m", path);
         }
 
         log_debug("apply: %s", path);
@@ -152,8 +149,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
                         if (feof(f))
                                 break;
 
-                        log_error("Failed to read file '%s', ignoring: %m", path);
-                        return -errno;
+                        return log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
                 }
 
                 l = strstrip(line);
@@ -204,9 +200,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return 0;
 
                 case ARG_VERSION:
-                        puts(PACKAGE_STRING);
-                        puts(SYSTEMD_FEATURES);
-                        return 0;
+                        return version();
 
                 case '?':
                         return -EINVAL;
@@ -232,7 +226,7 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        r = parse_proc_cmdline(parse_proc_cmdline_item);
+        r = parse_proc_cmdline(parse_proc_cmdline_item, NULL, true);
         if (r < 0)
                 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
 
@@ -257,7 +251,7 @@ int main(int argc, char *argv[]) {
                 }
 
         } else {
-                _cleanup_free_ char **files = NULL;
+                _cleanup_strv_free_ char **files = NULL;
                 char **fn, **i;
 
                 STRV_FOREACH(i, arg_proc_cmdline_modules) {