Module: check_mk
Branch: master
Commit: f2ed72b6af671f3a674df3b8adb8fdcd78c681a5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f2ed72b6af671f…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Oct 18 12:13:06 2012 +0200
livecheck: FIX freeze if called plugin locks up
---
ChangeLog | 2 ++
livestatus/src/livecheck.c | 19 ++++++++++---------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 29fad82..d3b1a3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -98,6 +98,8 @@
* FIX: changed check_type to be always active (0)
* FIX: fix bug in assignment of livecheck helpers
* FIX: close inherited unused filedescriptors after fork()
+ * FIX: kill process group of called plugin if timeout is reached
+ -> preventing possible freeze of livecheck
Checks & Agents:
* FIX: Linux mk_logwatch: iregex Parameter was never used
diff --git a/livestatus/src/livecheck.c b/livestatus/src/livecheck.c
index ff3f369..9659404 100644
--- a/livestatus/src/livecheck.c
+++ b/livestatus/src/livecheck.c
@@ -34,9 +34,9 @@
#include "strutil.h"
pid_t g_pid;
-void alarm_handler(int);
-void term_handler(int);
-char **parse_into_arguments(char *command);
+static void alarm_handler(int);
+static void term_handler(int);
+static char **parse_into_arguments(char *command);
int check_icmp(int argc, char **argv, char *output);
int icmp_sock = -1;
@@ -83,7 +83,6 @@ int main(int argc, char **argv)
ftime(&start);
char output[8192];
int return_code;
-
// Optimization(1):
// If it's check_icmp, we use our inline version
// of that. But only if we have (had) root priviledges
@@ -105,6 +104,10 @@ int main(int argc, char **argv)
if (geteuid() == 0)
setuid(getuid());
+ // Assign this child its own process group, so
+ // we can kill its entire process group when a timeout occurs
+ setpgid(getpid(), 0);
+
close(fd[0]); // close read end
dup2(fd[1], 1); // point stdout into pipe
dup2(fd[1], 2); // also point stderr into pipe
@@ -150,7 +153,6 @@ int main(int argc, char **argv)
if (timeout)
alarm(timeout);
-
int bytes_read = 0;
char *ptr_output = output;
const char *ptr_end = output + sizeof(output) - 1;
@@ -214,7 +216,6 @@ int main(int argc, char **argv)
(int)end.time,
end.millitm,
return_code);
-
char *ptr_output = output;
char *ptr_walk = output;
while (*ptr_walk != 0) {
@@ -239,7 +240,7 @@ int main(int argc, char **argv)
}
}
-char **parse_into_arguments(char *command)
+static char **parse_into_arguments(char *command)
{
static char *arguments[128];
char *c = command;
@@ -255,7 +256,7 @@ char **parse_into_arguments(char *command)
}
// Propagate signal to child, if we are killed
-void term_handler(int signum)
+static void term_handler(int signum)
{
if (g_pid) {
kill(g_pid, signum);
@@ -267,6 +268,6 @@ void term_handler(int signum)
void alarm_handler(int signum)
{
if (g_pid) {
- kill(g_pid, SIGKILL);
+ kill(-g_pid, SIGKILL);
}
}