1 /* @(#) $Id: main.c,v 1.27 2009/11/18 19:07:40 dcid Exp $ */
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 3) 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 /* Setting the name */
52 while((c = getopt(argc, argv, "VtdhfD:c:")) != -1)
70 ErrorExit("%s: -D needs an argument",ARGV0);
75 ErrorExit("%s: -c needs an argument",ARGV0);
88 debug1(STARTED_MSG,ARGV0);
91 /* Reading config file */
92 if(LogCollectorConfig(cfg) < 0)
93 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
96 /* Getting loop timeout */
97 loop_timeout = getDefine_Int("logcollector",
101 open_file_attempts = getDefine_Int("logcollector", "open_attempts",
104 debug_flag = getDefine_Int("logcollector",
108 /* Getting debug values */
109 while(debug_flag != 0)
116 /* Exit if test config */
121 /* No file available to monitor -- continue */
124 os_calloc(2, sizeof(logreader), logff);
125 logff[0].file = NULL;
126 logff[0].ffile = NULL;
127 logff[0].logformat = NULL;
129 logff[1].file = NULL;
130 logff[1].logformat = NULL;
132 merror(NO_FILE, ARGV0);
136 /* Starting signal handler */
142 /* Going on daemon mode */
148 /* Creating PID file */
149 if(CreatePID(ARGV0, getpid()) < 0)
150 merror(PID_ERROR, ARGV0);
154 /* Waiting 6 seconds for the analysisd/agentd to settle */
155 debug1("%s: DEBUG: Waiting main daemons to settle.", ARGV0);
159 /* Starting the queue. */
160 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
161 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);