static-nodes: create parent directories of output file
authorTom Gundersen <teg@jklm.no>
Sun, 14 Jul 2013 13:13:34 +0000 (15:13 +0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 15 Jul 2013 15:46:12 +0000 (12:46 -0300)
Allows us to drop call to "mkdir -p" from the systemd service file.

tools/static-nodes.c

index 351c02b..0195390 100644 (file)
@@ -154,12 +154,11 @@ static void help(void)
 static int do_static_nodes(int argc, char *argv[])
 {
        struct utsname kernel;
-       char modules[PATH_MAX];
+       char modules[PATH_MAX], buf[4096];
        const char *output = "/dev/stdout";
        FILE *in = NULL, *out = NULL;
        const struct static_nodes_format *format = &static_nodes_format_human;
-       char buf[4096];
-       int ret = EXIT_SUCCESS;
+       int r, ret = EXIT_SUCCESS;
 
        for (;;) {
                int c, idx = 0, valid;
@@ -227,6 +226,13 @@ static int do_static_nodes(int argc, char *argv[])
                goto finish;
        }
 
+       r = mkdir_parents(output, 0755);
+       if (r < 0) {
+               fprintf(stderr, "Error: could not create parent directory for %s - %m.\n", output);
+               ret = EXIT_FAILURE;
+               goto finish;
+       }
+
        out = fopen(output, "we");
        if (out == NULL) {
                fprintf(stderr, "Error: could not create %s - %m\n", output);