1 /* Copyright (C) 2010 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "logcollector.h"
14 /* Read multiline logs */
15 void *read_multiline(int pos, int *rc, int drop_it)
20 size_t buffer_size = 0;
22 char str[OS_MAXSTR + 1];
23 char buffer[OS_MAXSTR + 1];
27 buffer[OS_MAXSTR] = '\0';
28 str[OS_MAXSTR] = '\0';
31 linecount = atoi(logff[pos].logformat);
33 /* Get initial file location */
34 fgetpos(logff[pos].fp, &fp_pos);
36 while (fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL) {
39 /* Get the last occurrence of \n */
40 if ((p = strrchr(str, '\n')) != NULL) {
44 /* If we didn't get the new line, because the
45 * size is large, send what we got so far.
47 else if (strlen(str) >= (OS_MAXSTR - OS_LOG_HEADER - 2)) {
48 /* Message size > maximum allowed */
51 /* Message not complete. Return. */
52 debug1("%s: Message not complete. Trying again: '%s'", ARGV0, str);
53 fsetpos(logff[pos].fp, &fp_pos);
58 if ((p = strrchr(str, '\r')) != NULL) {
63 debug2("%s: DEBUG: Reading message: '%s'", ARGV0, str);
66 buffer_size = strlen(buffer);
67 if (buffer[0] != '\0') {
68 buffer[buffer_size] = ' ';
72 strncpy(buffer + buffer_size, str, OS_MAXSTR - buffer_size - 2);
74 if (linesgot < linecount) {
78 /* Send message to queue */
80 if (SendMSG(logr_queue, buffer, logff[pos].file,
82 merror(QUEUE_SEND, ARGV0);
83 if ((logr_queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) {
84 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);
92 /* Incorrect message size */
94 merror("%s: Large message size: '%s'", ARGV0, str);
95 while (fgets(str, OS_MAXSTR - 2, logff[pos].fp) != NULL) {
96 /* Get the last occurrence of \n */
97 if ((p = strrchr(str, '\n')) != NULL) {
104 fgetpos(logff[pos].fp, &fp_pos);