fixed a bug in 'fs' module that could kill Monitorix itself if open() couldn't fork()

This commit is contained in:
Jordi Sanfeliu 2014-04-22 11:08:12 +02:00
parent 6295cf7bbd
commit 3540b58718
1 changed files with 18 additions and 6 deletions

View File

@ -387,8 +387,12 @@ sub fs_init {
my $pid;
eval {
local $SIG{'ALRM'} = sub {
kill 9, $pid;
logger("$myself: Timeout! Process with PID $pid was hung after $config->{timeout} secs. Killed.");
if($pid) {
logger("$myself: Timeout! Process with PID '$pid' still hung after $config->{timeout} secs. Killed.");
kill 9, $pid;
} else {
logger("$myself: WARNING: \$pid has no value ('$pid') in ALRM sighandler.");
}
};
alarm($config->{timeout});
$pid = open(IN, "df -P $f |");
@ -621,8 +625,12 @@ sub fs_update {
my $pid;
eval {
local $SIG{'ALRM'} = sub {
kill 9, $pid;
logger("$myself: Timeout! Process with PID $pid was hung after $config->{timeout} secs. Killed.");
if($pid) {
logger("$myself: Timeout! Process with PID '$pid' still hung after $config->{timeout} secs. Killed.");
kill 9, $pid;
} else {
logger("$myself: WARNING: \$pid has no value ('$pid') in ALRM sighandler.");
}
@tmp = (0, 0, 0, 0);
};
alarm($config->{timeout});
@ -643,8 +651,12 @@ sub fs_update {
eval {
local $SIG{'ALRM'} = sub {
kill 9, $pid;
logger("$myself: Timeout! Process with PID $pid was hung after $config->{timeout} secs. Killed.");
if($pid) {
logger("$myself: Timeout! Process with PID '$pid' still hung after $config->{timeout} secs. Killed.");
kill 9, $pid;
} else {
logger("$myself: WARNING: \$pid has no value ('$pid') in ALRM sighandler.");
}
@tmp = (0, 0, 0, 0, 0, 0, 0);
};
alarm($config->{timeout});