The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2499
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 10dae10520fea5b479d1e73eb477c857b10fdc37 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Sun, 29 Jul 2018 22:59:37 +0200 Subject: [PATCH 1/6] cmd: s/pipe()/pipe2()/g Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/cmd/lxc_usernsexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c index 1426eed5d..427721ad8 100644 --- a/src/lxc/cmd/lxc_usernsexec.c +++ b/src/lxc/cmd/lxc_usernsexec.c @@ -360,7 +360,7 @@ int main(int argc, char *argv[]) if (argc < 1) argv = default_args; - if (pipe(pipe1) < 0 || pipe(pipe2) < 0) { + if (pipe2(pipe1, O_CLOEXEC) < 0 || pipe2(pipe2, O_CLOEXEC) < 0) { perror("pipe"); exit(EXIT_FAILURE); } From 5ea8cead29703daff461f671e07bc2d911b8e75a Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Sun, 29 Jul 2018 23:02:14 +0200 Subject: [PATCH 2/6] conf: s/pipe()/pipe2()/g Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index ff9bd091b..e55c40bf2 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -4359,7 +4359,7 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data, if (!idmap) return -1; - ret = pipe(p); + ret = pipe2(p, O_CLOEXEC); if (ret < 0) { SYSERROR("Failed to create pipe"); return -1; @@ -4441,7 +4441,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data, if (!conf) return -EINVAL; - ret = pipe(p); + ret = pipe2(p, O_CLOEXEC); if (ret < 0) { SYSERROR("opening pipe"); return -1; From ac376979c5a6cbf7aed5ca0ed0aa3b53ecee614f Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Sun, 29 Jul 2018 23:03:32 +0200 Subject: [PATCH 3/6] conf: always close pipe in run_userns_fn() Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/conf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index e55c40bf2..f4a95be79 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -4121,6 +4121,7 @@ struct userns_fn_data { static int run_userns_fn(void *data) { + int ret; char c; struct userns_fn_data *d = data; @@ -4130,14 +4131,14 @@ static int run_userns_fn(void *data) /* Wait for parent to finish establishing a new mapping in the user * namespace we are executing in. */ - if (lxc_read_nointr(d->p[0], &c, 1) != 1) - return -1; - + ret = lxc_read_nointr(d->p[0], &c, 1); /* Close read end of the pipe. */ close(d->p[0]); + if (ret != 1) + return -1; if (d->fn_name) - TRACE("calling function \"%s\"", d->fn_name); + TRACE("Calling function \"%s\"", d->fn_name); /* Call function to run. */ return d->fn(d->arg); From e558f94e14c481aa3a3fd68059197255ff65f392 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Sun, 29 Jul 2018 23:07:33 +0200 Subject: [PATCH 4/6] criu: s/pipe()/pipe2()/ Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/criu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/criu.c b/src/lxc/criu.c index 64ea4f024..ac4805aa6 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -988,7 +988,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ goto out_fini_handler; } - if (pipe(pipes) < 0) { + if (pipe2(pipes, O_CLOEXEC) < 0) { SYSERROR("pipe() failed"); goto out_fini_handler; } From 2d30d32034c8e9719f6b98449888fad0191a1fe9 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Sun, 29 Jul 2018 23:09:13 +0200 Subject: [PATCH 5/6] lxccontainer: cleanup do_lxcapi_get_interfaces() Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/lxccontainer.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index c5b515f60..98e260cfd 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -2292,21 +2292,19 @@ static bool remove_from_array(char ***names, char *cname, int size) return false; } -static char ** do_lxcapi_get_interfaces(struct lxc_container *c) +static char **do_lxcapi_get_interfaces(struct lxc_container *c) { pid_t pid; int i, count = 0, pipefd[2]; char **interfaces = NULL; char interface[IFNAMSIZ]; - if(pipe(pipefd) < 0) { - SYSERROR("pipe failed"); + if (pipe(pipefd) < 0) return NULL; - } pid = fork(); if (pid < 0) { - SYSERROR("failed to fork task to get interfaces information"); + SYSERROR("Failed to fork task to get interfaces information"); close(pipefd[0]); close(pipefd[1]); return NULL; @@ -2320,23 +2318,23 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c) close(pipefd[0]); if (!enter_net_ns(c)) { - SYSERROR("failed to enter namespace"); + SYSERROR("Failed to enter network namespace"); goto out; } /* Grab the list of interfaces */ if (getifaddrs(&interfaceArray)) { - SYSERROR("failed to get interfaces list"); + SYSERROR("Failed to get interfaces list"); goto out; } /* Iterate through the interfaces */ - for (tempIfAddr = interfaceArray; tempIfAddr != NULL; tempIfAddr = tempIfAddr->ifa_next) { + for (tempIfAddr = interfaceArray; tempIfAddr != NULL; + tempIfAddr = tempIfAddr->ifa_next) { nbytes = write(pipefd[1], tempIfAddr->ifa_name, IFNAMSIZ); - if (nbytes < 0) { - ERROR("write failed"); + if (nbytes < 0) goto out; - } + count++; } @@ -2358,16 +2356,16 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c) interface[IFNAMSIZ - 1] = '\0'; if (array_contains(&interfaces, interface, count)) - continue; + continue; - if(!add_to_array(&interfaces, interface, count)) + if (!add_to_array(&interfaces, interface, count)) ERROR("Failed to add \"%s\" to array", interface); count++; } if (wait_for_pid(pid) != 0) { - for(i=0;i<count;i++) + for (i = 0; i < count; i++) free(interfaces[i]); free(interfaces); @@ -2378,7 +2376,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c) close(pipefd[0]); /* Append NULL to the array */ - if(interfaces) + if (interfaces) interfaces = (char **)lxc_append_null_to_array((void **)interfaces, count); return interfaces; From 7ae732186b1565a5912a83f5988f8a85128439d2 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Sun, 29 Jul 2018 23:09:45 +0200 Subject: [PATCH 6/6] lxccontainer: s/pipe()/pipe2()/g Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/lxccontainer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 98e260cfd..5912a76ba 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -2299,7 +2299,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c) char **interfaces = NULL; char interface[IFNAMSIZ]; - if (pipe(pipefd) < 0) + if (pipe2(pipefd, O_CLOEXEC) < 0) return NULL; pid = fork(); @@ -2394,7 +2394,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface, int count = 0; char **addresses = NULL; - ret = pipe(pipefd); + ret = pipe2(pipefd, O_CLOEXEC); if (ret < 0) { SYSERROR("Failed to create pipe"); return NULL;
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel