From b4b7e3fc0f2008967202f2453e9c33b378e7a000 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 6 Mar 2019 10:36:11 -0500 Subject: [PATCH] Add a safety timeout to epoll Add a safety timeout just in case something goes wrong with the use of timerfd. This way the process should't be stuck forever. Signed-off-by: Simo Sorce [rharwood@redhat.com: remove outdated comment] Reviewed-by: Robbie Harwood Merges: #241 (cherry picked from commit d55be9fa2455fe52b6eb904ad427f22141ab3f26) (cherry picked from commit a494f23b6d8d43fe1a824cd69c3dd93a18fc75a1) --- src/client/gpm_common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/client/gpm_common.c b/src/client/gpm_common.c index 36df5cc..808f350 100644 --- a/src/client/gpm_common.c +++ b/src/client/gpm_common.c @@ -14,6 +14,7 @@ #define FRAGMENT_BIT (1 << 31) #define RESPONSE_TIMEOUT 15 +#define SAFETY_TIMEOUT RESPONSE_TIMEOUT * 10 * 1000 #define MAX_TIMEOUT_RETRY 3 struct gpm_ctx { @@ -291,7 +292,7 @@ static int gpm_epoll_wait(struct gpm_ctx *gpmctx, uint32_t event_flags) } do { - epoll_ret = epoll_wait(gpmctx->epollfd, events, 2, -1); + epoll_ret = epoll_wait(gpmctx->epollfd, events, 2, SAFETY_TIMEOUT); } while (epoll_ret < 0 && errno == EINTR); if (epoll_ret < 0) { @@ -299,8 +300,6 @@ static int gpm_epoll_wait(struct gpm_ctx *gpmctx, uint32_t event_flags) ret = errno; gpm_epoll_close(gpmctx); } else if (epoll_ret == 0) { - /* Shouldn't happen as timeout == -1; treat it like a timeout - * occurred. */ ret = ETIMEDOUT; gpm_epoll_close(gpmctx); } else if (epoll_ret == 1 && events[0].data.fd == gpmctx->timerfd) {