While testing a backup script, I noticed that pg_basebackup exits with 0, even if it had errors while writing the backup to disk when the backup file is to be sent to stdout. The attached patch should fix this problem (and some special cases when the last write fails).
Regards, Thomas
diff -uNr postgresql-9.1.2/src/bin/pg_basebackup/pg_basebackup.c postgresql-9.1.2-patch/src/bin/pg_basebackup/pg_basebackup.c --- postgresql-9.1.2/src/bin/pg_basebackup/pg_basebackup.c 2011-12-01 22:47:20.000000000 +0100 +++ postgresql-9.1.2-patch/src/bin/pg_basebackup/pg_basebackup.c 2012-01-23 13:14:16.000000000 +0100 @@ -410,6 +410,7 @@ { fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"), progname, filename, get_gz_error(ztarfile)); + disconnect_and_exit(1); } } else @@ -428,7 +429,14 @@ #ifdef HAVE_LIBZ if (ztarfile) gzclose(ztarfile); + else #endif + if (fflush (tarfile) != 0) + { + fprintf(stderr, _("%s: error flushing stdout: %s\n"), + strerror (errno)); + disconnect_and_exit(1); + } } else { @@ -437,7 +445,14 @@ gzclose(ztarfile); #endif if (tarfile != NULL) - fclose(tarfile); + { + if (fclose(tarfile) != 0) + { + fprintf(stderr, _("%s: error closing file \"%s\": %s\n"), + progname, filename, strerror (errno)); + disconnect_and_exit(1); + } + } } break; @@ -456,6 +471,7 @@ { fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"), progname, filename, get_gz_error(ztarfile)); + disconnect_and_exit(1); } } else
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers