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 BC566458BC for ; Sat, 31 Aug 2024 19:10:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B735C402D6; Sat, 31 Aug 2024 19:10:53 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id CAE07402A7 for ; Sat, 31 Aug 2024 19:10:50 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-201d5af11a4so25631445ad.3 for ; Sat, 31 Aug 2024 10:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1725124250; x=1725729050; 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=b0R5981mTN3VdC7ldOTyEi7nA2map0AaVZrd1XlpffU=; b=JIf/TU0qwZNKOInBIu6pS6edm3YpHTeZZ36+Uj6GCH2sHy9aj/imtt8wtC960/aA/x s9O/IiRKhclxthB95OwQBZ4RZZanLLVV/96Buf5s8HwYI4cYyzL8sa38vgtoCL4Da2m5 cpTDu+d/ayVM/ndWOQtlYGfoHNtQzn23uR4qnaAYv7sr2jo4/Vat+Hb+tQ2oekv8Vnkl UjUVLaIKZmny6tHvNYGzI45hmVX5i7mbr8WA+2GteBt6waGjxdCjt2Fk73u07h8Pv/Id cLDmm1JkM+DVI5TJN2WAFVj2ZpCGT7zSRWANKHx21SZ5Mn58i7A0nzzurgojmcGFhqQN WFdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725124250; x=1725729050; 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=b0R5981mTN3VdC7ldOTyEi7nA2map0AaVZrd1XlpffU=; b=Rpr6LGDjKRdcCWNP6+wwP6oDyK8X3trwmUqwzDpfXSYMYhQmLAOH+LWAYdpSz72q41 R+jXNCYyYiZbQav8t1jMeGfrXD+nw3TmCf7xAULJcRox7XWiO/c3ftJatzw6mNzuxZIw LC9YHyn/snHP/7zTqMXgbTi93DeccOK68SMRtHdHRI5VyiI/PZZr5m830Qv4uvp+Mji+ vwfjAdHh/I6I2TglBFlDzCvmhut+Qm73yoPeLzXMuRpJJEKy2QkatI971DtvhiGtX9DG qD96apcXIzqSdvhxN5zOqPQjUusuJT1Dyrc9WFdS2DTviRUdwJz1EjzzfTWyKn5H6GoJ lBZg== X-Forwarded-Encrypted: i=1; AJvYcCU9mK8tx7zPPzpzl2PgXNoUvT3GUrAJ6W0lUEUnMHXAQ9RVBcQi+D3A+9kDAVgEWZqZ1AH4480=@dpdk.org X-Gm-Message-State: AOJu0YzW5n9NxH66uPMs3JquFXseOJtVTtuQk1IcrEHCBskQ7BfH/PeI kFYQ/1m4kEWrL2kRVoEt6NLQB9cc1EVoViLY0fnvWmNkBTKIGrMivK2jQkItkQ0= X-Google-Smtp-Source: AGHT+IHwC/l9zXbl7GFFlX35dHp1kB6hxnBPp70kf8yvPYziHr5FPUd/t76g84v4d+Zm9gzmOc6Rjw== X-Received: by 2002:a17:903:18d:b0:1fd:a5a2:5838 with SMTP id d9443c01a7336-20545e44295mr30571535ad.6.1725124249928; Sat, 31 Aug 2024 10:10:49 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152cf12bsm43141735ad.83.2024.08.31.10.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Aug 2024 10:10:49 -0700 (PDT) From: Stephen Hemminger To: Kevin Traynor Cc: Stephen Hemminger , stable@dpdk.org, Olivier Matz Subject: [PATCH 5/5] app/testpmd: fix interactive mode on Windows Date: Sat, 31 Aug 2024 10:09:29 -0700 Message-ID: <20240831171035.27505-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240831171035.27505-1-stephen@networkplumber.org> References: <20240831171035.27505-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 6da5198ac7..126523117f 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; @@ -17979,30 +17981,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 1760dd79b8..27cd83ec74 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -4066,6 +4066,7 @@ static void signal_handler(int signum __rte_unused) { f_quit = 1; + prompt_exit(); } int @@ -4076,8 +4077,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