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.
pull/1195/head
Victor Julien 11 years ago
parent 08b06bac3f
commit d67289b60e

@ -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;

Loading…
Cancel
Save