mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
fix: check return values of freopen()
Some compiles complain about not checking the return value of freopen(), so we check it
This commit is contained in:
9
log.c
9
log.c
@@ -144,7 +144,14 @@ bool logger_init(t_configuration_options *opts, const char* ident, const char* l
|
||||
|
||||
if (*opts->logfile)
|
||||
{
|
||||
freopen(opts->logfile, "a", stderr);
|
||||
FILE *fd;
|
||||
fd = freopen(opts->logfile, "a", stderr);
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
fprintf(stderr, "error reopening stderr to '%s': %s",
|
||||
opts->logfile, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
33
repmgrd.c
33
repmgrd.c
@@ -179,6 +179,7 @@ main(int argc, char **argv)
|
||||
int optindex;
|
||||
int c, ret;
|
||||
bool daemonize = false;
|
||||
FILE *fd;
|
||||
|
||||
char standby_version[MAXVERSIONSTR], *ret_ver;
|
||||
|
||||
@@ -248,8 +249,19 @@ main(int argc, char **argv)
|
||||
terminate(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
freopen("/dev/null", "r", stdin);
|
||||
freopen("/dev/null", "w", stdout);
|
||||
fd = freopen("/dev/null", "r", stdin);
|
||||
if (fd == NULL)
|
||||
{
|
||||
fprintf(stderr, "error reopening stdin to '/dev/null': %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
fd = freopen("/dev/null", "w", stdout);
|
||||
if (fd == NULL)
|
||||
{
|
||||
fprintf(stderr, "error reopening stdout to '/dev/null': %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
logger_init(&local_options, progname, local_options.loglevel, local_options.logfacility);
|
||||
if (verbose)
|
||||
@@ -257,7 +269,13 @@ main(int argc, char **argv)
|
||||
|
||||
if (log_type == REPMGR_SYSLOG)
|
||||
{
|
||||
freopen("/dev/null", "w", stderr);
|
||||
fd = freopen("/dev/null", "w", stderr);
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
fprintf(stderr, "error reopening stderr to '/dev/null': %s",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(repmgr_schema, MAXLEN, "%s%s", DEFAULT_REPMGR_SCHEMA_PREFIX, local_options.cluster_name);
|
||||
@@ -365,7 +383,14 @@ main(int argc, char **argv)
|
||||
|
||||
if (*local_options.logfile)
|
||||
{
|
||||
freopen(local_options.logfile, "a", stderr);
|
||||
FILE *fd;
|
||||
fd = freopen(local_options.logfile, "a", stderr);
|
||||
if (fd == NULL)
|
||||
{
|
||||
fprintf(stderr, "error reopening stderr to '%s': %s",
|
||||
local_options.logfile, strerror(errno));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update_registration();
|
||||
|
||||
Reference in New Issue
Block a user