testpmd: fix early exit from signal

Message ID 20231026171133.250715-1-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series testpmd: fix early exit from signal |

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/github-robot: build success github build: passed
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-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 success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Stephen Hemminger Oct. 26, 2023, 5:11 p.m. UTC
  Other signals may occur causing read to get interrupted.
Loop until quit flag is set by signal, a character is entered,
or end of file. This fixes bug where testpmd would exit early
because of signal used by TAP device.

Bugzilla ID: 1305
Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-pmd/testpmd.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
  

Comments

Ferruh Yigit Oct. 27, 2023, 12:18 a.m. UTC | #1
On 10/26/2023 6:11 PM, Stephen Hemminger wrote:
> Other signals may occur causing read to get interrupted.
> Loop until quit flag is set by signal, a character is entered,
> or end of file. This fixes bug where testpmd would exit early
> because of signal used by TAP device.
> 
> Bugzilla ID: 1305
> Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal")
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> 

Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
  
David Marchand Oct. 27, 2023, 7:30 a.m. UTC | #2
On Thu, Oct 26, 2023 at 7:11 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> Other signals may occur causing read to get interrupted.
> Loop until quit flag is set by signal, a character is entered,
> or end of file. This fixes bug where testpmd would exit early
> because of signal used by TAP device.
>
> Bugzilla ID: 1305
> Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal")

We need this fix in LTS.
Cc: stable@dpdk.org


> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  app/test-pmd/testpmd.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
>
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index 595b77748c2a..619a59f5b891 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -11,7 +11,6 @@
>  #include <fcntl.h>
>  #ifndef RTE_EXEC_ENV_WINDOWS
>  #include <sys/mman.h>
> -#include <sys/select.h>
>  #endif
>  #include <sys/types.h>
>  #include <errno.h>
> @@ -4743,25 +4742,18 @@ main(int argc, char** argv)
>                         }
>                 } else {
>                         char c;
> -                       fd_set fds;
>
>                         printf("Press enter to exit\n");
> +                       while (f_quit == 0) {
> +                               /* end-of-file or any character exits loop */
> +                               if (read(0, &c, 1) >= 0)
> +                                       break;
>
> -                       FD_ZERO(&fds);
> -                       FD_SET(0, &fds);
> -
> -                       /* wait for signal or enter */
> -                       ret = select(1, &fds, NULL, NULL, NULL);
> -                       if (ret < 0 && errno != EINTR)
> -                               rte_exit(EXIT_FAILURE,
> -                                        "Select failed: %s\n",
> -                                        strerror(errno));
> -
> -                       /* if got enter then consume it */
> -                       if (ret == 1 && read(0, &c, 1) < 0)
> -                               rte_exit(EXIT_FAILURE,
> -                                        "Read failed: %s\n",
> -                                        strerror(errno));
> +                               if (errno == EINTR)
> +                                       continue;
> +                               rte_exit(EXIT_FAILURE, "Read failed: %s\n",
> +                                                strerror(errno));

Just a nit here.
Indent seems odd, I see an extra whitespace.

Otherwise the fix lgtm and resolves the issue reported in bz.
Reviewed-by: David Marchand <david.marchand@redhat.com>
  
Ferruh Yigit Oct. 27, 2023, 12:30 p.m. UTC | #3
On 10/27/2023 8:30 AM, David Marchand wrote:
> On Thu, Oct 26, 2023 at 7:11 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
>>
>> Other signals may occur causing read to get interrupted.
>> Loop until quit flag is set by signal, a character is entered,
>> or end of file. This fixes bug where testpmd would exit early
>> because of signal used by TAP device.
>>
>> Bugzilla ID: 1305
>> Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal")
> 
> We need this fix in LTS.
> Cc: stable@dpdk.org
> 
> 
>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>> 

<...>

> 
> Just a nit here.
> Indent seems odd, I see an extra whitespace.
> 

Empty line and indentation updated while merging.

> Otherwise the fix lgtm and resolves the issue reported in bz.
> Reviewed-by: David Marchand <david.marchand@redhat.com>
> 
> 

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 595b77748c2a..619a59f5b891 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -11,7 +11,6 @@ 
 #include <fcntl.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <sys/mman.h>
-#include <sys/select.h>
 #endif
 #include <sys/types.h>
 #include <errno.h>
@@ -4743,25 +4742,18 @@  main(int argc, char** argv)
 			}
 		} else {
 			char c;
-			fd_set fds;
 
 			printf("Press enter to exit\n");
+			while (f_quit == 0) {
+				/* end-of-file or any character exits loop */
+				if (read(0, &c, 1) >= 0)
+					break;
 
-			FD_ZERO(&fds);
-			FD_SET(0, &fds);
-
-			/* wait for signal or enter */
-			ret = select(1, &fds, NULL, NULL, NULL);
-			if (ret < 0 && errno != EINTR)
-				rte_exit(EXIT_FAILURE,
-					 "Select failed: %s\n",
-					 strerror(errno));
-
-			/* if got enter then consume it */
-			if (ret == 1 && read(0, &c, 1) < 0)
-				rte_exit(EXIT_FAILURE,
-					 "Read failed: %s\n",
-					 strerror(errno));
+				if (errno == EINTR)
+					continue;
+				rte_exit(EXIT_FAILURE, "Read failed: %s\n",
+						 strerror(errno));
+			}
 		}
 	}