[v4,2/2] testpmd: enable interrupt in interactive mode

Message ID 20230315173132.4044-3-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series Fix testpmd interrupt regression |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Stephen Hemminger March 15, 2023, 5:31 p.m. UTC
  The setting in terminal handling for both Unix style and
Windows was not ensuring that Ctrl-C character would
cause interrupt.

This is a first release bug. Testpmd interactive mode has
always disabled control-c handling on Linux.

Fixes: af75078fece3 ("first public release")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/cmdline/cmdline_os_unix.c    | 3 ++-
 lib/cmdline/cmdline_os_windows.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
  

Comments

Olivier Matz March 17, 2023, 4:20 p.m. UTC | #1
On Wed, Mar 15, 2023 at 10:31:32AM -0700, Stephen Hemminger wrote:
> The setting in terminal handling for both Unix style and
> Windows was not ensuring that Ctrl-C character would
> cause interrupt.
> 
> This is a first release bug. Testpmd interactive mode has
> always disabled control-c handling on Linux.

This was a design choice, not a bug. This design choice is discussable
today (at that time, dpdk was also running in baremetal without signals
or interrupt). The idea was to behave like a shell, i.e. ctrl-c just
clears the current line.

We may want to change this behavior (I remember an old discussion where
Bruce stated that he would prefer ctrl-c to kill the program), but it
will have an impact on all cmdline users, so to me it has to be
announced.


> 
> Fixes: af75078fece3 ("first public release")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/cmdline/cmdline_os_unix.c    | 3 ++-
>  lib/cmdline/cmdline_os_windows.c | 4 ++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/cmdline/cmdline_os_unix.c b/lib/cmdline/cmdline_os_unix.c
> index 5f9839a15f98..356c5b3f3ca2 100644
> --- a/lib/cmdline/cmdline_os_unix.c
> +++ b/lib/cmdline/cmdline_os_unix.c
> @@ -16,7 +16,8 @@ terminal_adjust(struct cmdline *cl)
>  	tcgetattr(0, &cl->oldterm);
>  
>  	memcpy(&term, &cl->oldterm, sizeof(term));
> -	term.c_lflag &= ~(ICANON | ECHO | ISIG);
> +	term.c_lflag &= ~(ICANON | ECHO);
> +	term.c_lflag |= ISIG;
>  	tcsetattr(0, TCSANOW, &term);
>  
>  	setbuf(stdin, NULL);
> diff --git a/lib/cmdline/cmdline_os_windows.c b/lib/cmdline/cmdline_os_windows.c
> index 80863bfc8a00..8cff3b175747 100644
> --- a/lib/cmdline/cmdline_os_windows.c
> +++ b/lib/cmdline/cmdline_os_windows.c
> @@ -32,10 +32,10 @@ terminal_adjust(struct cmdline *cl)
>  		mode &= ~(
>  			ENABLE_LINE_INPUT |      /* no line buffering */
>  			ENABLE_ECHO_INPUT |      /* no echo */
> -			ENABLE_PROCESSED_INPUT | /* pass Ctrl+C to program */
>  			ENABLE_MOUSE_INPUT |     /* no mouse events */
>  			ENABLE_WINDOW_INPUT);    /* no window resize events */
> -		mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
> +		mode |= ENABLE_VIRTUAL_TERMINAL_INPUT |
> +			ENABLE_PROCESSED_INPUT; /* Ctrl C processed by the system */
>  		SetConsoleMode(handle, mode);
>  	}
>  
> -- 
> 2.39.2
>
  
Stephen Hemminger March 17, 2023, 4:25 p.m. UTC | #2
On Fri, 17 Mar 2023 17:20:59 +0100
Olivier Matz <olivier.matz@6wind.com> wrote:

> On Wed, Mar 15, 2023 at 10:31:32AM -0700, Stephen Hemminger wrote:
> > The setting in terminal handling for both Unix style and
> > Windows was not ensuring that Ctrl-C character would
> > cause interrupt.
> > 
> > This is a first release bug. Testpmd interactive mode has
> > always disabled control-c handling on Linux.  
> 
> This was a design choice, not a bug. This design choice is discussable
> today (at that time, dpdk was also running in baremetal without signals
> or interrupt). The idea was to behave like a shell, i.e. ctrl-c just
> clears the current line.
> 
> We may want to change this behavior (I remember an old discussion where
> Bruce stated that he would prefer ctrl-c to kill the program), but it
> will have an impact on all cmdline users, so to me it has to be
> announced.


Ok, my motivation was to be able to test interrupt in testpmd
interactive mode. Without this change, it requires sending SIGINT
from another process.  Plus almost all programs that have an
interactive mode accept control-c to interrupt.

I split this patch off since it doesn't impact the bugfix
around testpmd and interrupts.
  

Patch

diff --git a/lib/cmdline/cmdline_os_unix.c b/lib/cmdline/cmdline_os_unix.c
index 5f9839a15f98..356c5b3f3ca2 100644
--- a/lib/cmdline/cmdline_os_unix.c
+++ b/lib/cmdline/cmdline_os_unix.c
@@ -16,7 +16,8 @@  terminal_adjust(struct cmdline *cl)
 	tcgetattr(0, &cl->oldterm);
 
 	memcpy(&term, &cl->oldterm, sizeof(term));
-	term.c_lflag &= ~(ICANON | ECHO | ISIG);
+	term.c_lflag &= ~(ICANON | ECHO);
+	term.c_lflag |= ISIG;
 	tcsetattr(0, TCSANOW, &term);
 
 	setbuf(stdin, NULL);
diff --git a/lib/cmdline/cmdline_os_windows.c b/lib/cmdline/cmdline_os_windows.c
index 80863bfc8a00..8cff3b175747 100644
--- a/lib/cmdline/cmdline_os_windows.c
+++ b/lib/cmdline/cmdline_os_windows.c
@@ -32,10 +32,10 @@  terminal_adjust(struct cmdline *cl)
 		mode &= ~(
 			ENABLE_LINE_INPUT |      /* no line buffering */
 			ENABLE_ECHO_INPUT |      /* no echo */
-			ENABLE_PROCESSED_INPUT | /* pass Ctrl+C to program */
 			ENABLE_MOUSE_INPUT |     /* no mouse events */
 			ENABLE_WINDOW_INPUT);    /* no window resize events */
-		mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
+		mode |= ENABLE_VIRTUAL_TERMINAL_INPUT |
+			ENABLE_PROCESSED_INPUT; /* Ctrl C processed by the system */
 		SetConsoleMode(handle, mode);
 	}