From 118ceb1a075c39441c6a31de352cbf0dd07e2aeb Mon Sep 17 00:00:00 2001 From: bernard Date: Sun, 18 Oct 2026 19:33:57 +0800 Subject: [PATCH 1/2] [components][lwp] handle TIOCLINUX and default window size - return zero keyboard modifiers for TIOCLINUX instead of failing - keep terminal applications that probe console state working - initialize the TTY window size to 24x80 when none is reported --- components/lwp/terminal/freebsd/tty_compat.c | 14 ++++++++++++-- components/lwp/terminal/tty_device.c | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/lwp/terminal/freebsd/tty_compat.c b/components/lwp/terminal/freebsd/tty_compat.c index 08ff49f8017e..c89da7a31577 100644 --- a/components/lwp/terminal/freebsd/tty_compat.c +++ b/components/lwp/terminal/freebsd/tty_compat.c @@ -547,9 +547,19 @@ int lwp_tty_ioctl_adapter(lwp_tty_t tp, int cmd, int oflags, void *args, rt_thre error = (IOCTL(FIONREAD, args, fflags, td)); break; -#ifdef USING_BSD_IOCTL_EXT - /* TIOCLINUX */ + case TIOCLINUX: { + /* + * Linux uses TIOCLINUX to obtain console keyboard modifier + * state. RT-Thread serial consoles do not expose that state, + * but applications such as mc only need this ioctl to be + * harmless when it is unavailable. + */ + unsigned char modifiers = 0; + error = _copy_to_user(args, &modifiers, sizeof(modifiers)); + break; + } +#ifdef USING_BSD_IOCTL_EXT case TIOCCONS: args->cmd = TIOCCONS; error = (sys_ioctl(td, (struct ioctl_args *)args)); diff --git a/components/lwp/terminal/tty_device.c b/components/lwp/terminal/tty_device.c index 17364fabc108..b4b36372508a 100644 --- a/components/lwp/terminal/tty_device.c +++ b/components/lwp/terminal/tty_device.c @@ -347,6 +347,10 @@ static void tty_init_termios(lwp_tty_t tp) t->__c_ispeed = TTYDEF_SPEED; t->__c_ospeed = TTYDEF_SPEED; + /* Keep terminal consumers usable when the host cannot report a size. */ + tp->t_winsize.ws_row = 24; + tp->t_winsize.ws_col = 80; + memcpy(&t->c_cc, tty_ctrl_charset, sizeof(tty_ctrl_charset) / sizeof(tty_ctrl_charset[0])); From ad944025a8e0dd03b9bfe1cee7e04bb2576234f4 Mon Sep 17 00:00:00 2001 From: bernard Date: Sun, 18 Oct 2026 20:41:46 +0800 Subject: [PATCH 2/2] [components][lwp] fix TTY init format and control character copy - place the TIOCLINUX case brace on its own line - use sizeof(tty_ctrl_charset) directly as the memcpy size - fix the cppcheck sizeofDivisionMemfunc warning --- components/lwp/terminal/freebsd/tty_compat.c | 3 ++- components/lwp/terminal/tty_device.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/lwp/terminal/freebsd/tty_compat.c b/components/lwp/terminal/freebsd/tty_compat.c index c89da7a31577..338489d54905 100644 --- a/components/lwp/terminal/freebsd/tty_compat.c +++ b/components/lwp/terminal/freebsd/tty_compat.c @@ -547,7 +547,8 @@ int lwp_tty_ioctl_adapter(lwp_tty_t tp, int cmd, int oflags, void *args, rt_thre error = (IOCTL(FIONREAD, args, fflags, td)); break; - case TIOCLINUX: { + case TIOCLINUX: + { /* * Linux uses TIOCLINUX to obtain console keyboard modifier * state. RT-Thread serial consoles do not expose that state, diff --git a/components/lwp/terminal/tty_device.c b/components/lwp/terminal/tty_device.c index b4b36372508a..a2936a0d1b51 100644 --- a/components/lwp/terminal/tty_device.c +++ b/components/lwp/terminal/tty_device.c @@ -351,8 +351,7 @@ static void tty_init_termios(lwp_tty_t tp) tp->t_winsize.ws_row = 24; tp->t_winsize.ws_col = 80; - memcpy(&t->c_cc, tty_ctrl_charset, - sizeof(tty_ctrl_charset) / sizeof(tty_ctrl_charset[0])); + memcpy(&t->c_cc, tty_ctrl_charset, sizeof(tty_ctrl_charset)); #ifdef USING_BSD_INIT_LOCK_DEVICE tp->t_termios_init_out = *t;