[PATCH v2 13/13] examples/eventdev_pipeline: make signal handler safe

Stephen Hemminger stephen at networkplumber.org
Mon Sep 7 19:03:31 CEST 2026


This example was calling functions like rte_exit and printing from a
signal handler which is not async signal safe.

Revise to spit the two signal actions here:
- The handler for SIGINT and SIGTERM set a flag which causes main
  loop to exit and proceed with normal clean shutdown. If a second
  SIGINT is received the process will get default signal handler
  (i.e process exit).

- The dump flag handler is changed form SIGTSTP (^Z) to use SIGUSR1
  since that is more standard practice in Linux.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 examples/eventdev_pipeline/main.c            | 39 ++++++++++++--------
 examples/eventdev_pipeline/pipeline_common.h | 13 ++++---
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/examples/eventdev_pipeline/main.c b/examples/eventdev_pipeline/main.c
index 65e0cd437c..00f409a07b 100644
--- a/examples/eventdev_pipeline/main.c
+++ b/examples/eventdev_pipeline/main.c
@@ -312,20 +312,16 @@ do_capability_setup(uint8_t eventdev_id)
 }
 
 static void
-signal_handler(int signum)
+signal_quit(int signum __rte_unused)
 {
-	static uint8_t once;
-
-	if (fdata->done)
-		rte_exit(1, "Exiting on signal %d\n", signum);
-	if ((signum == SIGINT || signum == SIGTERM) && !once) {
-		if (cdata.dump_dev)
-			rte_event_dev_dump(0, stdout);
-		once = 1;
+	if (fdata != NULL)
 		fdata->done = 1;
-	}
-	if (signum == SIGTSTP)
-		rte_event_dev_dump(0, stdout);
+}
+
+static void
+signal_dump(int signum __rte_unused)
+{
+	cdata.dump_dev_signal = 1;
 }
 
 static inline uint64_t
@@ -345,9 +341,19 @@ main(int argc, char **argv)
 	int lcore_id;
 	int err;
 
-	signal(SIGINT, signal_handler);
-	signal(SIGTERM, signal_handler);
-	signal(SIGTSTP, signal_handler);
+	/* second SIGINT/SIGTERM takes the default action */
+	struct sigaction sa = {
+		.sa_handler = signal_quit,
+		.sa_flags = SA_RESETHAND,
+	};
+	sigemptyset(&sa.sa_mask);
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	/* allow repeated dump signals */
+	sa.sa_handler = signal_dump;
+	sa.sa_flags = 0;
+	sigaction(SIGUSR1, &sa, NULL);
 
 	err = rte_eal_init(argc, argv);
 	if (err < 0)
@@ -452,6 +458,9 @@ main(int argc, char **argv)
 
 	rte_eal_mp_wait_lcore();
 
+	if (cdata.dump_dev)
+		rte_event_dev_dump(0, stdout);
+
 	if (!cdata.quiet && (port_stat(dev_id, worker_data[0].port_id) !=
 			(uint64_t)-ENOTSUP)) {
 		printf("\nPort Workload distribution:\n");
diff --git a/examples/eventdev_pipeline/pipeline_common.h b/examples/eventdev_pipeline/pipeline_common.h
index 7b8eb50240..274c6942ca 100644
--- a/examples/eventdev_pipeline/pipeline_common.h
+++ b/examples/eventdev_pipeline/pipeline_common.h
@@ -3,6 +3,7 @@
  * Copyright 2017 Cavium, Inc.
  */
 
+#include <signal.h>
 #include <stdbool.h>
 
 #include <rte_eal.h>
@@ -43,7 +44,7 @@ struct setup_data {
 };
 
 struct __rte_cache_aligned fastpath_data {
-	volatile int done;
+	volatile sig_atomic_t done;
 	uint32_t evdev_service_id;
 	uint32_t rxadptr_service_id;
 	uint32_t txadptr_service_id;
@@ -68,7 +69,7 @@ struct config_data {
 	int enable_queue_priorities;
 	int quiet;
 	int dump_dev;
-	int dump_dev_signal;
+	volatile sig_atomic_t dump_dev_signal;
 	int all_type_queues;
 	unsigned int num_stages;
 	unsigned int worker_cq_depth;
@@ -127,16 +128,16 @@ schedule_devices(unsigned int lcore_id)
 	if (fdata->sched_core[lcore_id]) {
 		rte_service_run_iter_on_app_lcore(fdata->evdev_service_id,
 				!fdata->sched_single);
-		if (cdata.dump_dev_signal) {
-			rte_event_dev_dump(0, stdout);
-			cdata.dump_dev_signal = 0;
-		}
 	}
 
 	if (fdata->tx_core[lcore_id]) {
 		rte_service_run_iter_on_app_lcore(fdata->txadptr_service_id,
 				!fdata->tx_single);
 	}
+	if (cdata.dump_dev_signal) {
+		rte_event_dev_dump(0, stdout);
+		cdata.dump_dev_signal = 0;
+	}
 }
 
 static void
-- 
2.53.0



More information about the dev mailing list