Bug #995896: Useless use of cat in Daemon.pm

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-06-06 14:19:27 -03:00
parent c2bb24befc
commit a0a42eebe8

View File

@@ -125,7 +125,7 @@ sub check_PID_file {
PTDEBUG && _d('Checking PID file', $PID_file);
if ( $PID_file && -f $PID_file ) {
my $pid;
eval { chomp($pid = `cat $PID_file`); };
eval { chomp($pid = slurp_file($PID_file)); };
die "Cannot cat $PID_file: $OS_ERROR" if $EVAL_ERROR;
PTDEBUG && _d('PID file exists; it contains PID', $pid);
if ( $pid ) {
@@ -221,6 +221,12 @@ sub DESTROY {
return;
}
sub slurp_file {
my ($file) = @_;
open my $fh, "<", $file or die "Couldn't slurp file: $!";
return do { local $/; <$fh> };
}
sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }