/*-------------------------------------------------------------------------
*
* common.c
- * catalog routines used by pg_dump; long ago these were shared
+ * Catalog routines used by pg_dump; long ago these were shared
* by another dump tool, but not anymore.
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
*
*-------------------------------------------------------------------------
*/
-#include "postgres_fe.h"
+#include "pg_backup_archiver.h"
#include <ctype.h>
#include "catalog/pg_class.h"
-
-#include "pg_backup_archiver.h"
#include "dumpmem.h"
+#include "dumputils.h"
/*
/*-------------------------------------------------------------------------
*
* dumpmem.c
- * memory routines used by pg_dump and pg_restore (but not pg_dumpall
- * because there is no failure location to report).
+ * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
+
#include "dumputils.h"
#include "dumpmem.h"
-#include <ctype.h>
/*
* Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out
- * safely; therefore, their return value is guaranteed to be non-NULL.
- * We also report the program name and close the database connection.
+ * out-of-memory condition occurs, these functions will bail out via exit();
+ *therefore, their return value is guaranteed to be non-NULL.
*/
char *
tmp = calloc(nmemb, size);
if (!tmp)
- exit_horribly(NULL, _("out of memory\n"));
+ exit_horribly(NULL, "out of memory\n");
return tmp;
}
tmp = realloc(ptr, size);
if (!tmp)
- exit_horribly(NULL, _("out of memory\n"));
+ exit_horribly(NULL, "out of memory\n");
return tmp;
}
/*-------------------------------------------------------------------------
*
* dumpmem.h
- * Common header file for the pg_dump and pg_restore
+ * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
#ifndef DUMPMEM_H
#define DUMPMEM_H
-#include "postgres_fe.h"
-
extern char *pg_strdup(const char *string);
extern void *pg_malloc(size_t size);
extern void *pg_calloc(size_t nmemb, size_t size);
#include <ctype.h>
-#include "dumpmem.h"
#include "dumputils.h"
#include "parser/keywords.h"
+/* Globals exported by this file */
int quote_all_identifiers = 0;
-const char *progname;
+const char *progname = NULL;
#define supports_grant_options(version) ((version) >= 70400)
}
+/*
+ * Write a printf-style message to stderr.
+ *
+ * The program name is prepended, if "progname" has been set.
+ * Also, if modulename isn't NULL, that's included too.
+ * Note that we'll try to translate the modulename and the fmt string.
+ */
void
write_msg(const char *modulename, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
- if (modulename)
- fprintf(stderr, "%s: [%s] ", progname, _(modulename));
- else
- fprintf(stderr, "%s: ", progname);
- vfprintf(stderr, _(fmt), ap);
+ vwrite_msg(modulename, fmt, ap);
va_end(ap);
}
+/*
+ * As write_msg, but pass a va_list not variable arguments.
+ */
+void
+vwrite_msg(const char *modulename, const char *fmt, va_list ap)
+{
+ if (progname)
+ {
+ if (modulename)
+ fprintf(stderr, "%s: [%s] ", progname, _(modulename));
+ else
+ fprintf(stderr, "%s: ", progname);
+ }
+ vfprintf(stderr, _(fmt), ap);
+}
+
+/*
+ * Fail and die, with a message to stderr. Parameters as for write_msg.
+ */
void
exit_horribly(const char *modulename, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
- write_msg(modulename, fmt, ap);
+ vwrite_msg(modulename, fmt, ap);
va_end(ap);
exit(1);
}
-
-
#include "pqexpbuffer.h"
extern int quote_all_identifiers;
+extern const char *progname;
extern void init_parallel_dump_utils(void);
extern const char *fmtId(const char *identifier);
PQExpBuffer buffer, const char *target, const char *objname);
extern void write_msg(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+extern void vwrite_msg(const char *modulename, const char *fmt, va_list ap)
+ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
extern void exit_horribly(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
pg_backup_db.c pg_backup_files.c pg_backup_null.c \
pg_backup_tar.c pg_restore.c pg_dumpall.c \
../../port/exec.c
-GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:3 simple_prompt \
+GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:2 simple_prompt \
ExecuteSqlCommand:3 ahlog:3
GETTEXT_FLAGS = \
write_msg:2:c-format \
die_horribly:3:c-format \
- exit_horribly:3:c-format \
+ exit_horribly:2:c-format \
ahlog:3:c-format
static int RestoringToDB(ArchiveHandle *AH);
static void dump_lo_buf(ArchiveHandle *AH);
-static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
+static void vdie_horribly(ArchiveHandle *AH, const char *modulename,
+ const char *fmt, va_list ap)
+ __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
return;
va_start(ap, fmt);
- write_msg(NULL, fmt, ap);
+ vwrite_msg(NULL, fmt, ap);
va_end(ap);
}
}
+/* Report a fatal error and exit(1) */
static void
-_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap)
+vdie_horribly(ArchiveHandle *AH, const char *modulename,
+ const char *fmt, va_list ap)
{
- write_msg(modulename, fmt, ap);
+ vwrite_msg(modulename, fmt, ap);
if (AH)
{
exit(1);
}
-/* Archiver use (just different arg declaration) */
+/* As above, but with variable arg list */
void
die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
- _die_horribly(AH, modulename, fmt, ap);
+ vdie_horribly(AH, modulename, fmt, ap);
va_end(ap);
}
va_start(ap, fmt);
if (AH->public.exit_on_error)
- _die_horribly(AH, modulename, fmt, ap);
+ vdie_horribly(AH, modulename, fmt, ap);
else
{
- write_msg(modulename, fmt, ap);
+ vwrite_msg(modulename, fmt, ap);
AH->public.n_errors++;
}
va_end(ap);
if (depIdx >= depSize)
{
depSize *= 2;
- deps = (DumpId *) realloc(deps, sizeof(DumpId) * depSize);
+ deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
}
sscanf(tmp, "%d", &deps[depIdx]);
free(tmp);
if (depIdx > 0) /* We have a non-null entry */
{
- deps = (DumpId *) realloc(deps, sizeof(DumpId) * depIdx);
+ deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depIdx);
te->dependencies = deps;
te->nDeps = depIdx;
}
return;
}
- te->lockDeps = realloc(lockids, nlockids * sizeof(DumpId));
+ te->lockDeps = pg_realloc(lockids, nlockids * sizeof(DumpId));
te->nLockDeps = nlockids;
}
int nLockDeps; /* number of such dependencies */
} TocEntry;
-/* Used everywhere */
-extern const char *progname;
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
static PGresult *executeQuery(PGconn *conn, const char *query);
static void executeCommand(PGconn *conn, const char *query);
-char *pg_strdup(const char *string);
-void *pg_malloc(size_t size);
-
static char pg_dump_bin[MAXPGPATH];
static PQExpBuffer pgdumpopts;
static bool skip_acls = false;
*-------------------------------------------------------------------------
*/
-#include "dumpmem.h"
#include "pg_backup_archiver.h"
+
+#include "dumpmem.h"
#include "dumputils.h"
#include <ctype.h>