]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
log: wrap rotation and write in lock
authorJason Ish <ish@unx.ca>
Mon, 26 Jun 2017 17:04:46 +0000 (11:04 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 28 Jun 2017 07:24:20 +0000 (09:24 +0200)
The application log is subject to rotation, so the check for
rotation, the actual rotation and write needs to be done under
lock to ensure the file pointer is in a consisten state
at the time of write().

Fixes issue:
https://redmine.openinfosecfoundation.org/issues/2155

src/util-debug.c
src/util-debug.h

index 97b1626b2bb6d0ea1686b83dc3b2e63dd35b5cc0..d4ddc14a2dafd9a8d1a7054fa1bd841ff6afeec6 100644 (file)
@@ -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;
index 5148fe19f60a4ccc658b502b3991c074709c09b3..8cf49beda39cfa17ab3d43c20aa732d7e109295e 100644 (file)
@@ -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;