Commit aa8c830d authored by unknown's avatar unknown
Browse files

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.
parent 8e0113be
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -37,18 +37,16 @@ sub mtr_get_pid_from_file ($) {
    open(FILE, '<', $pid_file_path)
      or mtr_error("can't open file \"$pid_file_path\": $!");

    # Read pid number from file
    my $pid= <FILE>;

    chomp($pid) if defined $pid;

    close FILE;

    return $pid if defined $pid && $pid ne '';
    return $pid if $pid=~ /^(\d+)/;

    mtr_debug("Pid file '$pid_file_path' is empty. " .
              "Sleeping $timeout second(s)...");
    mtr_debug("Pid file '$pid_file_path' does not yet contain pid number.\n" .
              "Sleeping $timeout second(s) more...");

    sleep(1);
    sleep($timeout);
  }

  mtr_error("Pid file '$pid_file_path' is corrupted. " .
+25 −15
Original line number Diff line number Diff line
@@ -438,6 +438,10 @@ sub mtr_kill_leftovers () {

    while ( my $elem= readdir(RUNDIR) )
    {
      # Only read pid from files that end with .pid
      if ( $elem =~ /.*[.]pid$/)
      {

	my $pidfile= "$rundir/$elem";

	if ( -f $pidfile )
@@ -459,6 +463,12 @@ sub mtr_kill_leftovers () {
	  }
	}
      }
      else
      {
	mtr_warning("Found non pid file $elem in $rundir");
	next;
      }
    }
    closedir(RUNDIR);

    if ( @pids )