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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
ip/ipnetns.c +5 -1
index 633b5b9..ee06eba 100644
@@ -407,7 +407,11 @@ 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)) {
+		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

From: vadimk

Quoted 2 lines

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

You need to ignore EEXIST.

David

Quoted 28 lines
---
 ip/ipnetns.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
ip/ipnetns.c +5 -2
index 633b5b9..ee06eba 100644
@@ -407,7 +407,11 @@ 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)) {
+		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
--

2.0.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html