From patchwork Wed Dec 23 20:03:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihong Wang X-Patchwork-Id: 9657 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 6C7088DB4; Thu, 24 Dec 2015 04:06:38 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 4A73D5A9D for ; Thu, 24 Dec 2015 04:06:33 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP; 23 Dec 2015 19:06:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,471,1444719600"; d="scan'208";a="623041290" Received: from unknown (HELO dpdk5.sh.intel.com) ([10.239.129.244]) by FMSMGA003.fm.intel.com with ESMTP; 23 Dec 2015 19:06:31 -0800 From: Zhihong Wang To: dev@dpdk.org Date: Wed, 23 Dec 2015 15:03:14 -0500 Message-Id: <1450900995-84185-3-git-send-email-zhihong.wang@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1450900995-84185-1-git-send-email-zhihong.wang@intel.com> References: <1450900995-84185-1-git-send-email-zhihong.wang@intel.com> Subject: [dpdk-dev] [PATCH 2/3] examples/l2fwd: Handle SIGINT and SIGTERM in l2fwd X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list 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 l2fwd. Signed-off-by: Zhihong Wang --- examples/l2fwd/main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index 720fd5a..0594037 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -534,6 +535,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 ((l2fwd_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) { @@ -546,6 +568,9 @@ main(int argc, char **argv) unsigned lcore_id, rx_lcore_id; unsigned nb_ports_in_mask = 0; + signal(SIGINT, sigint_handler); + signal(SIGTERM, sigint_handler); + /* init EAL */ ret = rte_eal_init(argc, argv); if (ret < 0)