From 615a83daf53b39f998d141fdcc1871d58f994724 Mon Sep 17 00:00:00 2001 From: guoshichao Date: Sun, 27 Apr 2025 11:24:30 +0800 Subject: [PATCH 1/8] ostest: disable the signal test when CONFIG_DISABLE_SIGNAL is enabld 1. sigprocmask_test/sighand_test/signest_test/suspend_test: these testcases are using to test the signal api 2. sigev_thread_test: this testcase need to access signal related function 3. timer_test: this testcase need to access signal related function Signed-off-by: guoshichao --- testing/ostest/ostest_main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/testing/ostest/ostest_main.c b/testing/ostest/ostest_main.c index 201d52e389f..ca9dda828dc 100644 --- a/testing/ostest/ostest_main.c +++ b/testing/ostest/ostest_main.c @@ -278,7 +278,8 @@ static int user_main(int argc, char *argv[]) * verify that status is retained correctly. */ -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) && \ + !defined(CONFIG_DISABLE_SIGNALS) { struct sigaction sa; int ret; @@ -511,6 +512,7 @@ static int user_main(int argc, char *argv[]) check_test_memory_usage(); #endif +#ifndef CONFIG_DISABLE_SIGNALS /* Verify that we can modify the signal mask */ printf("\nuser_main: sigprocmask test\n"); @@ -534,6 +536,8 @@ static int user_main(int argc, char *argv[]) check_test_memory_usage(); #endif +#endif /* !CONFIG_DISABLE_SIGNALS */ + #ifdef CONFIG_BUILD_FLAT printf("\nuser_main: wdog test\n"); wdog_test(); @@ -541,11 +545,13 @@ static int user_main(int argc, char *argv[]) #endif #ifndef CONFIG_DISABLE_POSIX_TIMERS +#ifndef CONFIG_DISABLE_SIGNALS /* Verify posix timers (with SIGEV_SIGNAL) */ printf("\nuser_main: POSIX timer test\n"); timer_test(); check_test_memory_usage(); +#endif #ifdef CONFIG_SIG_EVTHREAD /* Verify posix timers (with SIGEV_THREAD) */ @@ -705,7 +711,7 @@ int main(int argc, FAR char **argv) stdio_test(); #ifdef SDCC - /* I am not yet certain why SDCC does not like the following initilizers. + /* I am not yet certain why SDCC does not like the following initializers. * It involves some issues with 2- vs 3-byte pointer types. */ From 9b75138fbf109df9e9af9c0837a3589e9188e40a Mon Sep 17 00:00:00 2001 From: guoshichao Date: Fri, 30 May 2025 17:34:53 +0800 Subject: [PATCH 2/8] nsh/tools: add support for DISABLE_SIGNALS make the nsh tools can work with SIGNAL disabled Signed-off-by: guoshichao --- nshlib/nsh_builtin.c | 23 +++++++++++++++++------ nshlib/nsh_proccmds.c | 9 ++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c index 196220f41fa..bacf8ea6ada 100644 --- a/nshlib/nsh_builtin.c +++ b/nshlib/nsh_builtin.c @@ -74,10 +74,14 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, FAR char **argv, FAR const struct nsh_param_s *param) { -#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) +#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) && \ + !defined(CONFIG_DISABLE_SIGNALS) struct sigaction act; struct sigaction old; -#endif +#endif /* !CONFIG_NSH_DISABLEBG && CONFIG_SCHED_CHILD_STATUS && + * !CONFIG_DISABLE_SIGNALS + */ + int ret = OK; /* Lock the scheduler in an attempt to prevent the application from @@ -86,7 +90,8 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, sched_lock(); -#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) +#if !defined(CONFIG_NSH_DISABLEBG) && \ + defined(CONFIG_SCHED_CHILD_STATUS) && !defined(CONFIG_DISABLE_SIGNALS) /* Ignore the child status if run the application on background. */ if (vtbl->np.np_bg == true) @@ -98,7 +103,9 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, sigaction(SIGCHLD, &act, &old); } -#endif /* CONFIG_NSH_DISABLEBG */ +#endif /* !CONFIG_NSH_DISABLEBG && !CONFIG_SCHED_CHILD_STATUS && + * !CONFIG_DISABLE_SIGNALS + */ /* Try to find and execute the command within the list of builtin * applications. @@ -230,7 +237,8 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, #if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG) { -#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) +#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) && \ + !defined(CONFIG_DISABLE_SIGNALS) /* Restore the old actions */ @@ -241,7 +249,10 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, sigaction(SIGCHLD, &old, NULL); } -# endif +# endif /* !CONFIG_NSH_DISABLEBG && CONFIG_SCHED_CHILD_STATUS && \ + * !CONFIG_DISABLE_SIGNALS + */ + struct sched_param sched; sched_getparam(ret, &sched); nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, sched.sched_priority); diff --git a/nshlib/nsh_proccmds.c b/nshlib/nsh_proccmds.c index fe98105648c..cf067d0d76a 100644 --- a/nshlib/nsh_proccmds.c +++ b/nshlib/nsh_proccmds.c @@ -873,6 +873,7 @@ static int top_cmpcpuload(FAR const void *item1, FAR const void *item2) } } +#ifndef CONFIG_DISABLE_SIGNALS /**************************************************************************** * Name: top_exit ****************************************************************************/ @@ -882,7 +883,9 @@ static void top_exit(int signo, FAR siginfo_t *siginfo, FAR void *context) *(FAR bool *)siginfo->si_user = true; } -#endif +#endif /* !CONFIG_DISABLE_SIGNALS */ + +#endif /* !CONFIG_NSH_DISABLE_TOP && NSH_HAVE_CPULOAD */ /**************************************************************************** * Public Functions @@ -1357,7 +1360,9 @@ int cmd_top(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) FAR char *pidlist = NULL; size_t num = SIZE_MAX; size_t i; +#ifndef CONFIG_DISABLE_SIGNALS struct sigaction act; +#endif bool quit = false; int delay = 3; int ret = 0; @@ -1393,6 +1398,7 @@ int cmd_top(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) } } +#ifndef CONFIG_DISABLE_SIGNALS act.sa_user = &quit; act.sa_sigaction = top_exit; sigemptyset(&act.sa_mask); @@ -1402,6 +1408,7 @@ int cmd_top(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) nsh_error(vtbl, g_fmtcmdfailed, "top", "sigaction", NSH_ERRNO); return ERROR; } +#endif if (vtbl->isctty) { From 21eba6b38b9b185a3648efbcc5c8bf74b4115527 Mon Sep 17 00:00:00 2001 From: guoshichao Date: Thu, 25 Sep 2025 16:13:43 +0800 Subject: [PATCH 3/8] netutils: make the net tools can work with signal disabled using pthread_cancel to implement the exit logic, thus to make the netutils tools can work when signal disabled Signed-off-by: guoshichao --- netutils/dhcpc/dhcpc.c | 16 ++++++++++++++++ netutils/ping/icmp_ping.c | 4 ++++ netutils/telnetd/telnetd_daemon.c | 6 +++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c index dc6b46230b3..80a12e7ffc8 100644 --- a/netutils/dhcpc/dhcpc.c +++ b/netutils/dhcpc/dhcpc.c @@ -533,8 +533,16 @@ static void *dhcpc_run(void *args) struct dhcpc_state result; int ret; +#ifdef CONFIG_DISABLE_SIGNALS + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); +#endif + while (1) { +#ifdef CONFIG_DISABLE_SIGNALS + pthread_testcancel(); +#endif ret = dhcpc_request(pdhcpc, &result); if (ret == OK) { @@ -701,7 +709,9 @@ void dhcpc_close(FAR void *handle) void dhcpc_cancel(FAR void *handle) { struct dhcpc_state_s *pdhcpc = (struct dhcpc_state_s *)handle; +#ifndef CONFIG_DISABLE_SIGNALS sighandler_t old; +#endif int ret; if (pdhcpc) @@ -710,6 +720,9 @@ void dhcpc_cancel(FAR void *handle) if (pdhcpc->thread) { +#ifdef CONFIG_DISABLE_SIGNALS + pthread_cancel(pdhcpc->thread); +#else old = signal(SIGQUIT, SIG_IGN); /* Signal the dhcpc_run */ @@ -719,6 +732,7 @@ void dhcpc_cancel(FAR void *handle) { nerr("ERROR: pthread_kill DHCPC thread\n"); } +#endif /* Wait for the end of dhcpc_run */ @@ -729,7 +743,9 @@ void dhcpc_cancel(FAR void *handle) } pdhcpc->thread = 0; +#ifndef CONFIG_DISABLE_SIGNALS signal(SIGQUIT, old); +#endif } } } diff --git a/netutils/ping/icmp_ping.c b/netutils/ping/icmp_ping.c index efbc8a61a78..be884c18e66 100644 --- a/netutils/ping/icmp_ping.c +++ b/netutils/ping/icmp_ping.c @@ -91,6 +91,7 @@ static volatile bool g_exiting; * Private Functions ****************************************************************************/ +#ifndef CONFIG_DISABLE_SIGNALS /**************************************************************************** * Name: sigexit ****************************************************************************/ @@ -99,6 +100,7 @@ static void sigexit(int signo) { g_exiting = true; } +#endif /**************************************************************************** * Name: ping_newid @@ -199,7 +201,9 @@ void icmp_ping(FAR const struct ping_info_s *info) int i; g_exiting = false; +#ifndef CONFIG_DISABLE_SIGNALS signal(SIGINT, sigexit); +#endif /* Initialize result structure */ diff --git a/netutils/telnetd/telnetd_daemon.c b/netutils/telnetd/telnetd_daemon.c index ed02b156909..b8da3593017 100644 --- a/netutils/telnetd/telnetd_daemon.c +++ b/netutils/telnetd/telnetd_daemon.c @@ -74,7 +74,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config) #endif } addr; -#ifdef CONFIG_SCHED_HAVE_PARENT +#if defined(CONFIG_SCHED_HAVE_PARENT) && !defined(CONFIG_DISABLE_SIGNALS) struct sigaction sa; sigset_t blockset; #endif @@ -85,7 +85,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config) int optval; #endif -#ifdef CONFIG_SCHED_HAVE_PARENT +#if defined(CONFIG_SCHED_HAVE_PARENT) && !defined(CONFIG_DISABLE_SIGNALS) /* Call sigaction with the SA_NOCLDWAIT flag so that we do not transform * children into "zombies" when they terminate: Child exit status will * not be retained. @@ -113,7 +113,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config) nerr("ERROR: sigprocmask failed: %d\n", errno); goto errout; } -#endif /* CONFIG_SCHED_HAVE_PARENT */ +#endif /* CONFIG_SCHED_HAVE_PARENT && !CONFIG_DISABLE_SIGNALS */ /* Create a new TCP socket to use to listen for connections */ From 3d748195b0abe46a776b47570f73ab905ce94a83 Mon Sep 17 00:00:00 2001 From: guoshichao Date: Thu, 25 Sep 2025 14:33:46 +0800 Subject: [PATCH 4/8] cu: implement the cu exit logic like top cmd using the local cu_globals_s instance to manange the cu exit procedure Signed-off-by: guoshichao --- system/cu/cu_main.c | 70 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c index 20cd101b51b..d279180e8c3 100644 --- a/system/cu/cu_main.c +++ b/system/cu/cu_main.c @@ -79,8 +79,6 @@ enum parity_mode * Private Data ****************************************************************************/ -static struct cu_globals_s g_cu; - /**************************************************************************** * Public Data ****************************************************************************/ @@ -124,9 +122,10 @@ static FAR void *cu_listener(FAR void *parameter) return NULL; } -static void sigint(int sig) +static void cu_exit(int signo, FAR siginfo_t *siginfo, FAR void *context) { - g_cu.force_exit = true; + FAR struct cu_globals_s *cu = siginfo->si_user; + cu->force_exit = true; } #ifdef CONFIG_SERIAL_TERMIOS @@ -276,8 +275,8 @@ int main(int argc, FAR char *argv[]) { pthread_attr_t attr; struct sigaction sa; + struct cu_globals_s cu; FAR const char *devname = CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE; - FAR struct cu_globals_s *cu = &g_cu; #ifdef CONFIG_SERIAL_TERMIOS int baudrate = CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD; enum parity_mode parity = PARITY_NONE; @@ -292,14 +291,21 @@ int main(int argc, FAR char *argv[]) /* Initialize global data */ - memset(cu, 0, sizeof(*cu)); - cu->escape = '~'; + memset(&cu, 0, sizeof(struct cu_globals_s)); + cu.escape = '~'; /* Install signal handlers */ memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sigint; - sigaction(SIGINT, &sa, NULL); + sa.sa_user = &cu; + sa.sa_sigaction = cu_exit; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGINT, &sa, NULL) < 0) + { + cu_error("cu_main: ERROR during setup cu_exit sigaction(): %d\n", + errno); + return EXIT_FAILURE; + } optind = 0; /* Global that needs to be reset in FLAT mode */ while ((option = getopt(argc, argv, "l:s:ceE:fho?")) != ERROR) @@ -333,7 +339,7 @@ int main(int argc, FAR char *argv[]) break; case 'E': - cu->escape = atoi(optarg); + cu.escape = atoi(optarg); break; case 'h': @@ -356,8 +362,8 @@ int main(int argc, FAR char *argv[]) /* Open the serial device for reading and writing */ - cu->devfd = open(devname, O_RDWR); - if (cu->devfd < 0) + cu.devfd = open(devname, O_RDWR); + if (cu.devfd < 0) { cu_error("cu_main: ERROR: Failed to open %s for writing: %d\n", devname, errno); @@ -366,9 +372,9 @@ int main(int argc, FAR char *argv[]) /* Remember serial device termios attributes */ - if (isatty(cu->devfd)) + if (isatty(cu.devfd)) { - ret = tcgetattr(cu->devfd, &cu->devtio); + ret = tcgetattr(cu.devfd, &cu.devtio); if (ret) { cu_error("cu_main: ERROR during tcgetattr(): %d\n", errno); @@ -382,30 +388,30 @@ int main(int argc, FAR char *argv[]) if (isatty(STDERR_FILENO)) { - cu->stdfd = STDERR_FILENO; + cu.stdfd = STDERR_FILENO; } else if (isatty(STDOUT_FILENO)) { - cu->stdfd = STDOUT_FILENO; + cu.stdfd = STDOUT_FILENO; } else if (isatty(STDIN_FILENO)) { - cu->stdfd = STDIN_FILENO; + cu.stdfd = STDIN_FILENO; } else { - cu->stdfd = -1; + cu.stdfd = -1; } - if (cu->stdfd >= 0) + if (cu.stdfd >= 0) { - tcgetattr(cu->stdfd, &cu->stdtio); + tcgetattr(cu.stdfd, &cu.stdtio); } #ifdef CONFIG_SERIAL_TERMIOS - if (set_termios(cu, baudrate, parity, rtscts, nocrlf) != 0) + if (set_termios(&cu, baudrate, parity, rtscts, nocrlf) != 0) #else - if (set_termios(cu, nocrlf) != 0) + if (set_termios(&cu, nocrlf) != 0) #endif { goto errout_with_devfd_retrieve; @@ -424,7 +430,7 @@ int main(int argc, FAR char *argv[]) attr.priority = CONFIG_SYSTEM_CUTERM_PRIORITY; - ret = pthread_create(&cu->listener, &attr, cu_listener, cu); + ret = pthread_create(&cu.listener, &attr, cu_listener, &cu); pthread_attr_destroy(&attr); if (ret != 0) { @@ -434,7 +440,7 @@ int main(int argc, FAR char *argv[]) /* Send messages and get responses -- forever */ - while (!cu->force_exit) + while (!cu.force_exit) { char ch; @@ -443,7 +449,7 @@ int main(int argc, FAR char *argv[]) continue; } - if (start_of_line == 1 && ch == cu->escape) + if (start_of_line == 1 && ch == cu.escape) { /* We've seen and escape (~) character, echo it to local * terminal and read the next char from serial @@ -456,16 +462,16 @@ int main(int argc, FAR char *argv[]) continue; } - if (ch == cu->escape) + if (ch == cu.escape) { /* Escaping a tilde: handle like normal char */ - write(cu->devfd, &ch, 1); + write(cu.devfd, &ch, 1); continue; } else { - if (cu_cmd(cu, ch) == 1) + if (cu_cmd(&cu, ch) == 1) { break; } @@ -474,7 +480,7 @@ int main(int argc, FAR char *argv[]) /* Normal character */ - write(cu->devfd, &ch, 1); + write(cu.devfd, &ch, 1); /* Determine if we are now at the start of a new line or not */ @@ -488,15 +494,15 @@ int main(int argc, FAR char *argv[]) } } - pthread_cancel(cu->listener); + pthread_cancel(cu.listener); exitval = EXIT_SUCCESS; /* Error exits */ errout_with_devfd_retrieve: - retrieve_termios(cu); + retrieve_termios(&cu); errout_with_devfd: - close(cu->devfd); + close(cu.devfd); errout_with_devinit: return exitval; } From 744eed52c32991aff699f07a7bd18b226d761949 Mon Sep 17 00:00:00 2001 From: guoshichao Date: Thu, 25 Sep 2025 15:29:25 +0800 Subject: [PATCH 5/8] cu: merge the cu.h to cu_main.c merge the cu.h to cu_main.c, to make the cu tools code more cleaner Signed-off-by: guoshichao --- system/cu/cu.h | 92 --------------------------------------------- system/cu/cu_main.c | 33 +++++++++++++++- 2 files changed, 32 insertions(+), 93 deletions(-) delete mode 100644 system/cu/cu.h diff --git a/system/cu/cu.h b/system/cu/cu.h deleted file mode 100644 index be9b31fb321..00000000000 --- a/system/cu/cu.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * apps/system/cu/cu.h - * - * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2014 sysmocom - s.f.m.c. GmbH. All rights reserved. - * SPDX-FileContributor: Harald Welte - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_SYSTEM_CU_CU_H -#define __APPS_SYSTEM_CU_CU_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Configuration ************************************************************/ - -#ifndef CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE -# define CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE "/dev/ttyS0" -#endif - -#ifndef CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD -# define CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD 115200 -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* All terminal state data is packaged in a single structure to minimize - * name conflicts with other global symbols -- a poor man's name space. - */ - -struct cu_globals_s -{ - int devfd; /* I/O data to serial port */ - int stdfd; /* I/O data to standard console */ - int escape; /* Escape char */ - struct termios devtio; /* Original serial port setting */ - struct termios stdtio; /* Original standard console setting */ - pthread_t listener; /* Terminal listener thread */ - bool force_exit; /* Force exit */ -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#endif /* __APPS_SYSTEM_CU_CU_H */ diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c index d279180e8c3..2aa1415e41a 100644 --- a/system/cu/cu_main.c +++ b/system/cu/cu_main.c @@ -53,10 +53,26 @@ #include #include #include +#include +#include +#include +#include #include "system/readline.h" -#include "cu.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#ifndef CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE +# define CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE "/dev/ttyS0" +#endif + +#ifndef CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD +# define CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD 115200 +#endif #ifdef CONFIG_SYSTEM_CUTERM_DISABLE_ERROR_PRINT # define cu_error(...) @@ -75,6 +91,21 @@ enum parity_mode PARITY_ODD, }; +/* All terminal state data is packaged in a single structure to minimize + * name conflicts with other global symbols -- a poor man's name space. + */ + +struct cu_globals_s +{ + int devfd; /* I/O data to serial port */ + int stdfd; /* I/O data to standard console */ + int escape; /* Escape char */ + struct termios devtio; /* Original serial port setting */ + struct termios stdtio; /* Original standard console setting */ + pthread_t listener; /* Terminal listener thread */ + bool force_exit; /* Force exit */ +}; + /**************************************************************************** * Private Data ****************************************************************************/ From 67dd5d2e0913556b93ebffe2d205e6c59f1bb49c Mon Sep 17 00:00:00 2001 From: guoshichao Date: Thu, 25 Sep 2025 16:12:53 +0800 Subject: [PATCH 6/8] cu: make the cu tool can work with SIGNAL disabled The core functionality of the cu tool does not rely on signal features. Therefore, we can isolate the signal-related implementations to ensure that most functions of the cu tool remain operational even when signals are disabled. Signed-off-by: guoshichao --- system/cu/cu_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c index 2aa1415e41a..dd6b07bae57 100644 --- a/system/cu/cu_main.c +++ b/system/cu/cu_main.c @@ -153,11 +153,13 @@ static FAR void *cu_listener(FAR void *parameter) return NULL; } +#ifndef CONFIG_DISABLE_SIGNALS static void cu_exit(int signo, FAR siginfo_t *siginfo, FAR void *context) { FAR struct cu_globals_s *cu = siginfo->si_user; cu->force_exit = true; } +#endif #ifdef CONFIG_SERIAL_TERMIOS static int set_termios(FAR struct cu_globals_s *cu, int rate, @@ -305,7 +307,9 @@ static int cu_cmd(FAR struct cu_globals_s *cu, char bcmd) int main(int argc, FAR char *argv[]) { pthread_attr_t attr; +#ifndef CONFIG_DISABLE_SIGNALS struct sigaction sa; +#endif struct cu_globals_s cu; FAR const char *devname = CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE; #ifdef CONFIG_SERIAL_TERMIOS @@ -325,6 +329,7 @@ int main(int argc, FAR char *argv[]) memset(&cu, 0, sizeof(struct cu_globals_s)); cu.escape = '~'; +#ifndef CONFIG_DISABLE_SIGNALS /* Install signal handlers */ memset(&sa, 0, sizeof(sa)); @@ -337,6 +342,7 @@ int main(int argc, FAR char *argv[]) errno); return EXIT_FAILURE; } +#endif optind = 0; /* Global that needs to be reset in FLAT mode */ while ((option = getopt(argc, argv, "l:s:ceE:fho?")) != ERROR) From 107b63662ecaf1df1e1ef785b9c92c22c6d935cc Mon Sep 17 00:00:00 2001 From: v-tangmeng Date: Tue, 14 Oct 2025 10:27:42 +0800 Subject: [PATCH 7/8] examples: fix the compilation error caused by CONFIG_DISABLE_SIGNALS The commit 'add support for CONFIG_DISABLE_SIGNALS' led to: undefined reference to `signal' undefined reference to `sigaction' Signed-off-by: v-tangmeng --- examples/buttons/buttons_main.c | 2 ++ examples/chrono/chrono_main.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/examples/buttons/buttons_main.c b/examples/buttons/buttons_main.c index d4b36431c95..d78470b39f9 100644 --- a/examples/buttons/buttons_main.c +++ b/examples/buttons/buttons_main.c @@ -219,9 +219,11 @@ static int button_daemon(int argc, char *argv[]) goto errout_with_fd; } +#ifndef CONFIG_DISABLE_SIGNALS /* Ignore the default signal action */ signal(CONFIG_EXAMPLES_BUTTONS_SIGNO, SIG_IGN); +#endif #endif /* Now loop forever, waiting BUTTONs events */ diff --git a/examples/chrono/chrono_main.c b/examples/chrono/chrono_main.c index ee6658591d1..bcd1cbdf0af 100644 --- a/examples/chrono/chrono_main.c +++ b/examples/chrono/chrono_main.c @@ -165,9 +165,11 @@ static int chrono_daemon(int argc, char *argv[]) goto errout_with_fd; } +#ifndef CONFIG_DISABLE_SIGNALS /* Ignore the default signal action */ signal(BUTTON_SIGNO, SIG_IGN); +#endif /* Now loop forever, waiting BUTTONs events */ From 15ca04b3821792fef84241d21e9189f68e982213 Mon Sep 17 00:00:00 2001 From: v-tangmeng Date: Thu, 16 Oct 2025 14:04:40 +0800 Subject: [PATCH 8/8] examples/timer: fix the compilation error caused by CONFIG_DISABLE_SIGNALS The commit 'add support for CONFIG_DISABLE_SIGNALS' led to: undefined reference to `sigaction' Signed-off-by: v-tangmeng --- examples/timer/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/timer/Kconfig b/examples/timer/Kconfig index 3a997ccab24..c62dd640cb7 100644 --- a/examples/timer/Kconfig +++ b/examples/timer/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_TIMER tristate "Timer example" default n - depends on TIMER + depends on TIMER && !DISABLE_SIGNALS ---help--- Enable the timer example