aboutsummaryrefslogtreecommitdiff
path: root/src/common/controldata_utils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-04-08 14:55:14 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-04-08 14:55:14 -0400
commit9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 (patch)
tree6591af757bd9df12549279b4b87f01e0ce98bd79 /src/common/controldata_utils.c
parent5c431c7fb327e1abc70b7a197650f8d45fd5bede (diff)
downloadpostgresql-9a374b77fb53e4cfbca121e4fa278a7d71bde7c4.tar.gz
postgresql-9a374b77fb53e4cfbca121e4fa278a7d71bde7c4.zip
Improve frontend error logging style.
Get rid of the separate "FATAL" log level, as it was applied so inconsistently as to be meaningless. This mostly involves s/pg_log_fatal/pg_log_error/g. Create a macro pg_fatal() to handle the common use-case of pg_log_error() immediately followed by exit(1). Various modules had already invented either this or equivalent macros; standardize on pg_fatal() and apply it where possible. Invent the ability to add "detail" and "hint" messages to a frontend message, much as we have long had in the backend. Except where rewording was needed to convert existing coding to detail/hint style, I have (mostly) resisted the temptation to change existing message wording. Patch by me. Design and patch reviewed at various stages by Robert Haas, Kyotaro Horiguchi, Peter Eisentraut and Daniel Gustafsson. Discussion: https://postgr.es/m/1363732.1636496441@sss.pgh.pa.us
Diffstat (limited to 'src/common/controldata_utils.c')
-rw-r--r--src/common/controldata_utils.c40
1 files changed, 10 insertions, 30 deletions
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 348f046a440..4c0da6e124e 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -70,11 +70,8 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
ControlFilePath)));
#else
if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
- {
- pg_log_fatal("could not open file \"%s\" for reading: %m",
- ControlFilePath);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not open file \"%s\" for reading: %m",
+ ControlFilePath);
#endif
r = read(fd, ControlFile, sizeof(ControlFileData));
@@ -86,10 +83,7 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", ControlFilePath)));
#else
- {
- pg_log_fatal("could not read file \"%s\": %m", ControlFilePath);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not read file \"%s\": %m", ControlFilePath);
#endif
else
#ifndef FRONTEND
@@ -98,11 +92,8 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
errmsg("could not read file \"%s\": read %d of %zu",
ControlFilePath, r, sizeof(ControlFileData))));
#else
- {
- pg_log_fatal("could not read file \"%s\": read %d of %zu",
- ControlFilePath, r, sizeof(ControlFileData));
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not read file \"%s\": read %d of %zu",
+ ControlFilePath, r, sizeof(ControlFileData));
#endif
}
@@ -114,10 +105,7 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
ControlFilePath)));
#else
if (close(fd) != 0)
- {
- pg_log_fatal("could not close file \"%s\": %m", ControlFilePath);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not close file \"%s\": %m", ControlFilePath);
#endif
/* Check the CRC. */
@@ -203,10 +191,7 @@ update_controlfile(const char *DataDir,
#else
if ((fd = open(ControlFilePath, O_WRONLY | PG_BINARY,
pg_file_create_mode)) == -1)
- {
- pg_log_fatal("could not open file \"%s\": %m", ControlFilePath);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not open file \"%s\": %m", ControlFilePath);
#endif
errno = 0;
@@ -225,8 +210,7 @@ update_controlfile(const char *DataDir,
errmsg("could not write file \"%s\": %m",
ControlFilePath)));
#else
- pg_log_fatal("could not write file \"%s\": %m", ControlFilePath);
- exit(EXIT_FAILURE);
+ pg_fatal("could not write file \"%s\": %m", ControlFilePath);
#endif
}
#ifndef FRONTEND
@@ -245,10 +229,7 @@ update_controlfile(const char *DataDir,
pgstat_report_wait_end();
#else
if (fsync(fd) != 0)
- {
- pg_log_fatal("could not fsync file \"%s\": %m", ControlFilePath);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not fsync file \"%s\": %m", ControlFilePath);
#endif
}
@@ -260,8 +241,7 @@ update_controlfile(const char *DataDir,
errmsg("could not close file \"%s\": %m",
ControlFilePath)));
#else
- pg_log_fatal("could not close file \"%s\": %m", ControlFilePath);
- exit(EXIT_FAILURE);
+ pg_fatal("could not close file \"%s\": %m", ControlFilePath);
#endif
}
}