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)
This commit is contained in:
Christian Kruse
2014-01-21 13:49:21 +01:00
parent abebc53ddc
commit 41abf9a7ef

View File

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