diff --git a/src/debug.c b/src/debug.c index 474a6647f..89c7a53de 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1384,7 +1384,27 @@ static int debug_iohandler_fd(struct appctx *appctx) S_ISLNK(statbuf.st_mode) ? "link": S_ISSOCK(statbuf.st_mode) ? "sock": #ifdef USE_EPOLL - epoll_wait(fd, NULL, 0, 0) != -1 || errno != EBADF ? "epol": + /* trick: epoll_ctl() will return -ENOENT when trying + * to remove from a valid epoll FD an FD that was not + * registered against it. But we don't want to risk + * disabling a random FD. Instead we'll create a new + * one by duplicating 0 (it should be valid since + * pointing to a terminal or /dev/null), and try to + * remove it. + */ + ({ + int fd2 = dup(0); + int ret = fd2; + if (ret >= 0) { + ret = epoll_ctl(fd, EPOLL_CTL_DEL, fd2, NULL); + if (ret == -1 && errno == ENOENT) + ret = 0; // that's a real epoll + else + ret = -1; // it's something else + close(fd2); + } + ret; + }) == 0 ? "epol" : #endif "????", (uint)statbuf.st_mode & 07777,