From ab1bb94805916f1d4141956713919071e787f648 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Mon, 9 Feb 2026 22:01:09 -0300 Subject: [PATCH] user: add isatty smoke test via TCGETS --- user/init.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/user/init.c b/user/init.c index 1288879..277faab 100644 --- a/user/init.c +++ b/user/init.c @@ -76,6 +76,10 @@ enum { TIOCSPGRP = 0x5410, }; +enum { + ENOTTY = 25, +}; + enum { ICANON = 0x0001, ECHO = 0x0002, @@ -140,6 +144,17 @@ static int sys_write(int fd, const void* buf, uint32_t len) { return __syscall_fix(ret); } +static int sys_ioctl(int fd, uint32_t cmd, void* arg); + +static int isatty_fd(int fd) { + struct termios t; + if (sys_ioctl(fd, TCGETS, &t) < 0) { + if (errno == ENOTTY) return 0; + return -1; + } + return 1; +} + static int sys_getdents(int fd, void* buf, uint32_t len) { int ret; __asm__ volatile( @@ -1663,6 +1678,39 @@ void _start(void) { (uint32_t)(sizeof("[init] diskfs getdents OK\n") - 1)); } + // B5: isatty() POSIX-like smoke (via ioctl TCGETS) + { + int fd = sys_open("/dev/tty", 0); + if (fd < 0) { + sys_write(1, "[init] isatty open /dev/tty failed\n", + (uint32_t)(sizeof("[init] isatty open /dev/tty failed\n") - 1)); + sys_exit(1); + } + int r = isatty_fd(fd); + (void)sys_close(fd); + if (r != 1) { + sys_write(1, "[init] isatty(/dev/tty) failed\n", + (uint32_t)(sizeof("[init] isatty(/dev/tty) failed\n") - 1)); + sys_exit(1); + } + + fd = sys_open("/dev/null", 0); + if (fd < 0) { + sys_write(1, "[init] isatty open /dev/null failed\n", + (uint32_t)(sizeof("[init] isatty open /dev/null failed\n") - 1)); + sys_exit(1); + } + r = isatty_fd(fd); + (void)sys_close(fd); + if (r != 0) { + sys_write(1, "[init] isatty(/dev/null) expected 0\n", + (uint32_t)(sizeof("[init] isatty(/dev/null) expected 0\n") - 1)); + sys_exit(1); + } + + sys_write(1, "[init] isatty OK\n", (uint32_t)(sizeof("[init] isatty OK\n") - 1)); + } + enum { NCHILD = 100 }; int children[NCHILD]; for (int i = 0; i < NCHILD; i++) { -- 2.43.0