Mercurial > syslog2iptables
comparison src/syslog2iptables.cpp @ 2:6e88da080f08
initial coding
author | carl |
---|---|
date | Thu, 24 Nov 2005 10:31:09 -0800 |
parents | 551433a01cab |
children | 8fe310e5cd44 |
comparison
equal
deleted
inserted
replaced
1:551433a01cab | 2:6e88da080f08 |
---|---|
34 #include <sys/stat.h> | 34 #include <sys/stat.h> |
35 #include <sys/wait.h> /* header for waitpid() and various macros */ | 35 #include <sys/wait.h> /* header for waitpid() and various macros */ |
36 #include <signal.h> /* header for signal functions */ | 36 #include <signal.h> /* header for signal functions */ |
37 #include "includes.h" | 37 #include "includes.h" |
38 | 38 |
39 extern "C" { | |
40 void sig_chld(int signo); | |
41 } | |
39 int debug_syslog = 0; | 42 int debug_syslog = 0; |
40 bool syslog_opened = false; | 43 bool syslog_opened = false; |
41 bool use_syslog = true; // false to printf | 44 bool use_syslog = true; // false to printf |
42 bool loader_run = true; // used to stop the config loader thread | 45 bool loader_run = true; // used to stop the config loader thread |
43 CONFIG *config = NULL; // protected by the config_mutex | 46 CONFIG *config = NULL; // protected by the config_mutex |
194 use_syslog = false; | 197 use_syslog = false; |
195 debug_syslog = 10; | 198 debug_syslog = 10; |
196 CONFIG *conf = new_conf(); | 199 CONFIG *conf = new_conf(); |
197 if (conf) { | 200 if (conf) { |
198 conf->dump(); | 201 conf->dump(); |
202 for (int i=0; i<30; i++) { | |
203 conf->read(); | |
204 sleep(1); | |
205 } | |
199 delete conf; | 206 delete conf; |
200 return 0; | 207 return 0; |
201 } | 208 } |
202 else { | 209 else { |
203 return 1; // config failed to load | 210 return 1; // config failed to load |
240 if (!config) { | 247 if (!config) { |
241 my_syslog("failed to load initial configuration, quitting"); | 248 my_syslog("failed to load initial configuration, quitting"); |
242 exit(1); | 249 exit(1); |
243 } | 250 } |
244 | 251 |
252 // setup sigchld handler to prevent zombies | |
253 struct sigaction act; | |
254 act.sa_handler = sig_chld; // Assign sig_chld as our SIGCHLD handler | |
255 sigemptyset(&act.sa_mask); // We don't want to block any other signals in this example | |
256 act.sa_flags = SA_NOCLDSTOP; // only want children that have terminated | |
257 if (sigaction(SIGCHLD, &act, NULL) < 0) { | |
258 my_syslog("failed to setup SIGCHLD handler"); | |
259 exit(1); | |
260 } | |
261 | |
245 // only create threads after the fork() in daemon | 262 // only create threads after the fork() in daemon |
246 pthread_t tid; | 263 pthread_t tid; |
247 if (pthread_create(&tid, 0, config_loader, 0)) | 264 if (pthread_create(&tid, 0, config_loader, 0)) |
248 my_syslog("failed to create config loader thread"); | 265 my_syslog("failed to create config loader thread"); |
249 if (pthread_detach(tid)) | 266 if (pthread_detach(tid)) |