1 /* @(#) $Id: ./src/logcollector/read_multiline.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2010 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
17 #include "logcollector.h"
21 /* Read multiline logs. */
22 void *read_multiline(int pos, int *rc, int drop_it)
29 char str[OS_MAXSTR + 1];
30 char buffer[OS_MAXSTR +1];
35 buffer[OS_MAXSTR] = '\0';
39 linecount = atoi(logff[pos].logformat);
41 /* Getting initial file location */
42 fgetpos(logff[pos].fp, &fp_pos);
44 while(fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL)
48 /* Getting the last occurence of \n */
49 if ((p = strrchr(str, '\n')) != NULL)
54 /* If we didn't get the new line, because the
55 * size is large, send what we got so far.
57 else if(strlen(str) >= (OS_MAXSTR - OS_LOG_HEADER - 2))
59 /* Message size > maximum allowed */
64 /* Message not complete. Return. */
65 debug1("%s: Message not complete. Trying again: '%s'", ARGV0,str);
66 fsetpos(logff[pos].fp, &fp_pos);
71 if ((p = strrchr(str, '\r')) != NULL)
77 debug2("%s: DEBUG: Reading message: '%s'", ARGV0, str);
80 /* Adding to buffer. */
81 buffer_size = strlen(buffer);
84 buffer[buffer_size] = ' ';
88 strncpy(buffer + buffer_size, str, OS_MAXSTR - buffer_size -2);
91 if(linesgot < linecount)
97 /* Sending message to queue */
100 if(SendMSG(logr_queue, buffer, logff[pos].file,
103 merror(QUEUE_SEND, ARGV0);
104 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
106 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);
114 /* Incorrectly message size */
117 merror("%s: Large message size: '%s'", ARGV0, str);
118 while(fgets(str, OS_MAXSTR - 2, logff[pos].fp) != NULL)
120 /* Getting the last occurence of \n */
121 if ((p = strrchr(str, '\n')) != NULL)
129 fgetpos(logff[pos].fp, &fp_pos);