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 91017458EB for ; Mon, 2 Sep 2024 21:50:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 79C8C40E1C; Mon, 2 Sep 2024 21:50:30 +0200 (CEST) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mails.dpdk.org (Postfix) with ESMTP id 353C640E1C for ; Mon, 2 Sep 2024 21:50:29 +0200 (CEST) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71744362c22so1523359b3a.2 for ; Mon, 02 Sep 2024 12:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1725306628; x=1725911428; darn=dpdk.org; 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=EQHwMrbulkpzslhvHhQgg/tQ06KO2mwohVZJ9Jn0QYU=; b=wu5MlOoBpFmd/i+Ti6FtsbIwMgf86wikR4JB72zdejoFVindG2IAmHCl24v1NdttdI 6scIgCbenAmcTAhTNnivDbeLUI1kHszGAhDWLMk4YuD6EhKW1s8qnKoBai63hPg781sl +xZBrxVpzEM0QILJ35BH5TF5N4NntWNq2BONKM3uus6ATJpZQqCe8fglSdCnE2RJbrnB dZLj5ZJ92JlWnH0eta8MQxKNJ98z5zvgA1Oe5GcBSqRhRoUEpPeY0jxSbV0jMcWKJC1q 3NsgsZaTCaGVjkgJunq8pztTc9YgAAS7LLTgwI+LzaxQMyZ1hiAHSjwO5i9nlswRDCWI dRlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725306628; x=1725911428; 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=EQHwMrbulkpzslhvHhQgg/tQ06KO2mwohVZJ9Jn0QYU=; b=NFOesV+w93S7W4byQusJysrKgKNXJZ5M+dysBrLM/jyL6nx9u/5kJSWZXi0IIUh7MK gUcMg9R4eYzRXXv4nkwR4oyOXmgYiNzsZf7F3Vle1EAMVLAJUJ+JXjRngRRxELsbgCyx hMsgViN7TnSf60vImatlqpeXNvORsTCBTMBbuNYXYX9iFckCMQjXYJdksQ5i5PW/ZQWp zB+BdyhMmaPeUEWlCyXEjCBasT8Q72fqp2cUTCSgXwRdPF1MJQwAXCkXaEercYpHKB/t ZIp4kca/Cv1q+CcF70yGTR+GX2x9QDS3xwGzzhE8ZvVo2X3Qoh2+AGuY8aAIK4Q+mcPo Ft5A== X-Forwarded-Encrypted: i=1; AJvYcCUA24nlISBFVujDdRPyvBMwi4x0oekmyxuJcy/PxfNFBDhW53PcG/qBQbMZmOSPVXzFBgiUMX8=@dpdk.org X-Gm-Message-State: AOJu0YzbYd5vm7SQZ/euSpdo/l9jOFTLFBKe81dNUBla8AFK5lPFTIOW spWP8Bs9HjGUxNgN0lOh20f9jJRdSNh+dmiatmiwk6LiSzLQEAg7y1KwzVIPvn/8k19at4d9D9B gaPvUVQ== X-Google-Smtp-Source: AGHT+IHj/x9ysnb6QYogDYuMxBycHsa9t1W7kfiq1pac+HEQwQxQ9hHIY0aP9t7Lf6zN2N5dJTEcXA== X-Received: by 2002:a05:6a21:3414:b0:1cc:d7fa:6ea6 with SMTP id adf61e73a8af0-1cce1097977mr13263683637.35.1725306628163; Mon, 02 Sep 2024 12:50:28 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205e970d0b6sm8449975ad.214.2024.09.02.12.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 12:50:27 -0700 (PDT) From: Stephen Hemminger To: Kevin Traynor Cc: Stephen Hemminger , stable@dpdk.org, Olivier Matz Subject: [PATCH v2 3/3] app/testpmd: fix interactive mode on Windows Date: Mon, 2 Sep 2024 12:47:55 -0700 Message-ID: <20240902194909.132478-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240902194909.132478-1-stephen@networkplumber.org> References: <20240902194909.132478-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org The cmdline_poll() function is broken and was not fully tested, go back to using cmdline_interact(). Instead, use sigaction() to cancel read character on Unix OS's and a new helper to cancel I/O on Windows. Bugzilla ID: 1180 Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger Acked-by: Olivier Matz (cherry picked from commit f1d0993e034e39968a2c80a8561b46c260c27487) --- app/test-pmd/cmdline.c | 27 ++++++++++++++------------- 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, 50 insertions(+), 14 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index eeca7171a7..781b7ce0db 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -70,6 +70,8 @@ static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); +static struct cmdline *testpmd_cl; + /* *** Help command with introduction. *** */ struct cmd_help_brief_result { cmdline_fixed_string_t help; @@ -18039,30 +18041,29 @@ 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; - /* initialize non-constant commands */ cmd_set_fwd_mode_init(); cmd_set_fwd_retry_mode_init(); - 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); } static void diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index bade1feba4..fbfc090d68 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -4321,6 +4321,7 @@ static void signal_handler(int signum __rte_unused) { f_quit = 1; + prompt_exit(); } int @@ -4331,8 +4332,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 5600f012c2..d0601d69f4 100644 --- a/lib/cmdline/cmdline.c +++ b/lib/cmdline/cmdline.c @@ -175,6 +175,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 64a945a34f..9a4ec4e334 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 73ed9ba290..80863bfc8a 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 a3271c7693..86a46cdea6 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.45.2