mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
new config option, stdout/stdin closed
Now stdin and stdout get closed. Additionally stderr gets closed and reopened to the new config option „logfile“ if specified
This commit is contained in:
2
config.c
2
config.c
@@ -120,6 +120,8 @@ parse_config(const char *config_file, t_configuration_options *options)
|
||||
strncpy (options->pg_bindir, value, MAXLEN);
|
||||
else if (strcmp(name, "pg_ctl_options") == 0)
|
||||
strncpy (options->pgctl_options, value, MAXLEN);
|
||||
else if (strcmp(name, "logfile") == 0)
|
||||
strncpy(options->logfile, value, MAXLEN);
|
||||
else
|
||||
log_warning(_("%s/%s: Unknown name/value pair!\n"), name, value);
|
||||
}
|
||||
|
||||
3
config.h
3
config.h
@@ -42,9 +42,10 @@ typedef struct
|
||||
int reconnect_intvl;
|
||||
char pg_bindir[MAXLEN];
|
||||
char pgctl_options[MAXLEN];
|
||||
char logfile[MAXLEN];
|
||||
} t_configuration_options;
|
||||
|
||||
#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "" }
|
||||
#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "" }
|
||||
|
||||
void parse_config(const char *config_file, t_configuration_options *options);
|
||||
void parse_line(char *buff, char *name, char *value);
|
||||
|
||||
10
log.c
10
log.c
@@ -68,7 +68,7 @@ static int detect_log_facility(const char* facility);
|
||||
int log_type = REPMGR_STDERR;
|
||||
int log_level = LOG_NOTICE;
|
||||
|
||||
bool logger_init(const char* ident, const char* level, const char* facility)
|
||||
bool logger_init(t_configuration_options *opts, const char* ident, const char* level, const char* facility)
|
||||
{
|
||||
|
||||
int l;
|
||||
@@ -140,6 +140,14 @@ bool logger_init(const char* ident, const char* level, const char* facility)
|
||||
|
||||
#endif
|
||||
|
||||
fclose(stdin);
|
||||
fclose(stdout);
|
||||
|
||||
if (*opts->logfile)
|
||||
{
|
||||
freopen(opts->logfile, "a", stderr);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
2
log.h
2
log.h
@@ -114,7 +114,7 @@ void stderr_log_with_level(const char *level_name, int level, const char *fmt, .
|
||||
|
||||
/* Logger initialisation and shutdown */
|
||||
bool logger_shutdown(void);
|
||||
bool logger_init(const char* ident, const char* level, const char* facility);
|
||||
bool logger_init(t_configuration_options *opts, const char* ident, const char* level, const char* facility);
|
||||
void logger_min_verbose(int minimum);
|
||||
|
||||
extern int log_type;
|
||||
|
||||
2
repmgr.c
2
repmgr.c
@@ -322,7 +322,7 @@ main(int argc, char **argv)
|
||||
* at, but it often requires detailed logging to troubleshoot
|
||||
* problems.
|
||||
*/
|
||||
logger_init(progname, options.loglevel, options.logfacility);
|
||||
logger_init(&options, progname, options.loglevel, options.logfacility);
|
||||
if (runtime_options.verbose)
|
||||
logger_min_verbose(LOG_INFO);
|
||||
|
||||
|
||||
@@ -42,3 +42,8 @@ pg_bindir=/usr/bin/
|
||||
# you may add command line arguments for pg_ctl
|
||||
#
|
||||
# pg_ctl_options='-s'
|
||||
|
||||
#
|
||||
# redirect stderr to a logfile
|
||||
#
|
||||
# logfile='/var/log/repmgr.log'
|
||||
|
||||
@@ -272,7 +272,7 @@ main(int argc, char **argv)
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
logger_init(progname, local_options.loglevel, local_options.logfacility);
|
||||
logger_init(&local_options, progname, local_options.loglevel, local_options.logfacility);
|
||||
if (verbose)
|
||||
logger_min_verbose(LOG_INFO);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user