Improve the reading of .pid files from var/run
- Only read *.pid - Only allow it to contain a number mysql-test/lib/mtr_io.pl: Check that the value read from pidfile is a valid number consisting only of digits mysql-test/lib/mtr_process.pl: Only process .pid files in var/run dir and print a warning if other files are found there.
This commit is contained in:
parent
8e0113be8c
commit
aa8c830d9b
@ -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,25 +438,35 @@ sub mtr_kill_leftovers () {
|
|||||||
|
|
||||||
while ( my $elem= readdir(RUNDIR) )
|
while ( my $elem= readdir(RUNDIR) )
|
||||||
{
|
{
|
||||||
my $pidfile= "$rundir/$elem";
|
# Only read pid from files that end with .pid
|
||||||
|
if ( $elem =~ /.*[.]pid$/)
|
||||||
if ( -f $pidfile )
|
|
||||||
{
|
{
|
||||||
mtr_debug("Processing PID file: '$pidfile'...");
|
|
||||||
|
|
||||||
my $pid= mtr_get_pid_from_file($pidfile);
|
my $pidfile= "$rundir/$elem";
|
||||||
|
|
||||||
mtr_debug("Got pid: $pid from file '$pidfile'");
|
if ( -f $pidfile )
|
||||||
|
{
|
||||||
|
mtr_debug("Processing PID file: '$pidfile'...");
|
||||||
|
|
||||||
if ( $::glob_cygwin_perl or kill(0, $pid) )
|
my $pid= mtr_get_pid_from_file($pidfile);
|
||||||
{
|
|
||||||
mtr_debug("There is process with pid $pid -- scheduling for kill.");
|
mtr_debug("Got pid: $pid from file '$pidfile'");
|
||||||
push(@pids, $pid); # We know (cygwin guess) it exists
|
|
||||||
}
|
if ( $::glob_cygwin_perl or kill(0, $pid) )
|
||||||
else
|
{
|
||||||
{
|
mtr_debug("There is process with pid $pid -- scheduling for kill.");
|
||||||
mtr_debug("There is no process with pid $pid -- skipping.");
|
push(@pids, $pid); # We know (cygwin guess) it exists
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mtr_debug("There is no process with pid $pid -- skipping.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mtr_warning("Found non pid file $elem in $rundir");
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(RUNDIR);
|
closedir(RUNDIR);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user