[v2] app/testpmd: avoid exit without terminal restore

Message ID 20210125032953.430840-1-dapengx.yu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] app/testpmd: avoid exit without terminal restore |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance fail Performance Testing issues
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-testing warning Testing issues

Commit Message

Yu, DapengX Jan. 25, 2021, 3:29 a.m. UTC
  From: Dapeng Yu <dapengx.yu@intel.com>

In interactive mode, if testpmd exit by calling rte_exit without
restore terminal attributes, terminal will not echo keyboard input.

register a function with atexit() in prompt(), when exit() in
rte_exit() is called, the registered function restores terminal
attributes.

Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional configuration")
Cc: stable@dpdk.org

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
---
 app/test-pmd/cmdline.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
  

Comments

Li, Xiaoyun Jan. 26, 2021, 6:33 a.m. UTC | #1
Hi

> -----Original Message-----
> From: dapengx.yu@intel.com <dapengx.yu@intel.com>
> Sent: Monday, January 25, 2021 11:30
> To: Xing, Beilei <beilei.xing@intel.com>; Li, Xiaoyun <xiaoyun.li@intel.com>; Lu,
> Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard
> <bernard.iremonger@intel.com>; stephen@networkplumber.org
> Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
> Subject: [PATCH v2] app/testpmd: avoid exit without terminal restore
> 
> From: Dapeng Yu <dapengx.yu@intel.com>
> 
> In interactive mode, if testpmd exit by calling rte_exit without restore terminal
> attributes, terminal will not echo keyboard input.
> 
> register a function with atexit() in prompt(), when exit() in
> rte_exit() is called, the registered function restores terminal attributes.
> 
> Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional configuration")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> ---
>  app/test-pmd/cmdline.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index
> 89034c8b7..f7e18ba3d 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -17116,6 +17116,7 @@ cmdline_read_from_file(const char *filename)
> void
>  prompt(void)
>  {
> +	int ret;
>  	/* initialize non-constant commands */
>  	cmd_set_fwd_mode_init();
>  	cmd_set_fwd_retry_mode_init();
> @@ -17123,15 +17124,23 @@ prompt(void)
>  	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
>  	if (testpmd_cl == NULL)
>  		return;
> +
> +	ret = atexit(prompt_exit);
> +	if (ret != 0)
> +		printf("Cannot set exit function for cmdline\n");
> +
>  	cmdline_interact(testpmd_cl);
> -	cmdline_stdin_exit(testpmd_cl);
> +	if (ret != 0)

Why do you need to check ret here?
Even if registers prompt_exit failed, when users type "quit" and then break from cmdline_interact(), cmdline_stdin_exit() should be called to restore terminal settings.

> +		cmdline_stdin_exit(testpmd_cl);
>  }
> 
>  void
>  prompt_exit(void)
>  {
> -	if (testpmd_cl != NULL)
> +	if (testpmd_cl != NULL) {
>  		cmdline_quit(testpmd_cl);
> +		cmdline_stdin_exit(testpmd_cl);
> +	}
>  }
> 
>  static void
> --
> 2.27.0
  
Yu, DapengX Jan. 26, 2021, 7:13 a.m. UTC | #2
Hi Xiaoyun,

For this situation: registering prompt_exit succeed,  and user type "quit" command to exit testpmd.

If the second call to cmdline_stdin_exit is not excluded from the code conditionally, the cmdline_stdin_exit will be called twice;

1. the first time: in prompt()
    #0  cmdline_stdin_exit (cl=0x3638470) at ../lib/librte_cmdline/cmdline_socket.c:56
    #1  0x000000000051fb62 in prompt () at ../app/test-pmd/cmdline.c:17134
    #2  0x00000000005a4d0f in main (argc=2, argv=0x7fffffffda70) at ../app/test-pmd/testpmd.c:3849
2. the second time: in exit() .
    #0  cmdline_stdin_exit (cl=0x3638470) at ../lib/librte_cmdline/cmdline_socket.c:56
    #1  0x000000000051fb95 in prompt_exit () at ../app/test-pmd/cmdline.c:17142
    #2  0x00007ffff630fe9c in __run_exit_handlers () from /lib64/libc.so.6
    #3  0x00007ffff630ffd0 in exit () from /lib64/libc.so.6
    #4  0x00007ffff62f96aa in __libc_start_main () from /lib64/libc.so.6
    #5  0x00000000004ead2e in _start () 

-----Original Message-----
From: Li, Xiaoyun 
Sent: Tuesday, January 26, 2021 2:33 PM
To: Yu, DapengX <dapengx.yu@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard <bernard.iremonger@intel.com>; stephen@networkplumber.org
Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore

Hi

> -----Original Message-----
> From: dapengx.yu@intel.com <dapengx.yu@intel.com>
> Sent: Monday, January 25, 2021 11:30
> To: Xing, Beilei <beilei.xing@intel.com>; Li, Xiaoyun 
> <xiaoyun.li@intel.com>; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, 
> Bernard <bernard.iremonger@intel.com>; stephen@networkplumber.org
> Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
> Subject: [PATCH v2] app/testpmd: avoid exit without terminal restore
> 
> From: Dapeng Yu <dapengx.yu@intel.com>
> 
> In interactive mode, if testpmd exit by calling rte_exit without 
> restore terminal attributes, terminal will not echo keyboard input.
> 
> register a function with atexit() in prompt(), when exit() in
> rte_exit() is called, the registered function restores terminal attributes.
> 
> Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional 
> configuration")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> ---
>  app/test-pmd/cmdline.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 
> 89034c8b7..f7e18ba3d 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -17116,6 +17116,7 @@ cmdline_read_from_file(const char *filename) 
> void
>  prompt(void)
>  {
> +int ret;
>  /* initialize non-constant commands */  cmd_set_fwd_mode_init();  
> cmd_set_fwd_retry_mode_init(); @@ -17123,15 +17124,23 @@ prompt(void)  
> testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");  if (testpmd_cl 
> == NULL)  return;
> +
> +ret = atexit(prompt_exit);
> +if (ret != 0)
> +printf("Cannot set exit function for cmdline\n");
> +
>  cmdline_interact(testpmd_cl);
> -cmdline_stdin_exit(testpmd_cl);
> +if (ret != 0)

Why do you need to check ret here?
Even if registers prompt_exit failed, when users type "quit" and then break from cmdline_interact(), cmdline_stdin_exit() should be called to restore terminal settings.

> +cmdline_stdin_exit(testpmd_cl);
>  }
> 
>  void
>  prompt_exit(void)
>  {
> -if (testpmd_cl != NULL)
> +if (testpmd_cl != NULL) {
>  cmdline_quit(testpmd_cl);
> +cmdline_stdin_exit(testpmd_cl);
> +}
>  }
> 
>  static void
> --
> 2.27.0
  
Yu, DapengX Jan. 26, 2021, 7:44 a.m. UTC | #3
@Xiaoyun,
Add one more explanation.
even if registers prompt_exit failed, when users type "quit" and then break from cmdline_interact(), the ret check will not prevent cmdline_stdin_exit() to be called to restore terminal settings in this patch.

@Beilei
Can you give comment on this patch v2, so I can move on to resolve this issue related with this patch.

-----Original Message-----
From: Yu, DapengX 
Sent: Tuesday, January 26, 2021 3:13 PM
To: Li, Xiaoyun <xiaoyun.li@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard <bernard.iremonger@intel.com>; stephen@networkplumber.org
Cc: dev@dpdk.org; stable@dpdk.org
Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore

Hi Xiaoyun,

For this situation: registering prompt_exit succeed,  and user type "quit" command to exit testpmd.

If the second call to cmdline_stdin_exit is not excluded from the code conditionally, the cmdline_stdin_exit will be called twice;

1. the first time: in prompt()
    #0  cmdline_stdin_exit (cl=0x3638470) at ../lib/librte_cmdline/cmdline_socket.c:56
    #1  0x000000000051fb62 in prompt () at ../app/test-pmd/cmdline.c:17134
    #2  0x00000000005a4d0f in main (argc=2, argv=0x7fffffffda70) at ../app/test-pmd/testpmd.c:3849 2. the second time: in exit() .
    #0  cmdline_stdin_exit (cl=0x3638470) at ../lib/librte_cmdline/cmdline_socket.c:56
    #1  0x000000000051fb95 in prompt_exit () at ../app/test-pmd/cmdline.c:17142
    #2  0x00007ffff630fe9c in __run_exit_handlers () from /lib64/libc.so.6
    #3  0x00007ffff630ffd0 in exit () from /lib64/libc.so.6
    #4  0x00007ffff62f96aa in __libc_start_main () from /lib64/libc.so.6
    #5  0x00000000004ead2e in _start () 

-----Original Message-----
From: Li, Xiaoyun
Sent: Tuesday, January 26, 2021 2:33 PM
To: Yu, DapengX <dapengx.yu@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard <bernard.iremonger@intel.com>; stephen@networkplumber.org
Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore

Hi

> -----Original Message-----
> From: dapengx.yu@intel.com <dapengx.yu@intel.com>
> Sent: Monday, January 25, 2021 11:30
> To: Xing, Beilei <beilei.xing@intel.com>; Li, Xiaoyun 
> <xiaoyun.li@intel.com>; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, 
> Bernard <bernard.iremonger@intel.com>; stephen@networkplumber.org
> Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
> Subject: [PATCH v2] app/testpmd: avoid exit without terminal restore
> 
> From: Dapeng Yu <dapengx.yu@intel.com>
> 
> In interactive mode, if testpmd exit by calling rte_exit without 
> restore terminal attributes, terminal will not echo keyboard input.
> 
> register a function with atexit() in prompt(), when exit() in
> rte_exit() is called, the registered function restores terminal attributes.
> 
> Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional
> configuration")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> ---
>  app/test-pmd/cmdline.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 
> 89034c8b7..f7e18ba3d 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -17116,6 +17116,7 @@ cmdline_read_from_file(const char *filename) 
> void
>  prompt(void)
>  {
> +int ret;
>  /* initialize non-constant commands */  cmd_set_fwd_mode_init(); 
> cmd_set_fwd_retry_mode_init(); @@ -17123,15 +17124,23 @@ prompt(void) 
> testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");  if (testpmd_cl 
> == NULL)  return;
> +
> +ret = atexit(prompt_exit);
> +if (ret != 0)
> +printf("Cannot set exit function for cmdline\n");
> +
>  cmdline_interact(testpmd_cl);
> -cmdline_stdin_exit(testpmd_cl);
> +if (ret != 0)

Why do you need to check ret here?
Even if registers prompt_exit failed, when users type "quit" and then break from cmdline_interact(), cmdline_stdin_exit() should be called to restore terminal settings.

> +cmdline_stdin_exit(testpmd_cl);
>  }
> 
>  void
>  prompt_exit(void)
>  {
> -if (testpmd_cl != NULL)
> +if (testpmd_cl != NULL) {
>  cmdline_quit(testpmd_cl);
> +cmdline_stdin_exit(testpmd_cl);
> +}
>  }
> 
>  static void
> --
> 2.27.0
  
Li, Xiaoyun Jan. 26, 2021, 8:24 a.m. UTC | #4
Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>

> -----Original Message-----
> From: Yu, DapengX <dapengx.yu@intel.com>
> Sent: Tuesday, January 26, 2021 15:44
> To: Li, Xiaoyun <xiaoyun.li@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Lu,
> Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard
> <bernard.iremonger@intel.com>; stephen@networkplumber.org
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore
> 
> @Xiaoyun,
> Add one more explanation.
> even if registers prompt_exit failed, when users type "quit" and then break from
> cmdline_interact(), the ret check will not prevent cmdline_stdin_exit() to be
> called to restore terminal settings in this patch.
> 
> @Beilei
> Can you give comment on this patch v2, so I can move on to resolve this issue
> related with this patch.
> 
> -----Original Message-----
> From: Yu, DapengX
> Sent: Tuesday, January 26, 2021 3:13 PM
> To: Li, Xiaoyun <xiaoyun.li@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Lu,
> Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard
> <bernard.iremonger@intel.com>; stephen@networkplumber.org
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore
> 
> Hi Xiaoyun,
> 
> For this situation: registering prompt_exit succeed,  and user type "quit"
> command to exit testpmd.
> 
> If the second call to cmdline_stdin_exit is not excluded from the code
> conditionally, the cmdline_stdin_exit will be called twice;
> 
> 1. the first time: in prompt()
>     #0  cmdline_stdin_exit (cl=0x3638470)
> at ../lib/librte_cmdline/cmdline_socket.c:56
>     #1  0x000000000051fb62 in prompt () at ../app/test-pmd/cmdline.c:17134
>     #2  0x00000000005a4d0f in main (argc=2, argv=0x7fffffffda70) at ../app/test-
> pmd/testpmd.c:3849 2. the second time: in exit() .
>     #0  cmdline_stdin_exit (cl=0x3638470)
> at ../lib/librte_cmdline/cmdline_socket.c:56
>     #1  0x000000000051fb95 in prompt_exit () at ../app/test-
> pmd/cmdline.c:17142
>     #2  0x00007ffff630fe9c in __run_exit_handlers () from /lib64/libc.so.6
>     #3  0x00007ffff630ffd0 in exit () from /lib64/libc.so.6
>     #4  0x00007ffff62f96aa in __libc_start_main () from /lib64/libc.so.6
>     #5  0x00000000004ead2e in _start ()
> 
> -----Original Message-----
> From: Li, Xiaoyun
> Sent: Tuesday, January 26, 2021 2:33 PM
> To: Yu, DapengX <dapengx.yu@intel.com>; Xing, Beilei <beilei.xing@intel.com>;
> Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger, Bernard
> <bernard.iremonger@intel.com>; stephen@networkplumber.org
> Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
> Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore
> 
> Hi
> 
> > -----Original Message-----
> > From: dapengx.yu@intel.com <dapengx.yu@intel.com>
> > Sent: Monday, January 25, 2021 11:30
> > To: Xing, Beilei <beilei.xing@intel.com>; Li, Xiaoyun
> > <xiaoyun.li@intel.com>; Lu, Wenzhuo <wenzhuo.lu@intel.com>; Iremonger,
> > Bernard <bernard.iremonger@intel.com>; stephen@networkplumber.org
> > Cc: dev@dpdk.org; Yu, DapengX <dapengx.yu@intel.com>; stable@dpdk.org
> > Subject: [PATCH v2] app/testpmd: avoid exit without terminal restore
> >
> > From: Dapeng Yu <dapengx.yu@intel.com>
> >
> > In interactive mode, if testpmd exit by calling rte_exit without
> > restore terminal attributes, terminal will not echo keyboard input.
> >
> > register a function with atexit() in prompt(), when exit() in
> > rte_exit() is called, the registered function restores terminal attributes.
> >
> > Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional
> > configuration")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> > ---
> >  app/test-pmd/cmdline.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index
> > 89034c8b7..f7e18ba3d 100644
> > --- a/app/test-pmd/cmdline.c
> > +++ b/app/test-pmd/cmdline.c
> > @@ -17116,6 +17116,7 @@ cmdline_read_from_file(const char *filename)
> > void
> >  prompt(void)
> >  {
> > +int ret;
> >  /* initialize non-constant commands */  cmd_set_fwd_mode_init();
> > cmd_set_fwd_retry_mode_init(); @@ -17123,15 +17124,23 @@ prompt(void)
> > testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");  if (testpmd_cl
> > == NULL)  return;
> > +
> > +ret = atexit(prompt_exit);
> > +if (ret != 0)
> > +printf("Cannot set exit function for cmdline\n");
> > +
> >  cmdline_interact(testpmd_cl);
> > -cmdline_stdin_exit(testpmd_cl);
> > +if (ret != 0)
> 
> Why do you need to check ret here?
> Even if registers prompt_exit failed, when users type "quit" and then break from
> cmdline_interact(), cmdline_stdin_exit() should be called to restore terminal
> settings.
> 
> > +cmdline_stdin_exit(testpmd_cl);
> >  }
> >
> >  void
> >  prompt_exit(void)
> >  {
> > -if (testpmd_cl != NULL)
> > +if (testpmd_cl != NULL) {
> >  cmdline_quit(testpmd_cl);
> > +cmdline_stdin_exit(testpmd_cl);
> > +}
> >  }
> >
> >  static void
> > --
> > 2.27.0
> 
>
  
Ferruh Yigit Jan. 29, 2021, 10:46 a.m. UTC | #5
On 1/26/2021 8:24 AM, Li, Xiaoyun wrote:

<...>

>>>
>>> From: Dapeng Yu <dapengx.yu@intel.com>
>>>
>>> In interactive mode, if testpmd exit by calling rte_exit without
>>> restore terminal attributes, terminal will not echo keyboard input.
>>>
>>> register a function with atexit() in prompt(), when exit() in
>>> rte_exit() is called, the registered function restores terminal attributes.
>>>
>>> Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional
>>> configuration")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
 >
> Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
> 
Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 89034c8b7..f7e18ba3d 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -17116,6 +17116,7 @@  cmdline_read_from_file(const char *filename)
 void
 prompt(void)
 {
+	int ret;
 	/* initialize non-constant commands */
 	cmd_set_fwd_mode_init();
 	cmd_set_fwd_retry_mode_init();
@@ -17123,15 +17124,23 @@  prompt(void)
 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
 	if (testpmd_cl == NULL)
 		return;
+
+	ret = atexit(prompt_exit);
+	if (ret != 0)
+		printf("Cannot set exit function for cmdline\n");
+
 	cmdline_interact(testpmd_cl);
-	cmdline_stdin_exit(testpmd_cl);
+	if (ret != 0)
+		cmdline_stdin_exit(testpmd_cl);
 }
 
 void
 prompt_exit(void)
 {
-	if (testpmd_cl != NULL)
+	if (testpmd_cl != NULL) {
 		cmdline_quit(testpmd_cl);
+		cmdline_stdin_exit(testpmd_cl);
+	}
 }
 
 static void