1 /* @(#) $Id: ./src/logcollector/main.c, 2012/03/28 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
14 /* v0.4 (2005/11/11): Some cleanup and bug fixes
15 * v0.3 (2005/08/26): Reading all files in just one process
20 /* Logcollector daemon.
21 * Monitor some files and forward the output to our analysis system.
25 #include <sys/types.h>
33 #include "os_regex/os_regex.h"
35 #include "logcollector.h"
39 /* main: v0.3: 2005/04/04 */
40 int main(int argc, char **argv)
44 int test_config = 0,run_foreground = 0;
45 int accept_manager_commands = 0;
46 char *cfg = DEFAULTCPATH;
47 // TODO: delete or implement
48 char *dir __attribute__((unused)) = DEFAULTDIR;
51 /* Setuping up random */
62 /* Setting the name */
66 while((c = getopt(argc, argv, "VtdhfD:c:")) != -1)
85 ErrorExit("%s: -D needs an argument",ARGV0);
90 ErrorExit("%s: -c needs an argument",ARGV0);
103 /* Check current debug_level
104 * Command line setting takes precedence
106 if (debug_level == 0)
108 /* Getting debug level */
109 debug_level = getDefine_Int("logcollector", "debug", 0, 2);
110 while(debug_level != 0)
118 debug1(STARTED_MSG,ARGV0);
121 accept_manager_commands = getDefine_Int("logcollector", "remote_commands",
125 /* Reading config file */
126 if(LogCollectorConfig(cfg, accept_manager_commands) < 0)
127 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
130 /* Getting loop timeout */
131 loop_timeout = getDefine_Int("logcollector",
135 open_file_attempts = getDefine_Int("logcollector", "open_attempts",
138 accept_manager_commands = getDefine_Int("logcollector", "remote_commands",
142 /* Exit if test config */
147 /* No file available to monitor -- continue */
150 os_calloc(2, sizeof(logreader), logff);
151 logff[0].file = NULL;
152 logff[0].ffile = NULL;
153 logff[0].logformat = NULL;
155 logff[1].file = NULL;
156 logff[1].logformat = NULL;
158 merror(NO_FILE, ARGV0);
162 /* Starting signal handler */
168 /* Going on daemon mode */
174 /* Creating PID file */
175 if(CreatePID(ARGV0, getpid()) < 0)
176 merror(PID_ERROR, ARGV0);
180 /* Waiting 6 seconds for the analysisd/agentd to settle */
181 debug1("%s: DEBUG: Waiting main daemons to settle.", ARGV0);
185 /* Starting the queue. */
186 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
187 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);