[v3,2/3] testpmd: use sig_atomic_t for flag

Message ID 20230314173648.69528-3-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series testpmd control C fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger March 14, 2023, 5:36 p.m. UTC
  Standard conforming signal handling in applications should use sig_atomic_t
for flags set by signal handler.
 https://www.gnu.org/software/libc/manual/html_node/Atomic-Data-Access.html

This is really just a fancy way of saying ''int'' but adds
to platform portablilty for DPDK.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-pmd/testpmd.c | 6 +-----
 app/test-pmd/testpmd.h | 3 ++-
 2 files changed, 3 insertions(+), 6 deletions(-)
  

Comments

Stephen Hemminger March 15, 2023, 4:31 p.m. UTC | #1
On Tue, 14 Mar 2023 10:36:47 -0700
Stephen Hemminger <stephen@networkplumber.org> wrote:

> Standard conforming signal handling in applications should use sig_atomic_t
> for flags set by signal handler.
>  https://www.gnu.org/software/libc/manual/html_node/Atomic-Data-Access.html
> 
> This is really just a fancy way of saying ''int'' but adds
> to platform portablilty for DPDK.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Apparently, this fails on some distros because signal.h ends up including
some compatibility definitions that clash with the same definitions in
the ixgbe testpmd base code. Since fixing either base code or the distro
is a PIA not worth doing.
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 5cb6f9252395..aee926571f53 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -228,11 +228,7 @@  struct rte_eth_xstat_name *xstats_display;
 
 unsigned int xstats_display_num; /**< Size of extended statistics to show */
 
-/*
- * In container, it cannot terminate the process which running with 'stats-period'
- * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
- */
-volatile uint8_t f_quit;
+volatile sig_atomic_t f_quit;	/* Quit testpmd from signal */
 uint8_t cl_quit; /* Quit testpmd from cmdline. */
 
 /*
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index bdfbfd36d3c5..5c11d4f86301 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -6,6 +6,7 @@ 
 #define _TESTPMD_H_
 
 #include <stdbool.h>
+#include <signal.h>
 
 #ifdef RTE_LIB_GRO
 #include <rte_gro.h>
@@ -34,7 +35,7 @@ 
 #define RTE_PORT_HANDLING       (uint16_t)3
 
 extern uint8_t cl_quit;
-extern volatile uint8_t f_quit;
+extern volatile sig_atomic_t f_quit;
 
 /*
  * It is used to allocate the memory for hash key.