From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CCEC8A0093; Wed, 9 Nov 2022 05:10:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B54A1400D7; Wed, 9 Nov 2022 05:10:54 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 894DF400D4 for ; Wed, 9 Nov 2022 05:10:53 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id z26so15618469pff.1 for ; Tue, 08 Nov 2022 20:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xhrgDCnLEG2qPj/nrpvnnveuKuirs5h68eQQudWiF4g=; b=k7bFyGLfVDMJL/mQV6Q6FS4dPOIeX5tkwavCabFCmLXbujs5nMDAMKe4DXxzb0df2F 3MdcnqNUN6wEPjPcLh6LoXrmY1XdPn6/7Cvm4pbm75Zr1Q5/opCdp+V5If3r6kf6tKny DEsreQKMAanLB8NMb8TOkiBr+I6F2dZoEudf/Y4Nuxij8xDreLjk3RqwbyyC2VqIQ3q0 zhyk0BeYdw6t+4UgaHvFwy48QuUUeKt+bqCKX95L0dHXroS/J81oI95ybjtwZKR38qCQ W5ykNQESQtFiV9noIBdLxzc94fQEde7H9Luii3F3xsSPmfe95dzXl+BeVgpGAw9Per2G +rjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xhrgDCnLEG2qPj/nrpvnnveuKuirs5h68eQQudWiF4g=; b=TOLh+TJsiGdVUQSTZQWDDuiQTYa7TmlLk24ZyJ4utelgPMXGLa2eiOE40TcnodyyKT iBd2BhhlgvQEtA7+aIbJgtZ9zONw1vlAbJyZU4sYbSnqrk7ZB+xO6Vik7CIlExBBWq5K 5arnERO/OuhA+WWyz0vsRtSn3qwqmnKmCZ3tT0NfbO23E5qwPKGYn++Qdr6raf6X+ryQ SZtHklcpwk3JDlTn8RrG/tShxIVvw6wD0SqyBaDmKukULl+RQ4AL1X5loOu8g7IhSJj3 MSohJLO+/UQJZ0DAIoEhhhwn3crn3BjCfI3Bts69HWNsH5u3m+dLdbgXCF+IornODWY9 hJgQ== X-Gm-Message-State: ACrzQf1WqUt473zQglkx0SdL8rcc1L83XQRQKxdLfLfIarBSV7pR1uvY 6e6DOaJz8clqM1gfdoSHzMusoFcyxnRCTQ== X-Google-Smtp-Source: AMsMyM79BSWDmEIZGcrm/3+o6HdUiZCAu8ydTn9qHZ1l1QuKGZ1+k8RSTx4UNvDLALcxnuKwBXyvmw== X-Received: by 2002:a63:9c3:0:b0:46f:897a:78a4 with SMTP id 186-20020a6309c3000000b0046f897a78a4mr47179480pgj.624.1667967052226; Tue, 08 Nov 2022 20:10:52 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id v16-20020a63f850000000b004411a054d2dsm6409989pgj.82.2022.11.08.20.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 20:10:51 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: phil.yang@arm.com, Stephen Hemminger Subject: [PATCH v4] testpmd: cleanup cleanly from signal Date: Tue, 8 Nov 2022 20:10:46 -0800 Message-Id: <20221109041046.199840-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172328.185219-2-stephen@networkplumber.org> References: <20221014172328.185219-2-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Do a clean shutdown of testpmd when a signal is received; instead of having testpmd kill itself. This fixes problem where a signal could be received in the middle of a PMD and then the signal handler would call PMD's close routine which could cause a deadlock. Added benefit is it gets rid of Windows specific code. Fixes: d9a191a00e81 ("app/testpmd: fix quitting in container") Signed-off-by: Stephen Hemminger --- v4 - use select() because that is available on Windows; and other functions poll() and sigaction() are not. app/test-pmd/testpmd.c | 63 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index cf5942d0c422..274e96cac2d4 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -12,6 +12,7 @@ #ifndef RTE_EXEC_ENV_WINDOWS #include #endif +#include #include #include #include @@ -4251,26 +4252,11 @@ print_stats(void) static void signal_handler(int signum) { - if (signum == SIGINT || signum == SIGTERM) { - fprintf(stderr, "\nSignal %d received, preparing to exit...\n", - signum); -#ifdef RTE_LIB_PDUMP - /* uninitialize packet capture framework */ - rte_pdump_uninit(); -#endif -#ifdef RTE_LIB_LATENCYSTATS - if (latencystats_enabled != 0) - rte_latencystats_uninit(); -#endif - force_quit(); - /* Set flag to indicate the force termination. */ - f_quit = 1; - /* exit with the expected status */ -#ifndef RTE_EXEC_ENV_WINDOWS - signal(signum, SIG_DFL); - kill(getpid(), signum); -#endif - } + fprintf(stderr, "\nSignal %d %s received, preparing to exit...\n", + signum, strsignal(signum)); + + /* Set flag to indicate the force termination. */ + f_quit = 1; } int @@ -4449,9 +4435,6 @@ main(int argc, char** argv) } else #endif { - char c; - int rc; - f_quit = 0; printf("No commandline core given, start packet forwarding\n"); @@ -4476,15 +4459,37 @@ main(int argc, char** argv) prev_time = cur_time; rte_delay_us_sleep(US_PER_S); } - } + } else { + char c; + fd_set fds; - printf("Press enter to exit\n"); - rc = read(0, &c, 1); - pmd_test_exit(); - if (rc < 0) - return 1; + printf("Press enter to exit\n"); + + FD_ZERO(&fds); + FD_SET(0, &fds); + + if (select(1, &fds, NULL, NULL, NULL) <= 0) { + fprintf(stderr, "Select failed: %s\n", + strerror(errno)); + } else if (read(0, &c, 1) <= 0) { + fprintf(stderr, + "Read stdin failed: %s\n", + strerror(errno)); + } + } + stop_packet_forwarding(); + force_quit(); } +#ifdef RTE_LIB_PDUMP + /* uninitialize packet capture framework */ + rte_pdump_uninit(); +#endif +#ifdef RTE_LIB_LATENCYSTATS + if (latencystats_enabled != 0) + rte_latencystats_uninit(); +#endif + ret = rte_eal_cleanup(); if (ret != 0) rte_exit(EXIT_FAILURE, -- 2.35.1