]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_user_nic: use lxc_preserve_ns()
authorChristian Brauner <christian.brauner@canonical.com>
Fri, 28 Oct 2016 08:48:20 +0000 (10:48 +0200)
committerChristian Brauner <christian.brauner@canonical.com>
Sat, 19 Nov 2016 04:11:28 +0000 (05:11 +0100)
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/lxc_user_nic.c

index 0cb38ba0b02e241f18735fa604f7d8259acf1426..409a53a16cde0154bcdc4f718d62532e539c8ed3 100644 (file)
@@ -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;