From a90aad23a484efa69cdc81e276b22e3782d1b01b Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Tue, 16 May 2017 19:26:53 +0300 Subject: [PATCH] namespace: Group unlocking/closing operations in do_create_pid_ns_helper() Group them for 1)error and 2)parent cases. This minimize the code and will be used in next patches. Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- criu/namespaces.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/criu/namespaces.c b/criu/namespaces.c index 811492b80..fab5ca733 100644 --- a/criu/namespaces.c +++ b/criu/namespaces.c @@ -2627,7 +2627,7 @@ static int pid_ns_helper(struct ns_id *ns, int sk) static int do_create_pid_ns_helper(void *arg, int sk, pid_t unused_pid) { - int pid_ns_fd, mnt_ns_fd, i, lock_fd, transport_fd; + int pid_ns_fd, mnt_ns_fd, i, lock_fd, transport_fd, saved_errno; struct pstree_item *ns_reaper; struct ns_id *ns, *tmp; struct pid *pid; @@ -2681,19 +2681,20 @@ static int do_create_pid_ns_helper(void *arg, int sk, pid_t unused_pid) goto err; } child = fork(); - if (child < 0) { - flock(lock_fd, LOCK_UN); - close(lock_fd); - pr_perror("Can't fork"); - return -1; - } else if (!child) { + if (!child) { close(lock_fd); exit(pid_ns_helper(ns, sk)); } - close(sk); - futex_set_and_wake(&ns->pid.helper_created, 1); + saved_errno = errno; flock(lock_fd, LOCK_UN); close(lock_fd); + if (child < 0) { + errno = saved_errno; + pr_perror("Can't fork"); + goto err; + } + close(sk); + futex_set_and_wake(&ns->pid.helper_created, 1); pid->real = child; if (restore_ns(pid_ns_fd, &pid_ns_desc) < 0)