The forwarding loop in lcore_main() never terminates, so the
rte_eal_cleanup() and return in main() are unreachable. Clang
reports this with -Wunreachable-code.

Add a signal handler setting force_quit, as done by l2fwd and
others, and test it in the loop. The function is no longer
__rte_noreturn, so the existing cleanup now runs on exit.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 examples/skeleton/basicfwd.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c
index ca433fc89e..a05c8ea381 100644
--- a/examples/skeleton/basicfwd.c
+++ b/examples/skeleton/basicfwd.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2010-2015 Intel Corporation
  */
 
+#include <signal.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <inttypes.h>
@@ -18,6 +20,15 @@
 #define MBUF_CACHE_SIZE 250
 #define BURST_SIZE 32
 
+static volatile bool force_quit;
+
+static void
+signal_handler(int signum)
+{
+       if (signum == SIGINT || signum == SIGTERM)
+               force_quit = true;
+}
+
 /* basicfwd.c: Basic DPDK skeleton forwarding example. */
 
 /*
@@ -113,7 +124,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
  */
 
  /* Basic forwarding application lcore. 8< */
-static __rte_noreturn void
+static void
 lcore_main(void)
 {
        uint16_t port;
@@ -134,7 +145,7 @@ lcore_main(void)
                        rte_lcore_id());
 
        /* Main work of application loop. 8< */
-       for (;;) {
+       while (!force_quit) {
                /*
                 * Receive packets on a port and forward them on the paired
                 * port. The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.
@@ -182,6 +193,9 @@ main(int argc, char *argv[])
                rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
        /* >8 End of initializing the Environment Abstraction Layer (EAL). */
 
+       signal(SIGINT, signal_handler);
+       signal(SIGTERM, signal_handler);
+
        argc -= ret;
        argv += ret;
 
-- 
2.53.0

Reply via email to