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)

This commit is contained in:
Eric Frias 2014-07-16 13:39:14 -04:00
parent 06fe9e0303
commit b6f8570c35

View file

@ -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<boost::mutex> lock( slock );
fc::scoped_lock<boost::mutex> 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 );