[CRIU] [PATCH 10/14] namespace: Group unlocking/closing operations in do_create_pid_ns_helper()

Kirill Tkhai ktkhai at virtuozzo.com
Mon May 15 06:05:51 PDT 2017


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 <ktkhai at virtuozzo.com>
---
 criu/namespaces.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 9665107eb..74c0ad7f4 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -2621,7 +2621,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;
@@ -2675,19 +2675,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)



More information about the CRIU mailing list