1 /* Copyright (C) 2009 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
13 #include "logcollector.h"
15 /* Starting last time */
16 static char __mysql_last_time[18] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
19 void *read_mysql_log(int pos, int *rc, int drop_it)
24 char str[OS_MAXSTR + 1];
25 char buffer[OS_MAXSTR + 1];
27 str[OS_MAXSTR] = '\0';
31 while (fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL) {
33 str_len = strlen(str);
35 /* Get the last occurrence of \n */
36 if ((p = strrchr(str, '\n')) != NULL) {
39 /* If need clear is set, we just get the line and ignore it */
49 if ((p = strrchr(str, '\r')) != NULL) {
53 /* Look for empty string (only on windows) */
59 /* Windows can have comment on their logs */
65 /* MySQL messages have the following format:
72 isdigit((int)str[0]) &&
73 isdigit((int)str[1]) &&
74 isdigit((int)str[2]) &&
75 isdigit((int)str[3]) &&
76 isdigit((int)str[4]) &&
77 isdigit((int)str[5]) &&
78 isdigit((int)str[7]) &&
79 isdigit((int)str[8])) {
81 strncpy(__mysql_last_time, str, 16);
82 __mysql_last_time[15] = '\0';
85 /* Remove spaces and tabs */
87 while (*p == ' ' || *p == '\t') {
91 /* Valid MySQL message */
92 snprintf(buffer, OS_MAXSTR, "MySQL log: %s %s",
93 __mysql_last_time, p);
96 /* Multiple events at the same second share the same timestamp:
97 * 0909 2020 2020 2020 20
99 else if ((str_len > 10) && (__mysql_last_time[0] != '\0') &&
110 /* Remove extra spaces and tabs */
111 while (*p == ' ' || *p == '\t') {
115 /* Valid MySQL message */
116 snprintf(buffer, OS_MAXSTR, "MySQL log: %s %s",
117 __mysql_last_time, p);
122 debug2("%s: DEBUG: Reading mysql messages: '%s'", ARGV0, buffer);
124 /* Send message to queue */
126 if (SendMSG(logr_queue, buffer, logff[pos].file, MYSQL_MQ) < 0) {
127 merror(QUEUE_SEND, ARGV0);
128 if ((logr_queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) {
129 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);