lxc/0097-lxc-report-error-when-fork-exec-error-for-hooks.patch

73 lines
2.5 KiB
Diff
Raw Normal View History

From 8f74f51e2ea6fb316d99af96f091e35b105402ca Mon Sep 17 00:00:00 2001
2019-09-30 11:03:07 -04:00
From: tanyifeng <tanyifeng1@huawei.com>
Date: Wed, 15 May 2019 00:53:49 -0400
Subject: [PATCH 097/139] lxc: report error when fork/exec error for hooks
2019-09-30 11:03:07 -04:00
Signed-off-by: tanyifeng <tanyifeng1@huawei.com>
Signed-off-by: LiFeng <lifeng68@huawei.com>
---
src/lxc/conf.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 6cf86a4..341fdab 100644
2019-09-30 11:03:07 -04:00
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4559,21 +4559,12 @@ static struct lxc_popen_FILE *lxc_popen_ocihook(char *commandpath, char **args,
goto on_error;
if (child_pid == 0) {
- /* child */
- int inherit_fds[2] = {
- pipe_msg[0], pipe_fds[1]
- };
- if (lxc_check_inherited(NULL, true, inherit_fds, 2) != 0) {
- SYSERROR("check inherited fd failed");
- exit(127);
- }
-
close(pipe_msg[1]);
if (pipe_msg[0] != STDIN_FILENO)
dup2(pipe_msg[0], STDIN_FILENO);
else {
if (fcntl(pipe_msg[0], F_SETFD, 0) != 0) {
- SYSERROR("Failed to remove FD_CLOEXEC from fd.");
+ fprintf(stderr, "Failed to remove FD_CLOEXEC from fd.");
exit(127);
}
}
@@ -4600,6 +4591,11 @@ static struct lxc_popen_FILE *lxc_popen_ocihook(char *commandpath, char **args,
if (ret < 0)
_exit(EXIT_FAILURE);
+ if (lxc_check_inherited(NULL, true, NULL, 0) != 0) {
+ fprintf(stderr, "check inherited fd failed");
+ exit(127);
+ }
+
/*
* Unblock signals.
* This is the main/only reason
@@ -4615,6 +4611,7 @@ static struct lxc_popen_FILE *lxc_popen_ocihook(char *commandpath, char **args,
execvpe(commandpath, args, envs);
else
execvp(commandpath, args);
+ fprintf(stderr, "fork/exec %s: %s", commandpath, strerror(errno));
exit(127);
}
@@ -4764,8 +4761,8 @@ static int run_ocihook_buffer(struct oci_hook_conf *oconf, char *inmsg)
SYSERROR("Script exited with error.");
goto print_hook;
} else if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0) {
- ERROR("Script exited with status %d. output:%s", WEXITSTATUS(ret), output);
- lxc_write_error_message(conf->errfd, "%s:%d: running %s hook caused \"error running hook: exit status %d, output:%s\".",
+ ERROR("Script exited with status %d. output: %s", WEXITSTATUS(ret), output);
+ lxc_write_error_message(conf->errfd, "%s:%d: running %s hook caused \"error running hook: exit status %d, output: %s\".",
__FILE__, __LINE__,
(conf->which >= NUM_LXC_HOOKS) ? "invalid type" : lxchook_names[conf->which],
WEXITSTATUS(ret), output);
--
1.8.3.1
2019-09-30 11:03:07 -04:00