[PATCH] app: do not call printf in signal handlers

Stephen Hemminger stephen at networkplumber.org
Tue Jun 13 02:11:50 CEST 2023


Using printf is not async-signal safe and worst case may lead to deadlock.
Remove printf from signal handlers present in several applications.

Testpmd was already fixed by
commit 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal")

Signed-off-by: Prateek Agarwal <prateekag at cse.iitb.ac.in>
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 app/pdump/main.c             | 2 --
 app/test-eventdev/evt_main.c | 3 ---
 app/test-flow-perf/main.c    | 3 ---
 app/test/test_pmd_perf.c     | 1 -
 4 files changed, 9 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index c6cf9d9c8769..c94606275b28 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -571,8 +571,6 @@ static void
 signal_handler(int sig_num)
 {
 	if (sig_num == SIGINT) {
-		printf("\n\nSignal %d received, preparing to exit...\n",
-				sig_num);
 		quit_signal = 1;
 	}
 }
diff --git a/app/test-eventdev/evt_main.c b/app/test-eventdev/evt_main.c
index 5c7ac2cce9ab..13a8500ef730 100644
--- a/app/test-eventdev/evt_main.c
+++ b/app/test-eventdev/evt_main.c
@@ -21,9 +21,6 @@ static void
 signal_handler(int signum)
 {
 	if (signum == SIGINT || signum == SIGTERM) {
-		printf("\nSignal %d received, preparing to exit...\n",
-				signum);
-
 		if (test != NULL) {
 			/* request all lcores to exit from the main loop */
 			*(int *)test->test_priv = true;
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index e0ef78a84013..e224ef67983d 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -1708,9 +1708,6 @@ static void
 signal_handler(int signum)
 {
 	if (signum == SIGINT || signum == SIGTERM) {
-		printf("\n\nSignal %d received, preparing to exit...\n",
-					signum);
-		printf("Error: Stats are wrong due to sudden signal!\n\n");
 		force_quit = true;
 	}
 }
diff --git a/app/test/test_pmd_perf.c b/app/test/test_pmd_perf.c
index ff84d251ff5f..3ef590cb517d 100644
--- a/app/test/test_pmd_perf.c
+++ b/app/test/test_pmd_perf.c
@@ -318,7 +318,6 @@ signal_handler(int signum)
 {
 	/*  USR1 signal, stop testing */
 	if (signum == SIGUSR1) {
-		printf("Force Stop!\n");
 		stop = 1;
 	}
 
-- 
2.39.2



More information about the dev mailing list