]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: use lxc_preserve_ns()
authorChristian Brauner <christian.brauner@canonical.com>
Thu, 27 Oct 2016 12:39:45 +0000 (14:39 +0200)
committerChristian Brauner <christian.brauner@canonical.com>
Sat, 19 Nov 2016 04:11:23 +0000 (05:11 +0100)
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/conf.c

index 4f21f53995d7c83bfd70597a6b88a0dc55643f41..4c11161e6243181c7f24a0f59c04fd4032d6e9ef 100644 (file)
@@ -2399,24 +2399,20 @@ static int setup_network(struct lxc_list *network)
 /* try to move physical nics to the init netns */
 void lxc_restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
 {
-       int i, ret, oldfd;
-       char path[MAXPATHLEN];
+       int i, oldfd;
        char ifname[IFNAMSIZ];
 
        if (netnsfd < 0 || conf->num_savednics == 0)
                return;
 
-       INFO("running to reset %d nic names", conf->num_savednics);
+       INFO("Running to reset %d nic names.", conf->num_savednics);
 
-       ret = snprintf(path, MAXPATHLEN, "/proc/self/ns/net");
-       if (ret < 0 || ret >= MAXPATHLEN) {
-               WARN("Failed to open monitor netns fd");
-               return;
-       }
-       if ((oldfd = open(path, O_RDONLY)) < 0) {
-               SYSERROR("Failed to open monitor netns fd");
+       oldfd = lxc_preserve_ns(getpid(), "net");
+       if (oldfd < 0) {
+               SYSERROR("Failed to open monitor netns fd.");
                return;
        }
+
        if (setns(netnsfd, 0) != 0) {
                SYSERROR("Failed to enter container netns to reset nics");
                close(oldfd);