[PATCH v2 04/13] examples/symmetric_mp: do not print or exit in handler
Stephen Hemminger
stephen at networkplumber.org
Mon Sep 7 19:03:22 CEST 2026
The SIGINT and SIGTERM handler called printf() and exit() which are
not async-signal-safe.
Set a flag, let the forwarding loops return, and print the stats from
main() after joining the lcores.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
examples/multi_process/symmetric_mp/main.c | 26 ++++++++++++++++------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/examples/multi_process/symmetric_mp/main.c b/examples/multi_process/symmetric_mp/main.c
index 7314a9c6ea..e2d185ab1b 100644
--- a/examples/multi_process/symmetric_mp/main.c
+++ b/examples/multi_process/symmetric_mp/main.c
@@ -92,18 +92,25 @@ smp_usage(const char *prgname, const char *errmsg)
}
-/* signal handler configured for SIGTERM and SIGINT to print stats on exit */
+/* Set by SIGTERM and SIGINT handler to stop the forwarding loops. */
+static volatile sig_atomic_t quit;
+
+static void
+signal_handler(__rte_unused int signum)
+{
+ quit = 1;
+}
+
static void
-print_stats(int signum)
+print_stats(void)
{
unsigned i;
- printf("\nExiting on signal %d\n\n", signum);
+
for (i = 0; i < num_ports; i++){
const uint8_t p_num = ports[i];
printf("Port %u: RX - %u, TX - %u, Drop - %u\n", (unsigned)p_num,
pstats[p_num].rx, pstats[p_num].tx, pstats[p_num].drop);
}
- exit(0);
}
/* Parse the argument given in the command line of the application */
@@ -344,7 +351,7 @@ lcore_main(void *arg __rte_unused)
* queue number corresponding to our process number (not lcore id)
*/
- for (;;) {
+ while (!quit) {
struct rte_mbuf *buf[PKT_BURST];
for (p = start_port; p < end_port; p++) {
@@ -364,6 +371,8 @@ lcore_main(void *arg __rte_unused)
}
}
}
+
+ return 0;
}
/* Check the link status of all ports in up to 9s, and print them finally */
@@ -440,8 +449,8 @@ main(int argc, char **argv)
struct rte_mempool *mp;
/* set up signal handlers to print stats on exit */
- signal(SIGINT, print_stats);
- signal(SIGTERM, print_stats);
+ signal(SIGINT, signal_handler);
+ signal(SIGTERM, signal_handler);
/* initialise the EAL for all */
ret = rte_eal_init(argc, argv);
@@ -484,6 +493,9 @@ main(int argc, char **argv)
RTE_LOG(INFO, APP, "Finished Process Init.\n");
rte_eal_mp_remote_launch(lcore_main, NULL, CALL_MAIN);
+ rte_eal_mp_wait_lcore();
+
+ print_stats();
/* clean up the EAL */
rte_eal_cleanup();
--
2.53.0
More information about the dev
mailing list