This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 9aaca95f827dda4bbc2161367fc4c0c87c162417
Author: zhanghongyu <[email protected]>
AuthorDate: Mon Nov 30 17:45:07 2026 +0800

    netutils/iperf: build without CONFIG_ENABLE_ALL_SIGNALS
    
    sigaction() is only built with CONFIG_ENABLE_ALL_SIGNALS, so boards
    that pick partial signal support (DEFAULT_SMALL, e.g. bl602evb:wifi)
    failed to link:
    
      iperf.c: undefined reference to `sigaction'
    
    Install the stop handler only when sigaction() exists.  Without it a
    stop signal still interrupts the blocking socket call of the traffic
    thread with EINTR; the TCP loops already end on that error, and the
    UDP server now does too instead of retrying until the timeout.
    
    The Kconfig dependency named DISABLE_SIGNALS, which no longer exists;
    use DISABLE_ALL_SIGNALS, the level that removes the signal API.
    
    Assisted-by: Kiro:claude-opus-4
    Signed-off-by: zhanghongyu <[email protected]>
---
 netutils/iperf/Kconfig |  2 +-
 netutils/iperf/iperf.c | 22 +++++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/netutils/iperf/Kconfig b/netutils/iperf/Kconfig
index 65b791fbc..e33e4ec28 100644
--- a/netutils/iperf/Kconfig
+++ b/netutils/iperf/Kconfig
@@ -27,7 +27,7 @@
 config NETUTILS_IPERF
        bool "iperf example"
        default n
-       depends on NET && !DISABLE_SIGNALS
+       depends on NET && !DISABLE_ALL_SIGNALS
        select NETUTILS_NETLIB
        select LIBC_FLOATINGPOINT
        ---help---
diff --git a/netutils/iperf/iperf.c b/netutils/iperf/iperf.c
index 4e391d773..d1eee3e2c 100644
--- a/netutils/iperf/iperf.c
+++ b/netutils/iperf/iperf.c
@@ -120,8 +120,10 @@ inline static bool iperf_is_udp_server(FAR struct 
iperf_ctrl_t *ctrl);
 inline static bool iperf_is_tcp_client(FAR struct iperf_ctrl_t *ctrl);
 inline static bool iperf_is_tcp_server(FAR struct iperf_ctrl_t *ctrl);
 static void iperf_stop_sigset(FAR sigset_t *set);
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
 static void iperf_stop_handler(int signo, FAR siginfo_t *info,
                                FAR void *context);
+#endif
 static void iperf_stop_report(FAR struct iperf_ctrl_t *ctrl);
 static int iperf_get_socket_error_code(int sockfd);
 static int iperf_show_socket_error_reason(FAR const char *str, int sockfd);
@@ -211,6 +213,7 @@ static void iperf_stop_sigset(FAR sigset_t *set)
   sigaddset(set, SIGUSR1);
 }
 
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
 /****************************************************************************
  * Name: iperf_stop_handler
  *
@@ -220,6 +223,10 @@ static void iperf_stop_sigset(FAR sigset_t *set)
  *   on the traffic thread with EINTR.  The traffic thread's exit path then
  *   wakes the report thread through iperf_stop_report().
  *
+ *   Without CONFIG_ENABLE_ALL_SIGNALS there is no sigaction() and no
+ *   handler: the signal only interrupts the blocking socket call, and the
+ *   traffic loops treat that EINTR as the stop request.
+ *
  ****************************************************************************/
 
 static void iperf_stop_handler(int signo, FAR siginfo_t *info,
@@ -232,6 +239,7 @@ static void iperf_stop_handler(int signo, FAR siginfo_t 
*info,
       ctrl->finish = 1;
     }
 }
+#endif
 
 /****************************************************************************
  * Name: iperf_stop_report
@@ -932,7 +940,13 @@ static int iperf_udp_server(FAR struct iperf_ctrl_t *ctrl,
 
       if (actual_recv < 0)
         {
-          iperf_show_socket_error_reason("udp server recv", sockfd);
+          if (iperf_show_socket_error_reason("udp server recv",
+                                             sockfd) == EINTR)
+            {
+              /* Interrupted by a stop signal */
+
+              break;
+            }
         }
       else
         {
@@ -1298,11 +1312,13 @@ int iperf_start(FAR struct iperf_cfg_t *cfg)
 {
   struct iperf_ctrl_t ctrl;
   struct sched_param param;
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
   struct sigaction act;
   struct sigaction oldint;
   struct sigaction oldterm;
   struct sigaction oldpipe;
   struct sigaction oldusr1;
+#endif
   pthread_attr_t attr;
   sigset_t oldset;
   sigset_t set;
@@ -1352,6 +1368,7 @@ int iperf_start(FAR struct iperf_cfg_t *cfg)
   iperf_stop_sigset(&set);
   pthread_sigmask(SIG_BLOCK, &set, &oldset);
 
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
   memset(&act, 0, sizeof(act));
   act.sa_sigaction = iperf_stop_handler;
   act.sa_flags = SA_SIGINFO;
@@ -1361,6 +1378,7 @@ int iperf_start(FAR struct iperf_cfg_t *cfg)
   sigaction(SIGTERM, &act, &oldterm);
   sigaction(SIGPIPE, &act, &oldpipe);
   sigaction(SIGUSR1, &act, &oldusr1);
+#endif
 
   ret = -pthread_create(&ctrl.traffic_thread, &attr,
                         iperf_task_traffic, &ctrl);
@@ -1380,10 +1398,12 @@ int iperf_start(FAR struct iperf_cfg_t *cfg)
    */
 
   pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
   sigaction(SIGINT, &oldint, NULL);
   sigaction(SIGTERM, &oldterm, NULL);
   sigaction(SIGPIPE, &oldpipe, NULL);
   sigaction(SIGUSR1, &oldusr1, NULL);
+#endif
 
   free(ctrl.buffer);
   sem_destroy(&ctrl.report_wakeup);

Reply via email to