Handle SIGINT and SIGTERM signals.

Signed-off-by: Gagandeep Singh <g.si...@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 bbdb263143..1764fc7abc 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>
@@ -258,6 +259,9 @@ struct l2fwd_crypto_statistics 
crypto_statistics[RTE_CRYPTO_MAX_DEVS];
 /* default period is 10 seconds */
 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
 
+/* Global signal */
+unsigned int signal_received;
+
 /* Print out statistics on packets dropped */
 static void
 print_stats(void)
@@ -925,6 +929,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;
 
@@ -2762,6 +2768,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)
+{
+       signal_received = 1;
+       printf("Exiting on signal (%d)\n", signum);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -2774,6 +2787,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)
-- 
2.25.1

Reply via email to