From a75f0fa8bc43bbc34b7b2b71995d030dcd7d7305 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Fri, 24 Feb 2017 14:31:33 +0300 Subject: [PATCH] ns: Simplify create_net_ns() Merge code with the same functionality in one Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- criu/net.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/criu/net.c b/criu/net.c index 147ad3dff..d29ef6c56 100644 --- a/criu/net.c +++ b/criu/net.c @@ -1953,6 +1953,19 @@ static int open_net_ns(struct ns_id *nsid) return 0; } +static int do_create_net_ns(struct ns_id *ns) +{ + if (unshare(CLONE_NEWNET)) { + pr_perror("Unable to create a new netns"); + return -1; + } + if (prepare_net_ns(ns->id)) + return -1; + if (open_net_ns(ns)) + return -1; + return 0; +} + int prepare_net_namespaces() { struct ns_id *nsid; @@ -1964,15 +1977,7 @@ int prepare_net_namespaces() if (nsid->nd != &net_ns_desc) continue; - if (unshare(CLONE_NEWNET)) { - pr_perror("Unable to create a new netns"); - goto err; - } - - if (prepare_net_ns(nsid->id)) - goto err; - - if (open_net_ns(nsid)) + if (do_create_net_ns(nsid)) goto err; }