diff mbox

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

Message ID 1409229508-4652-1-git-send-email-vadim4j@gmail.com
State Superseded, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Vadym Kochan Aug. 28, 2014, 12:38 p.m. UTC
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(-)

Comments

David Laight Aug. 28, 2014, 12:52 p.m. UTC | #1
From: 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.

You need to ignore EEXIST.

	David

> ---
>  ip/ipnetns.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
> index 633b5b9..ee06eba 100644
> --- a/ip/ipnetns.c
> +++ b/ip/ipnetns.c
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

Patch

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 633b5b9..ee06eba 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -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