diff --git a/repmgrd.c b/repmgrd.c index b86a73b2..2158bd41 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -63,6 +63,8 @@ main(int argc, char **argv) RecordStatus record_status; + FILE *fd; + static struct option long_options[] = { /* general options */ @@ -221,11 +223,38 @@ main(int argc, char **argv) config_file_options.monitoring_history = true; } + + fd = freopen("/dev/null", "r", stdin); + if (fd == NULL) + { + fprintf(stderr, "error reopening stdin to \"/dev/null\":\n %s\n", + strerror(errno)); + } + + fd = freopen("/dev/null", "w", stdout); + if (fd == NULL) + { + fprintf(stderr, "error reopening stdout to \"/dev/null\":\n %s\n", + strerror(errno)); + } + logger_init(&config_file_options, progname()); if (verbose) logger_set_verbose(); + if (log_type == REPMGR_SYSLOG) + { + fd = freopen("/dev/null", "w", stderr); + + if (fd == NULL) + { + fprintf(stderr, "error reopening stderr to \"/dev/null\":\n %s\n", + strerror(errno)); + } + } + + log_info(_("connecting to database \"%s\""), config_file_options.conninfo); @@ -334,6 +363,8 @@ main(int argc, char **argv) setup_event_handlers(); #endif + + start_monitoring(); logger_shutdown();