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 4C137A00C2; Tue, 8 Nov 2022 19:53:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E0FB1400D7; Tue, 8 Nov 2022 19:53:51 +0100 (CET) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id 51ACC400D4 for ; Tue, 8 Nov 2022 19:53:51 +0100 (CET) Received: by mail-pf1-f172.google.com with SMTP id y203so14605186pfb.4 for ; Tue, 08 Nov 2022 10:53:51 -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=xEjfjx4nOFLt0nY60iOIzNaKUgeF8TALEm7rTrjVntA=; b=p73NU8YXpW9uzNQ97knd3gcUZBeq8C3uwBGeDGo5JPw8tfEe9ZMxWx61Len0dwdJ8a +KplE4dvNhlHH2t4MCFuOrWgJIbIpVoNzgXRO1mvwBGCwNkad2m2OgtS7ho2mQflHpDm GtXG16y7hnrET2tEjgwvGFnpc2YuDLrnMbXHzS7WKMuuxugQIg8AH+9byr8ExjlxEcPz bkyPHsWARST3kmTvFEWvMeDqZ0EaTgmTbyVngltYB75we1uHyURy6G3UOMApQVZwV36I w9YxQgx1o6JahO6JqmWZTio5JXEQVZ+nJMFL081EnFTmyrCtkGdK3O7pyNYuSuRhQ8gf ZqwQ== 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=xEjfjx4nOFLt0nY60iOIzNaKUgeF8TALEm7rTrjVntA=; b=3x92wgqWCHD5wmD2Y8OAwIAlEsv1XxBnX2tJvHhec4lnHNEGR74dhTE32IO8Qo/ecO hzSZkNlqS6WKKr3HRcmTdgYObaB/XkEePECCCGwPM/4egTKLYumBiRIYeJjfECJdZlRP FnqUwmBj7G1pkVz5lS3mOgHZSHCLs+0dmRqOXz+eOcr4uV1pf6+k3xX08o3ypp6dPxM4 puLKizdvVxPu4X9qduw3J4+TNJKEIszasw3TrugOxHPHbxw9jmkepd6cojNr5cb7KL4S 95yLVpXwfd3YI0CfcJgySIUqIXe32uDmsvGiP1ukH7Z9ij2/+T0o4Zwrv5xmiMTDdfZ8 aOeQ== X-Gm-Message-State: ACrzQf0taH4ImLzplD6Pi2RwI64DGgHj+oG/CWIDieslH25a9P4C9fv3 LikLa56cXTqQ9PWk5DTM+KlRKQjPEORQxw== X-Google-Smtp-Source: AMsMyM4eS3WINnVH9nM6AqJjH+bKDkWsPM9KletMqp8MDWwJouGuUwLBCZMeypUQIOjPJBBZdJoo3w== X-Received: by 2002:a65:604c:0:b0:46f:a98a:5ac3 with SMTP id a12-20020a65604c000000b0046fa98a5ac3mr44487093pgp.473.1667933629987; Tue, 08 Nov 2022 10:53:49 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id 186-20020a6205c3000000b0052d4b0d0c74sm6687727pff.70.2022.11.08.10.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 10:53:49 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: phil.yang@arm.com, Stephen Hemminger Subject: [PATCH v2] testpmd: cleanup cleanly from signal Date: Tue, 8 Nov 2022 10:53:46 -0800 Message-Id: <20221108185346.78676-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 clean shutdown of testpmd when a signal is received. Instead of having testpmd commit suicide when a signal is received, do a clean shutdown. 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. Fixes: d9a191a00e81 ("app/testpmd: fix quitting in container") Signed-off-by: Stephen Hemminger --- v2 - use sigaction() instead of poll() to handle interrupted read app/test-pmd/testpmd.c | 58 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index cf5942d0c422..29b17d7d6d82 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -15,6 +15,7 @@ #include #include #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 @@ -4280,9 +4266,14 @@ main(int argc, char** argv) portid_t port_id; uint16_t count; int ret; + struct sigaction sa = { + .sa_handler = signal_handler, + .sa_flags = 0, + }; - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); + /* Want read() to be interrupted not restarted */ + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); testpmd_logtype = rte_log_register("testpmd"); if (testpmd_logtype < 0) @@ -4476,15 +4467,26 @@ main(int argc, char** argv) prev_time = cur_time; rte_delay_us_sleep(US_PER_S); } + } else { + printf("Press enter to exit\n"); + rc = read(0, &c, 1); + if (rc < 0 && errno != EINTR) + fprintf(stderr, "Read stdin failed: %s\n", + strerror(errno)); } - - printf("Press enter to exit\n"); - rc = read(0, &c, 1); - pmd_test_exit(); - if (rc < 0) - return 1; + 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