Commit 0d6f9f8b authored by Christoph Berg's avatar Christoph Berg

pg_ctlcluster, PgCommon.pm: Fix warning on corrupt empty pid files.

parent f6f0aa06
......@@ -541,6 +541,7 @@ sub read_pidfile {
if (open PIDFILE, $_[0]) {
my $pid = <PIDFILE>;
close PIDFILE;
return undef unless ($pid);
chomp $pid;
($pid) = $pid =~ /^(\d+)\s*$/; # untaint
return $pid;
......
postgresql-common (159) UNRELEASED; urgency=medium
* pg_ctlcluster, PgCommon.pm: Fix warning on corrupt empty pid files.
* Debconf translation updates, thanks!
+ da by Joe Dalton. (Closes: #753952)
......
......@@ -45,12 +45,14 @@ sub check_valid_config {
# Return the PID from an existing PID file or undef if it does not exist.
# Arguments: <pid file path>
# TODO: Replace with read_pidfile
sub get_running_pid {
return undef unless -e $_[0];
if (open PIDFILE, $_[0]) {
my $pid = <PIDFILE>;
close PIDFILE;
return undef unless ($pid);
chomp $pid;
($pid) = $pid =~ /^(\d+)\s*$/; # untaint
return $pid;
......
......@@ -6,7 +6,7 @@ require File::Temp;
use lib 't';
use TestLib;
use Test::More tests => 155;
use Test::More tests => 158;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -160,6 +160,12 @@ is_program_out 'postgres', "pg_ctlcluster --force $version main stop", 2,
'pg_ctlcluster --force stop succeeds with stale PID file';
ok (! -e $pf, 'pid file was cleaned up');
create_pidfile '';
is_program_out 'postgres', "pg_ctlcluster --force $version main stop", 2,
"Removed stale pid file.\nCluster is not running.\n",
'pg_ctlcluster stop succeeds with empty PID file';
ok (! -e $pf, 'pid file was cleaned up');
# corrupt PID file while server is down
create_pidfile 'foo';
is_program_out 'postgres', "pg_ctlcluster $version main start", 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment