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 2001BA09ED; Sat, 12 Nov 2022 18:28:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D66034014F; Sat, 12 Nov 2022 18:28:45 +0100 (CET) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by mails.dpdk.org (Postfix) with ESMTP id 70E364003F for ; Sat, 12 Nov 2022 18:28:44 +0100 (CET) Received: by mail-pg1-f175.google.com with SMTP id h193so6797611pgc.10 for ; Sat, 12 Nov 2022 09:28:44 -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=XilB93DzxBxLEs+oVntoYpUg6SBxlDH7a9Dp5niwC28=; b=2sGp4ArAKbSgTT8KJibe4Tv9Cql1kS2OvMwPYmleJ3mfNeyEc6e4fOi4ov/XhENyX4 CMRY9UgpCgYXVdX+12MLxTHm+FyymKFPkrgqhpfbj+z9s0Pf/GqC/zOQqZrLZqDlrIeo wq9gn9gvnqTwY64PuoRLdmdXGwcoIZcrTBgus3IG/d2/j0tgnVqSQLoAIQzMULhsU/e6 qx5x+Evd40Rvh5CKuv7/7HuPLwPuZLLKWGf036LDIZ09q2v20/hT6ljNTjweP55HYKZZ QDimTIx/WrmaLBNpMcfbnC2hyJLKHm9mN/HHUrs0b63PMTDOkVUMCjEdpHtHQ8JmJ8Sy Sk2w== 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=XilB93DzxBxLEs+oVntoYpUg6SBxlDH7a9Dp5niwC28=; b=te05QysdyJ535IBjwkS8MG0tqGfTch54ETeATSEEPbzRwr9uYiVh3AkW/rnzWqw9E2 JqrJ/42s2XStp4I9vkJrpVobcQ2Nx1p+572yb4hAObVVElCrzPcigL4oVnGp6/ZItBsa +AEBH+p+Bj54syMo92uAN3QyHXQ7lzgLb7SYfcX9MfXCfagsjn0fiG6qIic6NEPebxWO RlFh8waOT5f3mbFqDY0/BZqei1HATzcueGqjmYw5f+yh1oTD5lP37qMCb4A2kdB9Z4Qd TiCTzJkg44ebBkg6C1zTQAXm91dykWkIt59r+1sLxRvKUr8tekQxkZkBTbxOSRD4rqGw X72g== X-Gm-Message-State: ANoB5pk6cOKhUXpXPLRXSoLuCNAiRN4t4lSoRIgx5NZaxqsNDgKmpfLq L33XgrfDDxGrcZHyFz0mtrGi9jdidnNB7w== X-Google-Smtp-Source: AA0mqf7EUmnbGiXwqqlSBxJAKtoVUsytQuSbEAYs4PZocxN3CmsonROvnWBaaO/kwpTrgaJs+U9chg== X-Received: by 2002:a63:5307:0:b0:45b:f8be:7402 with SMTP id h7-20020a635307000000b0045bf8be7402mr5832709pgb.484.1668274122922; Sat, 12 Nov 2022 09:28:42 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id k2-20020a628402000000b0056bd4ec964csm3551016pfd.194.2022.11.12.09.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 09:28:42 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh , Yuying Zhang , Phil Yang , Jianbo Liu Subject: [PATCH v8] testpmd: cleanup cleanly from signal Date: Sat, 12 Nov 2022 09:28:39 -0800 Message-Id: <20221112172839.70087-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 the problem where a signal could be received in the middle of a PMD and then the signal handler would call PMD's close routine leading to locking problems. An added benefit is it gets rid of some Windows specific code. Fixes: d9a191a00e81 ("app/testpmd: fix quitting in container") Signed-off-by: Stephen Hemminger --- v8 - fix build on Windows (again) Windows doesn't have FILENO_STDIN app/test-pmd/testpmd.c | 67 +++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index aa7ea29f15ba..b4fb6a2bcbcf 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 @@ -4224,13 +4225,6 @@ init_port(void) memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS); } -static void -force_quit(void) -{ - pmd_test_exit(); - prompt_exit(); -} - static void print_stats(void) { @@ -4249,28 +4243,9 @@ print_stats(void) } static void -signal_handler(int signum) +signal_handler(int signum __rte_unused) { - 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 - } + f_quit = 1; } int @@ -4449,9 +4424,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 +4448,38 @@ 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"); + + FD_ZERO(&fds); + FD_SET(0, &fds); - printf("Press enter to exit\n"); - rc = read(0, &c, 1); + ret = select(1, &fds, NULL, NULL, NULL); + if (ret < 0 && errno != EINTR) + rte_exit(EXIT_FAILURE, + "Select failed: %s\n", + strerror(errno)); + + if (ret == 1 && read(0, &c, 1) < 0) + rte_exit(EXIT_FAILURE, + "Read failed: %s\n", + strerror(errno)); + } pmd_test_exit(); - if (rc < 0) - return 1; } +#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