From: Christian Brauner Date: Fri, 28 Oct 2016 08:48:20 +0000 (+0200) Subject: lxc_user_nic: use lxc_preserve_ns() X-Git-Tag: lxc-2.1.0~260^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d04811edfe9b9ef9aac6fb645560202575b96b8;p=thirdparty%2Flxc.git lxc_user_nic: use lxc_preserve_ns() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c index 0cb38ba0b..409a53a16 100644 --- a/src/lxc/lxc_user_nic.c +++ b/src/lxc/lxc_user_nic.c @@ -673,25 +673,21 @@ again: static int rename_in_ns(int pid, char *oldname, char **newnamep) { - char nspath[MAXPATHLEN]; int fd = -1, ofd = -1, ret, ifindex = -1; bool grab_newname = false; - ret = snprintf(nspath, MAXPATHLEN, "/proc/%d/ns/net", getpid()); - if (ret < 0 || ret >= MAXPATHLEN) - return -1; - if ((ofd = open(nspath, O_RDONLY)) < 0) { - fprintf(stderr, "Opening %s\n", nspath); + ofd = lxc_preserve_ns(getpid(), "net"); + if (ofd < 0) { + fprintf(stderr, "Failed opening network namespace path for '%d'.", getpid()); return -1; } - ret = snprintf(nspath, MAXPATHLEN, "/proc/%d/ns/net", pid); - if (ret < 0 || ret >= MAXPATHLEN) - goto out_err; - if ((fd = open(nspath, O_RDONLY)) < 0) { - fprintf(stderr, "Opening %s\n", nspath); - goto out_err; + fd = lxc_preserve_ns(pid, "net"); + if (fd < 0) { + fprintf(stderr, "Failed opening network namespace path for '%d'.", pid); + return -1; } + if (setns(fd, 0) < 0) { fprintf(stderr, "setns to container network namespace\n"); goto out_err;