chiark / gitweb /
tests: add test for unit name printing
[elogind.git] / src / modules-load / modules-load.c
index 3f3b01852b53f47f27ef555ee30626c99f0e3df4..f6279e1975267b50645f72514cfcab5ada0b18c4 100644 (file)
@@ -49,17 +49,13 @@ static int add_modules(const char *p) {
         char **t, **k;
 
         k = strv_split(p, ",");
-        if (!k) {
-                log_error("Out of memory");
-                return -ENOMEM;
-        }
+        if (!k)
+                return log_oom();
 
         t = strv_merge(arg_proc_cmdline_modules, k);
         strv_free(k);
-        if (!t) {
-                log_error("Out of memory");
-                return -ENOMEM;
-        }
+        if (!t)
+                return log_oom();
 
         strv_free(arg_proc_cmdline_modules);
         arg_proc_cmdline_modules = t;
@@ -68,7 +64,8 @@ static int add_modules(const char *p) {
 }
 
 static int parse_proc_cmdline(void) {
-        char *line, *w, *state;
+        char _cleanup_free_ *line = NULL;
+        char *w, *state;
         int r;
         size_t l;
 
@@ -82,38 +79,30 @@ static int parse_proc_cmdline(void) {
         }
 
         FOREACH_WORD_QUOTED(w, l, line, state) {
-                char *word;
+                char _cleanup_free_ *word;
 
                 word = strndup(w, l);
-                if (!word) {
-                        r = -ENOMEM;
-                        goto finish;
-                }
+                if (!word)
+                        return log_oom();
 
                 if (startswith(word, "modules-load=")) {
 
-                        r = add_modules(word + 7);
+                        r = add_modules(word + 13);
                         if (r < 0)
-                                goto finish;
+                                return r;
 
                 } else if (startswith(word, "rd.modules-load=")) {
 
                         if (in_initrd()) {
-                                r = add_modules(word + 10);
+                                r = add_modules(word + 16);
                                 if (r < 0)
-                                        goto finish;
+                                        return r;
                         }
 
                 }
-
-                free(word);
         }
 
-        r = 0;
-
-finish:
-        free(line);
-        return r;
+        return 0;
 }
 
 static int load_module(struct kmod_ctx *ctx, const char *m) {
@@ -175,7 +164,7 @@ static int load_module(struct kmod_ctx *ctx, const char *m) {
 
 int main(int argc, char *argv[]) {
         int r = EXIT_FAILURE, k;
-        char **files, **fn, **i;
+        char **files = NULL, **fn, **i;
         struct kmod_ctx *ctx;
 
         if (argc > 1) {