From 41abf9a7ef2bea8251bde0387884f55cecbea402 Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Tue, 21 Jan 2014 13:49:21 +0100 Subject: [PATCH] fix: flushing and fsync()ing the log file When not flushing and fsync()ing it the output may be garbled due to concurrent writes to the file (system() spawns a child process with stdin/stdout/stderr inherited from it's parent) --- repmgrd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/repmgrd.c b/repmgrd.c index 5d2ffa85..09b0b763 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -1031,6 +1031,13 @@ do_failover(void) log_info(_("%s: This node is the best candidate to be the new primary, promoting...\n"), progname); log_debug(_("promote command is: \"%s\"\n"), local_options.promote_command); + + if (log_type == REPMGR_STDERR && *local_options.logfile) + { + fflush(stderr); + fsync(fileno(stderr)); + } + r = system(local_options.promote_command); if (r != 0) { @@ -1051,6 +1058,12 @@ do_failover(void) * New Primary need some time to be promoted. * The follow command should take care of that. */ + if (log_type == REPMGR_STDERR && *local_options.logfile) + { + fflush(stderr); + fsync(fileno(stderr)); + } + r = system(local_options.follow_command); if (r != 0) {