Skip to content

Commit

Permalink
WATCHDOG: log process termination to the journal
Browse files Browse the repository at this point in the history
This patch adds explicit system journal message in case process was
terminated by an internal watchdog.

Resolves: SSSD#5146
  • Loading branch information
alexey-tikhonov committed May 15, 2020
1 parent 1041e0c commit 936c50e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/monitor/monitor.c
Expand Up @@ -405,17 +405,34 @@ static int add_svc_conn_spy(struct mt_svc *svc)

static void svc_child_info(struct mt_svc *svc, int wait_status)
{
int exit_code = 0;
int pid = svc->pid;
const char *name = (svc->name ? svc->name : "");
const char *identity = (svc->identity ? svc->identity : "");

if (WIFEXITED(wait_status)) {
DEBUG(SSSDBG_OP_FAILURE,
"Child [%d] exited with code [%d]\n",
svc->pid, WEXITSTATUS(wait_status));
exit_code = WEXITSTATUS(wait_status);
if (exit_code == SSS_WATCHDOG_EXIT_CODE) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Child [%d] ('%s':'%s') was terminated by own WATCHDOG\n",
pid, name, identity);
sss_log(SSS_LOG_CRIT,
"Child [%d] ('%s':'%s') was terminated by own WATCHDOG. "
"Consult corresponding logs to figure out the reason.",
pid, name, identity);
} else {
DEBUG(SSSDBG_OP_FAILURE,
"Child [%d] ('%s':'%s') exited with code [%d]\n",
pid, name, identity, exit_code);
}
} else if (WIFSIGNALED(wait_status)) {
DEBUG(SSSDBG_OP_FAILURE,
"Child [%d] terminated with signal [%d]\n",
svc->pid, WTERMSIG(wait_status));
"Child [%d] ('%s':'%s') terminated with signal [%d]\n",
pid, name, identity, WTERMSIG(wait_status));
} else {
DEBUG(SSSDBG_FATAL_FAILURE,
"Child [%d] did not exit cleanly\n", svc->pid);
"Child [%d] ('%s':'%s') did not exit cleanly\n",
pid, name, identity);
/* Forcibly kill this child, just in case */
kill(svc->pid, SIGKILL);

Expand Down
2 changes: 2 additions & 0 deletions src/util/util.h
Expand Up @@ -103,6 +103,8 @@ extern int dbus_activated;
#define FLAGS_GEN_CONF 0x0008
#define FLAGS_NO_WATCHDOG 0x0010

#define SSS_WATCHDOG_EXIT_CODE 70 /* to match EX_SOFTWARE in sysexits.h */

#define PIPE_INIT { -1, -1 }

#define PIPE_FD_CLOSE(fd) do { \
Expand Down
2 changes: 1 addition & 1 deletion src/util/util_watchdog.c
Expand Up @@ -75,7 +75,7 @@ static void watchdog_handler(int sig)
if (getpid() == getpgrp()) {
kill(-getpgrp(), SIGTERM);
}
_exit(1);
_exit(SSS_WATCHDOG_EXIT_CODE);
}
}

Expand Down

0 comments on commit 936c50e

Please sign in to comment.