Skip to content

Commit 7b077af

Browse files
committed
Make get_controlfile() error logging consistent with src/common
As originally committed, get_controlfile() used a non-standard approach to error logging. Make it consistent with the majority of error logging done in src/common. Applies to master only.
1 parent b63bea5 commit 7b077af

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/common/controldata_utils.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@
2828
#include "common/controldata_utils.h"
2929
#include "port/pg_crc32c.h"
3030

31-
#ifndef FRONTEND
32-
/* NOTE: caller must provide gettext call around the format string */
33-
#define log_error(...) \
34-
elog(ERROR, __VA_ARGS__)
35-
#else
36-
#define log_error(...) \
37-
do { \
38-
char *buf = psprintf(__VA_ARGS__); \
39-
fprintf(stderr, "%s: %s\n", progname, buf); \
40-
exit(2); \
41-
} while (0)
42-
#endif
43-
4431
/*
4532
* get_controlfile(char *DataDir, const char *progname)
4633
*
@@ -59,12 +46,31 @@ get_controlfile(char *DataDir, const char *progname)
5946
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
6047

6148
if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
62-
log_error(_("could not open file \"%s\" for reading: %s"),
63-
ControlFilePath, strerror(errno));
49+
#ifndef FRONTEND
50+
ereport(ERROR,
51+
(errcode_for_file_access(),
52+
errmsg("could not open file \"%s\" for reading: %m",
53+
ControlFilePath)));
54+
#else
55+
{
56+
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
57+
progname, ControlFilePath, strerror(errno));
58+
exit(EXIT_FAILURE);
59+
}
60+
#endif
6461

6562
if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
66-
log_error(_("could not read file \"%s\": %s"),
67-
ControlFilePath, strerror(errno));
63+
#ifndef FRONTEND
64+
ereport(ERROR,
65+
(errcode_for_file_access(),
66+
errmsg("could not read file \"%s\": %m", ControlFilePath)));
67+
#else
68+
{
69+
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
70+
progname, ControlFilePath, strerror(errno));
71+
exit(EXIT_FAILURE);
72+
}
73+
#endif
6874

6975
close(fd);
7076

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy