Skip to contentSkip to conversation

ip netns: Show error message if mkdir failed to create /var/run/netns

PATCH In review vadimk 2 participants 2 messages Aug 28, 2014

Subsystems (2)
lore
Share & tools
lore

vadimk

author
#0 lore raw

PATCH 1/1 ip netns: Show error message if mkdir failed to create /var/run/netns

Currently if mkdir failed with "Permission denied" error then "mount --make-shared ..." error message will be showed because /var/run/netns does not exist.

---
 ip/ipnetns.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
ip/ipnetns.c +7 -1
index 633b5b9..7f82908 100644
@@ -407,7 +407,13 @@ static int netns_add(int argc, char **argv)
 	snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name);
 
 	/* Create the base netns directory if it doesn't exist */
-	mkdir(NETNS_RUN_DIR, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
+	if (mkdir(NETNS_RUN_DIR, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) {
+		if (errno != EEXIST) {
+			fprintf(stderr, "mkdir %s failed: %s\n",
+				NETNS_RUN_DIR, strerror(errno));
+			return -1;
+		}
+	}
 
 	/* Make it possible for network namespace mounts to propagate between
 	 * mount namespaces.  This makes it likely that a unmounting a network
Signature · 1 line
2.0.4
#1 lore raw
Quoted 3 lines · vadimk

Currently if mkdir failed with "Permission denied" error then "mount --make-shared ..." error message will be showed because /var/run/netns does not exist.
---

Your 'Signed-off-by' is missing.