From: Victor Julien Date: Tue, 28 Oct 2014 09:45:21 +0000 (+0100) Subject: output-filedata: close files even w/o data X-Git-Tag: suricata-2.1beta2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d67289b60e32436a6c351394096120fee0f9839f;p=thirdparty%2Fsuricata.git output-filedata: close files even w/o data If there is no data chunk but the file is closed/truncated anyway, logging is still required. --- diff --git a/src/output-filedata.c b/src/output-filedata.c index cd624437a0..8f466bafc6 100644 --- a/src/output-filedata.c +++ b/src/output-filedata.c @@ -91,6 +91,32 @@ int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, Outpu SC_ATOMIC_DECLARE(unsigned int, file_id); +static int CallLoggers(ThreadVars *tv, OutputLoggerThreadStore *store_list, + Packet *p, const File *ff, const FileData *ffd, uint8_t flags) +{ + OutputFiledataLogger *logger = list; + OutputLoggerThreadStore *store = store_list; + int file_logged = 0; + + while (logger && store) { + BUG_ON(logger->LogFunc == NULL); + + SCLogDebug("logger %p", logger); + PACKET_PROFILING_TMM_START(p, logger->module_id); + logger->LogFunc(tv, store->thread_data, (const Packet *)p, ff, ffd, flags); + PACKET_PROFILING_TMM_END(p, logger->module_id); + + file_logged = 1; + + logger = logger->next; + store = store->next; + + BUG_ON(logger == NULL && store != NULL); + BUG_ON(logger != NULL && store == NULL); + } + return file_logged; +} + static TmEcode OutputFiledataLog(ThreadVars *tv, Packet *p, void *thread_data, PacketQueue *pq, PacketQueue *postpq) { BUG_ON(thread_data == NULL); @@ -144,6 +170,14 @@ static TmEcode OutputFiledataLog(ThreadVars *tv, Packet *p, void *thread_data, P continue; } + /* if we have no data chunks left to log, we should still + * close the logger(s) */ + if (ff->chunks_head == NULL && (file_trunc || file_close)) { + CallLoggers(tv, store, p, ff, NULL, OUTPUT_FILEDATA_FLAG_CLOSE); + ff->flags |= FILE_STORED; + continue; + } + FileData *ffd; for (ffd = ff->chunks_head; ffd != NULL; ffd = ffd->next) { uint8_t flags = 0; @@ -189,24 +223,8 @@ static TmEcode OutputFiledataLog(ThreadVars *tv, Packet *p, void *thread_data, P if (ffd->next == NULL && ff->state >= FILE_STATE_CLOSED) flags |= OUTPUT_FILEDATA_FLAG_CLOSE; - logger = list; - store = op_thread_data->store; - while (logger && store) { - BUG_ON(logger->LogFunc == NULL); - - SCLogDebug("logger %p", logger); - PACKET_PROFILING_TMM_START(p, logger->module_id); - logger->LogFunc(tv, store->thread_data, (const Packet *)p, (const File *)ff, - (const FileData *)write_ffd, flags); - PACKET_PROFILING_TMM_END(p, logger->module_id); - file_logged = 1; - - logger = logger->next; - store = store->next; - - BUG_ON(logger == NULL && store != NULL); - BUG_ON(logger != NULL && store == NULL); - } + /* do the actual logging */ + file_logged = CallLoggers(tv, store, p, ff, write_ffd, flags); if (file_logged) { ffd->stored = 1;