Apply patch from Scott Lamb preventing an infinite loop when sending SIGALRM.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 14 Feb 2007 09:20:20 +0000 (09:20 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 14 Feb 2007 09:20:20 +0000 (09:20 +0000)
src/event.c
src/event.h
src/net.c

index e7fbb882c1cb9a42d426edfff48a9603181f2207..c791205f477d2bcda0c8ed50c03b53e631fc57ea 100644 (file)
@@ -57,6 +57,28 @@ void exit_events(void)
        avl_delete_tree(event_tree);
 }
 
+void flush_events(void)
+{
+       avl_tree_t *to_flush;
+       event_t *event;
+
+       /*
+        * Events can be inserted from event handlers, so only flush events
+        * already in the priority queue.
+        */
+
+       cp();
+
+       to_flush = event_tree;
+       init_events();
+       while (to_flush->head) {
+               event = to_flush->head->data;
+               event->handler(event->data);
+               avl_delete(to_flush, event);
+       }
+       avl_delete_tree(to_flush);
+}
+
 event_t *new_event(void)
 {
        cp();
index 275bed52498733024e2df6ec4543e21ef21e1e89..50e5b972572f0523e99c37fa6753a964cb127842 100644 (file)
@@ -38,6 +38,7 @@ typedef struct {
 
 extern void init_events(void);
 extern void exit_events(void);
+extern void flush_events(void);
 extern event_t *new_event(void) __attribute__ ((__malloc__));
 extern void free_event(event_t *);
 extern void event_add(event_t *);
index 31f1b0e4ca0f07d03585af74d1231b62331b91dd..f6b14704607477544b6a34f54cf2144096fe2548 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -429,12 +429,7 @@ int main_loop(void)
 
                if(sigalrm) {
                        logger(LOG_INFO, _("Flushing event queue"));
-
-                       while(event_tree->head) {
-                               event = event_tree->head->data;
-                               event->handler(event->data);
-                               event_del(event);
-                       }
+                       flush_events();
                        sigalrm = false;
                }