From: Gagandeep Singh Date: Fri, 20 May 2022 04:21:00 +0000 (+0530) Subject: examples/l2fwd-crypto: add signal handler for exit X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=76fbba28565d9beced9985554916619ecda3ce7c;p=dpdk.git examples/l2fwd-crypto: add signal handler for exit Handle SIGINT and SIGTERM signals. Signed-off-by: Gagandeep Singh Acked-by: Akhil Goyal --- diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index b1e2613ccf..bf4b862379 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -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 */ +static volatile bool signal_received; + /* Print out statistics on packets dropped */ static void print_stats(void) @@ -922,6 +926,8 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options) nb_rx = rte_eth_rx_burst(portid, 0, pkts_burst, MAX_PKT_BURST); + if (unlikely(signal_received)) + return; port_statistics[portid].rx += nb_rx; @@ -2760,6 +2766,13 @@ reserve_key_memory(struct l2fwd_crypto_options *options) options->aad.phys_addr = rte_malloc_virt2iova(options->aad.data); } +static void +raise_signal(int signum) +{ + if (signum == SIGINT || signum == SIGTERM) + signal_received = true; +} + int main(int argc, char **argv) { @@ -2772,6 +2785,9 @@ main(int argc, char **argv) int ret, enabled_cdevcount, enabled_portcount; uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = {0}; + signal(SIGINT, raise_signal); + signal(SIGTERM, raise_signal); + /* init EAL */ ret = rte_eal_init(argc, argv); if (ret < 0)