From 056c9f7fffdcc48e2fffd9faf8856f3014c7b703 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 27 Jul 2026 18:18:13 +0000 Subject: [PATCH] epollfd_ctx: engage poll fallback when Darwin kevent rejects an fd with EINVAL Old Darwin kqueues (up to ~10.8) reject EVFILT_READ/EVFILT_WRITE on pty masters and various other character devices with EINVAL, whereas the poll-only-fd fallback (NODE_TYPE_POLL) only engaged on ENODEV, the errno FreeBSD uses for this. The EINVAL surfaced as an epoll_ctl failure, so terminal emulators could not monitor their ptmx: foot on Mac OS X 10.6/PPC opened its window but never processed any pty output (fdm.c: 'failed to register FD=7 with epoll: Invalid argument'). Accept an in-band EINVAL for NODE_TYPE_OTHER fds on Apple as 'this device only supports poll', engaging the existing fallback. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01Kvag8nXEuGz9XJL3WdSxKC --- src/epollfd_ctx.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/epollfd_ctx.c b/src/epollfd_ctx.c index 08836a4..b4c5a05 100644 --- a/src/epollfd_ctx.c +++ b/src/epollfd_ctx.c @@ -994,7 +994,19 @@ epollfd_ctx__register_events(EpollFDCtx *epollfd, int kq, /* Check for fds that only support poll. */ if (((fd2_node->node_type == NODE_TYPE_OTHER && - kev[0].data == ENODEV) || + (kev[0].data == ENODEV +#ifdef __APPLE__ + /* + * Old Darwin kqueues (up to ~10.8) reject pty + * masters and various other character devices + * with EINVAL rather than ENODEV. Without this, + * terminal emulators cannot monitor their ptmx: + * epoll_ctl fails and input/output is never + * processed. + */ + || kev[0].data == EINVAL +#endif + )) || fd2_node->node_type == NODE_TYPE_POLL)) { assert((fd2_node->events & /**/ -- 2.43.0