diff --git a/src/util-debug.c b/src/util-debug.c index 97b1626b2b..d4ddc14a2d 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -577,11 +577,13 @@ SCError SCLogMessage(const SCLogLevel log_level, const char *file, log_level, file, line, function, error_code, message) == 0) { + SCMutexLock(&op_iface_ctx->fp_mutex); if (op_iface_ctx->rotation_flag) { SCLogReopen(op_iface_ctx); op_iface_ctx->rotation_flag = 0; } SCLogPrintToStream(op_iface_ctx->file_d, buffer); + SCMutexUnlock(&op_iface_ctx->fp_mutex); } break; case SC_LOG_OP_IFACE_SYSLOG: @@ -714,6 +716,7 @@ static inline SCLogOPIfaceCtx *SCLogInitFileOPIface(const char *file, goto error; } + SCMutexInit(&iface_ctx->fp_mutex, NULL); OutputRegisterFileRotationFlag(&iface_ctx->rotation_flag); iface_ctx->log_level = log_level; diff --git a/src/util-debug.h b/src/util-debug.h index 5148fe19f6..8cf49beda3 100644 --- a/src/util-debug.h +++ b/src/util-debug.h @@ -139,6 +139,9 @@ typedef struct SCLogOPIfaceCtx_ { /* override for the global_log_format(currently not used) */ const char *log_format; + /* Mutex used for locking around rotate/write to a file. */ + SCMutex fp_mutex; + struct SCLogOPIfaceCtx_ *next; } SCLogOPIfaceCtx;