Skip to content

Commit 0444dbf

Browse files
arch/sim: set stdin/stdout nonblocking in host_uart_start()
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 both stdin and stdout to nonblocking via ioctl(FIONBIO) so that read()/write() return 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: chenzihan1 <chenzihan1@xiaomi.com> Signed-off-by: ligd <liguangdi1@xiaomi.com> Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent b939b11 commit 0444dbf

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <sys/ioctl.h>
2828
#include <fcntl.h>
29+
#include <sys/ioctl.h>
2930
#include <stdbool.h>
3031
#include <unistd.h>
3132
#include <string.h>
@@ -95,6 +96,8 @@ static void restoremode(void)
9596

9697
void host_uart_start(void)
9798
{
99+
int nonblock = 1;
100+
98101
/* Get the current stdin terminal mode */
99102

100103
tcgetattr(0, &g_cooked);
@@ -103,6 +106,14 @@ void host_uart_start(void)
103106

104107
setrawmode(0);
105108

109+
host_uninterruptible_no_return(ioctl, 0, FIONBIO, &nonblock);
110+
111+
/* Set stdout to non-blocking to prevent write(1, ...) from blocking
112+
* the entire sim process when the host pipe buffer is full.
113+
*/
114+
115+
host_uninterruptible_no_return(ioctl, 1, FIONBIO, &nonblock);
116+
106117
/* Restore the original terminal mode before exit */
107118

108119
atexit(restoremode);

0 commit comments

Comments
 (0)