@@ -66,7 +66,7 @@ static int usage(void)
exit(-1);
}
-int get_netns_fd(const char *name)
+static int get_netns_fd_flags(const char *name, int flags)
{
char pathbuf[MAXPATHLEN];
const char *path, *ptr;
@@ -78,7 +78,12 @@ int get_netns_fd(const char *name)
NETNS_RUN_DIR, name );
path = pathbuf;
}
- return open(path, O_RDONLY);
+ return open(path, flags);
+}
+
+int get_netns_fd(const char *name)
+{
+ return get_netns_fd_flags(name, O_RDONLY);
}
static int netns_list(int argc, char **argv)
@@ -135,7 +140,6 @@ static int netns_exec(int argc, char **argv)
* aware, and execute a program in that environment.
*/
const char *name, *cmd;
- char net_path[MAXPATHLEN];
int netns;
if (argc < 1) {
@@ -149,8 +153,7 @@ static int netns_exec(int argc, char **argv)
name = argv[0];
cmd = argv[1];
- snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
- netns = open(net_path, O_RDONLY | O_CLOEXEC);
+ netns = get_netns_fd_flags(name, O_RDONLY | O_CLOEXEC);
if (netns < 0) {
fprintf(stderr, "Cannot open network namespace \"%s\": %s\n",
name, strerror(errno));
Enabling "ip netns exec" to be run with a net namespace specified by a file path rather than a filename under /var/run/nets. Signed-off-by: Shahar Lev <shahar@stratoscale.com> --- ip/ipnetns.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)