[PATCH 08/13] examples/ntb: do not print and re-raise from signal handler

Stephen Hemminger stephen at networkplumber.org
Mon Sep 7 01:24:43 CEST 2026


The handler called printf(), reset the disposition to SIG_DFL and
killed itself, so the process died without stopping the forwarding
lcores or closing the devices.

Set the existing per-lcore stopped flag instead, and mark it volatile
since it is now written from signal context.

SIGINT no longer terminates the application; it stops forwarding and
returns to the ntb> prompt, where quit does the teardown.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 examples/ntb/ntb_fwd.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c
index 33f3c1ef17..bbacce97db 100644
--- a/examples/ntb/ntb_fwd.c
+++ b/examples/ntb/ntb_fwd.c
@@ -41,7 +41,7 @@ struct ntb_fwd_stream {
 struct ntb_fwd_lcore_conf {
 	uint16_t stream_id;
 	uint16_t nb_stream;
-	uint8_t stopped;
+	volatile uint8_t stopped;
 };
 
 enum ntb_fwd_mode {
@@ -947,12 +947,16 @@ prompt(void)
 }
 
 static void
-signal_handler(int signum)
+signal_handler(__rte_unused int signum)
 {
-	if (signum == SIGINT || signum == SIGTERM) {
-		printf("\nSignal %d received, preparing to exit...\n", signum);
-		signal(signum, SIG_DFL);
-		kill(getpid(), signum);
+	struct ntb_fwd_lcore_conf *conf;
+	uint32_t lcore_id;
+
+	RTE_LCORE_FOREACH_WORKER(lcore_id) {
+		conf = &fwd_lcore_conf[lcore_id];
+
+		if (conf->nb_stream)
+			conf->stopped = 1;
 	}
 }
 
-- 
2.53.0



More information about the dev mailing list