3 /* Copyright (C) 2009 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
13 /* v0.4 (2005/11/11): Some cleanup and bug fixes
14 * v0.3 (2005/08/26): Reading all files in just one process
19 /* Logcollector daemon.
20 * Monitor some files and forward the output to our analysis system.
24 #include <sys/types.h>
32 #include "os_regex/os_regex.h"
34 #include "logcollector.h"
38 /* main: v0.3: 2005/04/04 */
39 int main(int argc, char **argv)
43 int test_config = 0,run_foreground = 0;
44 char *cfg = DEFAULTCPATH;
45 char *dir = DEFAULTDIR;
48 /* Setuping up random */
59 /* Setting the name */
63 while((c = getopt(argc, argv, "VtdhfD:c:")) != -1)
81 ErrorExit("%s: -D needs an argument",ARGV0);
86 ErrorExit("%s: -c needs an argument",ARGV0);
99 debug1(STARTED_MSG,ARGV0);
102 /* Reading config file */
103 if(LogCollectorConfig(cfg) < 0)
104 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
107 /* Getting loop timeout */
108 loop_timeout = getDefine_Int("logcollector",
112 open_file_attempts = getDefine_Int("logcollector", "open_attempts",
115 debug_flag = getDefine_Int("logcollector",
119 /* Getting debug values */
120 while(debug_flag != 0)
127 /* Exit if test config */
132 /* No file available to monitor -- continue */
135 os_calloc(2, sizeof(logreader), logff);
136 logff[0].file = NULL;
137 logff[0].ffile = NULL;
138 logff[0].logformat = NULL;
140 logff[1].file = NULL;
141 logff[1].logformat = NULL;
143 merror(NO_FILE, ARGV0);
147 /* Starting signal handler */
153 /* Going on daemon mode */
159 /* Creating PID file */
160 if(CreatePID(ARGV0, getpid()) < 0)
161 merror(PID_ERROR, ARGV0);
165 /* Waiting 6 seconds for the analysisd/agentd to settle */
166 debug1("%s: DEBUG: Waiting main daemons to settle.", ARGV0);
170 /* Starting the queue. */
171 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
172 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);