diff --git a/src/log-httplog.c b/src/log-httplog.c index 145e3591f0..ddcd7bdcec 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -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);