Mercurial > syslog2iptables
diff src/syslog2iptables.cpp @ 5:276c4edc8521
initial coding
author | carl |
---|---|
date | Fri, 02 Dec 2005 17:52:44 -0800 |
parents | 2737ab01659a |
children | d76f9ff42487 |
line wrap: on
line diff
--- a/src/syslog2iptables.cpp Thu Dec 01 17:17:37 2005 -0800 +++ b/src/syslog2iptables.cpp Fri Dec 02 17:52:44 2005 -0800 @@ -18,6 +18,10 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +// debug levels: +// 4 - show syslog lines that match regex +// 3 - show files open/close +// 1 - show config files loading #ifdef HAVE_CONFIG_H #include <config.h> @@ -56,7 +60,7 @@ if (use_syslog) { pthread_mutex_lock(&syslog_mutex); if (!syslog_opened) { - openlog("syslog2iptables", LOG_PID, LOG_MAIL); + openlog("syslog2iptables", LOG_PID, LOG_AUTHPRIV); syslog_opened = true; } syslog(LOG_NOTICE, "%s", text); @@ -166,43 +170,15 @@ void usage(char *prog); void usage(char *prog) { + fprintf(stderr, "Usage: %s [-d [level]] [-c]\n", prog); + fprintf(stderr, "-c will load and dump the config to stdout\n"); + fprintf(stderr, "-d will set the syslog message level, currently 0 to 3\n"); } -int main(int argc, char *argv[]) +void worker(); +void worker() { - token_init(); - bool check = true; - int c; - const char *args = "ch"; - extern char *optarg; - - // Process command line options - while ((c = getopt(argc, argv, args)) != -1) { - switch (c) { - case 'c': - check = true; - break; - - case 'h': - default: - usage(argv[0]); - exit(EX_USAGE); - } - } - - if (check) { - use_syslog = false; - debug_syslog = 10; - config = new_conf(); - if (config) { - config->dump(); - { - // just for testing - // initialize the thread sync objects - pthread_mutex_init(&config_mutex, 0); - pthread_mutex_init(&syslog_mutex, 0); - time_t t = time(NULL); CONFIG *c; pthread_mutex_lock(&config_mutex); @@ -221,6 +197,41 @@ c->sleep(10, t); } } + + +int main(int argc, char *argv[]) +{ + token_init(); + bool check = false; + int c; + const char *args = "d:ch"; + extern char *optarg; + + // Process command line options + while ((c = getopt(argc, argv, args)) != -1) { + switch (c) { + case 'c': + check = true; + break; + + case 'd': + if (optarg == NULL || *optarg == '\0') debug_syslog = 1; + else debug_syslog = atoi(optarg); + break; + + case 'h': + default: + usage(argv[0]); + exit(EX_USAGE); + } + } + + if (check) { + use_syslog = false; + debug_syslog = 10; + config = new_conf(); + if (config) { + config->dump(); delete config; return 0; } @@ -284,6 +295,7 @@ if (pthread_detach(tid)) my_syslog("failed to detach config loader thread"); - loader_run = false; // eventually the config loader thread will terminate + worker(); + return EXIT_SUCCESS; }