[PATCH v2 3/7] examples/l2fwd-crypto: add signal handler for exit
Stephen Hemminger
stephen at networkplumber.org
Tue May 17 18:32:12 CEST 2022
On Tue, 17 May 2022 09:08:54 +0530
Gagandeep Singh <g.singh at nxp.com> wrote:
> Handle SIGINT and SIGTERM signals.
>
> Signed-off-by: Gagandeep Singh <g.singh at nxp.com>
> ---
> examples/l2fwd-crypto/main.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
> index b1e2613ccf..0a1fc790fc 100644
> --- a/examples/l2fwd-crypto/main.c
> +++ b/examples/l2fwd-crypto/main.c
> @@ -18,6 +18,7 @@
> #include <getopt.h>
> #include <fcntl.h>
> #include <unistd.h>
> +#include <signal.h>
>
> #include <rte_string_fns.h>
> #include <rte_branch_prediction.h>
> @@ -256,6 +257,9 @@ struct l2fwd_crypto_statistics crypto_statistics[RTE_CRYPTO_MAX_DEVS];
> #define MAX_TIMER_PERIOD 86400UL /* 1 day max */
> #define DEFAULT_TIMER_PERIOD 10UL
>
> +/* Global signal */
> +unsigned int signal_received;
This won't work as expected.
This kind of flag needs to either be volatile or use explicit atomic builtins
because the compiler and CPU are free to believe that it never changes.
Traditional way to address this would be:
static volatile bool signal_received;
More advanced way would be to use __atomic_load/store builtin.
Also printf() is not technically safe to call from a signal handler.
More information about the dev
mailing list