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

xiaoxiang781216 pushed a commit to branch releases/13.1
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 7ea91ae63b95086b5788631226a50f4f93207cfb
Author: ligd <[email protected]>
AuthorDate: Sat Feb 28 12:11:14 2026 +0800

    sim/hostuart: set stdout to O_NONBLOCK to prevent blocking
    
    When NuttX sim is connected via pipe (e.g. by an automation tool),
    if the host side does not read stdout in time, the pipe buffer fills
    up and write(1, ...) blocks the entire sim process. This happens
    inside host_uninterruptible (irq disabled), so the NuttX scheduler
    is completely frozen and all threads stop.
    
    Set fd=1 (stdout) to O_NONBLOCK so that write() returns EAGAIN
    instead of blocking. The TX data stays in the NuttX xmit buffer
    and sim_tty_work retries every 1ms until the pipe has space.
    
    Signed-off-by: ligd <[email protected]>
---
 arch/sim/src/sim/posix/sim_hostuart.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/sim/src/sim/posix/sim_hostuart.c 
b/arch/sim/src/sim/posix/sim_hostuart.c
index 4976aadd902..d158e9f794c 100644
--- a/arch/sim/src/sim/posix/sim_hostuart.c
+++ b/arch/sim/src/sim/posix/sim_hostuart.c
@@ -111,6 +111,16 @@ void host_uart_start(void)
       host_uninterruptible_no_return(fcntl, 0, F_SETFL, flags | O_NONBLOCK);
     }
 
+  /* Set stdout to non-blocking to prevent write(1, ...) from blocking
+   * the entire sim process when the host pipe buffer is full.
+   */
+
+  flags = host_uninterruptible(fcntl, 1, F_GETFL, 0);
+  if (flags > 0)
+    {
+      host_uninterruptible_no_return(fcntl, 1, F_SETFL, flags | O_NONBLOCK);
+    }
+
   /* Restore the original terminal mode before exit */
 
   atexit(restoremode);

Reply via email to