X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=src%2Flogcollector%2Fmain.c;h=00a9c9edd799cc9cbfca767e410dbbd3024d251b;hb=789cbc8e52da68eba3517b920ef22e000cf3c9fd;hp=5340c85d0dbb1c8f3e407ef671bd87b47cc72c90;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/logcollector/main.c b/src/logcollector/main.c index 5340c85..00a9c9e 100755 --- a/src/logcollector/main.c +++ b/src/logcollector/main.c @@ -1,19 +1,20 @@ -/* @(#) $Id: main.c,v 1.27 2009/11/18 19:07:40 dcid Exp $ */ +/* @(#) $Id: ./src/logcollector/main.c, 2012/03/28 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ /* v0.4 (2005/11/11): Some cleanup and bug fixes - * v0.3 (2005/08/26): Reading all files in just one process + * v0.3 (2005/08/26): Reading all files in just one process * v0.2 (2005/04/04): - */ + */ /* Logcollector daemon. @@ -39,15 +40,28 @@ int main(int argc, char **argv) { int c; - int debug_flag = 0; + int debug_level = 0; int test_config = 0,run_foreground = 0; + int accept_manager_commands = 0; char *cfg = DEFAULTCPATH; - char *dir = DEFAULTDIR; + // TODO: delete or implement + char *dir __attribute__((unused)) = DEFAULTDIR; + /* Setuping up random */ + #ifndef WIN32 + #ifdef __OpenBSD__ + srandomdev(); + #else + srandom(time(0)); + #endif + #else + srandom(time(0)) + #endif + /* Setting the name */ OS_SetName(ARGV0); - + while((c = getopt(argc, argv, "VtdhfD:c:")) != -1) { @@ -61,6 +75,7 @@ int main(int argc, char **argv) break; case 'd': nowDebug(); + debug_level = 1; break; case 'f': run_foreground = 1; @@ -77,46 +92,57 @@ int main(int argc, char **argv) break; case 't': test_config = 1; - break; + break; default: help(ARGV0); - break; + break; } } + /* Check current debug_level + * Command line setting takes precedence + */ + if (debug_level == 0) + { + /* Getting debug level */ + debug_level = getDefine_Int("logcollector", "debug", 0, 2); + while(debug_level != 0) + { + nowDebug(); + debug_level--; + } + } + + debug1(STARTED_MSG,ARGV0); + accept_manager_commands = getDefine_Int("logcollector", "remote_commands", + 0, 1); + + /* Reading config file */ - if(LogCollectorConfig(cfg) < 0) + if(LogCollectorConfig(cfg, accept_manager_commands) < 0) ErrorExit(CONFIG_ERROR, ARGV0, cfg); - - + + /* Getting loop timeout */ loop_timeout = getDefine_Int("logcollector", "loop_timeout", 1, 120); - + open_file_attempts = getDefine_Int("logcollector", "open_attempts", 2, 998); - - debug_flag = getDefine_Int("logcollector", - "debug", - 0,2); - - /* Getting debug values */ - while(debug_flag != 0) - { - nowDebug(); - debug_flag--; - } + + accept_manager_commands = getDefine_Int("logcollector", "remote_commands", + 0, 1); /* Exit if test config */ if(test_config) exit(0); - + /* No file available to monitor -- continue */ if(logff == NULL) @@ -131,13 +157,13 @@ int main(int argc, char **argv) merror(NO_FILE, ARGV0); } - + /* Starting signal handler */ - StartSIG(ARGV0); + StartSIG(ARGV0); - if (!run_foreground) + if (!run_foreground) { /* Going on daemon mode */ nowDaemon(); @@ -149,21 +175,21 @@ int main(int argc, char **argv) if(CreatePID(ARGV0, getpid()) < 0) merror(PID_ERROR, ARGV0); - - + + /* Waiting 6 seconds for the analysisd/agentd to settle */ debug1("%s: DEBUG: Waiting main daemons to settle.", ARGV0); sleep(6); - - + + /* Starting the queue. */ if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0) ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH); - /* Main loop */ + /* Main loop */ LogCollectorStart(); - + return(0); }