From 386ea470d2371fb7916135e801e0d7f5e3c5b8fa Mon Sep 17 00:00:00 2001 From: tanyifeng Date: Wed, 15 May 2019 00:53:49 -0400 Subject: [PATCH 097/138] lxc: report error when fork/exec error for hooks Signed-off-by: tanyifeng Signed-off-by: LiFeng --- 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 --- 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