The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3333
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 2f3cae9b7f074df164a4634676ca305290a62652 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Fri, 27 Mar 2020 21:25:59 +0100 Subject: [PATCH] conf: simplify userns_exec_minimal() Signed-off-by: Christian Brauner <christian.brau...@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,
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel