From 3a379757b64bdb26f7ad72a0f4d121e2eb22b77e Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sun, 3 May 2009 14:37:20 +0200 Subject: [PATCH] lib update --- daemon/event.c | 15 +++++++++++++-- daemon/event.h | 1 + daemon/logging.c | 9 +++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/daemon/event.c b/daemon/event.c index 2f255c7..935a331 100644 --- a/daemon/event.c +++ b/daemon/event.c @@ -30,6 +30,7 @@ static LIST_HEAD(event_fd_list); static LIST_HEAD(event_timeout_list); +static int leave_loop; struct event_fd { struct list_head list; @@ -198,6 +199,11 @@ void event_remove_timeout(struct event_timeout *entry) entry->flags |= EVENT_DELETE; } +void event_loop_break(void) +{ + leave_loop = 1; +} + int event_loop(void) { fd_set *fdsets = malloc(sizeof(fd_set) * 2); @@ -206,7 +212,8 @@ int event_loop(void) return -1; } - while (1) { + leave_loop = 0; + while (!leave_loop) { struct timeval timeout, *timeout_p = NULL; if (!list_empty(&event_timeout_list)) { struct timeval now; @@ -247,6 +254,7 @@ int event_loop(void) fd_set *readfds = NULL, *writefds = NULL; struct event_fd *entry, *tmp; + int maxfd = -1; list_for_each_entry_safe(entry, tmp, &event_fd_list, list) { entry->flags &= ~EVENT_NEW; @@ -272,9 +280,11 @@ int event_loop(void) } FD_SET(entry->fd, writefds); } + + maxfd = (entry->fd > maxfd) ? entry->fd : maxfd; } - int i = select(FD_SETSIZE, readfds, writefds, NULL, timeout_p); + int i = select(maxfd +1, readfds, writefds, NULL, timeout_p); if (i <= 0) { /* On error, -1 is returned, and errno is set * appropriately; the sets and timeout become @@ -295,4 +305,5 @@ int event_loop(void) } } free(fdsets); + return 0; } diff --git a/daemon/event.h b/daemon/event.h index 05ae63f..0413b86 100644 --- a/daemon/event.h +++ b/daemon/event.h @@ -37,6 +37,7 @@ struct event_timeout * event_add_timeout( void event_remove_timeout(struct event_timeout *entry); +void event_loop_break(void); int event_loop(void); #endif /* _EVENT_H_ */ diff --git a/daemon/logging.c b/daemon/logging.c index 7d7bb14..ddc1128 100644 --- a/daemon/logging.c +++ b/daemon/logging.c @@ -77,11 +77,15 @@ int log_print(int prio, const char *fmt, ...) void log_close(void) { - if (buffer) + if (buffer) { free(buffer); + buffer = NULL; + } - if (log_fd) + if (log_fd) { fclose(log_fd); + log_fd = NULL; + } } int log_init(const char *logfile) @@ -100,6 +104,7 @@ int log_init(const char *logfile) return -1; } + log_prio = LOG_EVERYTIME; return 0; }