mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
Adds mutex around the write operation on the auditlogs
This commit is contained in:
parent
b4691aa748
commit
9343942398
@ -23,6 +23,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "audit_log/audit_log.h"
|
#include "audit_log/audit_log.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -33,6 +34,9 @@ namespace modsecurity {
|
|||||||
namespace audit_log {
|
namespace audit_log {
|
||||||
namespace writer {
|
namespace writer {
|
||||||
|
|
||||||
|
std::mutex g_writeMutex;
|
||||||
|
|
||||||
|
|
||||||
Parallel::~Parallel() {
|
Parallel::~Parallel() {
|
||||||
if (log1.is_open()) {
|
if (log1.is_open()) {
|
||||||
log1.close();
|
log1.close();
|
||||||
@ -91,6 +95,7 @@ bool Parallel::init() {
|
|||||||
|
|
||||||
|
|
||||||
bool Parallel::write(Transaction *transaction, int parts) {
|
bool Parallel::write(Transaction *transaction, int parts) {
|
||||||
|
std::lock_guard<std::mutex> guard(g_writeMutex);
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int fd;
|
int fd;
|
||||||
std::string log = transaction->toJSON(parts);
|
std::string log = transaction->toJSON(parts);
|
||||||
@ -124,14 +129,17 @@ bool Parallel::write(Transaction *transaction, int parts) {
|
|||||||
if (log1.is_open() && log2.is_open()) {
|
if (log1.is_open() && log2.is_open()) {
|
||||||
log2 << transaction->toOldAuditLogFormatIndex(fileName, log.length(),
|
log2 << transaction->toOldAuditLogFormatIndex(fileName, log.length(),
|
||||||
md5(log));
|
md5(log));
|
||||||
|
log2.flush();
|
||||||
}
|
}
|
||||||
if (log1.is_open() && !log2.is_open()) {
|
if (log1.is_open() && !log2.is_open()) {
|
||||||
log1 << transaction->toOldAuditLogFormatIndex(fileName, log.length(),
|
log1 << transaction->toOldAuditLogFormatIndex(fileName, log.length(),
|
||||||
md5(log));
|
md5(log));
|
||||||
|
log1.flush();
|
||||||
}
|
}
|
||||||
if (!log1.is_open() && log2.is_open()) {
|
if (!log1.is_open() && log2.is_open()) {
|
||||||
log2 << transaction->toOldAuditLogFormatIndex(fileName, log.length(),
|
log2 << transaction->toOldAuditLogFormatIndex(fileName, log.length(),
|
||||||
md5(log));
|
md5(log));
|
||||||
|
log2.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user