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 char *dir = DEFAULTDIR;
50 /* Setuping up random */
61 /* Setting the name */
65 while((c = getopt(argc, argv, "VtdhfD:c:")) != -1)
83 ErrorExit("%s: -D needs an argument",ARGV0);
88 ErrorExit("%s: -c needs an argument",ARGV0);
101 debug1(STARTED_MSG,ARGV0);
104 accept_manager_commands = getDefine_Int("logcollector", "remote_commands",
108 /* Reading config file */
109 if(LogCollectorConfig(cfg, accept_manager_commands) < 0)
110 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
113 /* Getting loop timeout */
114 loop_timeout = getDefine_Int("logcollector",
118 open_file_attempts = getDefine_Int("logcollector", "open_attempts",
121 debug_flag = getDefine_Int("logcollector",
124 accept_manager_commands = getDefine_Int("logcollector", "remote_commands",
127 /* Getting debug values */
128 while(debug_flag != 0)
135 /* Exit if test config */
140 /* No file available to monitor -- continue */
143 os_calloc(2, sizeof(logreader), logff);
144 logff[0].file = NULL;
145 logff[0].ffile = NULL;
146 logff[0].logformat = NULL;
148 logff[1].file = NULL;
149 logff[1].logformat = NULL;
151 merror(NO_FILE, ARGV0);
155 /* Starting signal handler */
161 /* Going on daemon mode */
167 /* Creating PID file */
168 if(CreatePID(ARGV0, getpid()) < 0)
169 merror(PID_ERROR, ARGV0);
173 /* Waiting 6 seconds for the analysisd/agentd to settle */
174 debug1("%s: DEBUG: Waiting main daemons to settle.", ARGV0);
178 /* Starting the queue. */
179 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
180 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);