[lxc-devel] [lxc/master] conf: simplify userns_exec_minimal()

brauner on Github lxc-bot at linuxcontainers.org
Fri Mar 27 20:26:59 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200327/e51f87fa/attachment.bin>
-------------- next part --------------
From 2f3cae9b7f074df164a4634676ca305290a62652 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 27 Mar 2020 21:25:59 +0100
Subject: [PATCH] conf: simplify userns_exec_minimal()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/conf.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 9e106b1006..43ce26b658 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4123,14 +4123,13 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data,
 int userns_exec_minimal(const struct lxc_conf *conf, int (*fn)(void *), void *data)
 {
 	call_cleaner(lxc_free_idmap) struct lxc_list *idmap = NULL;
-	int ret = -1, status = -1;
-	ssize_t rret;
 	char c = '1';
+	ssize_t ret;
 	pid_t pid;
 	int sock_fds[2];
 
-	if (!conf)
-		return -EINVAL;
+	if (!conf || !fn || !data)
+		return ret_errno(EINVAL);
 
 	idmap = get_minimal_idmap(conf);
 	if (!idmap)
@@ -4142,7 +4141,7 @@ int userns_exec_minimal(const struct lxc_conf *conf, int (*fn)(void *), void *da
 
 	pid = fork();
 	if (pid < 0) {
-		ERROR("Failed to clone process in new user namespace");
+		SYSERROR("Failed to create new process");
 		goto on_error;
 	}
 
@@ -4153,8 +4152,8 @@ int userns_exec_minimal(const struct lxc_conf *conf, int (*fn)(void *), void *da
 		if (ret < 0)
 			_exit(EXIT_FAILURE);
 
-		rret = lxc_write_nointr(sock_fds[0], &c, 1);
-		if (rret != 1)
+		ret = lxc_write_nointr(sock_fds[0], &c, 1);
+		if (ret != 1)
 			_exit(EXIT_FAILURE);
 
 		ret = lxc_read_nointr(sock_fds[0], &c, 1);
@@ -4215,13 +4214,10 @@ int userns_exec_minimal(const struct lxc_conf *conf, int (*fn)(void *), void *da
 	close_prot_errno_disarm(sock_fds[1]);
 
 	/* Wait for child to finish. */
-	if (pid > 0)
-		status = wait_for_pid(pid);
-
-	if (status < 0)
-		ret = -1;
+	if (pid < 0)
+		return -1;
 
-	return ret;
+	return wait_for_pid(pid);
 }
 
 int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,


More information about the lxc-devel mailing list