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
10 /* Logcollector daemon
11 * Monitor some files and forward the output to our analysis system
14 #include <sys/types.h>
22 #include "os_regex/os_regex.h"
23 #include "logcollector.h"
26 static void help_logcollector(void) __attribute__((noreturn));
29 /* Print help statement */
30 static void help_logcollector()
33 print_out(" %s: -[Vhdtf] [-c config]", ARGV0);
34 print_out(" -V Version and license message");
35 print_out(" -h This help message");
36 print_out(" -d Execute in debug mode. This parameter");
37 print_out(" can be specified multiple times");
38 print_out(" to increase the debug level.");
39 print_out(" -t Test configuration");
40 print_out(" -f Run in foreground");
41 print_out(" -c <config> Configuration file to use (default: %s)", DEFAULTCPATH);
46 int main(int argc, char **argv)
50 int test_config = 0, run_foreground = 0;
51 int accept_manager_commands = 0;
52 const char *cfg = DEFAULTCPATH;
60 while ((c = getopt(argc, argv, "Vtdhfc:")) != -1) {
77 ErrorExit("%s: -c needs an argument", ARGV0);
91 /* Check current debug_level
92 * Command line setting takes precedence
94 if (debug_level == 0) {
96 debug_level = getDefine_Int("logcollector", "debug", 0, 2);
97 while (debug_level != 0) {
103 debug1(STARTED_MSG, ARGV0);
105 accept_manager_commands = getDefine_Int("logcollector", "remote_commands",
108 /* Read config file */
109 if (LogCollectorConfig(cfg, accept_manager_commands) < 0) {
110 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
113 /* Get loop timeout */
114 loop_timeout = getDefine_Int("logcollector",
118 open_file_attempts = getDefine_Int("logcollector", "open_attempts",
121 /* Exit if test config */
126 /* No file available to monitor -- continue */
128 os_calloc(2, sizeof(logreader), logff);
129 logff[0].file = NULL;
130 logff[0].ffile = NULL;
131 logff[0].logformat = NULL;
133 logff[1].file = NULL;
134 logff[1].logformat = NULL;
136 merror(NO_FILE, ARGV0);
139 /* Start signal handler */
142 if (!run_foreground) {
143 /* Going on daemon mode */
148 /* Create PID file */
149 if (CreatePID(ARGV0, getpid()) < 0) {
150 merror(PID_ERROR, ARGV0);
153 /* Wait 6 seconds for the analysisd/agentd to settle */
154 debug1("%s: DEBUG: Waiting main daemons to settle.", ARGV0);
157 /* Start the queue */
158 if ((logr_queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) {
159 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);