summaryrefslogtreecommitdiff
path: root/src
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-14 16:56:58 +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-14 16:56:58 +0000
commita3f3fce1466938522e3ab8a722486ccf20333aa5 (patch)
treeb122478b45d3499c7c56d5f378675349a2e46815 /src
parent6e5b6c91625fd431ac3d1339f55a4aa278ff2604 (diff)
downloadconntrack-tools-a3f3fce1466938522e3ab8a722486ccf20333aa5.tar.gz
conntrack-tools-a3f3fce1466938522e3ab8a722486ccf20333aa5.zip
make sure add_alarm() and mod_alarm() insert sorted by due time
Diffstat (limited to 'src')
-rw-r--r--src/alarm.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/alarm.c b/src/alarm.c
index eb2226b..6aac4a3 100644
--- a/src/alarm.c
+++ b/src/alarm.c
@@ -46,13 +46,29 @@ void init_alarm(struct alarm_list *t)
t->function = NULL;
}
+void __add_alarm(struct alarm_list *alarm)
+{
+ struct list_head *i;
+ struct alarm_list *t;
+
+ list_for_each(i, &alarm_list) {
+ t = (struct alarm_list *) i;
+
+ if (timercmp(&alarm->tv, &t->tv, <)) {
+ list_add_tail(&alarm->head, &t->head);
+ return;
+ }
+ }
+ list_add_tail(&alarm->head, &alarm_list);
+}
+
void add_alarm(struct alarm_list *alarm)
{
struct timeval tv;
gettimeofday(&tv, NULL);
alarm->tv.tv_sec += tv.tv_sec;
- list_add_tail(&alarm->head, &alarm_list);
+ __add_alarm(alarm);
}
void del_alarm(struct alarm_list *alarm)
@@ -68,7 +84,7 @@ void mod_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc)
gettimeofday(&tv, NULL);
alarm->tv.tv_sec = tv.tv_sec + sc;
alarm->tv.tv_usec = tv.tv_usec + usc;
- list_add_tail(&alarm->head, &alarm_list);
+ __add_alarm(alarm);
}
int get_next_alarm(struct timeval *tv, struct timeval *next_alarm)