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 17FB741E88; Mon, 13 Mar 2023 22:38:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EF9EC40ED4; Mon, 13 Mar 2023 22:38:35 +0100 (CET) Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by mails.dpdk.org (Postfix) with ESMTP id E77BB40E03 for ; Mon, 13 Mar 2023 22:38:34 +0100 (CET) Received: by mail-pj1-f45.google.com with SMTP id nn12so13384855pjb.5 for ; Mon, 13 Mar 2023 14:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1678743514; 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=bbBdI57pE2LvJUNp3xBmhxu5bFfcthps7U1wcl+tdjg=; b=Sy5XaUILK3J3k9lTqucU1EmcsSYUzCedQABS8RmSPFFcobnB0DHDb+2pmklI9iorbj +0lOiAOmrvfd2Z06D13LOw+fqfbzg2IHwxmseOoiGJt/ZbOVB64qsiWTvIMYdad9z9sz 1jvVPXl99To1Gg5+wyONc8xXjOoP+XOnh2SW85XBaEk4F18x8VbHSwt0qPBKspyVn1jU E6HzmOWV4e74phCs+XSpLouKM/mhjR0VHaLpun3OWy8MwFc2JdaZ3Dpw9SxEZKrHBBpZ c/IG0vEnW1bjVFY4UCl3liFWADjKyxXn8T5LzkdaqH8SfOiFAkavxP393DoqBNpVgBiY fOMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678743514; 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=bbBdI57pE2LvJUNp3xBmhxu5bFfcthps7U1wcl+tdjg=; b=ACia4YfveNWZlxO1pU61vWzr+qoJLq2u1Ubq3wnH8iv0XjRYWo0vE4EmfahDOYEaOC QBa9JSSwiIcHXkG5vR1fmy5SW1HoUrMBTu+4ASxAezZ5ucwS5tDfWbRWS1rNup2OzoQD TCFZUauaCE1dEDf4BnwYP+9Lq02xRty+2qxrbOJC2lJUginAVCKJzmstntmPgqK/fU65 XMRnasiQcsFSLwYzyNfT5Si/W4mtbAxZhH4PY9bSa41pv1KV1KBOfVypZTVZ2tMCwvnX PBduwLvxo6RZN/Bdsg2YrpVjx4dh8KJchiJHAEClDX79rPUqRQH2xnlG9+rMI4r1sJZI F/pw== X-Gm-Message-State: AO0yUKVpFeKm3kHiN7nB7FjT+6aPVEV5lKCyYnec+G2AjYc5mbpgKPW9 6GGp50Qo0CQ9MLDdyqq3+h4ONDEDJl+OsY/jmsu7EQ== X-Google-Smtp-Source: AK7set8TjGgdroQjTG2qZu8+DgnBcyMeT6KdYGlMzYr7aaCpDXzY/6Y27Tp14TdqaKQSmE19It2qDQ== X-Received: by 2002:a17:90a:b88d:b0:23b:89df:4cf4 with SMTP id o13-20020a17090ab88d00b0023b89df4cf4mr6080848pjr.42.1678743513612; Mon, 13 Mar 2023 14:38:33 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id kr13-20020a170903080d00b0019f11caf11asm304143plb.166.2023.03.13.14.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 14:38:33 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFT v2] test-pmd: go back to using cmdline_interact Date: Mon, 13 Mar 2023 14:38:31 -0700 Message-Id: <20230313213831.80071-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313171905.67720-1-stephen@networkplumber.org> References: <20230313171905.67720-1-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 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. Signed-off-by: Stephen Hemminger --- v2 - make cmdline_cancel an exposed API app/test-pmd/cmdline.c | 27 ++++++++++++++------------- app/test-pmd/testpmd.c | 11 +++++++++++ lib/cmdline/cmdline.h | 10 ++++++++++ lib/cmdline/cmdline_os_unix.c | 5 +++++ lib/cmdline/cmdline_os_windows.c | 14 ++++++++++++++ lib/cmdline/version.map | 3 +++ 6 files changed, 57 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.h b/lib/cmdline/cmdline.h index b14355ef5121..2a1721cf9712 100644 --- a/lib/cmdline/cmdline.h +++ b/lib/cmdline/cmdline.h @@ -60,6 +60,16 @@ int cmdline_poll(struct cmdline *cl); void cmdline_interact(struct cmdline *cl); void cmdline_quit(struct cmdline *cl); + +/** + * This function causes the read() in cmdline_interact to exit. + * + * @param cl + * The command line object. + */ +__rte_experimental +void cmdline_cancel(struct cmdline *cl); + #ifdef __cplusplus } #endif diff --git a/lib/cmdline/cmdline_os_unix.c b/lib/cmdline/cmdline_os_unix.c index 755a6141546d..356c5b3f3ca2 100644 --- a/lib/cmdline/cmdline_os_unix.c +++ b/lib/cmdline/cmdline_os_unix.c @@ -52,3 +52,8 @@ cmdline_vdprintf(int fd, const char *format, va_list op) { return vdprintf(fd, format, op); } + +void +cmdline_cancel(__rte_unused struct cmdline *cl) +{ +} diff --git a/lib/cmdline/cmdline_os_windows.c b/lib/cmdline/cmdline_os_windows.c index be11409029a2..8cff3b175747 100644 --- a/lib/cmdline/cmdline_os_windows.c +++ b/lib/cmdline/cmdline_os_windows.c @@ -203,3 +203,17 @@ cmdline_vdprintf(int fd, const char *format, va_list op) return ret; } + +void +cmdline_cancel(struct cmdline *cl) +{ + if (!cl) + return; + + /* 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); + } +} diff --git a/lib/cmdline/version.map b/lib/cmdline/version.map index e3d59aaf8d61..a8a417cd6ff1 100644 --- a/lib/cmdline/version.map +++ b/lib/cmdline/version.map @@ -84,5 +84,8 @@ EXPERIMENTAL { # added in 22.07 cmdline_parse_check; + # added in 23.03 + cmdline_cancel; + local: *; }; -- 2.39.2