From bcddaa59a9050f3ae0e030f61ba4d965769103a2 Mon Sep 17 00:00:00 2001 From: yukangzhi Date: Thu, 10 Jul 2025 11:50:13 +0800 Subject: [PATCH] drivers/pipe: fix POLLHUP handling in poll() For POLICY_0, when a pipe only has a reader and no writer, if the pipe is empty, set POLLHUP. For POLICY_1, when a pipe only has a reader but no writer, if the pipe is empty, POLLHUP will not be set. This change corrects poll() behavior to match the two pipe policies. No API changes. Signed-off-by: yukangzhi --- drivers/pipes/pipe_common.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 3bdcef5ef16..810ead7f6e5 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -731,9 +731,13 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds, eventset |= POLLIN; } - /* Notify the POLLHUP event if the pipe is empty and no writers */ + /* Notify the POLLHUP event if the pipe is empty, + * while no writers and policy 0. + */ - if (nbytes == 0 && dev->d_nwriters <= 0) + if (nbytes == 0 && + dev->d_nwriters <= 0 && + PIPE_IS_POLICY_0(dev->d_flags)) { eventset |= POLLHUP; }