From b4c5fb93b72babc50c85dda6c0263c51d66f96ae Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 17 Jun 2008 09:37:44 +0000 Subject: [PATCH] Fix broken logic in the poll-fd compaction function, which resulted in a panic during this sequence: varnishd -d -d -T :8082 ctrl-D telnet localhost 8082 (from other terminal) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2722 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/mgt_event.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/varnish-cache/bin/varnishd/mgt_event.c b/varnish-cache/bin/varnishd/mgt_event.c index 07fe32d3..6577e639 100644 --- a/varnish-cache/bin/varnishd/mgt_event.c +++ b/varnish-cache/bin/varnishd/mgt_event.c @@ -373,23 +373,26 @@ ev_compact_pfd(struct evbase *evb) unsigned u; struct pollfd *p; struct ev *ep; + int lfd; + DBG(evb, "compact_pfd() lpfd = %d\n", evb->lpfd); p = evb->pfd; - ep = VTAILQ_FIRST(&evb->events); for (u = 0; u < evb->lpfd; u++, p++) { + DBG(evb, "...[%d] fd = %d\n", u, p->fd); if (p->fd >= 0) continue; - for(; ep != NULL; ep = VTAILQ_NEXT(ep, __list)) { - if (ep->fd >= 0 && ep->__poll_idx > u) + lfd = evb->pfd[evb->lpfd - 1].fd; + VTAILQ_FOREACH(ep, &evb->events, __list) + if (ep->fd == lfd) break; - } - if (ep == NULL) - break; - *p = evb->pfd[ep->__poll_idx]; + AN(ep); + DBG(evb, "...[%d] move %p pidx %d\n", u, ep, ep->__poll_idx); + *p = evb->pfd[--evb->lpfd]; ep->__poll_idx = u; } evb->lpfd = u; evb->compact_pfd = 0; + DBG(evb, "... lpfd = %d\n", evb->lpfd); } /*--------------------------------------------------------------------*/ -- 2.39.5