From 5c556ef4cfa578acf3c61aac1b24226cad1e21ef Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 10 Jan 2019 08:41:23 -0500 Subject: [PATCH] don't abort on failed EPOLL_CTL_MOD EPOLL_CTL_MOD is used to monitor an fd's writeable status when write was blocked, but due to a race condition it's possible that the same fd gets closed by another thread at the same time, causing the EPOLL_CTL_MOD to fail. As this is now expected, handle it appropriately. fixes #684 Change-Id: I1ddf16fdbf0fe3e98b4d908544735b823c4cf539 --- daemon/poller.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/daemon/poller.c b/daemon/poller.c index 7a5455923..2aeac20b6 100644 --- a/daemon/poller.c +++ b/daemon/poller.c @@ -340,12 +340,11 @@ int poller_poll(struct poller *p, int timeout) { ZERO(e); e.events = epoll_events(NULL, it); e.data.fd = it->item.fd; - if (epoll_ctl(p->fd, EPOLL_CTL_MOD, it->item.fd, &e)) - abort(); + int ret = epoll_ctl(p->fd, EPOLL_CTL_MOD, it->item.fd, &e); mutex_unlock(&p->lock); - if (it->item.writeable) + if (ret == 0 && it->item.writeable) it->item.writeable(it->item.fd, it->item.obj, it->item.uintp); } else if ((ev->events & POLLIN)) @@ -387,8 +386,7 @@ void poller_blocked(struct poller *p, int fd) { ZERO(e); e.events = epoll_events(NULL, p->items[fd]); e.data.fd = fd; - if (epoll_ctl(p->fd, EPOLL_CTL_MOD, fd, &e)) - abort(); + epoll_ctl(p->fd, EPOLL_CTL_MOD, fd, &e); fail: mutex_unlock(&p->lock);