Skip to content

Commit

Permalink
net: set the root net ns after restoring all namespaces
Browse files Browse the repository at this point in the history
Then we will create transport sockets and we want to know where
they will be created.

Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
  • Loading branch information
avagin committed Mar 29, 2017
1 parent 9a38c50 commit 9e97e6d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions criu/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,10 @@ static int prepare_net_ns_second_stage(struct ns_id *ns)
ns->net.nsfd_id = fdstore_add(fd);
if (ns->net.nsfd_id < 0)
ret = -1;
close(fd);

/* fd for the root is closed in prepare_net_namespaces() */
if (ns->type != NS_ROOT)
close(fd);
}

ns->ns_populated = true;
Expand Down Expand Up @@ -2094,7 +2097,7 @@ static int create_net_ns(void *arg)
int prepare_net_namespaces()
{
struct ns_id *nsid;
int ret = -1;
int ret = -1, rst = -1;

if (!(root_ns_mask & CLONE_NEWNET))
return 0;
Expand Down Expand Up @@ -2137,6 +2140,9 @@ int prepare_net_namespaces()
if (nsid->nd != &net_ns_desc)
continue;

if (nsid->type == NS_ROOT)
rst = nsid->net.ns_fd;

if (switch_ns_by_fd(nsid->net.ns_fd, &net_ns_desc, NULL))
goto err;

Expand All @@ -2146,11 +2152,20 @@ int prepare_net_namespaces()
close_safe(&nsid->net.nlsk);
}

if (rst < 0) {
pr_err("Unable to find the root net namespace");
goto err;
}

if (switch_ns_by_fd(rst, &net_ns_desc, NULL))
goto err;

close_service_fd(NS_FD_OFF);
ret = 0;
err:
if (ret)
pr_err("Can't create net_ns\n");
close_safe(&rst);

return ret;
}
Expand Down

0 comments on commit 9e97e6d

Please sign in to comment.