Improve the reading of .pid files from var/run

 - Only read *.pid
 - Only allow it to contain a number 
parent 64eb6553
...@@ -37,18 +37,16 @@ sub mtr_get_pid_from_file ($) { ...@@ -37,18 +37,16 @@ sub mtr_get_pid_from_file ($) {
open(FILE, '<', $pid_file_path) open(FILE, '<', $pid_file_path)
or mtr_error("can't open file \"$pid_file_path\": $!"); or mtr_error("can't open file \"$pid_file_path\": $!");
# Read pid number from file
my $pid= <FILE>; my $pid= <FILE>;
chomp($pid) if defined $pid;
close FILE; close FILE;
return $pid if defined $pid && $pid ne ''; return $pid if $pid=~ /^(\d+)/;
mtr_debug("Pid file '$pid_file_path' is empty. " . mtr_debug("Pid file '$pid_file_path' does not yet contain pid number.\n" .
"Sleeping $timeout second(s)..."); "Sleeping $timeout second(s) more...");
sleep(1); sleep($timeout);
} }
mtr_error("Pid file '$pid_file_path' is corrupted. " . mtr_error("Pid file '$pid_file_path' is corrupted. " .
......
...@@ -438,6 +438,10 @@ sub mtr_kill_leftovers () { ...@@ -438,6 +438,10 @@ sub mtr_kill_leftovers () {
while ( my $elem= readdir(RUNDIR) ) while ( my $elem= readdir(RUNDIR) )
{ {
# Only read pid from files that end with .pid
if ( $elem =~ /.*[.]pid$/)
{
my $pidfile= "$rundir/$elem"; my $pidfile= "$rundir/$elem";
if ( -f $pidfile ) if ( -f $pidfile )
...@@ -459,6 +463,12 @@ sub mtr_kill_leftovers () { ...@@ -459,6 +463,12 @@ sub mtr_kill_leftovers () {
} }
} }
} }
else
{
mtr_warning("Found non pid file $elem in $rundir");
next;
}
}
closedir(RUNDIR); closedir(RUNDIR);
if ( @pids ) if ( @pids )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment