Commit e437b4ba by Christian Brauner Committed by Stéphane Graber

conf: use lxc_preserve_ns()

parent e9f7729e
...@@ -2399,24 +2399,20 @@ static int setup_network(struct lxc_list *network) ...@@ -2399,24 +2399,20 @@ static int setup_network(struct lxc_list *network)
/* try to move physical nics to the init netns */ /* try to move physical nics to the init netns */
void lxc_restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf) void lxc_restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
{ {
int i, ret, oldfd; int i, oldfd;
char path[MAXPATHLEN];
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
if (netnsfd < 0 || conf->num_savednics == 0) if (netnsfd < 0 || conf->num_savednics == 0)
return; 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"); oldfd = lxc_preserve_ns(getpid(), "net");
if (ret < 0 || ret >= MAXPATHLEN) { if (oldfd < 0) {
WARN("Failed to open monitor netns fd"); SYSERROR("Failed to open monitor netns fd.");
return;
}
if ((oldfd = open(path, O_RDONLY)) < 0) {
SYSERROR("Failed to open monitor netns fd");
return; return;
} }
if (setns(netnsfd, 0) != 0) { if (setns(netnsfd, 0) != 0) {
SYSERROR("Failed to enter container netns to reset nics"); SYSERROR("Failed to enter container netns to reset nics");
close(oldfd); close(oldfd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment