Thread (7 messages) 7 messages, 2 authors, 2013-07-15

[PATCH 6/6] static-nodes: create parent directories of output file

From: Lucas De Marchi <hidden>
Date: 2013-07-15 05:12:59
Subsystem: the rest · Maintainer: Linus Torvalds

From: Tom Gundersen <redacted>

Allows us to drop call to "mkdir -p" from the systemd service file.
---
 tools/static-nodes.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/static-nodes.c b/tools/static-nodes.c
index 351c02b..0195390 100644
--- a/tools/static-nodes.c
+++ b/tools/static-nodes.c
@@ -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);
-- 
1.8.3.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help