From 9343942398b19d04dee45350771df84ba1d29bc9 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 20 Jan 2016 10:21:21 -0300 Subject: [PATCH] Adds mutex around the write operation on the auditlogs --- src/audit_log/writer/parallel.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/audit_log/writer/parallel.cc b/src/audit_log/writer/parallel.cc index e90b461c..c61ede36 100644 --- a/src/audit_log/writer/parallel.cc +++ b/src/audit_log/writer/parallel.cc @@ -23,6 +23,7 @@ #include #include +#include #include "audit_log/audit_log.h" #include "modsecurity/transaction.h" @@ -33,6 +34,9 @@ namespace modsecurity { namespace audit_log { namespace writer { +std::mutex g_writeMutex; + + Parallel::~Parallel() { if (log1.is_open()) { log1.close(); @@ -91,6 +95,7 @@ bool Parallel::init() { bool Parallel::write(Transaction *transaction, int parts) { + std::lock_guard guard(g_writeMutex); FILE *fp; int fd; std::string log = transaction->toJSON(parts); @@ -124,14 +129,17 @@ bool Parallel::write(Transaction *transaction, int parts) { if (log1.is_open() && log2.is_open()) { log2 << transaction->toOldAuditLogFormatIndex(fileName, log.length(), md5(log)); + log2.flush(); } if (log1.is_open() && !log2.is_open()) { log1 << transaction->toOldAuditLogFormatIndex(fileName, log.length(), md5(log)); + log1.flush(); } if (!log1.is_open() && log2.is_open()) { log2 << transaction->toOldAuditLogFormatIndex(fileName, log.length(), md5(log)); + log2.flush(); } return true;