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:
Christian Kruse
2014-01-16 15:22:34 +01:00
parent 4f3bd6612c
commit 9563877fbb
7 changed files with 21 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -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
View File

@@ -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
View File

@@ -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;

View File

@@ -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);

View File

@@ -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'

View File

@@ -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);