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 A512D41E86; Mon, 13 Mar 2023 18:19:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8424540E03; Mon, 13 Mar 2023 18:19:12 +0100 (CET) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id 910B0406BC for ; Mon, 13 Mar 2023 18:19:10 +0100 (CET) Received: by mail-pl1-f172.google.com with SMTP id k2so5865768pll.8 for ; Mon, 13 Mar 2023 10:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1678727949; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5cD3Xxqcu8kCuVREzQHY62rxECppn8PuuEUqY1814ic=; b=hbYAhSR4tevzZfz5iIKAbgBe64Z6xGNp7sydwanP6zQdxua8Btaw+uupnEV6JUTpH3 Jlg/UiQKTwVmChK1GuDgD5EjfZoh6nwvJ/tmhSqTg/xcOtS4GEUko1PF/WbHOSxHRAcp YpN8GWC+ua5hAL3tBe+bn9R6LACpQhuKkE6iYIPM1uItLV77nZroIIUBSTc8JjiKy339 BQv9Pv4SSfBK8k+QeKedol570ru5KzKx+UmncfIuu4nzZIpShSIpjpBvToIb/MX6zXDu 2i0IwOT9hkUXW4ts7G30Z1ivaqO5iUJBy1HZBWOx417//0TNy/pQ5SHY8ioswvvg9gHN Xe9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678727949; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5cD3Xxqcu8kCuVREzQHY62rxECppn8PuuEUqY1814ic=; b=0VSQmXJzoOMbiOHX8LeR/+QFBB3kfjNYzWF5wxUvgtKqbrSU2MOTkhheu84EUH5Ayj FTaRo1ho5lq6KdyyUUaIKEpkSgJ84V2UsbChP5UnBtDNTjUz/nDEotVuVH4fjQUP9Zwr NoPmH1WmZHLS7NQMJjF7b5Qccgkno52eUfwU0eePklj8QAhlhm6leIP5tKr0MQ4J1Z0V pOSZycCnwBY5F/qWrnE/W+c8r4mbt1pSpHakMnjNT8NSalow+MX5g64OgvdE2AVMZ3/W 09DjVb2EKWb5/01SZVDHQZFOKq8WVwzti3pj0W6qcK8IqIF7iKl7ApvbrazxOHTROtiN mqNA== X-Gm-Message-State: AO0yUKUrtuZVN2RjZmea6SQr/hhtLsPXEKJYV4bixp1LBdQdt+M9lt/A kycJApf5A2wOlCXOWd5bK4ADRPBEhMQ1caZY5qo62w== X-Google-Smtp-Source: AK7set/ZWfWa5zi+e81XATtat/2xretOZ8pg4mSgjQ9MP9DxW3UblVN6+VIpXEHKw99y8/xMOf39XA== X-Received: by 2002:a17:902:e748:b0:19e:82d5:634c with SMTP id p8-20020a170902e74800b0019e82d5634cmr38510952plf.53.1678727949440; Mon, 13 Mar 2023 10:19:09 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id kx14-20020a170902f94e00b001a064cff3c5sm56427plb.43.2023.03.13.10.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 10:19:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh , Yuying Zhang , Olivier Matz , Ferruh Yigit Subject: [RFT] test-pmd: go back to using cmdline_interact Date: Mon, 13 Mar 2023 10:19:05 -0700 Message-Id: <20230313171905.67720-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 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 The cmdline library poll function is broken on Windows and was never tested, don't use it. Instead, use sigaction() to cancel read character on Unix OS's and a new helper to cancel I/O on Windows. Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal") Bugzilla ID: 1180 Signed-off-by: Stephen Hemminger --- app/test-pmd/cmdline.c | 27 ++++++++++++++------------- app/test-pmd/testpmd.c | 11 +++++++++++ lib/cmdline/cmdline.c | 16 ++++++++++++++++ lib/cmdline/cmdline.h | 1 + 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 6fa870dc329b..072437d9bfcf 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -66,6 +66,7 @@ #include "cmdline_tm.h" #include "bpf_cmd.h" +static struct cmdline *testpmd_cl; static cmdline_parse_ctx_t *main_ctx; static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head = TAILQ_HEAD_INITIALIZER(driver_commands_head); @@ -13028,26 +13029,26 @@ cmdline_read_from_file(const char *filename) printf("Read CLI commands from %s\n", filename); } +void +prompt_exit(void) +{ + cmdline_cancel(testpmd_cl); + cmdline_quit(testpmd_cl); +} + /* prompt function, called from main on MAIN lcore */ void prompt(void) { - struct cmdline *cl; - - cl = cmdline_stdin_new(main_ctx, "testpmd> "); - if (cl == NULL) + testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); + if (testpmd_cl == NULL) { + fprintf(stderr, + "Failed to create stdin based cmdline context\n"); return; - - /* loop until signal or quit command */ - while (f_quit == 0 && cl_quit == 0) { - int status = cmdline_poll(cl); - - if (status < 0 || status == RDLINE_EXITED) - break; } - cmdline_quit(cl); - cmdline_stdin_exit(cl); + cmdline_interact(testpmd_cl); + cmdline_stdin_exit(testpmd_cl); } void diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 2ce19ed47ab4..5cb6f9252395 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -4469,6 +4469,7 @@ static void signal_handler(int signum __rte_unused) { f_quit = 1; + prompt_exit(); } int @@ -4479,8 +4480,18 @@ main(int argc, char** argv) uint16_t count; int ret; +#ifdef RTE_EXEC_ENV_WINDOWS signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); +#else + /* Want read() not to be restarted on signal */ + struct sigaction action = { + .sa_handler = signal_handler, + }; + + sigaction(SIGINT, &action, NULL); + sigaction(SIGTERM, &action, NULL); +#endif testpmd_logtype = rte_log_register("testpmd"); if (testpmd_logtype < 0) diff --git a/lib/cmdline/cmdline.c b/lib/cmdline/cmdline.c index 8ad0690d8533..69b3d9827290 100644 --- a/lib/cmdline/cmdline.c +++ b/lib/cmdline/cmdline.c @@ -176,6 +176,22 @@ cmdline_quit(struct cmdline *cl) rdline_quit(&cl->rdl); } +void +cmdline_cancel(struct cmdline *cl) +{ + if (!cl) + return; + +#ifdef RTE_EXEC_ENV_WINDOWS + /* force the outstanding read on console to exit */ + if (cl->oldterm.is_console_input) { + HANDLE handle = (HANDLE)_get_osfhandle(cl->s_in); + + CancelIoEx(handle, NULL); + } +#endif +} + int cmdline_poll(struct cmdline *cl) { diff --git a/lib/cmdline/cmdline.h b/lib/cmdline/cmdline.h index b14355ef5121..7dac90cfe7eb 100644 --- a/lib/cmdline/cmdline.h +++ b/lib/cmdline/cmdline.h @@ -58,6 +58,7 @@ cmdline_get_rdline(struct cmdline *cl); int cmdline_poll(struct cmdline *cl); void cmdline_interact(struct cmdline *cl); +void cmdline_cancel(struct cmdline *cl); void cmdline_quit(struct cmdline *cl); #ifdef __cplusplus -- 2.39.2