Handle SIGINT and SIGTERM in l3fwd. Signed-off-by: Zhihong Wang <zhihong.wang at intel.com> --- examples/l3fwd/main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 5b0c2dd..aae16d2 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -41,6 +41,7 @@ #include <stdarg.h> #include <errno.h> #include <getopt.h> +#include <signal.h> #include <rte_common.h> #include <rte_vect.h> @@ -2559,6 +2560,27 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) } } +/* When we receive a INT signal, close all ports */ +static void +sigint_handler(__rte_unused int signum) +{ + unsigned portid, nb_ports; + + printf("Preparing to exit...\n"); + nb_ports = rte_eth_dev_count(); + for (portid = 0; portid < nb_ports; portid++) { + if ((enabled_port_mask & (1 << portid)) == 0) { + continue; + } + printf("Stopping port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + printf("Bye...\n"); + exit(0); +} + int main(int argc, char **argv) { @@ -2572,6 +2594,9 @@ main(int argc, char **argv) uint32_t n_tx_queue, nb_lcores; uint8_t portid, nb_rx_queue, queue, socketid; + signal(SIGINT, sigint_handler); + signal(SIGTERM, sigint_handler); + /* init EAL */ ret = rte_eal_init(argc, argv); if (ret < 0) -- 2.5.0