From d15c193d42750a06660f40962f5158f880529f07 Mon Sep 17 00:00:00 2001 From: Kevin Webb Date: Wed, 27 Jan 2010 22:00:14 +0000 Subject: [PATCH] Remapped signals and added support for drl to reopen logfiles. --- TODO | 37 ------------------------------------- drl/drl_state.c | 1 + drl/estimate.c | 1 + drl/ulogd_DRL.c | 39 +++++++++++++++++++++++++++++++-------- ulogd.logrotate | 4 +++- 5 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index 3ab6194..0000000 --- a/TODO +++ /dev/null @@ -1,37 +0,0 @@ -libipulog: -X handle multi-part nlmsgs -- Error checking at netlink socket -- forward port my timeout enabled read-function from libipq to libipulog -- man pages - -kernel: -X queue the logging in the kernel and send multiple packets in one - multipart nlmsg -X add timer to flush queue in user-defineable time intervals -- IPv6 ULOG target - -ulogd: -X MYSQL output plugin -X syslog compatibility output plugin -- autoconf-detection of ipt_ULOG.h -X _fini() support for plugin destructors (needed for clean shutdown and - SIGHUP configfile reload -X commandline option for "to fork or not to fork" -X various command line options (we don't even have --version) -- add support for capabilities to run as non-root -X big endian fixes -X man pages -- IPv6 support (core and extensions) -X pcap output plugin (to use ethereal/tcpdump/... for the logs) -- enable user to specify directory where to look for kernel include files -- support for static linking -- make core maintain a list of keyid's that all the output plugins are - interested. The interpreters would be called with their respective - section of that list, and only compute those values that are actually - used by any of the running output plugins -- issues with ulogd_BASE and partially copied packets (--ulog-cprange) -- problem wrt. ulogd_BASE and fragments -- implement extension SIGHUP handlers (including config re-parse) - -conffile: -- rewrite parser. This stuff is a real mess. Anybody interested? diff --git a/drl/drl_state.c b/drl/drl_state.c index d0baa4a..339c109 100644 --- a/drl/drl_state.c +++ b/drl/drl_state.c @@ -317,6 +317,7 @@ void *limiter_receive_thread(void *unused) { sigaddset(&signal_mask, SIGHUP); sigaddset(&signal_mask, SIGUSR1); sigaddset(&signal_mask, SIGUSR2); + sigaddset(&signal_mask, SIGRTMAX); pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); diff --git a/drl/estimate.c b/drl/estimate.c index 24adbbf..ad8fcc7 100644 --- a/drl/estimate.c +++ b/drl/estimate.c @@ -677,6 +677,7 @@ void handle_estimation(void *arg) { sigaddset(&signal_mask, SIGHUP); sigaddset(&signal_mask, SIGUSR1); sigaddset(&signal_mask, SIGUSR2); + sigaddset(&signal_mask, SIGRTMAX); pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); /* Determine the number of intervals we should wait before hitting the diff --git a/drl/ulogd_DRL.c b/drl/ulogd_DRL.c index 8d9b20c..2bb4e52 100644 --- a/drl/ulogd_DRL.c +++ b/drl/ulogd_DRL.c @@ -1795,27 +1795,34 @@ static void *signal_thread_func(void *args) { sigaddset(&sigs, SIGHUP); sigaddset(&sigs, SIGUSR1); sigaddset(&sigs, SIGUSR2); + sigaddset(&sigs, SIGRTMAX); pthread_sigmask(SIG_BLOCK, &sigs, NULL); while (1) { sigemptyset(&sigs); - sigaddset(&sigs, SIGHUP); + //sigaddset(&sigs, SIGHUP); sigaddset(&sigs, SIGUSR1); sigaddset(&sigs, SIGUSR2); + sigaddset(&sigs, SIGRTMAX); err = sigwait(&sigs, &sig); if (err) { printlog(LOG_CRITICAL, "sigwait() returned an error.\n"); flushlog(); + continue; + } + + if (sig == SIGRTMAX) { + printf("Caught SIGRTMAX - toggling fake partitions.\n"); + do_partition = !do_partition; + continue; } switch (sig) { case SIGHUP: - printlog(LOG_WARN, "Caught SIGHUP - re-reading XML file.\n"); - reconfig(); - //time_reconfig(1000); /* instrumentation */ - flushlog(); + printlog(LOG_CRITICAL, "Caught SIGHUP in signal_thread_func?!?\n"); + printf("Caught SIGHUP in signal_thread_func?!?\n"); break; case SIGUSR1: pthread_rwlock_wrlock(&limiter.limiter_lock); @@ -1830,7 +1837,10 @@ static void *signal_thread_func(void *args) { pthread_rwlock_unlock(&limiter.limiter_lock); break; case SIGUSR2: - do_partition = !do_partition; + printlog(LOG_WARN, "Caught SIGUSR2 - re-reading XML file.\n"); + printf("Caught SIGUSR2 - re-reading XML file.\n"); + reconfig(); + flushlog(); break; default: /* Intentionally blank. */ @@ -1843,9 +1853,10 @@ static int drl_plugin_init() { sigset_t signal_mask; sigemptyset(&signal_mask); - sigaddset(&signal_mask, SIGHUP); + //sigaddset(&signal_mask, SIGHUP); sigaddset(&signal_mask, SIGUSR1); sigaddset(&signal_mask, SIGUSR2); + sigaddset(&signal_mask, SIGRTMAX); pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); if (pthread_create(&signal_thread, NULL, &signal_thread_func, NULL) != 0) { @@ -1882,10 +1893,22 @@ static int drl_plugin_init() { return 0; } +static void drl_signal(int sig) { + if (sig == SIGHUP) { + printf("Caught SIGHUP - reopening DRL log file.\n"); + + fclose(logfile); + logfile = fopen(drl_logfile.u.string, "a"); + printlog(LOG_CRITICAL, "Reopened logfile.\n"); + } else { + printlog(LOG_WARN, "Caught unexpected signal %d in drl_signal.\n", sig); + } +} + static ulog_output_t drl_op = { .name = "drl", .output = &_output_drl, - .signal = NULL, /* This appears to be broken. Using my own handler. */ + .signal = &drl_signal, .init = &drl_plugin_init, .fini = NULL, }; diff --git a/ulogd.logrotate b/ulogd.logrotate index b3fb6d1..2e8392d 100644 --- a/ulogd.logrotate +++ b/ulogd.logrotate @@ -1,4 +1,6 @@ -/var/log/ulogd.log /var/log/ulogd.syslogemu /var/log/ulogd.pktlog /var/log/ulogd.pcap { +/var/log/ulogd.log /var/log/ulogd-drl.log /var/log/ulogd.syslogemu /var/log/ulogd.pktlog /var/log/ulogd.pcap { + daily + rotate 14 missingok sharedscripts postrotate -- 2.43.0