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 57CBC41EBE; Fri, 17 Mar 2023 17:59:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4A0D342F98; Fri, 17 Mar 2023 17:59:46 +0100 (CET) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id 2E0B740395 for ; Fri, 17 Mar 2023 17:59:45 +0100 (CET) Received: by mail-pj1-f51.google.com with SMTP id gp15-20020a17090adf0f00b0023d1bbd9f9eso9830407pjb.0 for ; Fri, 17 Mar 2023 09:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1679072384; 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=DmdqsW8ZwbTUatBXYPHtVcLW763TIQAYTLOdhKI2rV0=; b=NNRM/BG+GdzG/yNm6yNtBxUBauQW2XGU71Upz5MA/vTQDOiIE4nf9i9KNPOMR8+sry DAd0PBXvFa8SwwFIQO+3F93ZiQ4O0h315U/WPbkUv74hmaFFIzL+oKFu51aROoc6ytwt wvYAYQQeJa/2RWTQrI7C1OpzR8xKYwcSJg9jMO/vFZe8pEwh2fry/7NSNpOfwfgRFz3N XBx+VIVcvtOEFa42aiyCKm/7G/Nsw8RiNTsDDid9oLoGqvtKclA6gHgirdQJCCQZUDKn lSwlZCj0akXVbmyFo3EhcsUn59RCluhkbLeYIFintYS/X0xDvXWyusr0k11U8YnM3tmQ hxOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679072384; 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=DmdqsW8ZwbTUatBXYPHtVcLW763TIQAYTLOdhKI2rV0=; b=hXs79g9eUIoAf1hx7G6lRdq/M8FZJpDJ6lznjqY3eMjxkkb5gVIdEnZOCeaT7m+xRm 24SNP6oCJTTnNmHqAuEj6ej4M2Y8KYXpJq2qAZCbJm0NpRETTSUMIZ2xrjACmQ2bx/TY +DMbx4ursPF+HJ1rXojNZxY/Pjuvp9UtVlrQFVy1hkB1W9/HGlJ9dbYx1JyE4Mc9SpLv FFGRKeypMYy7sxe8HSkKTF8sdKI3kbZcjYSGF+U+WQHKzfMANwQH19MC1b1vXdVnZdRn ESaH02rqdIynMEWaimfz7pLGW8kdCmS+W4GcwTASMWuEi3wiKX/utg5giRm+4TcDjPe8 oXCQ== X-Gm-Message-State: AO0yUKVzMeN20ag//f+oqWnbga6IAHEfcEv90zZrsL1n6nd4yfxuuSRk 5JyGC8GTMCj/omMdJ88v1akOjIJ8/2IjqwaKE+n7Hr3o X-Google-Smtp-Source: AK7set8zafXCZJ/gJnn/myFceYk5kfOSLVFjXBaf7QfNi+MmVJz4djfTusXtqvGYQIvyPnjVe4bjyA== X-Received: by 2002:a05:6a20:4e26:b0:d7:a352:ffa0 with SMTP id gk38-20020a056a204e2600b000d7a352ffa0mr3171603pzb.62.1679072383921; Fri, 17 Mar 2023 09:59:43 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id n21-20020a62e515000000b0058bc60dd98dsm1805584pff.23.2023.03.17.09.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 09:59:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh , Yuying Zhang , Olivier Matz , Ferruh Yigit Subject: [PATCH v5] testpmd: go back to using cmdline_interact Date: Fri, 17 Mar 2023 09:59:41 -0700 Message-Id: <20230317165941.62619-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_poll() function is broken and was not fully 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 --- v5 - Do not need to expose cmdline_cancel() as user api can make cmdline_quit() do it. Change to control C handling is separate issue and should be discussed more. app/test-pmd/cmdline.c | 26 +++++++++++++------------- app/test-pmd/testpmd.c | 11 +++++++++++ lib/cmdline/cmdline.c | 1 + lib/cmdline/cmdline_os_unix.c | 6 ++++++ lib/cmdline/cmdline_os_windows.c | 14 ++++++++++++++ lib/cmdline/cmdline_private.h | 5 ++++- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 6fa870dc329b..7b20bef4e9ba 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,25 @@ cmdline_read_from_file(const char *filename) printf("Read CLI commands from %s\n", filename); } +void +prompt_exit(void) +{ + 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..355c7d8ca635 100644 --- a/lib/cmdline/cmdline.c +++ b/lib/cmdline/cmdline.c @@ -173,6 +173,7 @@ cmdline_quit(struct cmdline *cl) { if (!cl) return; + cmdline_cancel(cl); rdline_quit(&cl->rdl); } diff --git a/lib/cmdline/cmdline_os_unix.c b/lib/cmdline/cmdline_os_unix.c index 64a945a34fb3..9a4ec4e33477 100644 --- a/lib/cmdline/cmdline_os_unix.c +++ b/lib/cmdline/cmdline_os_unix.c @@ -51,3 +51,9 @@ cmdline_vdprintf(int fd, const char *format, va_list op) { return vdprintf(fd, format, op); } + +/* This function is not needed on Linux, instead use sigaction() */ +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 73ed9ba290b8..80863bfc8a00 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/cmdline_private.h b/lib/cmdline/cmdline_private.h index a3271c76934a..86a46cdea61a 100644 --- a/lib/cmdline/cmdline_private.h +++ b/lib/cmdline/cmdline_private.h @@ -24,7 +24,7 @@ #define RDLINE_HISTORY_MAX_LINE 64 struct rdline { - enum rdline_status status; + volatile enum rdline_status status; /* rdline bufs */ struct cirbuf left; struct cirbuf right; @@ -90,6 +90,9 @@ int cmdline_poll_char(struct cmdline *cl); /* Read one character from input. */ ssize_t cmdline_read_char(struct cmdline *cl, char *c); +/* Force current cmdline read to unblock. */ +void cmdline_cancel(struct cmdline *cl); + /* vdprintf(3) */ __rte_format_printf(2, 0) int cmdline_vdprintf(int fd, const char *format, va_list op); -- 2.39.2