Skip to content

Commit

Permalink
Log::reopen_log_file: take m_flush_mutex
Browse files Browse the repository at this point in the history
Otherwise, _flush() might continue to write to m_fd after it's closed.
This might cause log data to go to a data object if the filestore then
reuses the fd during that time.

Fixes: #12465
Backport: firefly, hammer
Signed-off-by: Samuel Just <sjust@redhat.com>
(cherry picked from commit 8778ab3)
  • Loading branch information
athanatos authored and liewegas committed Jul 27, 2015
1 parent 45beb86 commit 154f18c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/log/Log.cc
Expand Up @@ -116,13 +116,17 @@ void Log::set_log_file(string fn)

void Log::reopen_log_file()
{
pthread_mutex_lock(&m_flush_mutex);
m_flush_mutex_holder = pthread_self();
if (m_fd >= 0)
VOID_TEMP_FAILURE_RETRY(::close(m_fd));
if (m_log_file.length()) {
m_fd = ::open(m_log_file.c_str(), O_CREAT|O_WRONLY|O_APPEND, 0644);
} else {
m_fd = -1;
}
m_flush_mutex_holder = 0;
pthread_mutex_unlock(&m_flush_mutex);
}

void Log::set_syslog_level(int log, int crash)
Expand Down

0 comments on commit 154f18c

Please sign in to comment.