X-Git-Url: http://git.onelab.eu/?p=distributedratelimiting.git;a=blobdiff_plain;f=drl%2Fulogd_DRL.c;h=f7b027256901326322647c007087b9982b726cb8;hp=170ab4375ea7e122ce901ec224882f9ebcd51332;hb=89df43dd6b8cb8df82cfbf395b923014d2826b5a;hpb=3cc87c8471668009b3426013fded8c6ec5a382da diff --git a/drl/ulogd_DRL.c b/drl/ulogd_DRL.c index 170ab43..f7b0272 100644 --- a/drl/ulogd_DRL.c +++ b/drl/ulogd_DRL.c @@ -713,6 +713,25 @@ static identity_t *new_identity(ident_config *config) { return ident; } +static int validate_htb_exists(int node, int parent) { + FILE *pipe = popen("/sbin/tc class show dev eth0", "r"); + char line[200]; + + while (fgets(line, 200, pipe) != NULL) { + int n, p; + char ignore[200]; + + sscanf(line, "class htb 1:%x parent 1:%x prio %s", &n, &p, ignore); + if (n == node && p == parent) { + pclose(pipe); + return 0; + } + } + + pclose(pipe); + return 1; +} + /* Determines the validity of the parameters of one ident_config. * * 0 valid @@ -754,6 +773,11 @@ static int validate_config(ident_config *config) { printlog(LOG_CRITICAL, "When create_htb is disabled in ulogd.conf, an identity must specify the htb_node and htb_parent propertities in its configuration.\n"); return 1; } + + if (validate_htb_exists(config->htb_node, config->htb_parent)) { + printlog(LOG_CRITICAL, "Identity specified htb node %x with parent %x. No such node/parent combo seems to exist!\n", config->htb_node, config->htb_parent); + return 1; + } } else { if (config->htb_node > -1 || config->htb_parent > -1) { printlog(LOG_WARN, "htb_node or htb_parent are configured but ignored because we're configured to create our own htb hierarchy.\n"); @@ -1502,10 +1526,10 @@ static int init_drl(void) { pthread_rwlock_init(&limiter.limiter_lock,NULL); /* determine our local IP by iterating through interfaces */ - if ((limiter.ip = get_local_ip())==0) { - printlog(LOG_CRITICAL, - "ulogd_DRL unable to aquire local IP address, not registering.\n"); - return (false); + limiter.ip = get_local_ip(); + if (limiter.ip == NULL) { + printlog(LOG_CRITICAL, "ulogd_DRL unable to aquire local IP address, not registering.\n"); + return false; } limiter.localaddr = inet_addr(limiter.ip); limiter.port = htons(LIMITER_LISTEN_PORT); @@ -1771,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); @@ -1806,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. */ @@ -1819,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) { @@ -1858,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, };