Commit cc8d4151 authored by Peter Eisentraut's avatar Peter Eisentraut

Unified logging system for command-line programs

This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.

Features:

- Program name is automatically prefixed.

- Message string does not end with newline.  This removes a common
  source of inconsistencies and omissions.

- Additionally, a final newline is automatically stripped, simplifying
  use of PQerrorMessage() etc., another common source of mistakes.

- I converted error message strings to use %m where possible.

- As a result of the above several points, more translatable message
  strings can be shared between different components and between
  frontends and backend, without gratuitous punctuation or whitespace
  differences.

- There is support for setting a "log level".  This is not meant to be
  user-facing, but can be used internally to implement debug or
  verbose modes.

- Lazy argument evaluation, so no significant overhead if logging at
  some level is disabled.

- Some color in the messages, similar to gcc and clang.  Set
  PG_COLOR=auto to try it out.  Some colors are predefined, but can be
  customized by setting PG_COLORS.

- Common files (common/, fe_utils/, etc.) can handle logging much more
  simply by just using one API without worrying too much about the
  context of the calling program, requiring callbacks, or having to
  pass "progname" around everywhere.

- Some programs called setvbuf() to make sure that stderr is
  unbuffered, even on Windows.  But not all programs did that.  This
  is now done centrally.

Soft goals:

- Reduces vertical space use and visual complexity of error reporting
  in the source code.

- Encourages more deliberate classification of messages.  For example,
  in some cases it wasn't clear without analyzing the surrounding code
  whether a message was meant as an error or just an info.

- Concepts and terms are vaguely aligned with popular logging
  frameworks such as log4j and Python logging.

This is all just about printing stuff out.  Nothing affects program
flow (e.g., fatal exits).  The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.

I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded.  One significant change is that
pg_rewind used to write all error messages to stdout.  That is now
changed to stderr.
Reviewed-by: default avatarDonald Dong <xdong@csumb.edu>
Reviewed-by: default avatarArthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
parent b4cc19ab
...@@ -274,6 +274,17 @@ PostgreSQL documentation ...@@ -274,6 +274,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -322,6 +322,17 @@ PostgreSQL documentation ...@@ -322,6 +322,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -400,6 +400,17 @@ PostgreSQL documentation ...@@ -400,6 +400,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -228,6 +228,17 @@ PostgreSQL documentation ...@@ -228,6 +228,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -220,6 +220,17 @@ PostgreSQL documentation ...@@ -220,6 +220,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -461,6 +461,17 @@ PostgreSQL documentation ...@@ -461,6 +461,17 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><envar>TZ</envar></term> <term><envar>TZ</envar></term>
......
...@@ -687,6 +687,12 @@ PostgreSQL documentation ...@@ -687,6 +687,12 @@ PostgreSQL documentation
(see <xref linkend="libpq-envars"/>). (see <xref linkend="libpq-envars"/>).
</para> </para>
<para>
The environment variable <envar>PG_COLOR</envar> specifies whether to use
color in diagnostics messages. Possible values are
<literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
...@@ -173,6 +173,17 @@ PostgreSQL documentation ...@@ -173,6 +173,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
......
...@@ -68,6 +68,17 @@ PostgreSQL documentation ...@@ -68,6 +68,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
</refentry> </refentry>
...@@ -1224,6 +1224,17 @@ PostgreSQL documentation ...@@ -1224,6 +1224,17 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -695,6 +695,17 @@ PostgreSQL documentation ...@@ -695,6 +695,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -164,6 +164,13 @@ PostgreSQL documentation ...@@ -164,6 +164,13 @@ PostgreSQL documentation
also uses the environment variables supported by <application>libpq</application> also uses the environment variables supported by <application>libpq</application>
(see <xref linkend="libpq-envars"/>). (see <xref linkend="libpq-envars"/>).
</para> </para>
<para>
The environment variable <envar>PG_COLOR</envar> specifies whether to use
color in diagnostics messages. Possible values are
<literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</refsect1> </refsect1>
<refsect1 id="app-pg-isready-notes"> <refsect1 id="app-pg-isready-notes">
......
...@@ -408,6 +408,12 @@ PostgreSQL documentation ...@@ -408,6 +408,12 @@ PostgreSQL documentation
(see <xref linkend="libpq-envars"/>). (see <xref linkend="libpq-envars"/>).
</para> </para>
<para>
The environment variable <envar>PG_COLOR</envar> specifies whether to use
color in diagnostics messages. Possible values are
<literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
...@@ -397,6 +397,13 @@ PostgreSQL documentation ...@@ -397,6 +397,13 @@ PostgreSQL documentation
uses the environment variables supported by <application>libpq</application> uses the environment variables supported by <application>libpq</application>
(see <xref linkend="libpq-envars"/>). (see <xref linkend="libpq-envars"/>).
</para> </para>
<para>
The environment variable <envar>PG_COLOR</envar> specifies whether to use
color in diagnostics messages. Possible values are
<literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
...@@ -320,6 +320,23 @@ PostgreSQL documentation ...@@ -320,6 +320,23 @@ PostgreSQL documentation
</variablelist> </variablelist>
</refsect1> </refsect1>
<refsect1>
<title>Environment</title>
<variablelist>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1> <refsect1>
<title>Notes</title> <title>Notes</title>
......
...@@ -822,6 +822,17 @@ ...@@ -822,6 +822,17 @@
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -234,6 +234,13 @@ PostgreSQL documentation ...@@ -234,6 +234,13 @@ PostgreSQL documentation
<application>pg_rewind</application> also uses the environment variables <application>pg_rewind</application> also uses the environment variables
supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>). supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>).
</para> </para>
<para>
The environment variable <envar>PG_COLOR</envar> specifies whether to use
color in diagnostics messages. Possible values are
<literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
...@@ -206,6 +206,32 @@ PostgreSQL documentation ...@@ -206,6 +206,32 @@ PostgreSQL documentation
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>Environment</title>
<variablelist>
<varlistentry>
<term><envar>PGDATA</envar></term>
<listitem>
<para>
Data directory; see also the <option>-p</option> option.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1> <refsect1>
<title>Notes</title> <title>Notes</title>
<para> <para>
......
...@@ -4333,6 +4333,17 @@ $endif ...@@ -4333,6 +4333,17 @@ $endif
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><envar>PSQL_EDITOR</envar></term> <term><envar>PSQL_EDITOR</envar></term>
<term><envar>EDITOR</envar></term> <term><envar>EDITOR</envar></term>
......
...@@ -352,6 +352,17 @@ PostgreSQL documentation ...@@ -352,6 +352,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -451,6 +451,17 @@ PostgreSQL documentation ...@@ -451,6 +451,17 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><envar>PG_COLOR</envar></term>
<listitem>
<para>
Specifies whether to use color in diagnostics messages. Possible values
are <literal>always</literal>, <literal>auto</literal>,
<literal>never</literal>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<para> <para>
......
...@@ -4761,7 +4761,7 @@ ReadControlFile(void) ...@@ -4761,7 +4761,7 @@ ReadControlFile(void)
void void
UpdateControlFile(void) UpdateControlFile(void)
{ {
update_controlfile(DataDir, NULL, ControlFile, true); update_controlfile(DataDir, ControlFile, true);
} }
/* /*
......
...@@ -54,7 +54,7 @@ pg_control_system(PG_FUNCTION_ARGS) ...@@ -54,7 +54,7 @@ pg_control_system(PG_FUNCTION_ARGS)
tupdesc = BlessTupleDesc(tupdesc); tupdesc = BlessTupleDesc(tupdesc);
/* read the control file */ /* read the control file */
ControlFile = get_controlfile(DataDir, NULL, &crc_ok); ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok) if (!crc_ok)
ereport(ERROR, ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file"))); (errmsg("calculated CRC checksum does not match value stored in file")));
...@@ -132,7 +132,7 @@ pg_control_checkpoint(PG_FUNCTION_ARGS) ...@@ -132,7 +132,7 @@ pg_control_checkpoint(PG_FUNCTION_ARGS)
tupdesc = BlessTupleDesc(tupdesc); tupdesc = BlessTupleDesc(tupdesc);
/* Read the control file. */ /* Read the control file. */
ControlFile = get_controlfile(DataDir, NULL, &crc_ok); ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok) if (!crc_ok)
ereport(ERROR, ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file"))); (errmsg("calculated CRC checksum does not match value stored in file")));
...@@ -236,7 +236,7 @@ pg_control_recovery(PG_FUNCTION_ARGS) ...@@ -236,7 +236,7 @@ pg_control_recovery(PG_FUNCTION_ARGS)
tupdesc = BlessTupleDesc(tupdesc); tupdesc = BlessTupleDesc(tupdesc);
/* read the control file */ /* read the control file */
ControlFile = get_controlfile(DataDir, NULL, &crc_ok); ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok) if (!crc_ok)
ereport(ERROR, ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file"))); (errmsg("calculated CRC checksum does not match value stored in file")));
...@@ -303,7 +303,7 @@ pg_control_init(PG_FUNCTION_ARGS) ...@@ -303,7 +303,7 @@ pg_control_init(PG_FUNCTION_ARGS)
tupdesc = BlessTupleDesc(tupdesc); tupdesc = BlessTupleDesc(tupdesc);
/* read the control file */ /* read the control file */
ControlFile = get_controlfile(DataDir, NULL, &crc_ok); ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok) if (!crc_ok)
ereport(ERROR, ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file"))); (errmsg("calculated CRC checksum does not match value stored in file")));
......
This diff is collapsed.
# src/bin/initdb/nls.mk # src/bin/initdb/nls.mk
CATALOG_NAME = initdb CATALOG_NAME = initdb
AVAIL_LANGUAGES = cs de es fr he it ja ko pl pt_BR ru sv tr vi zh_CN AVAIL_LANGUAGES = cs de es fr he it ja ko pl pt_BR ru sv tr vi zh_CN
GETTEXT_FILES = findtimezone.c initdb.c ../../common/exec.c ../../common/fe_memutils.c ../../common/file_utils.c ../../common/pgfnames.c ../../common/restricted_token.c ../../common/rmtree.c ../../common/username.c ../../common/wait_error.c ../../port/dirmod.c GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) findtimezone.c initdb.c ../../common/exec.c ../../common/fe_memutils.c ../../common/file_utils.c ../../common/pgfnames.c ../../common/restricted_token.c ../../common/rmtree.c ../../common/username.c ../../common/wait_error.c ../../port/dirmod.c
GETTEXT_TRIGGERS = simple_prompt GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) simple_prompt
GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
...@@ -7,11 +7,13 @@ subdir = src/bin/pg_archivecleanup ...@@ -7,11 +7,13 @@ subdir = src/bin/pg_archivecleanup
top_builddir = ../../.. top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils
OBJS = pg_archivecleanup.o $(WIN32RES) OBJS = pg_archivecleanup.o $(WIN32RES)
all: pg_archivecleanup all: pg_archivecleanup
pg_archivecleanup: $(OBJS) | submake-libpgport pg_archivecleanup: $(OBJS) | submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs install: all installdirs
......
# src/bin/pg_archivecleanup/nls.mk # src/bin/pg_archivecleanup/nls.mk
CATALOG_NAME = pg_archivecleanup CATALOG_NAME = pg_archivecleanup
AVAIL_LANGUAGES =de es fr ja ko pl ru sv tr vi AVAIL_LANGUAGES =de es fr ja ko pl ru sv tr vi
GETTEXT_FILES = pg_archivecleanup.c GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) pg_archivecleanup.c
GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS)
GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
...@@ -17,18 +17,18 @@ ...@@ -17,18 +17,18 @@
#include "pg_getopt.h" #include "pg_getopt.h"
#include "fe_utils/logging.h"
#include "access/xlog_internal.h" #include "access/xlog_internal.h"
const char *progname; const char *progname;
/* Options and defaults */ /* Options and defaults */
bool debug = false; /* are we debugging? */
bool dryrun = false; /* are we performing a dry-run operation? */ bool dryrun = false; /* are we performing a dry-run operation? */
char *additional_ext = NULL; /* Extension to remove from filenames */ char *additional_ext = NULL; /* Extension to remove from filenames */
char *archiveLocation; /* where to find the archive? */ char *archiveLocation; /* where to find the archive? */
char *restartWALFileName; /* the file from which we can restart restore */ char *restartWALFileName; /* the file from which we can restart restore */
char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */
char exclusiveCleanupFileName[MAXFNAMELEN]; /* the oldest file we want char exclusiveCleanupFileName[MAXFNAMELEN]; /* the oldest file we want
* to remain in archive */ * to remain in archive */
...@@ -65,8 +65,8 @@ Initialize(void) ...@@ -65,8 +65,8 @@ Initialize(void)
if (stat(archiveLocation, &stat_buf) != 0 || if (stat(archiveLocation, &stat_buf) != 0 ||
!S_ISDIR(stat_buf.st_mode)) !S_ISDIR(stat_buf.st_mode))
{ {
fprintf(stderr, _("%s: archive location \"%s\" does not exist\n"), pg_log_error("archive location \"%s\" does not exist",
progname, archiveLocation); archiveLocation);
exit(2); exit(2);
} }
} }
...@@ -123,6 +123,8 @@ CleanupPriorWALFiles(void) ...@@ -123,6 +123,8 @@ CleanupPriorWALFiles(void)
if ((IsXLogFileName(walfile) || IsPartialXLogFileName(walfile)) && if ((IsXLogFileName(walfile) || IsPartialXLogFileName(walfile)) &&
strcmp(walfile + 8, exclusiveCleanupFileName + 8) < 0) strcmp(walfile + 8, exclusiveCleanupFileName + 8) < 0)
{ {
char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */
/* /*
* Use the original file name again now, including any * Use the original file name again now, including any
* extension that might have been chopped off before testing * extension that might have been chopped off before testing
...@@ -139,37 +141,32 @@ CleanupPriorWALFiles(void) ...@@ -139,37 +141,32 @@ CleanupPriorWALFiles(void)
* user can pipe the output into some other program. * user can pipe the output into some other program.
*/ */
printf("%s\n", WALFilePath); printf("%s\n", WALFilePath);
if (debug) pg_log_debug("file \"%s\" would be removed", WALFilePath);
fprintf(stderr,
_("%s: file \"%s\" would be removed\n"),
progname, WALFilePath);
continue; continue;
} }
if (debug) pg_log_debug("removing file \"%s\"", WALFilePath);
fprintf(stderr, _("%s: removing file \"%s\"\n"),
progname, WALFilePath);
rc = unlink(WALFilePath); rc = unlink(WALFilePath);
if (rc != 0) if (rc != 0)
{ {
fprintf(stderr, _("%s: ERROR: could not remove file \"%s\": %s\n"), pg_log_error("could not remove file \"%s\": %m",
progname, WALFilePath, strerror(errno)); WALFilePath);
break; break;
} }
} }
} }
if (errno) if (errno)
fprintf(stderr, _("%s: could not read archive location \"%s\": %s\n"), pg_log_error("could not read archive location \"%s\": %m",
progname, archiveLocation, strerror(errno)); archiveLocation);
if (closedir(xldir)) if (closedir(xldir))
fprintf(stderr, _("%s: could not close archive location \"%s\": %s\n"), pg_log_error("could not close archive location \"%s\": %m",
progname, archiveLocation, strerror(errno)); archiveLocation);
} }
else else
fprintf(stderr, _("%s: could not open archive location \"%s\": %s\n"), pg_log_error("could not open archive location \"%s\": %m",
progname, archiveLocation, strerror(errno)); archiveLocation);
} }
/* /*
...@@ -241,7 +238,7 @@ SetWALFileNameForCleanup(void) ...@@ -241,7 +238,7 @@ SetWALFileNameForCleanup(void)
if (!fnameOK) if (!fnameOK)
{ {
fprintf(stderr, _("%s: invalid file name argument\n"), progname); pg_log_error("invalid file name argument");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2); exit(2);
} }
...@@ -282,6 +279,7 @@ main(int argc, char **argv) ...@@ -282,6 +279,7 @@ main(int argc, char **argv)
{ {
int c; int c;
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_archivecleanup")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_archivecleanup"));
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
...@@ -304,7 +302,7 @@ main(int argc, char **argv) ...@@ -304,7 +302,7 @@ main(int argc, char **argv)
switch (c) switch (c)
{ {
case 'd': /* Debug mode */ case 'd': /* Debug mode */
debug = true; pg_logging_set_level(PG_LOG_DEBUG);
break; break;
case 'n': /* Dry-Run mode */ case 'n': /* Dry-Run mode */
dryrun = true; dryrun = true;
...@@ -334,7 +332,7 @@ main(int argc, char **argv) ...@@ -334,7 +332,7 @@ main(int argc, char **argv)
} }
else else
{ {
fprintf(stderr, _("%s: must specify archive location\n"), progname); pg_log_error("must specify archive location");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2); exit(2);
} }
...@@ -346,14 +344,14 @@ main(int argc, char **argv) ...@@ -346,14 +344,14 @@ main(int argc, char **argv)
} }
else else
{ {
fprintf(stderr, _("%s: must specify oldest kept WAL file\n"), progname); pg_log_error("must specify oldest kept WAL file");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2); exit(2);
} }
if (optind < argc) if (optind < argc)
{ {
fprintf(stderr, _("%s: too many command-line arguments\n"), progname); pg_log_error("too many command-line arguments");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2); exit(2);
} }
...@@ -368,13 +366,8 @@ main(int argc, char **argv) ...@@ -368,13 +366,8 @@ main(int argc, char **argv)
*/ */
SetWALFileNameForCleanup(); SetWALFileNameForCleanup();
if (debug) pg_log_debug("keeping WAL file \"%s/%s\" and later",
{
snprintf(WALFilePath, MAXPGPATH, "%s/%s",
archiveLocation, exclusiveCleanupFileName); archiveLocation, exclusiveCleanupFileName);
fprintf(stderr, _("%s: keeping WAL file \"%s\" and later\n"),
progname, WALFilePath);
}
/* /*
* Remove WAL files older than cut-off * Remove WAL files older than cut-off
......
# src/bin/pg_basebackup/nls.mk # src/bin/pg_basebackup/nls.mk
CATALOG_NAME = pg_basebackup CATALOG_NAME = pg_basebackup
AVAIL_LANGUAGES = de es fr he it ja ko pl pt_BR ru sv tr vi zh_CN AVAIL_LANGUAGES = de es fr he it ja ko pl pt_BR ru sv tr vi zh_CN
GETTEXT_FILES = pg_basebackup.c pg_receivewal.c pg_recvlogical.c receivelog.c streamutil.c walmethods.c ../../common/fe_memutils.c ../../common/file_utils.c GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) pg_basebackup.c pg_receivewal.c pg_recvlogical.c receivelog.c streamutil.c walmethods.c ../../common/fe_memutils.c ../../common/file_utils.c
GETTEXT_TRIGGERS = simple_prompt tar_set_error GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) simple_prompt tar_set_error
GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "common/file_perm.h" #include "common/file_perm.h"
#include "datatype/timestamp.h" #include "datatype/timestamp.h"
#include "fe_utils/connect.h" #include "fe_utils/connect.h"
#include "fe_utils/logging.h"
#include "port/pg_bswap.h" #include "port/pg_bswap.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
...@@ -90,7 +91,7 @@ GetConnection(void) ...@@ -90,7 +91,7 @@ GetConnection(void)
conn_opts = PQconninfoParse(connection_string, &err_msg); conn_opts = PQconninfoParse(connection_string, &err_msg);
if (conn_opts == NULL) if (conn_opts == NULL)
{ {
fprintf(stderr, "%s: %s", progname, err_msg); pg_log_error("%s", err_msg);
exit(1); exit(1);
} }
...@@ -183,8 +184,7 @@ GetConnection(void) ...@@ -183,8 +184,7 @@ GetConnection(void)
*/ */
if (!tmpconn) if (!tmpconn)
{ {
fprintf(stderr, _("%s: could not connect to server\n"), pg_log_error("could not connect to server");
progname);
exit(1); exit(1);
} }
...@@ -201,8 +201,8 @@ GetConnection(void) ...@@ -201,8 +201,8 @@ GetConnection(void)
if (PQstatus(tmpconn) != CONNECTION_OK) if (PQstatus(tmpconn) != CONNECTION_OK)
{ {
fprintf(stderr, _("%s: could not connect to server: %s"), pg_log_error("could not connect to server: %s",
progname, PQerrorMessage(tmpconn)); PQerrorMessage(tmpconn));
PQfinish(tmpconn); PQfinish(tmpconn);
free(values); free(values);
free(keywords); free(keywords);
...@@ -230,8 +230,8 @@ GetConnection(void) ...@@ -230,8 +230,8 @@ GetConnection(void)
res = PQexec(tmpconn, ALWAYS_SECURE_SEARCH_PATH_SQL); res = PQexec(tmpconn, ALWAYS_SECURE_SEARCH_PATH_SQL);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, _("%s: could not clear search_path: %s"), pg_log_error("could not clear search_path: %s",
progname, PQerrorMessage(tmpconn)); PQerrorMessage(tmpconn));
PQclear(res); PQclear(res);
PQfinish(tmpconn); PQfinish(tmpconn);
exit(1); exit(1);
...@@ -246,18 +246,14 @@ GetConnection(void) ...@@ -246,18 +246,14 @@ GetConnection(void)
tmpparam = PQparameterStatus(tmpconn, "integer_datetimes"); tmpparam = PQparameterStatus(tmpconn, "integer_datetimes");
if (!tmpparam) if (!tmpparam)
{ {
fprintf(stderr, pg_log_error("could not determine server setting for integer_datetimes");
_("%s: could not determine server setting for integer_datetimes\n"),
progname);
PQfinish(tmpconn); PQfinish(tmpconn);
exit(1); exit(1);
} }
if (strcmp(tmpparam, "on") != 0) if (strcmp(tmpparam, "on") != 0)
{ {
fprintf(stderr, pg_log_error("integer_datetimes compile flag does not match server");
_("%s: integer_datetimes compile flag does not match server\n"),
progname);
PQfinish(tmpconn); PQfinish(tmpconn);
exit(1); exit(1);
} }
...@@ -300,17 +296,16 @@ RetrieveWalSegSize(PGconn *conn) ...@@ -300,17 +296,16 @@ RetrieveWalSegSize(PGconn *conn)
res = PQexec(conn, "SHOW wal_segment_size"); res = PQexec(conn, "SHOW wal_segment_size");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), pg_log_error("could not send replication command \"%s\": %s",
progname, "SHOW wal_segment_size", PQerrorMessage(conn)); "SHOW wal_segment_size", PQerrorMessage(conn));
PQclear(res); PQclear(res);
return false; return false;
} }
if (PQntuples(res) != 1 || PQnfields(res) < 1) if (PQntuples(res) != 1 || PQnfields(res) < 1)
{ {
fprintf(stderr, pg_log_error("could not fetch WAL segment size: got %d rows and %d fields, expected %d rows and %d or more fields",
_("%s: could not fetch WAL segment size: got %d rows and %d fields, expected %d rows and %d or more fields\n"), PQntuples(res), PQnfields(res), 1, 1);
progname, PQntuples(res), PQnfields(res), 1, 1);
PQclear(res); PQclear(res);
return false; return false;
...@@ -319,8 +314,7 @@ RetrieveWalSegSize(PGconn *conn) ...@@ -319,8 +314,7 @@ RetrieveWalSegSize(PGconn *conn)
/* fetch xlog value and unit from the result */ /* fetch xlog value and unit from the result */
if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2) if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2)
{ {
fprintf(stderr, _("%s: WAL segment size could not be parsed\n"), pg_log_error("WAL segment size could not be parsed");
progname);
return false; return false;
} }
...@@ -335,11 +329,10 @@ RetrieveWalSegSize(PGconn *conn) ...@@ -335,11 +329,10 @@ RetrieveWalSegSize(PGconn *conn)
if (!IsValidWalSegSize(WalSegSz)) if (!IsValidWalSegSize(WalSegSz))
{ {
fprintf(stderr, pg_log_error(ngettext("WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d byte",
ngettext("%s: WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d byte\n", "WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d bytes",
"%s: WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d bytes\n",
WalSegSz), WalSegSz),
progname, WalSegSz); WalSegSz);
return false; return false;
} }
...@@ -374,17 +367,16 @@ RetrieveDataDirCreatePerm(PGconn *conn) ...@@ -374,17 +367,16 @@ RetrieveDataDirCreatePerm(PGconn *conn)
res = PQexec(conn, "SHOW data_directory_mode"); res = PQexec(conn, "SHOW data_directory_mode");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), pg_log_error("could not send replication command \"%s\": %s",
progname, "SHOW data_directory_mode", PQerrorMessage(conn)); "SHOW data_directory_mode", PQerrorMessage(conn));
PQclear(res); PQclear(res);
return false; return false;
} }
if (PQntuples(res) != 1 || PQnfields(res) < 1) if (PQntuples(res) != 1 || PQnfields(res) < 1)
{ {
fprintf(stderr, pg_log_error("could not fetch group access flag: got %d rows and %d fields, expected %d rows and %d or more fields",
_("%s: could not fetch group access flag: got %d rows and %d fields, expected %d rows and %d or more fields\n"), PQntuples(res), PQnfields(res), 1, 1);
progname, PQntuples(res), PQnfields(res), 1, 1);
PQclear(res); PQclear(res);
return false; return false;
...@@ -392,8 +384,8 @@ RetrieveDataDirCreatePerm(PGconn *conn) ...@@ -392,8 +384,8 @@ RetrieveDataDirCreatePerm(PGconn *conn)
if (sscanf(PQgetvalue(res, 0, 0), "%o", &data_directory_mode) != 1) if (sscanf(PQgetvalue(res, 0, 0), "%o", &data_directory_mode) != 1)
{ {
fprintf(stderr, _("%s: group access flag could not be parsed: %s\n"), pg_log_error("group access flag could not be parsed: %s",
progname, PQgetvalue(res, 0, 0)); PQgetvalue(res, 0, 0));
PQclear(res); PQclear(res);
return false; return false;
...@@ -427,17 +419,16 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, ...@@ -427,17 +419,16 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
res = PQexec(conn, "IDENTIFY_SYSTEM"); res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), pg_log_error("could not send replication command \"%s\": %s",
progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn)); "IDENTIFY_SYSTEM", PQerrorMessage(conn));
PQclear(res); PQclear(res);
return false; return false;
} }
if (PQntuples(res) != 1 || PQnfields(res) < 3) if (PQntuples(res) != 1 || PQnfields(res) < 3)
{ {
fprintf(stderr, pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
_("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"), PQntuples(res), PQnfields(res), 1, 3);
progname, PQntuples(res), PQnfields(res), 1, 3);
PQclear(res); PQclear(res);
return false; return false;
...@@ -456,9 +447,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, ...@@ -456,9 +447,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
{ {
if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2) if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2)
{ {
fprintf(stderr, pg_log_error("could not parse write-ahead log location \"%s\"",
_("%s: could not parse write-ahead log location \"%s\"\n"), PQgetvalue(res, 0, 2));
progname, PQgetvalue(res, 0, 2));
PQclear(res); PQclear(res);
return false; return false;
...@@ -474,9 +464,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, ...@@ -474,9 +464,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
{ {
if (PQnfields(res) < 4) if (PQnfields(res) < 4)
{ {
fprintf(stderr, pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
_("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"), PQntuples(res), PQnfields(res), 1, 4);
progname, PQntuples(res), PQnfields(res), 1, 4);
PQclear(res); PQclear(res);
return false; return false;
...@@ -541,8 +530,8 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, ...@@ -541,8 +530,8 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
} }
else else
{ {
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), pg_log_error("could not send replication command \"%s\": %s",
progname, query->data, PQerrorMessage(conn)); query->data, PQerrorMessage(conn));
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
PQclear(res); PQclear(res);
...@@ -552,9 +541,8 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, ...@@ -552,9 +541,8 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
if (PQntuples(res) != 1 || PQnfields(res) != 4) if (PQntuples(res) != 1 || PQnfields(res) != 4)
{ {
fprintf(stderr, pg_log_error("could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields",
_("%s: could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"), slot_name,
progname, slot_name,
PQntuples(res), PQnfields(res), 1, 4); PQntuples(res), PQnfields(res), 1, 4);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
...@@ -587,8 +575,8 @@ DropReplicationSlot(PGconn *conn, const char *slot_name) ...@@ -587,8 +575,8 @@ DropReplicationSlot(PGconn *conn, const char *slot_name)
res = PQexec(conn, query->data); res = PQexec(conn, query->data);
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), pg_log_error("could not send replication command \"%s\": %s",
progname, query->data, PQerrorMessage(conn)); query->data, PQerrorMessage(conn));
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
PQclear(res); PQclear(res);
...@@ -597,9 +585,8 @@ DropReplicationSlot(PGconn *conn, const char *slot_name) ...@@ -597,9 +585,8 @@ DropReplicationSlot(PGconn *conn, const char *slot_name)
if (PQntuples(res) != 0 || PQnfields(res) != 0) if (PQntuples(res) != 0 || PQnfields(res) != 0)
{ {
fprintf(stderr, pg_log_error("could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields",
_("%s: could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"), slot_name,
progname, slot_name,
PQntuples(res), PQnfields(res), 0, 0); PQntuples(res), PQnfields(res), 0, 0);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
......
...@@ -155,8 +155,8 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ ...@@ -155,8 +155,8 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
*/ */
if (dir_data->sync) if (dir_data->sync)
{ {
if (fsync_fname(tmppath, false, progname) != 0 || if (fsync_fname(tmppath, false) != 0 ||
fsync_parent_path(tmppath, progname) != 0) fsync_parent_path(tmppath) != 0)
{ {
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
if (dir_data->compression > 0) if (dir_data->compression > 0)
...@@ -244,7 +244,7 @@ dir_close(Walfile f, WalCloseMethod method) ...@@ -244,7 +244,7 @@ dir_close(Walfile f, WalCloseMethod method)
snprintf(tmppath2, sizeof(tmppath2), "%s/%s%s", snprintf(tmppath2, sizeof(tmppath2), "%s/%s%s",
dir_data->basedir, df->pathname, dir_data->basedir, df->pathname,
dir_data->compression > 0 ? ".gz" : ""); dir_data->compression > 0 ? ".gz" : "");
r = durable_rename(tmppath, tmppath2, progname); r = durable_rename(tmppath, tmppath2);
} }
else if (method == CLOSE_UNLINK) else if (method == CLOSE_UNLINK)
{ {
...@@ -264,9 +264,9 @@ dir_close(Walfile f, WalCloseMethod method) ...@@ -264,9 +264,9 @@ dir_close(Walfile f, WalCloseMethod method)
*/ */
if (dir_data->sync) if (dir_data->sync)
{ {
r = fsync_fname(df->fullpath, false, progname); r = fsync_fname(df->fullpath, false);
if (r == 0) if (r == 0)
r = fsync_parent_path(df->fullpath, progname); r = fsync_parent_path(df->fullpath);
} }
} }
} }
...@@ -339,7 +339,7 @@ dir_finish(void) ...@@ -339,7 +339,7 @@ dir_finish(void)
* Files are fsynced when they are closed, but we need to fsync the * Files are fsynced when they are closed, but we need to fsync the
* directory entry here as well. * directory entry here as well.
*/ */
if (fsync_fname(dir_data->basedir, true, progname) != 0) if (fsync_fname(dir_data->basedir, true) != 0)
return false; return false;
} }
return true; return true;
...@@ -970,9 +970,9 @@ tar_finish(void) ...@@ -970,9 +970,9 @@ tar_finish(void)
if (tar_data->sync) if (tar_data->sync)
{ {
if (fsync_fname(tar_data->tarfilename, false, progname) != 0) if (fsync_fname(tar_data->tarfilename, false) != 0)
return false; return false;
if (fsync_parent_path(tar_data->tarfilename, progname) != 0) if (fsync_parent_path(tar_data->tarfilename) != 0)
return false; return false;
} }
......
...@@ -15,11 +15,13 @@ subdir = src/bin/pg_checksums ...@@ -15,11 +15,13 @@ subdir = src/bin/pg_checksums
top_builddir = ../../.. top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils
OBJS= pg_checksums.o $(WIN32RES) OBJS= pg_checksums.o $(WIN32RES)
all: pg_checksums all: pg_checksums
pg_checksums: $(OBJS) | submake-libpgport pg_checksums: $(OBJS) | submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs install: all installdirs
......
# src/bin/pg_checksums/nls.mk # src/bin/pg_checksums/nls.mk
CATALOG_NAME = pg_checksums CATALOG_NAME = pg_checksums
AVAIL_LANGUAGES = AVAIL_LANGUAGES =
GETTEXT_FILES = pg_checksums.c GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) pg_checksums.c
GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS)
GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "common/controldata_utils.h" #include "common/controldata_utils.h"
#include "common/file_perm.h" #include "common/file_perm.h"
#include "common/file_utils.h" #include "common/file_utils.h"
#include "fe_utils/logging.h"
#include "getopt_long.h" #include "getopt_long.h"
#include "pg_getopt.h" #include "pg_getopt.h"
#include "storage/bufpage.h" #include "storage/bufpage.h"
...@@ -126,8 +127,7 @@ scan_file(const char *fn, BlockNumber segmentno) ...@@ -126,8 +127,7 @@ scan_file(const char *fn, BlockNumber segmentno)
if (f < 0) if (f < 0)
{ {
fprintf(stderr, _("%s: could not open file \"%s\": %s\n"), pg_log_error("could not open file \"%s\": %m", fn);
progname, fn, strerror(errno));
exit(1); exit(1);
} }
...@@ -142,8 +142,8 @@ scan_file(const char *fn, BlockNumber segmentno) ...@@ -142,8 +142,8 @@ scan_file(const char *fn, BlockNumber segmentno)
break; break;
if (r != BLCKSZ) if (r != BLCKSZ)
{ {
fprintf(stderr, _("%s: could not read block %u in file \"%s\": read %d of %d\n"), pg_log_error("could not read block %u in file \"%s\": read %d of %d",
progname, blockno, fn, r, BLCKSZ); blockno, fn, r, BLCKSZ);
exit(1); exit(1);
} }
blocks++; blocks++;
...@@ -158,8 +158,8 @@ scan_file(const char *fn, BlockNumber segmentno) ...@@ -158,8 +158,8 @@ scan_file(const char *fn, BlockNumber segmentno)
if (csum != header->pd_checksum) if (csum != header->pd_checksum)
{ {
if (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_VERSION) if (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_VERSION)
fprintf(stderr, _("%s: checksum verification failed in file \"%s\", block %u: calculated checksum %X but block contains %X\n"), pg_log_error("checksum verification failed in file \"%s\", block %u: calculated checksum %X but block contains %X",
progname, fn, blockno, csum, header->pd_checksum); fn, blockno, csum, header->pd_checksum);
badblocks++; badblocks++;
} }
} }
...@@ -171,15 +171,15 @@ scan_file(const char *fn, BlockNumber segmentno) ...@@ -171,15 +171,15 @@ scan_file(const char *fn, BlockNumber segmentno)
/* Seek back to beginning of block */ /* Seek back to beginning of block */
if (lseek(f, -BLCKSZ, SEEK_CUR) < 0) if (lseek(f, -BLCKSZ, SEEK_CUR) < 0)
{ {
fprintf(stderr, _("%s: seek failed for block %d in file \"%s\": %s\n"), progname, blockno, fn, strerror(errno)); pg_log_error("seek failed for block %d in file \"%s\": %m", blockno, fn);
exit(1); exit(1);
} }
/* Write block with checksum */ /* Write block with checksum */
if (write(f, buf.data, BLCKSZ) != BLCKSZ) if (write(f, buf.data, BLCKSZ) != BLCKSZ)
{ {
fprintf(stderr, _("%s: could not update checksum of block %d in file \"%s\": %s\n"), pg_log_error("could not update checksum of block %d in file \"%s\": %m",
progname, blockno, fn, strerror(errno)); blockno, fn);
exit(1); exit(1);
} }
} }
...@@ -188,11 +188,9 @@ scan_file(const char *fn, BlockNumber segmentno) ...@@ -188,11 +188,9 @@ scan_file(const char *fn, BlockNumber segmentno)
if (verbose) if (verbose)
{ {
if (mode == PG_MODE_CHECK) if (mode == PG_MODE_CHECK)
fprintf(stderr, pg_log_info("checksums verified in file \"%s\"", fn);
_("%s: checksums verified in file \"%s\"\n"), progname, fn);
if (mode == PG_MODE_ENABLE) if (mode == PG_MODE_ENABLE)
fprintf(stderr, pg_log_info("checksums enabled in file \"%s\"", fn);
_("%s: checksums enabled in file \"%s\"\n"), progname, fn);
} }
close(f); close(f);
...@@ -209,8 +207,7 @@ scan_directory(const char *basedir, const char *subdir) ...@@ -209,8 +207,7 @@ scan_directory(const char *basedir, const char *subdir)
dir = opendir(path); dir = opendir(path);
if (!dir) if (!dir)
{ {
fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"), pg_log_error("could not open directory \"%s\": %m", path);
progname, path, strerror(errno));
exit(1); exit(1);
} }
while ((de = readdir(dir)) != NULL) while ((de = readdir(dir)) != NULL)
...@@ -237,8 +234,7 @@ scan_directory(const char *basedir, const char *subdir) ...@@ -237,8 +234,7 @@ scan_directory(const char *basedir, const char *subdir)
snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name); snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
if (lstat(fn, &st) < 0) if (lstat(fn, &st) < 0)
{ {
fprintf(stderr, _("%s: could not stat file \"%s\": %s\n"), pg_log_error("could not stat file \"%s\": %m", fn);
progname, fn, strerror(errno));
exit(1); exit(1);
} }
if (S_ISREG(st.st_mode)) if (S_ISREG(st.st_mode))
...@@ -265,8 +261,8 @@ scan_directory(const char *basedir, const char *subdir) ...@@ -265,8 +261,8 @@ scan_directory(const char *basedir, const char *subdir)
segmentno = atoi(segmentpath); segmentno = atoi(segmentpath);
if (segmentno == 0) if (segmentno == 0)
{ {
fprintf(stderr, _("%s: invalid segment number %d in file name \"%s\"\n"), pg_log_error("invalid segment number %d in file name \"%s\"",
progname, segmentno, fn); segmentno, fn);
exit(1); exit(1);
} }
} }
...@@ -309,8 +305,8 @@ main(int argc, char *argv[]) ...@@ -309,8 +305,8 @@ main(int argc, char *argv[])
int option_index; int option_index;
bool crc_ok; bool crc_ok;
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_checksums")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_checksums"));
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
if (argc > 1) if (argc > 1)
...@@ -352,7 +348,7 @@ main(int argc, char *argv[]) ...@@ -352,7 +348,7 @@ main(int argc, char *argv[])
case 'r': case 'r':
if (atoi(optarg) == 0) if (atoi(optarg) == 0)
{ {
fprintf(stderr, _("%s: invalid relfilenode specification, must be numeric: %s\n"), progname, optarg); pg_log_error("invalid relfilenode specification, must be numeric: %s", optarg);
exit(1); exit(1);
} }
only_relfilenode = pstrdup(optarg); only_relfilenode = pstrdup(optarg);
...@@ -373,7 +369,7 @@ main(int argc, char *argv[]) ...@@ -373,7 +369,7 @@ main(int argc, char *argv[])
/* If no DataDir was specified, and none could be found, error out */ /* If no DataDir was specified, and none could be found, error out */
if (DataDir == NULL) if (DataDir == NULL)
{ {
fprintf(stderr, _("%s: no data directory specified\n"), progname); pg_log_error("no data directory specified");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1); exit(1);
} }
...@@ -382,8 +378,8 @@ main(int argc, char *argv[]) ...@@ -382,8 +378,8 @@ main(int argc, char *argv[])
/* Complain if any arguments remain */ /* Complain if any arguments remain */
if (optind < argc) if (optind < argc)
{ {
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), pg_log_error("too many command-line arguments (first is \"%s\")",
progname, argv[optind]); argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname); progname);
exit(1); exit(1);
...@@ -392,31 +388,29 @@ main(int argc, char *argv[]) ...@@ -392,31 +388,29 @@ main(int argc, char *argv[])
/* Relfilenode checking only works in --check mode */ /* Relfilenode checking only works in --check mode */
if (mode != PG_MODE_CHECK && only_relfilenode) if (mode != PG_MODE_CHECK && only_relfilenode)
{ {
fprintf(stderr, _("%s: relfilenode option only possible with --check\n"), progname); pg_log_error("relfilenode option only possible with --check");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname); progname);
exit(1); exit(1);
} }
/* Check if cluster is running */ /* Check if cluster is running */
ControlFile = get_controlfile(DataDir, progname, &crc_ok); ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok) if (!crc_ok)
{ {
fprintf(stderr, _("%s: pg_control CRC value is incorrect\n"), progname); pg_log_error("pg_control CRC value is incorrect");
exit(1); exit(1);
} }
if (ControlFile->pg_control_version != PG_CONTROL_VERSION) if (ControlFile->pg_control_version != PG_CONTROL_VERSION)
{ {
fprintf(stderr, _("%s: cluster is not compatible with this version of pg_checksums\n"), pg_log_error("cluster is not compatible with this version of pg_checksums");
progname);
exit(1); exit(1);
} }
if (ControlFile->blcksz != BLCKSZ) if (ControlFile->blcksz != BLCKSZ)
{ {
fprintf(stderr, _("%s: database cluster is not compatible.\n"), pg_log_error("database cluster is not compatible");
progname);
fprintf(stderr, _("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.\n"), fprintf(stderr, _("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.\n"),
ControlFile->blcksz, BLCKSZ); ControlFile->blcksz, BLCKSZ);
exit(1); exit(1);
...@@ -425,28 +419,28 @@ main(int argc, char *argv[]) ...@@ -425,28 +419,28 @@ main(int argc, char *argv[])
if (ControlFile->state != DB_SHUTDOWNED && if (ControlFile->state != DB_SHUTDOWNED &&
ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY) ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY)
{ {
fprintf(stderr, _("%s: cluster must be shut down\n"), progname); pg_log_error("cluster must be shut down");
exit(1); exit(1);
} }
if (ControlFile->data_checksum_version == 0 && if (ControlFile->data_checksum_version == 0 &&
mode == PG_MODE_CHECK) mode == PG_MODE_CHECK)
{ {
fprintf(stderr, _("%s: data checksums are not enabled in cluster\n"), progname); pg_log_error("data checksums are not enabled in cluster");
exit(1); exit(1);
} }
if (ControlFile->data_checksum_version == 0 && if (ControlFile->data_checksum_version == 0 &&
mode == PG_MODE_DISABLE) mode == PG_MODE_DISABLE)
{ {
fprintf(stderr, _("%s: data checksums are already disabled in cluster\n"), progname); pg_log_error("data checksums are already disabled in cluster");
exit(1); exit(1);
} }
if (ControlFile->data_checksum_version > 0 && if (ControlFile->data_checksum_version > 0 &&
mode == PG_MODE_ENABLE) mode == PG_MODE_ENABLE)
{ {
fprintf(stderr, _("%s: data checksums are already enabled in cluster\n"), progname); pg_log_error("data checksums are already enabled in cluster");
exit(1); exit(1);
} }
...@@ -482,12 +476,12 @@ main(int argc, char *argv[]) ...@@ -482,12 +476,12 @@ main(int argc, char *argv[])
if (do_sync) if (do_sync)
{ {
printf(_("Syncing data directory\n")); pg_log_info("syncing data directory");
fsync_pgdata(DataDir, progname, PG_VERSION_NUM); fsync_pgdata(DataDir, PG_VERSION_NUM);
} }
printf(_("Updating control file\n")); pg_log_info("updating control file");
update_controlfile(DataDir, progname, ControlFile, do_sync); update_controlfile(DataDir, ControlFile, do_sync);
if (verbose) if (verbose)
printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version); printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);
......
...@@ -15,11 +15,13 @@ subdir = src/bin/pg_controldata ...@@ -15,11 +15,13 @@ subdir = src/bin/pg_controldata
top_builddir = ../../.. top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils
OBJS= pg_controldata.o $(WIN32RES) OBJS= pg_controldata.o $(WIN32RES)
all: pg_controldata all: pg_controldata
pg_controldata: $(OBJS) | submake-libpgport pg_controldata: $(OBJS) | submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs install: all installdirs
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "access/xlog_internal.h" #include "access/xlog_internal.h"
#include "catalog/pg_control.h" #include "catalog/pg_control.h"
#include "common/controldata_utils.h" #include "common/controldata_utils.h"
#include "fe_utils/logging.h"
#include "pg_getopt.h" #include "pg_getopt.h"
#include "getopt_long.h" #include "getopt_long.h"
...@@ -107,8 +108,8 @@ main(int argc, char *argv[]) ...@@ -107,8 +108,8 @@ main(int argc, char *argv[])
int i; int i;
int WalSegSz; int WalSegSz;
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
if (argc > 1) if (argc > 1)
...@@ -150,8 +151,8 @@ main(int argc, char *argv[]) ...@@ -150,8 +151,8 @@ main(int argc, char *argv[])
/* Complain if any arguments remain */ /* Complain if any arguments remain */
if (optind < argc) if (optind < argc)
{ {
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), pg_log_error("too many command-line arguments (first is \"%s\")",
progname, argv[optind]); argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname); progname);
exit(1); exit(1);
...@@ -159,13 +160,13 @@ main(int argc, char *argv[]) ...@@ -159,13 +160,13 @@ main(int argc, char *argv[])
if (DataDir == NULL) if (DataDir == NULL)
{ {
fprintf(stderr, _("%s: no data directory specified\n"), progname); pg_log_error("no data directory specified");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1); exit(1);
} }
/* get a copy of the control file */ /* get a copy of the control file */
ControlFile = get_controlfile(DataDir, progname, &crc_ok); ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok) if (!crc_ok)
printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n" printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
"Either the file is corrupt, or it has a different layout than this program\n" "Either the file is corrupt, or it has a different layout than this program\n"
......
...@@ -16,6 +16,8 @@ subdir = src/bin/pg_ctl ...@@ -16,6 +16,8 @@ subdir = src/bin/pg_ctl
top_builddir = ../../.. top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils
# On Windows, we need to link with libpq, just for use of pqexpbuffer; # On Windows, we need to link with libpq, just for use of pqexpbuffer;
# but let's not pull that in on platforms where we don't need it. # but let's not pull that in on platforms where we don't need it.
ifeq ($(PORTNAME), win32) ifeq ($(PORTNAME), win32)
...@@ -28,7 +30,7 @@ OBJS= pg_ctl.o $(WIN32RES) ...@@ -28,7 +30,7 @@ OBJS= pg_ctl.o $(WIN32RES)
all: pg_ctl all: pg_ctl
pg_ctl: $(OBJS) | submake-libpgport $(SUBMAKE_LIBPQ) pg_ctl: $(OBJS) | submake-libpgport submake-libpgfeutils $(SUBMAKE_LIBPQ)
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs install: all installdirs
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "catalog/pg_control.h" #include "catalog/pg_control.h"
#include "common/controldata_utils.h" #include "common/controldata_utils.h"
#include "common/file_perm.h" #include "common/file_perm.h"
#include "fe_utils/logging.h"
#include "getopt_long.h" #include "getopt_long.h"
#include "utils/pidfile.h" #include "utils/pidfile.h"
...@@ -2231,7 +2232,7 @@ get_control_dbstate(void) ...@@ -2231,7 +2232,7 @@ get_control_dbstate(void)
{ {
DBState ret; DBState ret;
bool crc_ok; bool crc_ok;
ControlFileData *control_file_data = get_controlfile(pg_data, progname, &crc_ok); ControlFileData *control_file_data = get_controlfile(pg_data, &crc_ok);
if (!crc_ok) if (!crc_ok)
{ {
...@@ -2268,10 +2269,7 @@ main(int argc, char **argv) ...@@ -2268,10 +2269,7 @@ main(int argc, char **argv)
int c; int c;
pgpid_t killproc = 0; pgpid_t killproc = 0;
#ifdef WIN32 pg_logging_init(argv[0]);
setvbuf(stderr, NULL, _IONBF, 0);
#endif
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_ctl")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_ctl"));
start_time = time(NULL); start_time = time(NULL);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <ctype.h> #include <ctype.h>
#include "catalog/pg_class_d.h" #include "catalog/pg_class_d.h"
#include "fe_utils/logging.h"
#include "fe_utils/string_utils.h" #include "fe_utils/string_utils.h"
...@@ -120,17 +121,14 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -120,17 +121,14 @@ getSchemaData(Archive *fout, int *numTablesPtr)
* extension membership needs to be consultable during decisions about * extension membership needs to be consultable during decisions about
* whether other objects are to be dumped. * whether other objects are to be dumped.
*/ */
if (g_verbose) pg_log_info("reading extensions");
write_msg(NULL, "reading extensions\n");
extinfo = getExtensions(fout, &numExtensions); extinfo = getExtensions(fout, &numExtensions);
extinfoindex = buildIndexArray(extinfo, numExtensions, sizeof(ExtensionInfo)); extinfoindex = buildIndexArray(extinfo, numExtensions, sizeof(ExtensionInfo));
if (g_verbose) pg_log_info("identifying extension members");
write_msg(NULL, "identifying extension members\n");
getExtensionMembership(fout, extinfo, numExtensions); getExtensionMembership(fout, extinfo, numExtensions);
if (g_verbose) pg_log_info("reading schemas");
write_msg(NULL, "reading schemas\n");
nspinfo = getNamespaces(fout, &numNamespaces); nspinfo = getNamespaces(fout, &numNamespaces);
nspinfoindex = buildIndexArray(nspinfo, numNamespaces, sizeof(NamespaceInfo)); nspinfoindex = buildIndexArray(nspinfo, numNamespaces, sizeof(NamespaceInfo));
...@@ -140,160 +138,124 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -140,160 +138,124 @@ getSchemaData(Archive *fout, int *numTablesPtr)
* However, we have to do getNamespaces first because the tables get * However, we have to do getNamespaces first because the tables get
* linked to their containing namespaces during getTables. * linked to their containing namespaces during getTables.
*/ */
if (g_verbose) pg_log_info("reading user-defined tables");
write_msg(NULL, "reading user-defined tables\n");
tblinfo = getTables(fout, &numTables); tblinfo = getTables(fout, &numTables);
tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo)); tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
/* Do this after we've built tblinfoindex */ /* Do this after we've built tblinfoindex */
getOwnedSeqs(fout, tblinfo, numTables); getOwnedSeqs(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("reading user-defined functions");
write_msg(NULL, "reading user-defined functions\n");
funinfo = getFuncs(fout, &numFuncs); funinfo = getFuncs(fout, &numFuncs);
funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo)); funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
/* this must be after getTables and getFuncs */ /* this must be after getTables and getFuncs */
if (g_verbose) pg_log_info("reading user-defined types");
write_msg(NULL, "reading user-defined types\n");
typinfo = getTypes(fout, &numTypes); typinfo = getTypes(fout, &numTypes);
typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo)); typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo));
/* this must be after getFuncs, too */ /* this must be after getFuncs, too */
if (g_verbose) pg_log_info("reading procedural languages");
write_msg(NULL, "reading procedural languages\n");
getProcLangs(fout, &numProcLangs); getProcLangs(fout, &numProcLangs);
if (g_verbose) pg_log_info("reading user-defined aggregate functions");
write_msg(NULL, "reading user-defined aggregate functions\n");
getAggregates(fout, &numAggregates); getAggregates(fout, &numAggregates);
if (g_verbose) pg_log_info("reading user-defined operators");
write_msg(NULL, "reading user-defined operators\n");
oprinfo = getOperators(fout, &numOperators); oprinfo = getOperators(fout, &numOperators);
oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo)); oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo));
if (g_verbose) pg_log_info("reading user-defined access methods");
write_msg(NULL, "reading user-defined access methods\n");
getAccessMethods(fout, &numAccessMethods); getAccessMethods(fout, &numAccessMethods);
if (g_verbose) pg_log_info("reading user-defined operator classes");
write_msg(NULL, "reading user-defined operator classes\n");
getOpclasses(fout, &numOpclasses); getOpclasses(fout, &numOpclasses);
if (g_verbose) pg_log_info("reading user-defined operator families");
write_msg(NULL, "reading user-defined operator families\n");
getOpfamilies(fout, &numOpfamilies); getOpfamilies(fout, &numOpfamilies);
if (g_verbose) pg_log_info("reading user-defined text search parsers");
write_msg(NULL, "reading user-defined text search parsers\n");
getTSParsers(fout, &numTSParsers); getTSParsers(fout, &numTSParsers);
if (g_verbose) pg_log_info("reading user-defined text search templates");
write_msg(NULL, "reading user-defined text search templates\n");
getTSTemplates(fout, &numTSTemplates); getTSTemplates(fout, &numTSTemplates);
if (g_verbose) pg_log_info("reading user-defined text search dictionaries");
write_msg(NULL, "reading user-defined text search dictionaries\n");
getTSDictionaries(fout, &numTSDicts); getTSDictionaries(fout, &numTSDicts);
if (g_verbose) pg_log_info("reading user-defined text search configurations");
write_msg(NULL, "reading user-defined text search configurations\n");
getTSConfigurations(fout, &numTSConfigs); getTSConfigurations(fout, &numTSConfigs);
if (g_verbose) pg_log_info("reading user-defined foreign-data wrappers");
write_msg(NULL, "reading user-defined foreign-data wrappers\n");
getForeignDataWrappers(fout, &numForeignDataWrappers); getForeignDataWrappers(fout, &numForeignDataWrappers);
if (g_verbose) pg_log_info("reading user-defined foreign servers");
write_msg(NULL, "reading user-defined foreign servers\n");
getForeignServers(fout, &numForeignServers); getForeignServers(fout, &numForeignServers);
if (g_verbose) pg_log_info("reading default privileges");
write_msg(NULL, "reading default privileges\n");
getDefaultACLs(fout, &numDefaultACLs); getDefaultACLs(fout, &numDefaultACLs);
if (g_verbose) pg_log_info("reading user-defined collations");
write_msg(NULL, "reading user-defined collations\n");
collinfo = getCollations(fout, &numCollations); collinfo = getCollations(fout, &numCollations);
collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo)); collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo));
if (g_verbose) pg_log_info("reading user-defined conversions");
write_msg(NULL, "reading user-defined conversions\n");
getConversions(fout, &numConversions); getConversions(fout, &numConversions);
if (g_verbose) pg_log_info("reading type casts");
write_msg(NULL, "reading type casts\n");
getCasts(fout, &numCasts); getCasts(fout, &numCasts);
if (g_verbose) pg_log_info("reading transforms");
write_msg(NULL, "reading transforms\n");
getTransforms(fout, &numTransforms); getTransforms(fout, &numTransforms);
if (g_verbose) pg_log_info("reading table inheritance information");
write_msg(NULL, "reading table inheritance information\n");
inhinfo = getInherits(fout, &numInherits); inhinfo = getInherits(fout, &numInherits);
if (g_verbose) pg_log_info("reading event triggers");
write_msg(NULL, "reading event triggers\n");
getEventTriggers(fout, &numEventTriggers); getEventTriggers(fout, &numEventTriggers);
/* Identify extension configuration tables that should be dumped */ /* Identify extension configuration tables that should be dumped */
if (g_verbose) pg_log_info("finding extension tables");
write_msg(NULL, "finding extension tables\n");
processExtensionTables(fout, extinfo, numExtensions); processExtensionTables(fout, extinfo, numExtensions);
/* Link tables to parents, mark parents of target tables interesting */ /* Link tables to parents, mark parents of target tables interesting */
if (g_verbose) pg_log_info("finding inheritance relationships");
write_msg(NULL, "finding inheritance relationships\n");
flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits); flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits);
if (g_verbose) pg_log_info("reading column info for interesting tables");
write_msg(NULL, "reading column info for interesting tables\n");
getTableAttrs(fout, tblinfo, numTables); getTableAttrs(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("flagging inherited columns in subtables");
write_msg(NULL, "flagging inherited columns in subtables\n");
flagInhAttrs(fout->dopt, tblinfo, numTables); flagInhAttrs(fout->dopt, tblinfo, numTables);
if (g_verbose) pg_log_info("reading indexes");
write_msg(NULL, "reading indexes\n");
getIndexes(fout, tblinfo, numTables); getIndexes(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("flagging indexes in partitioned tables");
write_msg(NULL, "flagging indexes in partitioned tables\n");
flagInhIndexes(fout, tblinfo, numTables); flagInhIndexes(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("reading extended statistics");
write_msg(NULL, "reading extended statistics\n");
getExtendedStatistics(fout); getExtendedStatistics(fout);
if (g_verbose) pg_log_info("reading constraints");
write_msg(NULL, "reading constraints\n");
getConstraints(fout, tblinfo, numTables); getConstraints(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("reading triggers");
write_msg(NULL, "reading triggers\n");
getTriggers(fout, tblinfo, numTables); getTriggers(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("reading rewrite rules");
write_msg(NULL, "reading rewrite rules\n");
getRules(fout, &numRules); getRules(fout, &numRules);
if (g_verbose) pg_log_info("reading policies");
write_msg(NULL, "reading policies\n");
getPolicies(fout, tblinfo, numTables); getPolicies(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("reading publications");
write_msg(NULL, "reading publications\n");
getPublications(fout); getPublications(fout);
if (g_verbose) pg_log_info("reading publication membership");
write_msg(NULL, "reading publication membership\n");
getPublicationTables(fout, tblinfo, numTables); getPublicationTables(fout, tblinfo, numTables);
if (g_verbose) pg_log_info("reading subscriptions");
write_msg(NULL, "reading subscriptions\n");
getSubscriptions(fout); getSubscriptions(fout);
*numTablesPtr = numTables; *numTablesPtr = numTables;
...@@ -1059,7 +1021,7 @@ findParentsByOid(TableInfo *self, ...@@ -1059,7 +1021,7 @@ findParentsByOid(TableInfo *self,
parent = findTableByOid(inhinfo[i].inhparent); parent = findTableByOid(inhinfo[i].inhparent);
if (parent == NULL) if (parent == NULL)
{ {
write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n", pg_log_error("failed sanity check, parent OID %u of table \"%s\" (OID %u) not found",
inhinfo[i].inhparent, inhinfo[i].inhparent,
self->dobj.name, self->dobj.name,
oid); oid);
...@@ -1101,7 +1063,7 @@ parseOidArray(const char *str, Oid *array, int arraysize) ...@@ -1101,7 +1063,7 @@ parseOidArray(const char *str, Oid *array, int arraysize)
{ {
if (argNum >= arraysize) if (argNum >= arraysize)
{ {
write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str); pg_log_error("could not parse numeric array \"%s\": too many numbers", str);
exit_nicely(1); exit_nicely(1);
} }
temp[j] = '\0'; temp[j] = '\0';
...@@ -1116,7 +1078,7 @@ parseOidArray(const char *str, Oid *array, int arraysize) ...@@ -1116,7 +1078,7 @@ parseOidArray(const char *str, Oid *array, int arraysize)
if (!(isdigit((unsigned char) s) || s == '-') || if (!(isdigit((unsigned char) s) || s == '-') ||
j >= sizeof(temp) - 1) j >= sizeof(temp) - 1)
{ {
write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str); pg_log_error("could not parse numeric array \"%s\": invalid character in number", str);
exit_nicely(1); exit_nicely(1);
} }
temp[j++] = s; temp[j++] = s;
......
...@@ -74,9 +74,6 @@ struct CompressorState ...@@ -74,9 +74,6 @@ struct CompressorState
#endif #endif
}; };
/* translator: this is a module name */
static const char *modulename = gettext_noop("compress_io");
static void ParseCompressionOption(int compression, CompressionAlgorithm *alg, static void ParseCompressionOption(int compression, CompressionAlgorithm *alg,
int *level); int *level);
...@@ -111,8 +108,7 @@ ParseCompressionOption(int compression, CompressionAlgorithm *alg, int *level) ...@@ -111,8 +108,7 @@ ParseCompressionOption(int compression, CompressionAlgorithm *alg, int *level)
*alg = COMPR_ALG_NONE; *alg = COMPR_ALG_NONE;
else else
{ {
exit_horribly(modulename, "invalid compression code: %d\n", fatal("invalid compression code: %d", compression);
compression);
*alg = COMPR_ALG_NONE; /* keep compiler quiet */ *alg = COMPR_ALG_NONE; /* keep compiler quiet */
} }
...@@ -135,7 +131,7 @@ AllocateCompressor(int compression, WriteFunc writeF) ...@@ -135,7 +131,7 @@ AllocateCompressor(int compression, WriteFunc writeF)
#ifndef HAVE_LIBZ #ifndef HAVE_LIBZ
if (alg == COMPR_ALG_LIBZ) if (alg == COMPR_ALG_LIBZ)
exit_horribly(modulename, "not built with zlib support\n"); fatal("not built with zlib support");
#endif #endif
cs = (CompressorState *) pg_malloc0(sizeof(CompressorState)); cs = (CompressorState *) pg_malloc0(sizeof(CompressorState));
...@@ -171,7 +167,7 @@ ReadDataFromArchive(ArchiveHandle *AH, int compression, ReadFunc readF) ...@@ -171,7 +167,7 @@ ReadDataFromArchive(ArchiveHandle *AH, int compression, ReadFunc readF)
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
ReadDataFromArchiveZlib(AH, readF); ReadDataFromArchiveZlib(AH, readF);
#else #else
exit_horribly(modulename, "not built with zlib support\n"); fatal("not built with zlib support");
#endif #endif
} }
} }
...@@ -189,7 +185,7 @@ WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs, ...@@ -189,7 +185,7 @@ WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
WriteDataToArchiveZlib(AH, cs, data, dLen); WriteDataToArchiveZlib(AH, cs, data, dLen);
#else #else
exit_horribly(modulename, "not built with zlib support\n"); fatal("not built with zlib support");
#endif #endif
break; break;
case COMPR_ALG_NONE: case COMPR_ALG_NONE:
...@@ -238,8 +234,7 @@ InitCompressorZlib(CompressorState *cs, int level) ...@@ -238,8 +234,7 @@ InitCompressorZlib(CompressorState *cs, int level)
cs->zlibOutSize = ZLIB_OUT_SIZE; cs->zlibOutSize = ZLIB_OUT_SIZE;
if (deflateInit(zp, level) != Z_OK) if (deflateInit(zp, level) != Z_OK)
exit_horribly(modulename, fatal("could not initialize compression library: %s",
"could not initialize compression library: %s\n",
zp->msg); zp->msg);
/* Just be paranoid - maybe End is called after Start, with no Write */ /* Just be paranoid - maybe End is called after Start, with no Write */
...@@ -259,8 +254,7 @@ EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs) ...@@ -259,8 +254,7 @@ EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs)
DeflateCompressorZlib(AH, cs, true); DeflateCompressorZlib(AH, cs, true);
if (deflateEnd(zp) != Z_OK) if (deflateEnd(zp) != Z_OK)
exit_horribly(modulename, fatal("could not close compression stream: %s", zp->msg);
"could not close compression stream: %s\n", zp->msg);
free(cs->zlibOut); free(cs->zlibOut);
free(cs->zp); free(cs->zp);
...@@ -277,8 +271,7 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush) ...@@ -277,8 +271,7 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
{ {
res = deflate(zp, flush ? Z_FINISH : Z_NO_FLUSH); res = deflate(zp, flush ? Z_FINISH : Z_NO_FLUSH);
if (res == Z_STREAM_ERROR) if (res == Z_STREAM_ERROR)
exit_horribly(modulename, fatal("could not compress data: %s", zp->msg);
"could not compress data: %s\n", zp->msg);
if ((flush && (zp->avail_out < cs->zlibOutSize)) if ((flush && (zp->avail_out < cs->zlibOutSize))
|| (zp->avail_out == 0) || (zp->avail_out == 0)
|| (zp->avail_in != 0) || (zp->avail_in != 0)
...@@ -340,8 +333,7 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF) ...@@ -340,8 +333,7 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
out = pg_malloc(ZLIB_OUT_SIZE + 1); out = pg_malloc(ZLIB_OUT_SIZE + 1);
if (inflateInit(zp) != Z_OK) if (inflateInit(zp) != Z_OK)
exit_horribly(modulename, fatal("could not initialize compression library: %s",
"could not initialize compression library: %s\n",
zp->msg); zp->msg);
/* no minimal chunk size for zlib */ /* no minimal chunk size for zlib */
...@@ -357,8 +349,7 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF) ...@@ -357,8 +349,7 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
res = inflate(zp, 0); res = inflate(zp, 0);
if (res != Z_OK && res != Z_STREAM_END) if (res != Z_OK && res != Z_STREAM_END)
exit_horribly(modulename, fatal("could not uncompress data: %s", zp->msg);
"could not uncompress data: %s\n", zp->msg);
out[ZLIB_OUT_SIZE - zp->avail_out] = '\0'; out[ZLIB_OUT_SIZE - zp->avail_out] = '\0';
ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH); ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
...@@ -373,16 +364,14 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF) ...@@ -373,16 +364,14 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
zp->avail_out = ZLIB_OUT_SIZE; zp->avail_out = ZLIB_OUT_SIZE;
res = inflate(zp, 0); res = inflate(zp, 0);
if (res != Z_OK && res != Z_STREAM_END) if (res != Z_OK && res != Z_STREAM_END)
exit_horribly(modulename, fatal("could not uncompress data: %s", zp->msg);
"could not uncompress data: %s\n", zp->msg);
out[ZLIB_OUT_SIZE - zp->avail_out] = '\0'; out[ZLIB_OUT_SIZE - zp->avail_out] = '\0';
ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH); ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
} }
if (inflateEnd(zp) != Z_OK) if (inflateEnd(zp) != Z_OK)
exit_horribly(modulename, fatal("could not close compression library: %s", zp->msg);
"could not close compression library: %s\n", zp->msg);
free(buf); free(buf);
free(out); free(out);
...@@ -516,7 +505,7 @@ cfopen_write(const char *path, const char *mode, int compression) ...@@ -516,7 +505,7 @@ cfopen_write(const char *path, const char *mode, int compression)
fp = cfopen(fname, mode, compression); fp = cfopen(fname, mode, compression);
free_keep_errno(fname); free_keep_errno(fname);
#else #else
exit_horribly(modulename, "not built with zlib support\n"); fatal("not built with zlib support");
fp = NULL; /* keep compiler quiet */ fp = NULL; /* keep compiler quiet */
#endif #endif
} }
...@@ -559,7 +548,7 @@ cfopen(const char *path, const char *mode, int compression) ...@@ -559,7 +548,7 @@ cfopen(const char *path, const char *mode, int compression)
fp = NULL; fp = NULL;
} }
#else #else
exit_horribly(modulename, "not built with zlib support\n"); fatal("not built with zlib support");
#endif #endif
} }
else else
...@@ -596,8 +585,7 @@ cfread(void *ptr, int size, cfp *fp) ...@@ -596,8 +585,7 @@ cfread(void *ptr, int size, cfp *fp)
int errnum; int errnum;
const char *errmsg = gzerror(fp->compressedfp, &errnum); const char *errmsg = gzerror(fp->compressedfp, &errnum);
exit_horribly(modulename, fatal("could not read from input file: %s",
"could not read from input file: %s\n",
errnum == Z_ERRNO ? strerror(errno) : errmsg); errnum == Z_ERRNO ? strerror(errno) : errmsg);
} }
} }
...@@ -634,11 +622,9 @@ cfgetc(cfp *fp) ...@@ -634,11 +622,9 @@ cfgetc(cfp *fp)
if (ret == EOF) if (ret == EOF)
{ {
if (!gzeof(fp->compressedfp)) if (!gzeof(fp->compressedfp))
exit_horribly(modulename, fatal("could not read from input file: %s", strerror(errno));
"could not read from input file: %s\n", strerror(errno));
else else
exit_horribly(modulename, fatal("could not read from input file: end of file");
"could not read from input file: end of file\n");
} }
} }
else else
......
# src/bin/pg_dump/nls.mk # src/bin/pg_dump/nls.mk
CATALOG_NAME = pg_dump CATALOG_NAME = pg_dump
AVAIL_LANGUAGES = cs de es fr he it ja ko pl pt_BR ru sv tr zh_CN AVAIL_LANGUAGES = cs de es fr he it ja ko pl pt_BR ru sv tr zh_CN
GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \ GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) \
pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \
pg_backup_null.c pg_backup_tar.c \ pg_backup_null.c pg_backup_tar.c \
pg_backup_directory.c dumputils.c compress_io.c \ pg_backup_directory.c dumputils.c compress_io.c \
pg_dump.c common.c pg_dump_sort.c \ pg_dump.c common.c pg_dump_sort.c \
...@@ -9,10 +10,9 @@ GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \ ...@@ -9,10 +10,9 @@ GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \
parallel.c parallel.h pg_backup_utils.c pg_backup_utils.h \ parallel.c parallel.h pg_backup_utils.c pg_backup_utils.h \
../../common/exec.c ../../common/fe_memutils.c \ ../../common/exec.c ../../common/fe_memutils.c \
../../common/wait_error.c ../../common/wait_error.c
GETTEXT_TRIGGERS = write_msg:2 exit_horribly:2 simple_prompt \ GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) \
ExecuteSqlCommand:3 ahlog:3 warn_or_exit_horribly:3 fatal simple_prompt \
GETTEXT_FLAGS = \ ExecuteSqlCommand:3 warn_or_exit_horribly:3
write_msg:2:c-format \ GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS) \
exit_horribly:2:c-format \ fatal:1:c-format \
ahlog:3:c-format \ warn_or_exit_horribly:2:c-format
warn_or_exit_horribly:3:c-format
...@@ -197,8 +197,6 @@ bool parallel_init_done = false; ...@@ -197,8 +197,6 @@ bool parallel_init_done = false;
DWORD mainThreadId; DWORD mainThreadId;
#endif /* WIN32 */ #endif /* WIN32 */
static const char *modulename = gettext_noop("parallel archiver");
/* Local function prototypes */ /* Local function prototypes */
static ParallelSlot *GetMyPSlot(ParallelState *pstate); static ParallelSlot *GetMyPSlot(ParallelState *pstate);
static void archive_close_connection(int code, void *arg); static void archive_close_connection(int code, void *arg);
...@@ -262,7 +260,7 @@ init_parallel_dump_utils(void) ...@@ -262,7 +260,7 @@ init_parallel_dump_utils(void)
err = WSAStartup(MAKEWORD(2, 2), &wsaData); err = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (err != 0) if (err != 0)
{ {
fprintf(stderr, _("%s: WSAStartup failed: %d\n"), progname, err); pg_log_error("WSAStartup failed: %d", err);
exit_nicely(1); exit_nicely(1);
} }
/* ... and arrange to shut it down at exit */ /* ... and arrange to shut it down at exit */
...@@ -404,8 +402,8 @@ archive_close_connection(int code, void *arg) ...@@ -404,8 +402,8 @@ archive_close_connection(int code, void *arg)
* Forcibly shut down any remaining workers, waiting for them to finish. * Forcibly shut down any remaining workers, waiting for them to finish.
* *
* Note that we don't expect to come here during normal exit (the workers * Note that we don't expect to come here during normal exit (the workers
* should be long gone, and the ParallelState too). We're only here in an * should be long gone, and the ParallelState too). We're only here in a
* exit_horribly() situation, so intervening to cancel active commands is * fatal() situation, so intervening to cancel active commands is
* appropriate. * appropriate.
*/ */
static void static void
...@@ -697,7 +695,7 @@ consoleHandler(DWORD dwCtrlType) ...@@ -697,7 +695,7 @@ consoleHandler(DWORD dwCtrlType)
/* /*
* Report we're quitting, using nothing more complicated than * Report we're quitting, using nothing more complicated than
* write(2). (We might be able to get away with using write_msg() * write(2). (We might be able to get away with using pg_log_*()
* here, but since we terminated other threads uncleanly above, it * here, but since we terminated other threads uncleanly above, it
* seems better to assume as little as possible.) * seems better to assume as little as possible.)
*/ */
...@@ -967,9 +965,7 @@ ParallelBackupStart(ArchiveHandle *AH) ...@@ -967,9 +965,7 @@ ParallelBackupStart(ArchiveHandle *AH)
/* Create communication pipes for this worker */ /* Create communication pipes for this worker */
if (pgpipe(pipeMW) < 0 || pgpipe(pipeWM) < 0) if (pgpipe(pipeMW) < 0 || pgpipe(pipeWM) < 0)
exit_horribly(modulename, fatal("could not create communication channels: %m");
"could not create communication channels: %s\n",
strerror(errno));
pstate->te[i] = NULL; /* just for safety */ pstate->te[i] = NULL; /* just for safety */
...@@ -1032,9 +1028,7 @@ ParallelBackupStart(ArchiveHandle *AH) ...@@ -1032,9 +1028,7 @@ ParallelBackupStart(ArchiveHandle *AH)
else if (pid < 0) else if (pid < 0)
{ {
/* fork failed */ /* fork failed */
exit_horribly(modulename, fatal("could not create worker process: %m");
"could not create worker process: %s\n",
strerror(errno));
} }
/* In Master after successful fork */ /* In Master after successful fork */
...@@ -1163,8 +1157,7 @@ parseWorkerCommand(ArchiveHandle *AH, TocEntry **te, T_Action *act, ...@@ -1163,8 +1157,7 @@ parseWorkerCommand(ArchiveHandle *AH, TocEntry **te, T_Action *act,
Assert(*te != NULL); Assert(*te != NULL);
} }
else else
exit_horribly(modulename, fatal("unrecognized command received from master: \"%s\"",
"unrecognized command received from master: \"%s\"\n",
msg); msg);
} }
...@@ -1207,8 +1200,7 @@ parseWorkerResponse(ArchiveHandle *AH, TocEntry *te, ...@@ -1207,8 +1200,7 @@ parseWorkerResponse(ArchiveHandle *AH, TocEntry *te,
AH->public.n_errors += n_errors; AH->public.n_errors += n_errors;
} }
else else
exit_horribly(modulename, fatal("invalid message received from worker: \"%s\"",
"invalid message received from worker: \"%s\"\n",
msg); msg);
return status; return status;
...@@ -1340,11 +1332,10 @@ lockTableForWorker(ArchiveHandle *AH, TocEntry *te) ...@@ -1340,11 +1332,10 @@ lockTableForWorker(ArchiveHandle *AH, TocEntry *te)
res = PQexec(AH->connection, query->data); res = PQexec(AH->connection, query->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
exit_horribly(modulename, fatal("could not obtain lock on relation \"%s\"\n"
"could not obtain lock on relation \"%s\"\n"
"This usually means that someone requested an ACCESS EXCLUSIVE lock " "This usually means that someone requested an ACCESS EXCLUSIVE lock "
"on the table after the pg_dump parent process had gotten the " "on the table after the pg_dump parent process had gotten the "
"initial ACCESS SHARE lock on the table.\n", qualId); "initial ACCESS SHARE lock on the table.", qualId);
PQclear(res); PQclear(res);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
...@@ -1430,7 +1421,7 @@ ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait) ...@@ -1430,7 +1421,7 @@ ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait)
{ {
/* If do_wait is true, we must have detected EOF on some socket */ /* If do_wait is true, we must have detected EOF on some socket */
if (do_wait) if (do_wait)
exit_horribly(modulename, "a worker process died unexpectedly\n"); fatal("a worker process died unexpectedly");
return false; return false;
} }
...@@ -1447,8 +1438,7 @@ ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait) ...@@ -1447,8 +1438,7 @@ ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait)
pstate->te[worker] = NULL; pstate->te[worker] = NULL;
} }
else else
exit_horribly(modulename, fatal("invalid message received from worker: \"%s\"",
"invalid message received from worker: \"%s\"\n",
msg); msg);
/* Free the string returned from getMessageFromWorker */ /* Free the string returned from getMessageFromWorker */
...@@ -1553,9 +1543,7 @@ sendMessageToMaster(int pipefd[2], const char *str) ...@@ -1553,9 +1543,7 @@ sendMessageToMaster(int pipefd[2], const char *str)
int len = strlen(str) + 1; int len = strlen(str) + 1;
if (pipewrite(pipefd[PIPE_WRITE], str, len) != len) if (pipewrite(pipefd[PIPE_WRITE], str, len) != len)
exit_horribly(modulename, fatal("could not write to the communication channel: %m");
"could not write to the communication channel: %s\n",
strerror(errno));
} }
/* /*
...@@ -1632,7 +1620,7 @@ getMessageFromWorker(ParallelState *pstate, bool do_wait, int *worker) ...@@ -1632,7 +1620,7 @@ getMessageFromWorker(ParallelState *pstate, bool do_wait, int *worker)
} }
if (i < 0) if (i < 0)
exit_horribly(modulename, "select() failed: %s\n", strerror(errno)); fatal("select() failed: %m");
for (i = 0; i < pstate->numWorkers; i++) for (i = 0; i < pstate->numWorkers; i++)
{ {
...@@ -1671,9 +1659,7 @@ sendMessageToWorker(ParallelState *pstate, int worker, const char *str) ...@@ -1671,9 +1659,7 @@ sendMessageToWorker(ParallelState *pstate, int worker, const char *str)
if (pipewrite(pstate->parallelSlot[worker].pipeWrite, str, len) != len) if (pipewrite(pstate->parallelSlot[worker].pipeWrite, str, len) != len)
{ {
exit_horribly(modulename, fatal("could not write to the communication channel: %m");
"could not write to the communication channel: %s\n",
strerror(errno));
} }
} }
...@@ -1757,7 +1743,7 @@ pgpipe(int handles[2]) ...@@ -1757,7 +1743,7 @@ pgpipe(int handles[2])
*/ */
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == PGINVALID_SOCKET) if ((s = socket(AF_INET, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
{ {
write_msg(modulename, "pgpipe: could not create socket: error code %d\n", pg_log_error("pgpipe: could not create socket: error code %d",
WSAGetLastError()); WSAGetLastError());
return -1; return -1;
} }
...@@ -1768,21 +1754,21 @@ pgpipe(int handles[2]) ...@@ -1768,21 +1754,21 @@ pgpipe(int handles[2])
serv_addr.sin_addr.s_addr = pg_hton32(INADDR_LOOPBACK); serv_addr.sin_addr.s_addr = pg_hton32(INADDR_LOOPBACK);
if (bind(s, (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR) if (bind(s, (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR)
{ {
write_msg(modulename, "pgpipe: could not bind: error code %d\n", pg_log_error("pgpipe: could not bind: error code %d",
WSAGetLastError()); WSAGetLastError());
closesocket(s); closesocket(s);
return -1; return -1;
} }
if (listen(s, 1) == SOCKET_ERROR) if (listen(s, 1) == SOCKET_ERROR)
{ {
write_msg(modulename, "pgpipe: could not listen: error code %d\n", pg_log_error("pgpipe: could not listen: error code %d",
WSAGetLastError()); WSAGetLastError());
closesocket(s); closesocket(s);
return -1; return -1;
} }
if (getsockname(s, (SOCKADDR *) &serv_addr, &len) == SOCKET_ERROR) if (getsockname(s, (SOCKADDR *) &serv_addr, &len) == SOCKET_ERROR)
{ {
write_msg(modulename, "pgpipe: getsockname() failed: error code %d\n", pg_log_error("pgpipe: getsockname() failed: error code %d",
WSAGetLastError()); WSAGetLastError());
closesocket(s); closesocket(s);
return -1; return -1;
...@@ -1793,7 +1779,7 @@ pgpipe(int handles[2]) ...@@ -1793,7 +1779,7 @@ pgpipe(int handles[2])
*/ */
if ((tmp_sock = socket(AF_INET, SOCK_STREAM, 0)) == PGINVALID_SOCKET) if ((tmp_sock = socket(AF_INET, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
{ {
write_msg(modulename, "pgpipe: could not create second socket: error code %d\n", pg_log_error("pgpipe: could not create second socket: error code %d",
WSAGetLastError()); WSAGetLastError());
closesocket(s); closesocket(s);
return -1; return -1;
...@@ -1802,7 +1788,7 @@ pgpipe(int handles[2]) ...@@ -1802,7 +1788,7 @@ pgpipe(int handles[2])
if (connect(handles[1], (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR) if (connect(handles[1], (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR)
{ {
write_msg(modulename, "pgpipe: could not connect socket: error code %d\n", pg_log_error("pgpipe: could not connect socket: error code %d",
WSAGetLastError()); WSAGetLastError());
closesocket(handles[1]); closesocket(handles[1]);
handles[1] = -1; handles[1] = -1;
...@@ -1811,7 +1797,7 @@ pgpipe(int handles[2]) ...@@ -1811,7 +1797,7 @@ pgpipe(int handles[2])
} }
if ((tmp_sock = accept(s, (SOCKADDR *) &serv_addr, &len)) == PGINVALID_SOCKET) if ((tmp_sock = accept(s, (SOCKADDR *) &serv_addr, &len)) == PGINVALID_SOCKET)
{ {
write_msg(modulename, "pgpipe: could not accept connection: error code %d\n", pg_log_error("pgpipe: could not accept connection: error code %d",
WSAGetLastError()); WSAGetLastError());
closesocket(handles[1]); closesocket(handles[1]);
handles[1] = -1; handles[1] = -1;
......
This diff is collapsed.
...@@ -132,17 +132,14 @@ struct ParallelState; ...@@ -132,17 +132,14 @@ struct ParallelState;
#define READ_ERROR_EXIT(fd) \ #define READ_ERROR_EXIT(fd) \
do { \ do { \
if (feof(fd)) \ if (feof(fd)) \
exit_horribly(modulename, \ fatal("could not read from input file: end of file"); \
"could not read from input file: end of file\n"); \
else \ else \
exit_horribly(modulename, \ fatal("could not read from input file: %m"); \
"could not read from input file: %s\n", strerror(errno)); \
} while (0) } while (0)
#define WRITE_ERROR_EXIT \ #define WRITE_ERROR_EXIT \
do { \ do { \
exit_horribly(modulename, "could not write to output file: %s\n", \ fatal("could not write to output file: %m"); \
strerror(errno)); \
} while (0) } while (0)
typedef enum T_Action typedef enum T_Action
...@@ -252,8 +249,6 @@ struct _archiveHandle ...@@ -252,8 +249,6 @@ struct _archiveHandle
char *archiveDumpVersion; /* When reading an archive, the version of char *archiveDumpVersion; /* When reading an archive, the version of
* the dumper */ * the dumper */
int debugLevel; /* Used for logging (currently only by
* --verbose) */
size_t intSize; /* Size of an integer in the archive */ size_t intSize; /* Size of an integer in the archive */
size_t offSize; /* Size of a file offset in the archive - size_t offSize; /* Size of a file offset in the archive -
* Added V1.7 */ * Added V1.7 */
...@@ -411,7 +406,7 @@ struct _tocEntry ...@@ -411,7 +406,7 @@ struct _tocEntry
extern int parallel_restore(ArchiveHandle *AH, TocEntry *te); extern int parallel_restore(ArchiveHandle *AH, TocEntry *te);
extern void on_exit_close_archive(Archive *AHX); extern void on_exit_close_archive(Archive *AHX);
extern void warn_or_exit_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) pg_attribute_printf(3, 4); extern void warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2, 3);
/* Options for ArchiveEntry */ /* Options for ArchiveEntry */
typedef struct _archiveOpts typedef struct _archiveOpts
...@@ -487,6 +482,4 @@ extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid); ...@@ -487,6 +482,4 @@ extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid);
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH); void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH);
int ahprintf(ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2, 3); int ahprintf(ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2, 3);
void ahlog(ArchiveHandle *AH, int level, const char *fmt,...) pg_attribute_printf(3, 4);
#endif #endif
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "parallel.h" #include "parallel.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "common/file_utils.h" #include "common/file_utils.h"
#include "fe_utils/logging.h"
/*-------- /*--------
* Routines in the format interface * Routines in the format interface
...@@ -91,10 +92,6 @@ static pgoff_t _getFilePos(ArchiveHandle *AH, lclContext *ctx); ...@@ -91,10 +92,6 @@ static pgoff_t _getFilePos(ArchiveHandle *AH, lclContext *ctx);
static void _CustomWriteFunc(ArchiveHandle *AH, const char *buf, size_t len); static void _CustomWriteFunc(ArchiveHandle *AH, const char *buf, size_t len);
static size_t _CustomReadFunc(ArchiveHandle *AH, char **buf, size_t *buflen); static size_t _CustomReadFunc(ArchiveHandle *AH, char **buf, size_t *buflen);
/* translator: this is a module name */
static const char *modulename = gettext_noop("custom archiver");
/* /*
* Init routine required by ALL formats. This is a global routine * Init routine required by ALL formats. This is a global routine
...@@ -159,15 +156,13 @@ InitArchiveFmt_Custom(ArchiveHandle *AH) ...@@ -159,15 +156,13 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
{ {
AH->FH = fopen(AH->fSpec, PG_BINARY_W); AH->FH = fopen(AH->fSpec, PG_BINARY_W);
if (!AH->FH) if (!AH->FH)
exit_horribly(modulename, "could not open output file \"%s\": %s\n", fatal("could not open output file \"%s\": %m", AH->fSpec);
AH->fSpec, strerror(errno));
} }
else else
{ {
AH->FH = stdout; AH->FH = stdout;
if (!AH->FH) if (!AH->FH)
exit_horribly(modulename, "could not open output file: %s\n", fatal("could not open output file: %m");
strerror(errno));
} }
ctx->hasSeek = checkSeek(AH->FH); ctx->hasSeek = checkSeek(AH->FH);
...@@ -178,15 +173,13 @@ InitArchiveFmt_Custom(ArchiveHandle *AH) ...@@ -178,15 +173,13 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
{ {
AH->FH = fopen(AH->fSpec, PG_BINARY_R); AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (!AH->FH) if (!AH->FH)
exit_horribly(modulename, "could not open input file \"%s\": %s\n", fatal("could not open input file \"%s\": %m", AH->fSpec);
AH->fSpec, strerror(errno));
} }
else else
{ {
AH->FH = stdin; AH->FH = stdin;
if (!AH->FH) if (!AH->FH)
exit_horribly(modulename, "could not open input file: %s\n", fatal("could not open input file: %m");
strerror(errno));
} }
ctx->hasSeek = checkSeek(AH->FH); ctx->hasSeek = checkSeek(AH->FH);
...@@ -381,7 +374,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid) ...@@ -381,7 +374,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
lclContext *ctx = (lclContext *) AH->formatData; lclContext *ctx = (lclContext *) AH->formatData;
if (oid == 0) if (oid == 0)
exit_horribly(modulename, "invalid OID for large object\n"); fatal("invalid OID for large object");
WriteInt(AH, oid); WriteInt(AH, oid);
...@@ -451,8 +444,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te) ...@@ -451,8 +444,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
break; break;
default: /* Always have a default */ default: /* Always have a default */
exit_horribly(modulename, fatal("unrecognized data block type (%d) while searching archive",
"unrecognized data block type (%d) while searching archive\n",
blkType); blkType);
break; break;
} }
...@@ -463,8 +455,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te) ...@@ -463,8 +455,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
{ {
/* We can just seek to the place we need to be. */ /* We can just seek to the place we need to be. */
if (fseeko(AH->FH, tctx->dataPos, SEEK_SET) != 0) if (fseeko(AH->FH, tctx->dataPos, SEEK_SET) != 0)
exit_horribly(modulename, "error during file seek: %s\n", fatal("error during file seek: %m");
strerror(errno));
_readBlockHeader(AH, &blkType, &id); _readBlockHeader(AH, &blkType, &id);
} }
...@@ -473,24 +464,24 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te) ...@@ -473,24 +464,24 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
if (blkType == EOF) if (blkType == EOF)
{ {
if (tctx->dataState == K_OFFSET_POS_NOT_SET) if (tctx->dataState == K_OFFSET_POS_NOT_SET)
exit_horribly(modulename, "could not find block ID %d in archive -- " fatal("could not find block ID %d in archive -- "
"possibly due to out-of-order restore request, " "possibly due to out-of-order restore request, "
"which cannot be handled due to lack of data offsets in archive\n", "which cannot be handled due to lack of data offsets in archive",
te->dumpId); te->dumpId);
else if (!ctx->hasSeek) else if (!ctx->hasSeek)
exit_horribly(modulename, "could not find block ID %d in archive -- " fatal("could not find block ID %d in archive -- "
"possibly due to out-of-order restore request, " "possibly due to out-of-order restore request, "
"which cannot be handled due to non-seekable input file\n", "which cannot be handled due to non-seekable input file",
te->dumpId); te->dumpId);
else /* huh, the dataPos led us to EOF? */ else /* huh, the dataPos led us to EOF? */
exit_horribly(modulename, "could not find block ID %d in archive -- " fatal("could not find block ID %d in archive -- "
"possibly corrupt archive\n", "possibly corrupt archive",
te->dumpId); te->dumpId);
} }
/* Are we sane? */ /* Are we sane? */
if (id != te->dumpId) if (id != te->dumpId)
exit_horribly(modulename, "found unexpected block ID (%d) when reading data -- expected %d\n", fatal("found unexpected block ID (%d) when reading data -- expected %d",
id, te->dumpId); id, te->dumpId);
switch (blkType) switch (blkType)
...@@ -504,7 +495,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te) ...@@ -504,7 +495,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
break; break;
default: /* Always have a default */ default: /* Always have a default */
exit_horribly(modulename, "unrecognized data block type %d while restoring archive\n", fatal("unrecognized data block type %d while restoring archive",
blkType); blkType);
break; break;
} }
...@@ -584,11 +575,9 @@ _skipData(ArchiveHandle *AH) ...@@ -584,11 +575,9 @@ _skipData(ArchiveHandle *AH)
if ((cnt = fread(buf, 1, blkLen, AH->FH)) != blkLen) if ((cnt = fread(buf, 1, blkLen, AH->FH)) != blkLen)
{ {
if (feof(AH->FH)) if (feof(AH->FH))
exit_horribly(modulename, fatal("could not read from input file: end of file");
"could not read from input file: end of file\n");
else else
exit_horribly(modulename, fatal("could not read from input file: %m");
"could not read from input file: %s\n", strerror(errno));
} }
ctx->filePos += blkLen; ctx->filePos += blkLen;
...@@ -706,8 +695,7 @@ _CloseArchive(ArchiveHandle *AH) ...@@ -706,8 +695,7 @@ _CloseArchive(ArchiveHandle *AH)
/* Remember TOC's seek position for use below */ /* Remember TOC's seek position for use below */
tpos = ftello(AH->FH); tpos = ftello(AH->FH);
if (tpos < 0 && ctx->hasSeek) if (tpos < 0 && ctx->hasSeek)
exit_horribly(modulename, "could not determine seek position in archive file: %s\n", fatal("could not determine seek position in archive file: %m");
strerror(errno));
WriteToc(AH); WriteToc(AH);
ctx->dataStart = _getFilePos(AH, ctx); ctx->dataStart = _getFilePos(AH, ctx);
WriteDataChunks(AH, NULL); WriteDataChunks(AH, NULL);
...@@ -724,11 +712,11 @@ _CloseArchive(ArchiveHandle *AH) ...@@ -724,11 +712,11 @@ _CloseArchive(ArchiveHandle *AH)
} }
if (fclose(AH->FH) != 0) if (fclose(AH->FH) != 0)
exit_horribly(modulename, "could not close archive file: %s\n", strerror(errno)); fatal("could not close archive file: %m");
/* Sync the output file if one is defined */ /* Sync the output file if one is defined */
if (AH->dosync && AH->mode == archModeWrite && AH->fSpec) if (AH->dosync && AH->mode == archModeWrite && AH->fSpec)
(void) fsync_fname(AH->fSpec, false, progname); (void) fsync_fname(AH->fSpec, false);
AH->FH = NULL; AH->FH = NULL;
} }
...@@ -747,36 +735,32 @@ _ReopenArchive(ArchiveHandle *AH) ...@@ -747,36 +735,32 @@ _ReopenArchive(ArchiveHandle *AH)
pgoff_t tpos; pgoff_t tpos;
if (AH->mode == archModeWrite) if (AH->mode == archModeWrite)
exit_horribly(modulename, "can only reopen input archives\n"); fatal("can only reopen input archives");
/* /*
* These two cases are user-facing errors since they represent unsupported * These two cases are user-facing errors since they represent unsupported
* (but not invalid) use-cases. Word the error messages appropriately. * (but not invalid) use-cases. Word the error messages appropriately.
*/ */
if (AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0) if (AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0)
exit_horribly(modulename, "parallel restore from standard input is not supported\n"); fatal("parallel restore from standard input is not supported");
if (!ctx->hasSeek) if (!ctx->hasSeek)
exit_horribly(modulename, "parallel restore from non-seekable file is not supported\n"); fatal("parallel restore from non-seekable file is not supported");
tpos = ftello(AH->FH); tpos = ftello(AH->FH);
if (tpos < 0) if (tpos < 0)
exit_horribly(modulename, "could not determine seek position in archive file: %s\n", fatal("could not determine seek position in archive file: %m");
strerror(errno));
#ifndef WIN32 #ifndef WIN32
if (fclose(AH->FH) != 0) if (fclose(AH->FH) != 0)
exit_horribly(modulename, "could not close archive file: %s\n", fatal("could not close archive file: %m");
strerror(errno));
#endif #endif
AH->FH = fopen(AH->fSpec, PG_BINARY_R); AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (!AH->FH) if (!AH->FH)
exit_horribly(modulename, "could not open input file \"%s\": %s\n", fatal("could not open input file \"%s\": %m", AH->fSpec);
AH->fSpec, strerror(errno));
if (fseeko(AH->FH, tpos, SEEK_SET) != 0) if (fseeko(AH->FH, tpos, SEEK_SET) != 0)
exit_horribly(modulename, "could not set seek position in archive file: %s\n", fatal("could not set seek position in archive file: %m");
strerror(errno));
} }
/* /*
...@@ -831,8 +815,7 @@ _PrepParallelRestore(ArchiveHandle *AH) ...@@ -831,8 +815,7 @@ _PrepParallelRestore(ArchiveHandle *AH)
pgoff_t endpos; pgoff_t endpos;
if (fseeko(AH->FH, 0, SEEK_END) != 0) if (fseeko(AH->FH, 0, SEEK_END) != 0)
exit_horribly(modulename, "error during file seek: %s\n", fatal("error during file seek: %m");
strerror(errno));
endpos = ftello(AH->FH); endpos = ftello(AH->FH);
if (endpos > prev_tctx->dataPos) if (endpos > prev_tctx->dataPos)
prev_te->dataLength = endpos - prev_tctx->dataPos; prev_te->dataLength = endpos - prev_tctx->dataPos;
...@@ -853,7 +836,7 @@ _Clone(ArchiveHandle *AH) ...@@ -853,7 +836,7 @@ _Clone(ArchiveHandle *AH)
/* sanity check, shouldn't happen */ /* sanity check, shouldn't happen */
if (ctx->cs != NULL) if (ctx->cs != NULL)
exit_horribly(modulename, "compressor active\n"); fatal("compressor active");
/* /*
* Note: we do not make a local lo_buf because we expect at most one BLOBS * Note: we do not make a local lo_buf because we expect at most one BLOBS
...@@ -905,11 +888,10 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx) ...@@ -905,11 +888,10 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
*/ */
pos = ftello(AH->FH); pos = ftello(AH->FH);
if (pos < 0) if (pos < 0)
exit_horribly(modulename, "could not determine seek position in archive file: %s\n", fatal("could not determine seek position in archive file: %m");
strerror(errno));
if (pos != ctx->filePos) if (pos != ctx->filePos)
write_msg(modulename, "WARNING: ftell mismatch with expected position -- ftell used\n"); pg_log_warning("ftell mismatch with expected position -- ftell used");
} }
else else
pos = ctx->filePos; pos = ctx->filePos;
...@@ -928,7 +910,7 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id) ...@@ -928,7 +910,7 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
int byt; int byt;
/* /*
* Note: if we are at EOF with a pre-1.3 input file, we'll exit_horribly * Note: if we are at EOF with a pre-1.3 input file, we'll fatal()
* inside ReadInt rather than returning EOF. It doesn't seem worth * inside ReadInt rather than returning EOF. It doesn't seem worth
* jumping through hoops to deal with that case better, because no such * jumping through hoops to deal with that case better, because no such
* files are likely to exist in the wild: only some 7.1 development * files are likely to exist in the wild: only some 7.1 development
......
This diff is collapsed.
This diff is collapsed.
...@@ -72,7 +72,7 @@ InitArchiveFmt_Null(ArchiveHandle *AH) ...@@ -72,7 +72,7 @@ InitArchiveFmt_Null(ArchiveHandle *AH)
* Now prevent reading... * Now prevent reading...
*/ */
if (AH->mode == archModeRead) if (AH->mode == archModeRead)
exit_horribly(NULL, "this format cannot be read\n"); fatal("this format cannot be read");
} }
/* /*
...@@ -147,7 +147,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid) ...@@ -147,7 +147,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
bool old_blob_style = (AH->version < K_VERS_1_12); bool old_blob_style = (AH->version < K_VERS_1_12);
if (oid == 0) if (oid == 0)
exit_horribly(NULL, "invalid OID for large object\n"); fatal("invalid OID for large object");
/* With an old archive we must do drop and create logic here */ /* With an old archive we must do drop and create logic here */
if (old_blob_style && AH->public.ropt->dropSchema) if (old_blob_style && AH->public.ropt->dropSchema)
......
This diff is collapsed.
...@@ -51,8 +51,7 @@ set_dump_section(const char *arg, int *dumpSections) ...@@ -51,8 +51,7 @@ set_dump_section(const char *arg, int *dumpSections)
*dumpSections |= DUMP_POST_DATA; *dumpSections |= DUMP_POST_DATA;
else else
{ {
fprintf(stderr, _("%s: unrecognized section name: \"%s\"\n"), pg_log_error("unrecognized section name: \"%s\"", arg);
progname, arg);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname); progname);
exit_nicely(1); exit_nicely(1);
...@@ -60,62 +59,15 @@ set_dump_section(const char *arg, int *dumpSections) ...@@ -60,62 +59,15 @@ set_dump_section(const char *arg, int *dumpSections)
} }
/*
* 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);
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.
*
* Note that on_exit_nicely callbacks will get run.
*/
void
exit_horribly(const char *modulename, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
vwrite_msg(modulename, fmt, ap);
va_end(ap);
exit_nicely(1);
}
/* Register a callback to be run when exit_nicely is invoked. */ /* Register a callback to be run when exit_nicely is invoked. */
void void
on_exit_nicely(on_exit_nicely_callback function, void *arg) on_exit_nicely(on_exit_nicely_callback function, void *arg)
{ {
if (on_exit_nicely_index >= MAX_ON_EXIT_NICELY) if (on_exit_nicely_index >= MAX_ON_EXIT_NICELY)
exit_horribly(NULL, "out of on_exit_nicely slots\n"); {
pg_log_fatal("out of on_exit_nicely slots");
exit_nicely(1);
}
on_exit_nicely_list[on_exit_nicely_index].function = function; on_exit_nicely_list[on_exit_nicely_index].function = function;
on_exit_nicely_list[on_exit_nicely_index].arg = arg; on_exit_nicely_list[on_exit_nicely_index].arg = arg;
on_exit_nicely_index++; on_exit_nicely_index++;
......
This diff is collapsed.
This diff is collapsed.
...@@ -639,7 +639,6 @@ typedef struct _extensionMemberId ...@@ -639,7 +639,6 @@ typedef struct _extensionMemberId
/* global decls */ /* global decls */
extern bool force_quotes; /* double-quotes for identifiers flag */ extern bool force_quotes; /* double-quotes for identifiers flag */
extern bool g_verbose; /* verbose flag */
/* placeholders for comment starting and ending delimiters */ /* placeholders for comment starting and ending delimiters */
extern char g_comment_start[10]; extern char g_comment_start[10];
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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