~percona-toolkit-dev/percona-toolkit/fix-1062563-1063912-ptc-pxc-bugs

« back to all changes in this revision

Viewing changes to bin/pt-trend

Merge fix-995896-cat-in-daemon

Show diffs side-by-side

added added

removed removed

Lines of Context:
1148
1148
   PTDEBUG && _d('Checking PID file', $PID_file);
1149
1149
   if ( $PID_file && -f $PID_file ) {
1150
1150
      my $pid;
1151
 
      eval { chomp($pid = `cat $PID_file`); };
1152
 
      die "Cannot cat $PID_file: $OS_ERROR" if $EVAL_ERROR;
 
1151
      eval {
 
1152
         chomp($pid = (slurp_file($PID_file) || ''));
 
1153
      };
 
1154
      if ( $EVAL_ERROR ) {
 
1155
         die "The PID file $PID_file already exists but it cannot be read: "
 
1156
            . $EVAL_ERROR;
 
1157
      }
1153
1158
      PTDEBUG && _d('PID file exists; it contains PID', $pid);
1154
1159
      if ( $pid ) {
1155
1160
         my $pid_is_alive = kill 0, $pid;
1226
1231
   return;
1227
1232
}
1228
1233
 
 
1234
sub slurp_file {
 
1235
   my ($file) = @_;
 
1236
   return unless $file;
 
1237
   open my $fh, "<", $file or die "Cannot open $file: $OS_ERROR";
 
1238
   return do { local $/; <$fh> };
 
1239
}
 
1240
 
1229
1241
sub _d {
1230
1242
   my ($package, undef, $line) = caller 0;
1231
1243
   @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }