Commit 0195e5c4 authored by Tom Lane's avatar Tom Lane

Clean up after recent pg_dump patches.

Fix entirely broken handling of va_list printing routines, update some
out-of-date comments, fix some bogus inclusion orders, fix NLS declarations,
fix missed realloc calls.
parent 2ff36abe
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* common.c * 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. * by another dump tool, but not anymore.
* *
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
...@@ -13,14 +13,13 @@ ...@@ -13,14 +13,13 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h" #include "pg_backup_archiver.h"
#include <ctype.h> #include <ctype.h>
#include "catalog/pg_class.h" #include "catalog/pg_class.h"
#include "pg_backup_archiver.h"
#include "dumpmem.h" #include "dumpmem.h"
#include "dumputils.h"
/* /*
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* dumpmem.c * dumpmem.c
* memory routines used by pg_dump and pg_restore (but not pg_dumpall * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
* because there is no failure location to report).
* *
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
...@@ -14,16 +13,15 @@ ...@@ -14,16 +13,15 @@
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "dumputils.h" #include "dumputils.h"
#include "dumpmem.h" #include "dumpmem.h"
#include <ctype.h>
/* /*
* Safer versions of some standard C library functions. If an * Safer versions of some standard C library functions. If an
* out-of-memory condition occurs, these functions will bail out * out-of-memory condition occurs, these functions will bail out via exit();
* safely; therefore, their return value is guaranteed to be non-NULL. *therefore, their return value is guaranteed to be non-NULL.
* We also report the program name and close the database connection.
*/ */
char * char *
...@@ -57,7 +55,7 @@ pg_calloc(size_t nmemb, size_t size) ...@@ -57,7 +55,7 @@ pg_calloc(size_t nmemb, size_t size)
tmp = calloc(nmemb, size); tmp = calloc(nmemb, size);
if (!tmp) if (!tmp)
exit_horribly(NULL, _("out of memory\n")); exit_horribly(NULL, "out of memory\n");
return tmp; return tmp;
} }
...@@ -68,6 +66,6 @@ pg_realloc(void *ptr, size_t size) ...@@ -68,6 +66,6 @@ pg_realloc(void *ptr, size_t size)
tmp = realloc(ptr, size); tmp = realloc(ptr, size);
if (!tmp) if (!tmp)
exit_horribly(NULL, _("out of memory\n")); exit_horribly(NULL, "out of memory\n");
return tmp; return tmp;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* dumpmem.h * 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) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#ifndef DUMPMEM_H #ifndef DUMPMEM_H
#define DUMPMEM_H #define DUMPMEM_H
#include "postgres_fe.h"
extern char *pg_strdup(const char *string); extern char *pg_strdup(const char *string);
extern void *pg_malloc(size_t size); extern void *pg_malloc(size_t size);
extern void *pg_calloc(size_t nmemb, size_t size); extern void *pg_calloc(size_t nmemb, size_t size);
......
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
#include <ctype.h> #include <ctype.h>
#include "dumpmem.h"
#include "dumputils.h" #include "dumputils.h"
#include "parser/keywords.h" #include "parser/keywords.h"
/* Globals exported by this file */
int quote_all_identifiers = 0; int quote_all_identifiers = 0;
const char *progname; const char *progname = NULL;
#define supports_grant_options(version) ((version) >= 70400) #define supports_grant_options(version) ((version) >= 70400)
...@@ -1214,31 +1214,51 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, ...@@ -1214,31 +1214,51 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
} }
/*
* 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 void
write_msg(const char *modulename, const char *fmt,...) write_msg(const char *modulename, const char *fmt,...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
if (modulename) vwrite_msg(modulename, fmt, ap);
fprintf(stderr, "%s: [%s] ", progname, _(modulename));
else
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, _(fmt), ap);
va_end(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 void
exit_horribly(const char *modulename, const char *fmt,...) exit_horribly(const char *modulename, const char *fmt,...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
write_msg(modulename, fmt, ap); vwrite_msg(modulename, fmt, ap);
va_end(ap); va_end(ap);
exit(1); exit(1);
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
extern int quote_all_identifiers; extern int quote_all_identifiers;
extern const char *progname;
extern void init_parallel_dump_utils(void); extern void init_parallel_dump_utils(void);
extern const char *fmtId(const char *identifier); extern const char *fmtId(const char *identifier);
...@@ -53,6 +54,8 @@ extern void emitShSecLabels(PGconn *conn, PGresult *res, ...@@ -53,6 +54,8 @@ extern void emitShSecLabels(PGconn *conn, PGresult *res,
PQExpBuffer buffer, const char *target, const char *objname); PQExpBuffer buffer, const char *target, const char *objname);
extern void write_msg(const char *modulename, const char *fmt,...) extern void write_msg(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); __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,...) extern void exit_horribly(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
......
...@@ -5,10 +5,10 @@ GETTEXT_FILES = pg_dump.c common.c pg_backup_archiver.c pg_backup_custom.c \ ...@@ -5,10 +5,10 @@ GETTEXT_FILES = pg_dump.c common.c pg_backup_archiver.c pg_backup_custom.c \
pg_backup_db.c pg_backup_files.c pg_backup_null.c \ pg_backup_db.c pg_backup_files.c pg_backup_null.c \
pg_backup_tar.c pg_restore.c pg_dumpall.c \ pg_backup_tar.c pg_restore.c pg_dumpall.c \
../../port/exec.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 ExecuteSqlCommand:3 ahlog:3
GETTEXT_FLAGS = \ GETTEXT_FLAGS = \
write_msg:2:c-format \ write_msg:2:c-format \
die_horribly:3:c-format \ die_horribly:3:c-format \
exit_horribly:3:c-format \ exit_horribly:2:c-format \
ahlog:3:c-format ahlog:3:c-format
...@@ -118,7 +118,9 @@ static int _discoverArchiveFormat(ArchiveHandle *AH); ...@@ -118,7 +118,9 @@ static int _discoverArchiveFormat(ArchiveHandle *AH);
static int RestoringToDB(ArchiveHandle *AH); static int RestoringToDB(ArchiveHandle *AH);
static void dump_lo_buf(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 dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
static void SetOutput(ArchiveHandle *AH, char *filename, int compression); static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
...@@ -1299,7 +1301,7 @@ ahlog(ArchiveHandle *AH, int level, const char *fmt,...) ...@@ -1299,7 +1301,7 @@ ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
return; return;
va_start(ap, fmt); va_start(ap, fmt);
write_msg(NULL, fmt, ap); vwrite_msg(NULL, fmt, ap);
va_end(ap); va_end(ap);
} }
...@@ -1418,10 +1420,12 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH) ...@@ -1418,10 +1420,12 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
} }
/* Report a fatal error and exit(1) */
static void 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) if (AH)
{ {
...@@ -1434,14 +1438,14 @@ _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_lis ...@@ -1434,14 +1438,14 @@ _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_lis
exit(1); exit(1);
} }
/* Archiver use (just different arg declaration) */ /* As above, but with variable arg list */
void void
die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
_die_horribly(AH, modulename, fmt, ap); vdie_horribly(AH, modulename, fmt, ap);
va_end(ap); va_end(ap);
} }
...@@ -1486,10 +1490,10 @@ warn_or_die_horribly(ArchiveHandle *AH, ...@@ -1486,10 +1490,10 @@ warn_or_die_horribly(ArchiveHandle *AH,
va_start(ap, fmt); va_start(ap, fmt);
if (AH->public.exit_on_error) if (AH->public.exit_on_error)
_die_horribly(AH, modulename, fmt, ap); vdie_horribly(AH, modulename, fmt, ap);
else else
{ {
write_msg(modulename, fmt, ap); vwrite_msg(modulename, fmt, ap);
AH->public.n_errors++; AH->public.n_errors++;
} }
va_end(ap); va_end(ap);
...@@ -2218,7 +2222,7 @@ ReadToc(ArchiveHandle *AH) ...@@ -2218,7 +2222,7 @@ ReadToc(ArchiveHandle *AH)
if (depIdx >= depSize) if (depIdx >= depSize)
{ {
depSize *= 2; depSize *= 2;
deps = (DumpId *) realloc(deps, sizeof(DumpId) * depSize); deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
} }
sscanf(tmp, "%d", &deps[depIdx]); sscanf(tmp, "%d", &deps[depIdx]);
free(tmp); free(tmp);
...@@ -2227,7 +2231,7 @@ ReadToc(ArchiveHandle *AH) ...@@ -2227,7 +2231,7 @@ ReadToc(ArchiveHandle *AH)
if (depIdx > 0) /* We have a non-null entry */ 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->dependencies = deps;
te->nDeps = depIdx; te->nDeps = depIdx;
} }
...@@ -4062,7 +4066,7 @@ identify_locking_dependencies(TocEntry *te) ...@@ -4062,7 +4066,7 @@ identify_locking_dependencies(TocEntry *te)
return; return;
} }
te->lockDeps = realloc(lockids, nlockids * sizeof(DumpId)); te->lockDeps = pg_realloc(lockids, nlockids * sizeof(DumpId));
te->nLockDeps = nlockids; te->nLockDeps = nlockids;
} }
......
...@@ -298,8 +298,6 @@ typedef struct _tocEntry ...@@ -298,8 +298,6 @@ typedef struct _tocEntry
int nLockDeps; /* number of such dependencies */ int nLockDeps; /* number of such dependencies */
} TocEntry; } 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 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))); extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
......
...@@ -61,9 +61,6 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha ...@@ -61,9 +61,6 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha
static PGresult *executeQuery(PGconn *conn, const char *query); static PGresult *executeQuery(PGconn *conn, const char *query);
static void executeCommand(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 char pg_dump_bin[MAXPGPATH];
static PQExpBuffer pgdumpopts; static PQExpBuffer pgdumpopts;
static bool skip_acls = false; static bool skip_acls = false;
......
...@@ -39,8 +39,9 @@ ...@@ -39,8 +39,9 @@
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "dumpmem.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "dumpmem.h"
#include "dumputils.h" #include "dumputils.h"
#include <ctype.h> #include <ctype.h>
......
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