From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhihong Wang Subject: [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd Date: Wed, 23 Dec 2015 15:03:15 -0500 Message-ID: <1450900995-84185-4-git-send-email-zhihong.wang@intel.com> References: <1450900995-84185-1-git-send-email-zhihong.wang@intel.com> To: dev@dpdk.org Return-path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 701915A87 for ; Thu, 24 Dec 2015 04:06:33 +0100 (CET) In-Reply-To: <1450900995-84185-1-git-send-email-zhihong.wang@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Handle SIGINT and SIGTERM in l3fwd. Signed-off-by: Zhihong Wang --- 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 #include #include +#include #include #include @@ -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