[netfilter-cvslog] r7281 - in trunk/conntrack-tools: include src
pablo at netfilter.org
pablo at netfilter.org
Tue Jan 22 02:25:35 CET 2008
Author: pablo at netfilter.org
Date: 2008-01-22 02:25:34 +0100 (Tue, 22 Jan 2008)
New Revision: 7281
Modified:
trunk/conntrack-tools/include/alarm.h
trunk/conntrack-tools/src/alarm.c
trunk/conntrack-tools/src/run.c
Log:
Max Kellermann <max at duempel.org>:
- Pass next_alarm to __run() only if there is an alarm
- Eliminate the "timeout" parameter
- the alarm functions get_next_alarm_run() and do_alarm_run() return an timeval pointer instead of a boolean
Modified: trunk/conntrack-tools/include/alarm.h
===================================================================
--- trunk/conntrack-tools/include/alarm.h 2008-01-20 23:56:55 UTC (rev 7280)
+++ trunk/conntrack-tools/include/alarm.h 2008-01-22 01:25:34 UTC (rev 7281)
@@ -26,8 +26,10 @@
void del_alarm(struct alarm_list *alarm);
-int get_next_alarm_run(struct timeval *next_alarm);
+struct timeval *
+get_next_alarm_run(struct timeval *next_alarm);
-int do_alarm_run(struct timeval *next_alarm);
+struct timeval *
+do_alarm_run(struct timeval *next_alarm);
#endif
Modified: trunk/conntrack-tools/src/alarm.c
===================================================================
--- trunk/conntrack-tools/src/alarm.c 2008-01-20 23:56:55 UTC (rev 7280)
+++ trunk/conntrack-tools/src/alarm.c 2008-01-22 01:25:34 UTC (rev 7281)
@@ -74,7 +74,7 @@
}
}
-static int
+static struct timeval *
calculate_next_run(struct timeval *cand,
struct timeval *tv,
struct timeval *next_run)
@@ -87,12 +87,13 @@
next_run->tv_sec = 0;
next_run->tv_usec = 0;
}
- return 1;
+ return next_run;
}
- return 0;
+ return NULL;
}
-int get_next_alarm_run(struct timeval *next_run)
+struct timeval *
+get_next_alarm_run(struct timeval *next_run)
{
int i;
struct alarm_list *t;
@@ -133,7 +134,8 @@
return 0;
}
-int do_alarm_run(struct timeval *next_run)
+struct timeval *
+do_alarm_run(struct timeval *next_run)
{
int i;
struct alarm_list *t, *next, *prev;
Modified: trunk/conntrack-tools/src/run.c
===================================================================
--- trunk/conntrack-tools/src/run.c 2008-01-20 23:56:55 UTC (rev 7280)
+++ trunk/conntrack-tools/src/run.c 2008-01-22 01:25:34 UTC (rev 7281)
@@ -158,16 +158,11 @@
return 0;
}
-static int __run(struct timeval *next_alarm, int *timeout)
+static void __run(struct timeval *next_alarm)
{
int max, ret;
fd_set readfds;
- struct timeval *tmp = next_alarm;
- /* No alarms, select must block */
- if (*timeout == 0)
- tmp = NULL;
-
FD_ZERO(&readfds);
FD_SET(STATE(local), &readfds);
FD_SET(nfct_fd(STATE(event)), &readfds);
@@ -177,21 +172,17 @@
if (STATE(mode)->add_fds_to_set)
max = MAX(max, STATE(mode)->add_fds_to_set(&readfds));
- ret = select(max+1, &readfds, NULL, NULL, tmp);
+ ret = select(max+1, &readfds, NULL, NULL, next_alarm);
if (ret == -1) {
/* interrupted syscall, retry */
if (errno == EINTR)
- return 0;
+ return;
dlog(LOG_WARNING,
"select failed: %s", strerror(errno));
- return 0;
+ return;
}
- /* timeout expired, run the alarm list */
- if (tmp != NULL && !timerisset(tmp))
- return 1;
-
/* signals are racy */
sigprocmask(SIG_BLOCK, &STATE(block), NULL);
@@ -235,33 +226,26 @@
if (STATE(mode)->run)
STATE(mode)->run(&readfds);
- /* check if we have introduced any new alarms */
- if (*timeout == 0 && alarm_counter > 0) {
- *timeout = 1;
- if (!get_next_alarm_run(next_alarm))
- dlog(LOG_ERR, "Bug in alarm?");
- return 0;
- }
-
sigprocmask(SIG_UNBLOCK, &STATE(block), NULL);
-
- return 0;
}
void __attribute__((noreturn))
run(void)
{
- int timeout;
struct timeval next_alarm;
+ struct timeval *next;
/* initialization: get the next alarm available */
- timeout = get_next_alarm_run(&next_alarm);
+ next = get_next_alarm_run(&next_alarm);
while(1) {
- if (__run(&next_alarm, &timeout)) {
- sigprocmask(SIG_BLOCK, &STATE(block), NULL);
- timeout = do_alarm_run(&next_alarm);
- sigprocmask(SIG_UNBLOCK, &STATE(block), NULL);
- }
+ __run(next);
+
+ sigprocmask(SIG_BLOCK, &STATE(block), NULL);
+ if (next != NULL && !timerisset(next))
+ next = do_alarm_run(&next_alarm);
+ else
+ next = get_next_alarm_run(&next_alarm);
+ sigprocmask(SIG_UNBLOCK, &STATE(block), NULL);
}
}
More information about the netfilter-cvslog
mailing list