From 4b70e201af5bcc4926ab9b877592ba210b32ccdc Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 31 Dec 2016 18:36:47 +0100 Subject: [PATCH] lib: Fixed blocker iteration bug in mtio-select introduced by mblock. --- lib/mtio-select.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/mtio-select.c b/lib/mtio-select.c index 6e9a767..e0a4177 100644 --- a/lib/mtio-select.c +++ b/lib/mtio-select.c @@ -36,12 +36,17 @@ static int exitstatus; struct blocker { struct blocker *n, *p; + struct iterator *it; int fd; int ev, rev, id; time_t to; struct muth *th; }; +struct iterator { + struct blocker *bl; +}; + static void addblock(struct blocker *bl) { bl->n = blockers; @@ -58,6 +63,11 @@ static void remblock(struct blocker *bl) bl->p->n = bl->n; if(bl == blockers) blockers = bl->n; + if(bl->it) { + if((bl->it->bl = bl->n) != NULL) + bl->it->bl->it = bl->it; + bl->it = NULL; + } } struct selected mblock(time_t to, int n, struct selected *spec) @@ -111,7 +121,8 @@ int ioloop(void) { int ret; fd_set rfds, wfds, efds; - struct blocker *bl, *nbl; + struct blocker *bl; + struct iterator it; struct timeval toval; time_t now, timeout; int maxfd; @@ -150,8 +161,9 @@ int ioloop(void) } } else { now = time(NULL); - for(bl = blockers; bl; bl = nbl) { - nbl = bl->n; + for(bl = it.bl = blockers; bl; bl = it.bl) { + if((it.bl = bl->n) != NULL) + it.bl->it = ⁢ ev = 0; if(FD_ISSET(bl->fd, &rfds)) ev |= EV_READ; @@ -174,6 +186,8 @@ int ioloop(void) resume(bl->th, bl->id); } } + if(it.bl) + it.bl->it = NULL; } } } -- 2.11.0