Commit 2754edba authored by msvensson@shellback.(none)'s avatar msvensson@shellback.(none)
Browse files

Improve the reading of .pid files from var/run

 - Only read *.pid
 - Only allow it to contain a number 
parent 64eb6553
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 )