From 5566f232efe359d0c461cd9fb489e78afc3ccd95 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 31 Dec 2015 12:50:26 +0100 Subject: syslogd: add a watchdog to kill the process if it's stuck In case the syslogd process is stuck, causing a mark not to be sent, the next mark will detect the situation and will cause the process to die. In order to speed up the detection compared to the default 20 minutes mark interval, we arm the timer for 5 seconds when trying to send a mark. So in the worst case by default a stuck process could be detected after 20 minutes + 5 seconds. --- sysklogd/syslogd.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 7b400d1..d06794c 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -548,7 +548,23 @@ static void domark(int sig) { if (MarkInterval > 0) { pending_mark++; - alarm(MarkInterval); + if (pending_mark > 1) { +#ifdef CONFIG_FEATURE_IPC_SYSLOG + if (sem_owned(s_semid)) + sem_up(s_semid); +#endif + unlink(lfile); + if (pidFilePath) + unlink(pidFilePath); +#ifdef CONFIG_FEATURE_IPC_SYSLOG + ipcsyslog_cleanup(); +#endif + bb_error_msg_and_die("hung log daemon detected"); + } + /* check in 5 seconds max if we've made some progress. If + * not, we're stuck and have to die. + */ + alarm(5); } } @@ -719,6 +735,7 @@ static void doSyslogd(void) if (pending_mark > 0) { pending_mark = 0; + alarm(MarkInterval); logMessage(LOG_SYSLOG | LOG_INFO, "-- MARK --"); } -- 1.7.12.1