Apply patch from Scott Lamb preventing an infinite loop when sending SIGALRM.

This commit is contained in:
Guus Sliepen 2007-02-14 09:20:20 +00:00
parent 16c8b0e5bb
commit 6c6535a416
3 changed files with 24 additions and 6 deletions

View file

@ -57,6 +57,28 @@ void exit_events(void)
avl_delete_tree(event_tree); 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) event_t *new_event(void)
{ {
cp(); cp();

View file

@ -38,6 +38,7 @@ typedef struct {
extern void init_events(void); extern void init_events(void);
extern void exit_events(void); extern void exit_events(void);
extern void flush_events(void);
extern event_t *new_event(void) __attribute__ ((__malloc__)); extern event_t *new_event(void) __attribute__ ((__malloc__));
extern void free_event(event_t *); extern void free_event(event_t *);
extern void event_add(event_t *); extern void event_add(event_t *);

View file

@ -429,12 +429,7 @@ int main_loop(void)
if(sigalrm) { if(sigalrm) {
logger(LOG_INFO, _("Flushing event queue")); logger(LOG_INFO, _("Flushing event queue"));
flush_events();
while(event_tree->head) {
event = event_tree->head->data;
event->handler(event->data);
event_del(event);
}
sigalrm = false; sigalrm = false;
} }