summaryrefslogtreecommitdiffstats
path: root/src/run.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-01-09 22:52:31 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-01-09 22:52:31 +0000
commit920b90f2b03c60b6940e83cdce8c4b4bfbbc4268 (patch)
tree1dc9fe70ee9304ea0ca72ceb6a2a07537d302cb8 /src/run.c
parent6023de67c84e531939b77454783835c65f694bff (diff)
wake up the daemon iff there are real events to handle instead of polling (Based on comments from Max Kellerman)
Diffstat (limited to 'src/run.c')
-rw-r--r--src/run.c47
1 files changed, 15 insertions, 32 deletions
diff --git a/src/run.c b/src/run.c
index 609b454..3dc8ecc 100644
--- a/src/run.c
+++ b/src/run.c
@@ -25,7 +25,6 @@
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
-#include "timer.h"
void killer(int foo)
{
@@ -38,7 +37,6 @@ void killer(int foo)
ignore_pool_destroy(STATE(ignore_pool));
local_server_destroy(STATE(local));
STATE(mode)->kill();
- destroy_alarm_scheduler();
unlink(CONFIG(lockfile));
dlog(STATE(log), LOG_NOTICE, "---- shutdown received ----");
close_log();
@@ -103,11 +101,6 @@ int init(void)
return -1;
}
- if (init_alarm_scheduler() == -1) {
- dlog(STATE(log), LOG_ERR, "can't initialize alarm scheduler");
- return -1;
- }
-
/* local UNIX socket */
STATE(local) = local_server_create(&CONFIG(local));
if (!STATE(local)) {
@@ -151,14 +144,10 @@ int init(void)
return 0;
}
-static void __run(long credit, int step)
+static int __run(struct timeval *next_alarm)
{
int max, ret;
fd_set readfds;
- struct timeval tv = {
- .tv_sec = 0,
- .tv_usec = credit,
- };
FD_ZERO(&readfds);
FD_SET(STATE(local), &readfds);
@@ -169,7 +158,7 @@ static void __run(long credit, int step)
if (STATE(mode)->add_fds_to_set)
max = MAX(max, STATE(mode)->add_fds_to_set(&readfds));
- ret = select(max+1, &readfds, NULL, NULL, &tv);
+ ret = select(max+1, &readfds, NULL, NULL, next_alarm);
if (ret == -1) {
/* interrupted syscall, retry */
if (errno == EINTR)
@@ -180,6 +169,10 @@ static void __run(long credit, int step)
return;
}
+ /* timeout expired, run the alarm list */
+ if (ret == 0)
+ return 1;
+
/* signals are racy */
sigprocmask(SIG_BLOCK, &STATE(block), NULL);
@@ -221,35 +214,25 @@ static void __run(long credit, int step)
}
if (STATE(mode)->run)
- STATE(mode)->run(&readfds, step);
+ STATE(mode)->run(&readfds);
sigprocmask(SIG_UNBLOCK, &STATE(block), NULL);
+
+ return 0;
}
void run(void)
{
- int step = 0;
- struct timer timer;
-
- timer_init(&timer);
+ struct timeval next_alarm = {
+ .tv_sec = 1,
+ .tv_usec = 0
+ };
while(1) {
- timer_start(&timer);
- __run(GET_CREDITS(timer), step);
- timer_stop(&timer);
-
- if (timer_adjust_credit(&timer)) {
- timer_start(&timer);
+ if (__run(&next_alarm)) {
sigprocmask(SIG_BLOCK, &STATE(block), NULL);
- do_alarm_run(step);
+ do_alarm_run(&next_alarm);
sigprocmask(SIG_UNBLOCK, &STATE(block), NULL);
- timer_stop(&timer);
-
- if (timer_adjust_credit(&timer))
- dlog(STATE(log), LOG_WARNING,
- "alarm run takes too long!");
-
- step = (step + 1) < STEPS_PER_SECONDS ? step + 1 : 0;
}
}
}