From 0f8b1ac5a638ed1b8d46d9317c29f9ce745074bc Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 3 Jun 2026 19:46:15 -0300 Subject: [PATCH] pipefs: change how HUP/ERR is handled --- kernel-src/fs/pipefs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel-src/fs/pipefs.c b/kernel-src/fs/pipefs.c index 64b9f6fe..8f6eb3cf 100644 --- a/kernel-src/fs/pipefs.c +++ b/kernel-src/fs/pipefs.c @@ -113,21 +113,21 @@ static int internalpoll(vnode_t *node, polldata_t *data, int events) { pipenode_t *pipenode = (pipenode_t *)node; int revents = 0; + if (pipenode->writers == 0 && pipenode->open) + revents |= POLLHUP; + + if (pipenode->readers == 0 && pipenode->open) + revents |= POLLHUP; + if (events & POLLIN) { - events |= POLLHUP; - if (pipenode->writers == 0 && pipenode->open) - revents |= POLLHUP; if (RINGBUFFER_DATACOUNT(&pipenode->data) > 0) revents |= POLLIN; } if (events & POLLOUT) { - events |= POLLERR; - if (pipenode->readers == 0 && pipenode->open) - revents |= POLLERR; // poll will only return POLLOUT if an atomic write can be done without blocking // this is undocumented in POSIX but many unices implement it like this - else if (RINGBUFFER_DATACOUNT(&pipenode->data) < BUFFER_SIZE - PIPE_ATOMIC_SIZE) + if (RINGBUFFER_DATACOUNT(&pipenode->data) < BUFFER_SIZE - PIPE_ATOMIC_SIZE) revents |= POLLOUT; } @@ -231,7 +231,7 @@ int pipefs_write(vnode_t *node, iovec_iterator_t *iovec_iterator, size_t size, u while (1) { // check for space or if the read end has been closed int revents = internalpoll(node, NULL, POLLOUT); - if (revents & POLLERR) + if (revents & (POLLERR | POLLHUP)) break; size_t freebytes = RINGBUFFER_FREESPACE(&pipenode->data);