casaroli opened a new pull request, #21018:
URL: https://github.com/apache/nuttx/pull/21018

   ## Summary
   
   When the last reference to a PTY master closes, the slave sees a hang-up. A 
read on the slave already returns 0 (end of file), and poll() reports POLLHUP. 
A write on the slave returned EPIPE from the internal pipe. POSIX (XBD 11.1.10, 
Modem Disconnect) wants EIO for a write to a terminal after a hang-up, and 
Linux also returns EIO.
   
   This PR returns -EIO instead of -EPIPE from a write on the slave after the 
master is closed. A read still returns 0, as POSIX says for a read after a 
modem disconnect.
   
   ## Impact
   
   Only a write on a PTY slave after its master is closed: errno is EIO, not 
EPIPE. Flat, protected and kernel builds use the same code. Other writes do not 
change.
   
   ## Testing
   
   Test program `ptyhup.c` with `CONFIG_PSEUDOTERM` and 
`CONFIG_PSEUDOTERM_SUSV1`: it opens `/dev/ptmx` and the slave, closes the 
master, and checks poll(), read() and write() on the slave, and a read() that 
is blocked in another thread.
   
   | | master | this PR |
   |---|---|---|
   | poll(POLLIN) on the slave | POLLHUP | POLLHUP |
   | read() on the slave | 0 | 0 |
   | read() blocked in another thread | wakes up with 0 | wakes up with 0 |
   | write() on the slave | -1, EPIPE: FAIL | -1, EIO: PASS |
   
   The same results on qemu-armv8a:knsh (kernel, test program as an ELF file) 
and qemu-armv8a:nsh (flat, test program built in), both under QEMU with HVF. 
ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh.
   
   Build with `CONFIG_PSEUDOTERM` and `CONFIG_PSEUDOTERM_SUSV1`, each OK: 
qemu-armv8a:nsh (flat, arm64), qemu-armv8a:knsh (kernel, arm64), rv-virt:nsh64 
(flat, rv64), rv-virt:pnsh64 (protected, rv64), rv-virt:knsh64 (kernel, rv64).
   
   `tools/checkpatch.sh -c -u -m -g` passes. No documentation change: the 
documentation does not describe the error codes of a PTY.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to