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 C3142A034C; Wed, 9 Nov 2022 18:29:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67D88400EF; Wed, 9 Nov 2022 18:29:34 +0100 (CET) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mails.dpdk.org (Postfix) with ESMTP id 991B5400D4 for ; Wed, 9 Nov 2022 18:29:32 +0100 (CET) Received: by mail-pg1-f170.google.com with SMTP id 136so12940005pga.1 for ; Wed, 09 Nov 2022 09:29:31 -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=EWs2h2AVpbW+D66JG0B2VmqTu6a5Y2u/SZZIry8hN7Y=; b=3BvyyxWy20Xp6ENGI8FgyWVhzfdmM72Kn3VsAyir6AgC18bpmHAjOpxbQae/WUh7So kkP063a3jfWmzQHUxpoxIG3ixalrrg0trKS23disHZWjv+LTDrZW/GMC4exBUSpkD5ey sAk9JUXx3svBl6Yq5icLFx5+9VjUo4uY3yImUMLoiWJnFtdBN9AqIdro4CQ/kQC22Bap mDaNPV3TjItPEHYppI1GkN5w9sOOx0+1qGvJqDraHNHPFBzbkcjxTANFufUrtaJChZjw vBVttiL9fgjvM8v33DcXd5IZZD3AZIwUAYxn07+L1JFhcgYNKJJnBaJjlN/+ph8/Zc48 AIcA== 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=EWs2h2AVpbW+D66JG0B2VmqTu6a5Y2u/SZZIry8hN7Y=; b=hGBIxWwHR16BWia3oVwy689I01qch96knSeDQ3pYXgSTXKz93Tx/VdYh2R2TcCJ/Em Z4EZZCnvriI/rdye5yHIhOEbOIiZb54Gj2f/+B8rOfZMa0CrC//c0vaOyOPzafPh4o30 ESXyG5qhvkqae6IlhFi0HtmBMknFR51fNfyLIAB8c5DCmFpXvB3emInkfu6mAL6HYt3o GFIn9D7NX3jeW05UoMXZ1w376sa42yZ095E4QfOeWIYaTxN1fFLMWDW3CWYyMyiLB59b dGiisi2zskCml2hS6VgQSje8ZbH75Q5kV9zgCxQww6mLGkturq3lIm8JB/kkE7kQ8RuW LJyQ== X-Gm-Message-State: ANoB5pmsnw+KBjmRXzMCNkrorejbixmiKIVFVZObmpcpKxciX4rjvAOc nZZ8i6heiwiUt1jJpIF1lPf1TQ8pFPuBXw== X-Google-Smtp-Source: AA0mqf42c/l84P3d6ifou3stTDETRIbyoIVLTJztSl8M2Cld1nU7dGIHv3Qw1SqggZI72KTaXfT+mw== X-Received: by 2002:a63:5d46:0:b0:470:942a:e7f8 with SMTP id o6-20020a635d46000000b00470942ae7f8mr6461206pgm.61.1668014970692; Wed, 09 Nov 2022 09:29:30 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id u12-20020a170902714c00b001888a46e2d0sm4122466plm.162.2022.11.09.09.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 09:29:29 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: phil.yang@arm.com, Stephen Hemminger Subject: [PATCH v5] testpmd: cleanup cleanly from signal Date: Wed, 9 Nov 2022 09:29:27 -0800 Message-Id: <20221109172927.71411-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 --- v5 - fix build on Windows. Windows has select() function but the prototype is in winsock.h not sys/select.h 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..be8fa7f0a0b1 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -11,6 +11,7 @@ #include #ifndef RTE_EXEC_ENV_WINDOWS #include +#include #endif #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 received, preparing to exit...\n", + 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