From b6f8570c3503c42b88b81300cb5349bfa8ee341c Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Wed, 16 Jul 2014 13:39:14 -0400 Subject: [PATCH] Lock mutex during more of the log rotation process (attempting to prevent crashes that have been seen while logging at the same time as log rotation) --- src/log/file_appender.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/log/file_appender.cpp b/src/log/file_appender.cpp index dad9716..686ed65 100644 --- a/src/log/file_appender.cpp +++ b/src/log/file_appender.cpp @@ -101,20 +101,23 @@ namespace fc { const auto link_filename = cfg.filename.string(); const auto log_filename = link_filename + "." + timestamp_string; - if( !initializing ) { - if( start_time <= _current_file_start_time ) - { - _rotation_task = schedule( [this]() { rotate_files(); }, _current_file_start_time + cfg.rotation_interval.to_seconds() ); - return; - } + fc::scoped_lock lock( slock ); - fc::scoped_lock lock( slock ); - out.flush(); - out.close(); + if( !initializing ) + { + if( start_time <= _current_file_start_time ) + { + _rotation_task = schedule( [this]() { rotate_files(); }, _current_file_start_time + cfg.rotation_interval.to_seconds() ); + return; + } + + out.flush(); + out.close(); + } + + out.open( log_filename.c_str() ); } - - out.open( log_filename.c_str() ); remove_all( link_filename ); create_hard_link( log_filename, link_filename );