Commit 4e21eafd authored by Martin Pitt's avatar Martin Pitt

* t/030_errors.t: Create a temporary 10 MB loop mount on /var/lib/postgresql

  and check that pg_createcluster fails with an appropriate error and leaves
  no cruft behind.
* pg_createcluster: Call pg_dropcluster to clean up cruft if anything fails
  in the cluster creation process. This avoids an inconsistent system if e.
  g. running out of disk space during installation. Closes: #368335
parent f21f61f6
......@@ -10,8 +10,14 @@ postgresql-common (55) unstable; urgency=low
pg_createcluster fails (/var might be full and the admin might want to use
a different directory). Merely print out an error message and point to
pg_createcluster and its manpage. (part of bug #368335)
-- Martin Pitt <mpitt@debian.org> Thu, 1 Jun 2006 23:02:20 +0200
* t/030_errors.t: Create a temporary 10 MB loop mount on /var/lib/postgresql
and check that pg_createcluster fails with an appropriate error and leaves
no cruft behind.
* pg_createcluster: Call pg_dropcluster to clean up cruft if anything fails
in the cluster creation process. This avoids an inconsistent system if e.
g. running out of disk space during installation. Closes: #368335
-- Martin Pitt <mpitt@debian.org> Fri, 2 Jun 2006 00:17:07 +0200
postgresql-common (54) unstable; urgency=low
......
......@@ -179,6 +179,8 @@ sub setup_pg_hba {
my $startconf = 'auto';
my $createsuccess = 0;
exit 1 unless GetOptions ('u|user=s' => \$owneruid, 'g|group=s' => \$ownergid,
's|socketdir=s' => \$socketdir, 'd|datadir=s' => \$datadir,
'start' => \$start, 'e|encoding=s' => \$encoding,
......@@ -387,11 +389,21 @@ print ENV "# environment variables for postmaster process
close ENV;
chmod 0644, "$confdir/environment";
$createsuccess = 1;
# start it if requested
if ($start) {
system '/usr/bin/pg_ctlcluster', $version, $cluster, 'start';
}
END {
# clean up cruft if something went wrong
unless ($createsuccess) {
system "pg_dropcluster $version $cluster 2>/dev/null";
exit 1;
}
}
__END__
=head1 NAME
......
......@@ -2,9 +2,11 @@
use strict;
require File::Temp;
use lib 't';
use TestLib;
use Test::More tests => 111;
use Test::More tests => 124;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -225,4 +227,25 @@ unlike_program_out 0, "pg_dropcluster $MAJORS[-1] broken", 0, qr/error/i,
check_clean;
# check that a failed pg_createcluster leaves no cruft behind: create a 10 MB
# loop partition, temporarily mount it to /var/lib/postgresql
my $loop = new File::Temp (UNLINK => 1) or die "could not create temporary file: $!";
truncate $loop, 10000000 or die "truncate: $!";
close $loop;
END { system "umount /var/lib/postgresql 2>/dev/null; losetup -d /dev/loop7 2>/dev/null"; }
(system "losetup /dev/loop7 $loop && mkfs.ext2 /dev/loop7 >/dev/null 2>&1 && mount -t ext2 /dev/loop7 /var/lib/postgresql") == 0 or
die 'Could not create and mount loop partition';
like_program_out 0, "pg_createcluster $MAJORS[-1] test", 1, qr/No space left on device/i,
'pg_createcluster fails due to insufficient disk space';
ok_dir '/var/lib/postgresql', ['lost+found'],
'No files in /var/lib/postgresql /left behind after failed pg_createcluster';
ok_dir '/etc/postgresql', [],
'No files in /etc/postgresql /left behind after failed pg_createcluster';
system "umount /var/lib/postgresql; losetup -d /dev/loop7";
check_clean;
# vim: filetype=perl
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