This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 49ac098eeb2 drivers/serial/pty: Return EIO from a slave write after a 
hang-up.
49ac098eeb2 is described below

commit 49ac098eeb254989aa01f989370520c61159f03b
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 20 17:01:27 2026 +0200

    drivers/serial/pty: Return EIO from a slave write after a hang-up.
    
    When the master of a PTY is closed, the slave sees a hang-up.  A read
    on the slave already returns 0 and poll() reports POLLHUP, but a write
    returned EPIPE from the internal pipe.  POSIX wants EIO for a write to a
    terminal after a modem disconnect (XBD 11.1.10), and Linux also
    returns EIO.
    
    Return -EIO instead of -EPIPE from a write on the slave.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 drivers/serial/pty.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index 636b30678b1..c8e372dc36a 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -717,6 +717,13 @@ static ssize_t pty_write(FAR struct file *filep,
       ntotal = file_write(&dev->pd_sink, buffer, len);
     }
 
+  /* The master is closed: POSIX wants EIO after a hang-up, not EPIPE */
+
+  if (ntotal == -EPIPE && !dev->pd_master)
+    {
+      ntotal = -EIO;
+    }
+
   return ntotal;
 }
 

Reply via email to