Per recent discussions on pgsql-hackers regarding parallel pg_dump.
inhinfo[i].inhparent,
self->dobj.name,
oid);
- exit_nicely();
+ exit_nicely(1);
}
self->parents[j++] = parent;
}
if (argNum >= arraysize)
{
write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str);
- exit_nicely();
+ exit_nicely(1);
}
temp[j] = '\0';
array[argNum++] = atooid(temp);
j >= sizeof(temp) - 1)
{
write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str);
- exit_nicely();
+ exit_nicely(1);
}
temp[j++] = s;
}
#include "compress_io.h"
#include "dumpmem.h"
+#include "dumputils.h"
/*----------------------
* Compressor API
*alg = COMPR_ALG_NONE;
else
{
- die_horribly(NULL, modulename, "Invalid compression code: %d\n",
- compression);
+ exit_horribly(modulename, "Invalid compression code: %d\n",
+ compression);
*alg = COMPR_ALG_NONE; /* keep compiler quiet */
}
#ifndef HAVE_LIBZ
if (alg == COMPR_ALG_LIBZ)
- die_horribly(NULL, modulename, "not built with zlib support\n");
+ exit_horribly(modulename, "not built with zlib support\n");
#endif
cs = (CompressorState *) pg_calloc(1, sizeof(CompressorState));
#ifdef HAVE_LIBZ
ReadDataFromArchiveZlib(AH, readF);
#else
- die_horribly(NULL, modulename, "not built with zlib support\n");
+ exit_horribly(modulename, "not built with zlib support\n");
#endif
}
}
#ifdef HAVE_LIBZ
return WriteDataToArchiveZlib(AH, cs, data, dLen);
#else
- die_horribly(NULL, modulename, "not built with zlib support\n");
+ exit_horribly(modulename, "not built with zlib support\n");
#endif
case COMPR_ALG_NONE:
return WriteDataToArchiveNone(AH, cs, data, dLen);
cs->zlibOutSize = ZLIB_OUT_SIZE;
if (deflateInit(zp, level) != Z_OK)
- die_horribly(NULL, modulename,
- "could not initialize compression library: %s\n",
- zp->msg);
+ exit_horribly(modulename,
+ "could not initialize compression library: %s\n",
+ zp->msg);
/* Just be paranoid - maybe End is called after Start, with no Write */
zp->next_out = (void *) cs->zlibOut;
out = pg_malloc(ZLIB_OUT_SIZE + 1);
if (inflateInit(zp) != Z_OK)
- die_horribly(NULL, modulename,
- "could not initialize compression library: %s\n",
- zp->msg);
+ exit_horribly(modulename,
+ "could not initialize compression library: %s\n",
+ zp->msg);
/* no minimal chunk size for zlib */
while ((cnt = readF(AH, &buf, &buflen)))
fp = cfopen(fname, mode, 1);
free(fname);
#else
- die_horribly(NULL, modulename, "not built with zlib support\n");
+ exit_horribly(modulename, "not built with zlib support\n");
fp = NULL; /* keep compiler quiet */
#endif
}
fp = NULL;
}
#else
- die_horribly(NULL, modulename, "not built with zlib support\n");
+ exit_horribly(modulename, "not built with zlib support\n");
#endif
}
else
int quote_all_identifiers = 0;
const char *progname = NULL;
+#define MAX_ON_EXIT_NICELY 20
+
+static struct
+{
+ on_exit_nicely_callback function;
+ void *arg;
+} on_exit_nicely_list[MAX_ON_EXIT_NICELY];
+
+static int on_exit_nicely_index;
#define supports_grant_options(version) ((version) >= 70400)
vwrite_msg(modulename, fmt, ap);
va_end(ap);
- exit(1);
+ exit_nicely(1);
}
/*
progname, arg);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
}
+
+/* Register a callback to be run when exit_nicely is invoked. */
+void
+on_exit_nicely(on_exit_nicely_callback function, void *arg)
+{
+ if (on_exit_nicely_index >= MAX_ON_EXIT_NICELY)
+ exit_horribly(NULL, "out of on_exit_nicely slots");
+ on_exit_nicely_list[on_exit_nicely_index].function = function;
+ on_exit_nicely_list[on_exit_nicely_index].arg = arg;
+ on_exit_nicely_index++;
+}
+
+/* Run accumulated on_exit_nicely callbacks and then exit quietly. */
+void
+exit_nicely(int code)
+{
+ while (--on_exit_nicely_index >= 0)
+ (*on_exit_nicely_list[on_exit_nicely_index].function)(code,
+ on_exit_nicely_list[on_exit_nicely_index].arg);
+ exit(code);
+}
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
extern void set_section (const char *arg, int *dumpSections);
+typedef void (*on_exit_nicely_callback) (int code, void *arg);
+extern void on_exit_nicely(on_exit_nicely_callback function, void *arg);
+extern void exit_nicely(int code) __attribute__((noreturn));
+
#endif /* DUMPUTILS_H */
* Main archiver interface.
*/
-
-/* Lets the archive know we have a DB connection to shutdown if it dies */
-
-PGconn *ConnectDatabase(Archive *AH,
+extern PGconn *ConnectDatabase(Archive *AH,
const char *dbname,
const char *pghost,
const char *pgport,
const char *username,
enum trivalue prompt_password);
+extern void DisconnectDatabase(Archive *AHX);
/* Called to add a TOC entry */
extern void ArchiveEntry(Archive *AHX,
RestoreOutput(AH, sav);
if (ropt->useDB)
- {
- PQfinish(AH->connection);
- AH->connection = NULL;
- }
+ DisconnectDatabase(&AH->public);
}
/*
{
if (AH->public.verbose)
write_msg(NULL, "*** aborted because of error\n");
- if (AH->connection)
- PQfinish(AH->connection);
+ DisconnectDatabase(&AH->public);
}
- exit(1);
+ exit_nicely(1);
}
/* As above, but with variable arg list */
* mainly to ensure that we don't exceed the specified number of parallel
* connections.
*/
- PQfinish(AH->connection);
- AH->connection = NULL;
+ DisconnectDatabase(&AH->public);
/* blow away any transient state from the old connection */
if (AH->currUser)
retval = restore_toc_entry(AH, te, ropt, true);
/* And clean up */
- PQfinish(AH->connection);
- AH->connection = NULL;
+ DisconnectDatabase((Archive *) AH);
/* If we reopened the file, we are done with it, so close it now */
if (te->section == SECTION_DATA)
return AH->connection;
}
+void
+DisconnectDatabase(Archive *AHX)
+{
+ ArchiveHandle *AH = (ArchiveHandle *) AHX;
+
+ PQfinish(AH->connection); /* noop if AH->connection is NULL */
+ AH->connection = NULL;
+}
+
static void
notice_processor(void *arg, const char *message)
#include "compress_io.h"
#include "dumpmem.h"
+#include "dumputils.h"
#include <dirent.h>
#include <sys/stat.h>
if (stat(dir, &st) == 0)
{
if (S_ISDIR(st.st_mode))
- die_horribly(NULL, modulename,
- "cannot create directory %s, it exists already\n",
- dir);
+ exit_horribly(modulename,
+ "cannot create directory %s, it exists already\n",
+ dir);
else
- die_horribly(NULL, modulename,
- "cannot create directory %s, a file with this name "
- "exists already\n", dir);
+ exit_horribly(modulename,
+ "cannot create directory %s, a file with this name "
+ "exists already\n", dir);
}
/*
* between our two calls.
*/
if (mkdir(dir, 0700) < 0)
- die_horribly(NULL, modulename, "could not create directory %s: %s",
- dir, strerror(errno));
+ exit_horribly(modulename, "could not create directory %s: %s",
+ dir, strerror(errno));
}
{
AH->FH = fopen(AH->fSpec, PG_BINARY_W);
if (AH->FH == NULL)
- die_horribly(NULL, modulename, "could not open output file \"%s\": %s\n",
- AH->fSpec, strerror(errno));
+ exit_horribly(modulename, "could not open output file \"%s\": %s\n",
+ AH->fSpec, strerror(errno));
}
else
{
AH->FH = stdout;
if (AH->FH == NULL)
- die_horribly(NULL, modulename, "could not open output file: %s\n",
- strerror(errno));
+ exit_horribly(modulename, "could not open output file: %s\n",
+ strerror(errno));
}
ctx->hasSeek = checkSeek(AH->FH);
{
AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (AH->FH == NULL)
- die_horribly(NULL, modulename, "could not open input file \"%s\": %s\n",
- AH->fSpec, strerror(errno));
+ exit_horribly(modulename, "could not open input file \"%s\": %s\n",
+ AH->fSpec, strerror(errno));
}
else
{
AH->FH = stdin;
if (AH->FH == NULL)
- die_horribly(NULL, modulename, "could not open input file: %s\n",
- strerror(errno));
+ exit_horribly(modulename, "could not open input file: %s\n",
+ strerror(errno));
}
ctx->hasSeek = checkSeek(AH->FH);
#include "pg_backup_archiver.h"
#include "pg_backup_tar.h"
#include "dumpmem.h"
+#include "dumputils.h"
#include <sys/stat.h>
#include <ctype.h>
{
ctx->tarFH = fopen(AH->fSpec, PG_BINARY_W);
if (ctx->tarFH == NULL)
- die_horribly(NULL, modulename,
- "could not open TOC file \"%s\" for output: %s\n",
- AH->fSpec, strerror(errno));
+ exit_horribly(modulename,
+ "could not open TOC file \"%s\" for output: %s\n",
+ AH->fSpec, strerror(errno));
}
else
{
ctx->tarFH = stdout;
if (ctx->tarFH == NULL)
- die_horribly(NULL, modulename,
- "could not open TOC file for output: %s\n",
- strerror(errno));
+ exit_horribly(modulename,
+ "could not open TOC file for output: %s\n",
+ strerror(errno));
}
ctx->tarFHpos = 0;
* positioning.
*/
if (AH->compression != 0)
- die_horribly(NULL, modulename, "compression is not supported by tar archive format\n");
+ exit_horribly(modulename,
+ "compression is not supported by tar archive format\n");
}
else
{ /* Read Mode */
{
ctx->tarFH = fopen(AH->fSpec, PG_BINARY_R);
if (ctx->tarFH == NULL)
- die_horribly(NULL, modulename, "could not open TOC file \"%s\" for input: %s\n",
- AH->fSpec, strerror(errno));
+ exit_horribly(modulename, "could not open TOC file \"%s\" for input: %s\n",
+ AH->fSpec, strerror(errno));
}
else
{
ctx->tarFH = stdin;
if (ctx->tarFH == NULL)
- die_horribly(NULL, modulename, "could not open TOC file for input: %s\n",
- strerror(errno));
+ exit_horribly(modulename, "could not open TOC file for input: %s\n",
+ strerror(errno));
}
/*
static void help(const char *progname);
+static void pgdump_cleanup_at_exit(int code, void *arg);
static void setup_connection(Archive *AH, const char *dumpencoding,
char *use_role);
static ArchiveFormat parseArchiveFormat(const char *format, ArchiveMode *mode);
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
help(progname);
- exit(0);
+ exit_nicely(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pg_dump (PostgreSQL) " PG_VERSION);
- exit(0);
+ exit_nicely(0);
}
}
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
- exit(1);
+ exit_nicely(1);
}
}
progname, argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
/* --column-inserts implies --inserts */
if (dataOnly && schemaOnly)
{
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
- exit(1);
+ exit_nicely(1);
}
if ((dataOnly || schemaOnly) && dumpSections != DUMP_UNSECTIONED)
{
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used with --section\n");
- exit(1);
+ exit_nicely(1);
}
if (dataOnly)
if (dataOnly && outputClean)
{
write_msg(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
- exit(1);
+ exit_nicely(1);
}
if (dump_inserts && oids)
{
write_msg(NULL, "options --inserts/--column-inserts and -o/--oids cannot be used together\n");
write_msg(NULL, "(The INSERT command cannot set OIDs.)\n");
- exit(1);
+ exit_nicely(1);
}
/* Identify archive format to emit */
/* Open the output file */
fout = CreateArchive(filename, archiveFormat, compressLevel, archiveMode);
+ on_exit_nicely(pgdump_cleanup_at_exit, fout);
if (fout == NULL)
{
write_msg(NULL, "could not open output file \"%s\" for writing\n", filename);
- exit(1);
+ exit_nicely(1);
}
/* Let the archiver know how noisy to be */
if (my_version < 0)
{
write_msg(NULL, "could not parse version string \"%s\"\n", PG_VERSION);
- exit(1);
+ exit_nicely(1);
}
/*
if (schema_include_oids.head == NULL)
{
write_msg(NULL, "No matching schemas were found\n");
- exit_nicely();
+ exit_nicely(1);
}
}
expand_schema_name_patterns(fout, &schema_exclude_patterns,
if (table_include_oids.head == NULL)
{
write_msg(NULL, "No matching tables were found\n");
- exit_nicely();
+ exit_nicely(1);
}
}
expand_table_name_patterns(fout, &table_exclude_patterns,
CloseArchive(fout);
- PQfinish(g_conn);
-
- exit(0);
+ exit_nicely(0);
}
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
}
-void
-exit_nicely(void)
+static void
+pgdump_cleanup_at_exit(int code, void *arg)
{
- PQfinish(g_conn);
- if (g_verbose)
- write_msg(NULL, "*** aborted because of error\n");
- exit(1);
+ Archive *AH = (Archive *) arg;
+
+ DisconnectDatabase(AH);
}
static void
{
write_msg(NULL, "invalid client encoding \"%s\" specified\n",
dumpencoding);
- exit(1);
+ exit_nicely(1);
}
}
else
{
write_msg(NULL, "invalid output format \"%s\" specified\n", format);
- exit(1);
+ exit_nicely(1);
}
return archiveFormat;
}
if (fout->remoteVersion < 70300)
{
write_msg(NULL, "server version must be at least 7.3 to use schema selection switches\n");
- exit_nicely();
+ exit_nicely(1);
}
query = createPQExpBuffer();
write_msg(NULL, "Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.\n", classname);
write_msg(NULL, "Error message from server: %s", PQerrorMessage(g_conn));
write_msg(NULL, "The command was: %s\n", q->data);
- exit_nicely();
+ exit_nicely(1);
}
/* Check command status and return to normal libpq state */
write_msg(NULL, "Dumping the contents of table \"%s\" failed: PQgetResult() failed.\n", classname);
write_msg(NULL, "Error message from server: %s", PQerrorMessage(g_conn));
write_msg(NULL, "The command was: %s\n", q->data);
- exit_nicely();
+ exit_nicely(1);
}
PQclear(res);
{
write_msg(NULL, "missing pg_database entry for database \"%s\"\n",
datname);
- exit_nicely();
+ exit_nicely(1);
}
if (ntups != 1)
{
write_msg(NULL, "query returned more than one (%d) pg_database entry for database \"%s\"\n",
ntups, datname);
- exit_nicely();
+ exit_nicely(1);
}
i_tableoid = PQfnumber(res, "tableoid");
if (PQntuples(lo_res) != 1)
{
write_msg(NULL, "dumpDatabase(): could not find pg_largeobject.relfrozenxid\n");
- exit_nicely();
+ exit_nicely(1);
}
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
if (PQntuples(lo_res) != 1)
{
write_msg(NULL, "dumpDatabase(): could not find pg_largeobject_metadata.relfrozenxid\n");
- exit_nicely();
+ exit_nicely(1);
}
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
{
write_msg(NULL, "could not open large object %u: %s",
blobOid, PQerrorMessage(g_conn));
- exit_nicely();
+ exit_nicely(1);
}
StartBlob(fout, blobOid);
{
write_msg(NULL, "error reading large object %u: %s",
blobOid, PQerrorMessage(g_conn));
- exit_nicely();
+ exit_nicely(1);
}
WriteData(fout, buf, cnt);
"query returned %d rows instead of one: %s\n",
ntups),
ntups, upgrade_query->data);
- exit_nicely();
+ exit_nicely(1);
}
pg_type_array_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "typarray")));
"query returned %d rows instead of one: %s\n",
ntups),
ntups, upgrade_query->data);
- exit_nicely();
+ exit_nicely(1);
}
pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
"query returned %d rows instead of one: %s\n",
ntups),
ntups, upgrade_query->data);
- exit_nicely();
+ exit_nicely(1);
}
pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
if (extobj == NULL)
{
write_msg(NULL, "could not find parent extension for %s", objlabel);
- exit_nicely();
+ exit_nicely(1);
}
appendPQExpBuffer(upgrade_buffer,
return nsinfo;
}
write_msg(NULL, "schema with OID %u does not exist\n", nsoid);
- exit_nicely();
+ exit_nicely(1);
}
else
{
write_msg(NULL, "failed sanity check, parent table OID %u of pg_rewrite entry OID %u not found\n",
ruletableoid,
ruleinfo[i].dobj.catId.oid);
- exit_nicely();
+ exit_nicely(1);
}
ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
write_msg(NULL, "query produced null referenced table name for foreign key trigger \"%s\" on table \"%s\" (OID of table: %u)\n",
tginfo[j].dobj.name, tbinfo->dobj.name,
tginfo[j].tgconstrrelid);
- exit_nicely();
+ exit_nicely(1);
}
tginfo[j].tgconstrrelname = pg_strdup(PQgetvalue(res, j, i_tgconstrrelname));
}
{
write_msg(NULL, "invalid column numbering in table \"%s\"\n",
tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, i_attname));
tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, i_atttypname));
{
write_msg(NULL, "invalid adnum value %d for table \"%s\"\n",
adnum, tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
/*
tbinfo->ncheck),
tbinfo->ncheck, tbinfo->dobj.name, numConstrs);
write_msg(NULL, "(The system catalogs might be corrupted.)\n");
- exit_nicely();
+ exit_nicely(1);
}
constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
{
write_msg(NULL, "query returned %d pg_range entries for range type \"%s\"\n",
PQntuples(res), tyinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
/*
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
typlen = PQgetvalue(res, 0, PQfnumber(res, "typlen"));
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
typnotnull = PQgetvalue(res, 0, PQfnumber(res, "typnotnull"));
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
proretset = PQgetvalue(res, 0, PQfnumber(res, "proretset"));
{
write_msg(NULL, "unrecognized provolatile value for function \"%s\"\n",
finfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
}
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
i_oprkind = PQfnumber(res, "oprkind");
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query);
- exit_nicely();
+ exit_nicely(1);
}
result = pg_strdup(PQgetvalue(res, 0, 0));
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
i_opcintype = PQfnumber(res, "opcintype");
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
i_amname = PQfnumber(res, "amname");
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
i_collcollate = PQfnumber(res, "collcollate");
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
i_conforencoding = PQfnumber(res, "conforencoding");
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
i_aggtransfn = PQfnumber(res, "aggtransfn");
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
nspname = PQgetvalue(res, 0, 0);
tmplname = PQgetvalue(res, 0, 1);
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
nspname = PQgetvalue(res, 0, 0);
prsname = PQgetvalue(res, 0, 1);
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
fdwname = PQgetvalue(res, 0, 0);
/* shouldn't get here */
write_msg(NULL, "unknown object type (%d) in default privileges\n",
(int) daclinfo->defaclobjtype);
- exit_nicely();
+ exit_nicely(1);
type = ""; /* keep compiler quiet */
}
{
write_msg(NULL, "could not parse default ACL list (%s)\n",
daclinfo->defaclacl);
- exit_nicely();
+ exit_nicely(1);
}
ArchiveEntry(fout, daclinfo->dobj.catId, daclinfo->dobj.dumpId,
{
write_msg(NULL, "could not parse ACL list (%s) for object \"%s\" (%s)\n",
acls, name, type);
- exit_nicely();
+ exit_nicely(1);
}
if (sql->len > 0)
else
write_msg(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
viewdef = PQgetvalue(res, 0, 0);
{
write_msg(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
/*
"query returned %d foreign server entries for foreign table \"%s\"\n",
PQntuples(res)),
PQntuples(res), tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
i_srvname = PQfnumber(res, "srvname");
i_ftoptions = PQfnumber(res, "ftoptions");
}
write_msg(NULL, "invalid column number %d for table \"%s\"\n",
attrnum, tblInfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
return NULL; /* keep compiler quiet */
}
{
write_msg(NULL, "missing index for constraint \"%s\"\n",
coninfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
if (binary_upgrade)
else
{
write_msg(NULL, "unrecognized constraint type: %c\n", coninfo->contype);
- exit_nicely();
+ exit_nicely(1);
}
/* Dump Constraint Comments --- only works for table constraints */
if (ntups < 1)
{
write_msg(NULL, "missing pg_database entry for this database\n");
- exit_nicely();
+ exit_nicely(1);
}
if (ntups > 1)
{
write_msg(NULL, "found more than one pg_database entry for this database\n");
- exit_nicely();
+ exit_nicely(1);
}
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid")));
PQclear(res);
if (ntups < 1)
{
write_msg(NULL, "could not find entry for pg_indexes in pg_class\n");
- exit_nicely();
+ exit_nicely(1);
}
if (ntups > 1)
{
write_msg(NULL, "found more than one entry for pg_indexes in pg_class\n");
- exit_nicely();
+ exit_nicely(1);
}
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid")));
PQclear(res);
"query to get data of sequence \"%s\" returned %d rows (expected 1)\n",
PQntuples(res)),
tbinfo->dobj.name, PQntuples(res));
- exit_nicely();
+ exit_nicely(1);
}
/* Disable this check: it fails if sequence has been renamed */
{
write_msg(NULL, "query to get data of sequence \"%s\" returned name \"%s\"\n",
tbinfo->dobj.name, PQgetvalue(res, 0, 0));
- exit_nicely();
+ exit_nicely(1);
}
#endif
else
{
write_msg(NULL, "unexpected tgtype value: %d\n", tginfo->tgtype);
- exit_nicely();
+ exit_nicely(1);
}
findx = 0;
tginfo->tgargs,
tginfo->dobj.name,
tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
if (findx > 0)
{
write_msg(NULL, "query to get rule \"%s\" for table \"%s\" failed: wrong number of rows returned\n",
rinfo->dobj.name, tbinfo->dobj.name);
- exit_nicely();
+ exit_nicely(1);
}
printfPQExpBuffer(cmd, "%s\n", PQgetvalue(res, 0, 0));
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
- exit_nicely();
+ exit_nicely(1);
}
if (fout->remoteVersion >= 70100)
extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
-extern void exit_nicely(void) __attribute__((noreturn));
-
extern void parseOidArray(const char *str, Oid *array, int arraysize);
extern void sortDumpableObjects(DumpableObject **objs, int numObjs);
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
help();
- exit(0);
+ exit_nicely(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pg_dumpall (PostgreSQL) " PG_VERSION);
- exit(0);
+ exit_nicely(0);
}
}
"but was not the same version as %s.\n"
"Check your installation.\n"),
full_path, progname);
- exit(1);
+ exit_nicely(1);
}
pgdumpopts = createPQExpBuffer();
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
- exit(1);
+ exit_nicely(1);
}
}
progname, argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
/* Make sure the user hasn't specified a mix of globals-only options */
progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
if (globals_only && tablespaces_only)
progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
if (roles_only && tablespaces_only)
progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
/* Add long options to the pg_dump argument list */
{
fprintf(stderr, _("%s: could not connect to database \"%s\"\n"),
progname, pgdb);
- exit(1);
+ exit_nicely(1);
}
}
else
progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
}
{
fprintf(stderr, _("%s: could not open the output file \"%s\": %s\n"),
progname, filename, strerror(errno));
- exit(1);
+ exit_nicely(1);
}
}
else
if (filename)
fclose(OPF);
- exit(0);
+ exit_nicely(0);
}
fprintf(stderr, _("%s: could not parse ACL list (%s) for tablespace \"%s\"\n"),
progname, spcacl, fspcname);
PQfinish(conn);
- exit(1);
+ exit_nicely(1);
}
if (spccomment && strlen(spccomment))
fprintf(stderr, _("%s: could not parse ACL list (%s) for database \"%s\"\n"),
progname, dbacl, fdbname);
PQfinish(conn);
- exit(1);
+ exit_nicely(1);
}
fprintf(OPF, "%s", buf->data);
if (ret != 0)
{
fprintf(stderr, _("%s: pg_dump failed on database \"%s\", exiting\n"), progname, dbname);
- exit(1);
+ exit_nicely(1);
}
if (filename)
{
fprintf(stderr, _("%s: could not re-open the output file \"%s\": %s\n"),
progname, filename, strerror(errno));
- exit(1);
+ exit_nicely(1);
}
}
{
fprintf(stderr, _("%s: could not connect to database \"%s\"\n"),
progname, dbname);
- exit(1);
+ exit_nicely(1);
}
if (PQstatus(conn) == CONNECTION_BAD &&
fprintf(stderr,
_("%s: could not connect to database \"%s\": %s\n"),
progname, dbname, PQerrorMessage(conn));
- exit(1);
+ exit_nicely(1);
}
else
{
if (!remoteversion_str)
{
fprintf(stderr, _("%s: could not get server version\n"), progname);
- exit(1);
+ exit_nicely(1);
}
server_version = parse_version(remoteversion_str);
if (server_version < 0)
{
fprintf(stderr, _("%s: could not parse server version \"%s\"\n"),
progname, remoteversion_str);
- exit(1);
+ exit_nicely(1);
}
my_version = parse_version(PG_VERSION);
{
fprintf(stderr, _("%s: could not parse version \"%s\"\n"),
progname, PG_VERSION);
- exit(1);
+ exit_nicely(1);
}
/*
fprintf(stderr, _("server version: %s; %s version: %s\n"),
remoteversion_str, progname, PG_VERSION);
fprintf(stderr, _("aborting because of server version mismatch\n"));
- exit(1);
+ exit_nicely(1);
}
/*
fprintf(stderr, _("%s: query was: %s\n"),
progname, query);
PQfinish(conn);
- exit(1);
+ exit_nicely(1);
}
return res;
fprintf(stderr, _("%s: query was: %s\n"),
progname, query);
PQfinish(conn);
- exit(1);
+ exit_nicely(1);
}
PQclear(res);
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
usage(progname);
- exit(0);
+ exit_nicely(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
puts("pg_restore (PostgreSQL) " PG_VERSION);
- exit(0);
+ exit_nicely(0);
}
}
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
- exit(1);
+ exit_nicely(1);
}
}
progname, argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
if (opts->dataOnly && opts->schemaOnly)
{
fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used together\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
if ((opts->dataOnly || opts->schemaOnly) && (opts->dumpSections != DUMP_UNSECTIONED))
{
fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used with --section\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
if (opts->dataOnly)
progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
opts->useDB = 1;
}
{
fprintf(stderr, _("%s: cannot specify both --single-transaction and multiple jobs\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
opts->disable_triggers = disable_triggers;
default:
write_msg(NULL, "unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"\n",
opts->formatName);
- exit(1);
+ exit_nicely(1);
}
}