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