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 AB978A00C2; Tue, 8 Nov 2022 21:24:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4FB90400D7; Tue, 8 Nov 2022 21:24:48 +0100 (CET) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 28E2C400D4 for ; Tue, 8 Nov 2022 21:24:47 +0100 (CET) Received: by mail-pf1-f169.google.com with SMTP id q9so14790279pfg.5 for ; Tue, 08 Nov 2022 12:24:46 -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=870uPzUXh5Dp2Qnhph0auycsqTUMDEoIYM4nP6TK0T4=; b=lHWRiUgx58b/Zg4O8z0Wq3Zm7Nh1wQ5oqCWLCOkCsXXurGuhqiXZagTDoqBJAOjk/N jJPDM0oVCai+QVy38Yl0IoOXG8tM8DYDXzWeNPaWHRYMEO0wDNm/I/8hyhA7eKY2GHvI dup5KVjvnCe04OE4I5WevxPQZJgAvqcZgstWmUW+wOo6i7E4AEZmu7q3v2kz3R31SUOH EgPbFul/UoNLiW9na3APHcTG+PvaQCBod5P/cVSCsWkvm32uAgXixlWTDfmkYvSNeKaT 2+ygFPx8nen66U/w/tbH89PUoLkn1pFOo/gcNvV42UKuZeXihHSUynCaKIo/N0EqPYtQ WUOQ== 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=870uPzUXh5Dp2Qnhph0auycsqTUMDEoIYM4nP6TK0T4=; b=sDKmCWMgnTNT7vkjjthoJQmeIbSh2jQC1I+nKGhGzGEgfS+cgGH7WnJYqcs+K6sHDq XSWvf8nzUTe9c81b28pU/WRUxte+3YarggbHfuReSFMozAugBhkIshAKBjdNt3bd9jy2 5sP+WsW/EsKWKf+7l+DEzkswFrfjv37m9sxs8gXODkxPl68x0R9QQ+jIy9F0Tfwi4InE RpfedYyANrWDPM/79y60Lg1gviLSwXYJtqbcAZkfFNLFUhMgy/bI/Ryf/LVm5PCq4HIg Hm9TDSO86UyZjv7GT1EB2huGeGcjn2+P6TMOgyDLokOjX2jdYednqYcX3ngxoCRLzjcI 7JnQ== X-Gm-Message-State: ACrzQf2S4rhBVTq9DEJa1j/5V6EC9YY+yRD51KVaa4iy14ayguiRuoWV H3UXZauJ8vcCIf91ZdhzgRlPtjYHg+s5tg== X-Google-Smtp-Source: AMsMyM48+aXEIiiZwGo6WCDYWx6vdqLqy3cM0YZKzkib/OjJKnShxu17YKS/u6L50XnTJs+5IV9vqw== X-Received: by 2002:a63:6c48:0:b0:470:66d:d171 with SMTP id h69-20020a636c48000000b00470066dd171mr31430126pgc.3.1667939085753; Tue, 08 Nov 2022 12:24:45 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id k127-20020a632485000000b0046ffe3fea77sm6211207pgk.76.2022.11.08.12.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 12:24:44 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: phil.yang@arm.com, Stephen Hemminger Subject: [PATCH v3] testpmd: cleanup cleanly from signal Date: Tue, 8 Nov 2022 12:24:42 -0800 Message-Id: <20221108202442.80557-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 --- v3 - drop unnecessary poll.h that causes windows build failure app/test-pmd/testpmd.c | 57 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index cf5942d0c422..341788f5bc84 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -4251,26 +4251,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 +4265,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 +4466,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