* [PATCH] ip netns: Create /var/run/netns dir when do 'ip netns monitor'
@ 2014-08-31 19:45 Vadim Kochan
0 siblings, 0 replies; only message in thread
From: Vadim Kochan @ 2014-08-31 19:45 UTC (permalink / raw)
To: netdev; +Cc: Vadim Kochan
netns monitor fails when there is no /var/run/netns dir
which might be created later while monitoring.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
ip/ipnetns.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 7f82908..90a496f 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -383,6 +383,20 @@ static int netns_delete(int argc, char **argv)
return 0;
}
+static int create_netns_dir(void)
+{
+ /* Create the base netns directory if it doesn't exist */
+ 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;
+ }
+ }
+
+ return 0;
+}
+
static int netns_add(int argc, char **argv)
{
/* This function creates a new network namespace and
@@ -406,14 +420,8 @@ 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 */
- 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;
- }
- }
+ if (create_netns_dir())
+ return -1;
/* Make it possible for network namespace mounts to propagate between
* mount namespaces. This makes it likely that a unmounting a network
@@ -476,6 +484,10 @@ static int netns_monitor(int argc, char **argv)
strerror(errno));
return -1;
}
+
+ if (create_netns_dir())
+ return -1;
+
if (inotify_add_watch(fd, NETNS_RUN_DIR, IN_CREATE | IN_DELETE) < 0) {
fprintf(stderr, "inotify_add_watch failed: %s\n",
strerror(errno));
--
2.1.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2014-08-31 19:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-31 19:45 [PATCH] ip netns: Create /var/run/netns dir when do 'ip netns monitor' Vadim Kochan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).