3 /* Copyright (C) 2010 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
16 #include "logcollector.h"
20 /* Read multiline logs. */
21 void *read_multiline(int pos, int *rc, int drop_it)
28 char str[OS_MAXSTR + 1];
29 char buffer[OS_MAXSTR +1];
34 buffer[OS_MAXSTR] = '\0';
38 linecount = atoi(logff[pos].logformat);
40 /* Getting initial file location */
41 fgetpos(logff[pos].fp, &fp_pos);
43 while(fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL)
47 /* Getting the last occurence of \n */
48 if ((p = strrchr(str, '\n')) != NULL)
53 /* If we didn't get the new line, because the
54 * size is large, send what we got so far.
56 else if(strlen(str) >= (OS_MAXSTR - OS_LOG_HEADER - 2))
58 /* Message size > maximum allowed */
63 /* Message not complete. Return. */
64 debug1("%s: Message not complete. Trying again: '%s'", ARGV0,str);
65 fsetpos(logff[pos].fp, &fp_pos);
70 if ((p = strrchr(str, '\r')) != NULL)
76 debug2("%s: DEBUG: Reading message: '%s'", ARGV0, str);
79 /* Adding to buffer. */
80 buffer_size = strlen(buffer);
83 buffer[buffer_size] = ' ';
87 strncpy(buffer + buffer_size, str, OS_MAXSTR - buffer_size -2);
90 if(linesgot < linecount)
96 /* Sending message to queue */
99 if(SendMSG(logr_queue, buffer, logff[pos].file,
102 merror(QUEUE_SEND, ARGV0);
103 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
105 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);
113 /* Incorrectly message size */
116 merror("%s: Large message size: '%s'", ARGV0, str);
117 while(fgets(str, OS_MAXSTR - 2, logff[pos].fp) != NULL)
119 /* Getting the last occurence of \n */
120 if ((p = strrchr(str, '\n')) != NULL)
128 fgetpos(logff[pos].fp, &fp_pos);