Skip to content

Commit ae66695

Browse files
GUIDINGLIacassis
authored andcommitted
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 <liguangdi1@xiaomi.com>
1 parent 60ac52c commit ae66695

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

arch/sim/src/sim/posix/sim_hostuart.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ void host_uart_start(void)
111111
host_uninterruptible_no_return(fcntl, 0, F_SETFL, flags | O_NONBLOCK);
112112
}
113113

114+
/* Set stdout to non-blocking to prevent write(1, ...) from blocking
115+
* the entire sim process when the host pipe buffer is full.
116+
*/
117+
118+
flags = host_uninterruptible(fcntl, 1, F_GETFL, 0);
119+
if (flags > 0)
120+
{
121+
host_uninterruptible_no_return(fcntl, 1, F_SETFL, flags | O_NONBLOCK);
122+
}
123+
114124
/* Restore the original terminal mode before exit */
115125

116126
atexit(restoremode);

0 commit comments

Comments
 (0)