Skip to content

Commit

Permalink
Merge pull request #65 from giuseppe/conmon-return-exit-code-container
Browse files Browse the repository at this point in the history
conmon: propagate error code from the container
  • Loading branch information
rhatdan authored Aug 19, 2019
2 parents a1cdfff + 74da3fb commit af8e5a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,32 @@ static void setup_oom_handling(int pid)

static void do_exit_command()
{
pid_t exit_pid;
gchar **args;
size_t n_args = 0;

if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
_pexit("Failed to reset signal for SIGCHLD");
}

exit_pid = fork();
if (exit_pid < 0) {
_pexit("Failed to fork");
}

if (exit_pid) {
int ret, exit_status = 0;

do
ret = waitpid(exit_pid, &exit_status, 0);
while (ret < 0 && errno == EINTR);

if (exit_status)
_exit(exit_status);

return;
}

/* Count the additional args, if any. */
if (opt_exit_args)
for (; opt_exit_args[n_args]; n_args++)
Expand Down Expand Up @@ -1655,5 +1678,5 @@ int main(int argc, char *argv[])
if (attach_symlink_dir_path != NULL && unlink(attach_symlink_dir_path) == -1 && errno != ENOENT)
pexit("Failed to remove symlink for attach socket directory");

return EXIT_SUCCESS;
return exit_status;
}
8 changes: 8 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ extern log_level_t log_level;
extern char *log_cid;
extern gboolean use_syslog;

#define _pexit(s) \
do { \
fprintf(stderr, "[conmon:e]: %s %s\n", s, strerror(errno)); \
if (use_syslog) \
syslog(LOG_ERR, "conmon %.20s <error>: %s %s\n", log_cid, s, strerror(errno)); \
_exit(EXIT_FAILURE); \
} while (0)

#define pexit(s) \
do { \
fprintf(stderr, "[conmon:e]: %s %s\n", s, strerror(errno)); \
Expand Down

0 comments on commit af8e5a6

Please sign in to comment.