The packet handling loop in main() never terminates, so the
rte_eal_cleanup() after it is unreachable. Clang reports this
with -Wunreachable-code.

Add a signal handler setting force_quit, as done by the server
process and others, and test it in the loop so that cleanup runs
on exit. Return zero explicitly rather than falling off the end
of main().

Signed-off-by: Stephen Hemminger <[email protected]>
---
 .../client_server_mp/mp_client/client.c       | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/examples/multi_process/client_server_mp/mp_client/client.c 
b/examples/multi_process/client_server_mp/mp_client/client.c
index 087c38ef73..2916881541 100644
--- a/examples/multi_process/client_server_mp/mp_client/client.c
+++ b/examples/multi_process/client_server_mp/mp_client/client.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2010-2016 Intel Corporation
  */
 
+#include <signal.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <inttypes.h>
@@ -195,9 +197,18 @@ handle_packet(struct rte_mbuf *buf)
 
 }
 
+static volatile bool force_quit;
+
+static void
+signal_handler(int signum)
+{
+       if (signum == SIGINT || signum == SIGTERM)
+               force_quit = true;
+}
+
 /*
  * Application main function - loops through
- * receiving and processing packets. Never returns
+ * receiving and processing packets until interrupted
  */
 int
 main(int argc, char *argv[])
@@ -213,6 +224,9 @@ main(int argc, char *argv[])
 
        if ((retval = rte_eal_init(argc, argv)) < 0)
                return -1;
+
+       signal(SIGINT, signal_handler);
+       signal(SIGTERM, signal_handler);
        argc -= retval;
        argv += retval;
 
@@ -243,7 +257,7 @@ main(int argc, char *argv[])
        printf("\nClient process %d handling packets\n", client_id);
        printf("[Press Ctrl-C to quit ...]\n");
 
-       for (;;) {
+       while (!force_quit) {
                uint16_t i, rx_pkts;
 
                rx_pkts = rte_ring_dequeue_burst(rx_ring, pkts,
@@ -270,4 +284,6 @@ main(int argc, char *argv[])
 
        /* clean up the EAL */
        rte_eal_cleanup();
+
+       return 0;
 }
-- 
2.53.0

Reply via email to