]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Small http.log improvement: bail out early if there is nothing to log. Make output...
authorVictor Julien <victor@inliniac.net>
Thu, 15 Mar 2012 11:01:09 +0000 (12:01 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 15 Mar 2012 11:01:09 +0000 (12:01 +0100)
src/log-httplog.c

index 145e3591f04e9ed8f7e9519a9640ba61d2553967..ddcd7bdcecc67ed8621343ba299580407613cdc0 100644 (file)
@@ -209,6 +209,11 @@ static TmEcode LogHttpLogIPWrapper(ThreadVars *tv, Packet *p, void *data, Packet
     }
     size_t loggable = (size_t)r;
 
+    /* nothing to do */
+    if (logged >= loggable) {
+        goto end;
+    }
+
     HtpState *htp_state = (HtpState *)AppLayerGetProtoStateFromPacket(p);
     if (htp_state == NULL) {
         SCLogDebug("no http state, so no request logging");
@@ -256,7 +261,6 @@ static TmEcode LogHttpLogIPWrapper(ThreadVars *tv, Packet *p, void *data, Packet
         dp = p->sp;
     }
 
-    SCMutexLock(&hlog->file_ctx->fp_mutex);
     for (idx = logged; idx < loggable; idx++)
     {
         tx = list_get(htp_state->connp->conn->transactions, idx);
@@ -265,6 +269,9 @@ static TmEcode LogHttpLogIPWrapper(ThreadVars *tv, Packet *p, void *data, Packet
             continue;
         }
 
+        /* output now starting, so get output lock */
+        SCMutexLock(&hlog->file_ctx->fp_mutex);
+
         SCLogDebug("got a HTTP request and now logging !!");
         /* time */
         fprintf(hlog->file_ctx->fp, "%s ", timebuf);
@@ -310,11 +317,11 @@ static TmEcode LogHttpLogIPWrapper(ThreadVars *tv, Packet *p, void *data, Packet
                 srcip, sp, dstip, dp);
 
         aft->uri_cnt ++;
+        fflush(hlog->file_ctx->fp);
+        SCMutexUnlock(&hlog->file_ctx->fp_mutex);
 
         AppLayerTransactionUpdateLoggedId(p->flow);
     }
-    fflush(hlog->file_ctx->fp);
-    SCMutexUnlock(&hlog->file_ctx->fp_mutex);
 
 end:
     SCMutexUnlock(&p->flow->m);