Module: check_mk
Branch: master
Commit: 84730d34a011306f3f7495c2eecd042113b65474
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=84730d34a01130…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Nov 24 13:43:40 2015 +0100
Make sure SIGALRM can be delivered. Check fork() for errors.
---
agents/waitmax.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/agents/waitmax.c b/agents/waitmax.c
index c4ce4c7..0a1cf4c 100644
--- a/agents/waitmax.c
+++ b/agents/waitmax.c
@@ -92,6 +92,15 @@ static void signalhandler(int signum __attribute__((__unused__)))
if (kill(g_pid, g_signum) == 0) g_timeout = 1;
}
+static void unblock_signal(int signum)
+{
+ sigset_t signals_to_unblock;
+ sigemptyset(&signals_to_unblock);
+ sigaddset(&signals_to_unblock, signum);
+ if (sigprocmask(SIG_UNBLOCK, &signals_to_unblock, NULL) == -1)
+ exit_with("sigprocmask failed", errno, 1);
+}
+
static struct option long_options[] = {{"version", no_argument, 0,
'V'},
{"help", no_argument, 0, 'h'},
{"signal", required_argument, 0,
's'},
@@ -124,12 +133,16 @@ int main(int argc, char **argv)
if (maxtime <= 0) usage(1);
g_pid = fork();
+ if (g_pid == -1) exit_with("fork() failed", errno, 1);
+
if (g_pid == 0) {
signal(SIGALRM, signalhandler);
execvp(argv[optind + 1], argv + optind + 1);
exit_with(argv[optind + 1], errno, 253);
}
+ /* Make sure SIGALRM is not blocked (e.g. by parent). */
+ unblock_signal(SIGALRM);
signal(SIGALRM, signalhandler);
alarm(maxtime);