Skip to contentSkip to conversation

testpmd: fix early exit from signal

PATCH In review Stephen Hemminger 3 participants 3 messages Oct 26, 2023 – Oct 27, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 testpmd: fix early exit from signal

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")
---
 app/test-pmd/testpmd.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
app/test-pmd/testpmd.c +9 -17
index 595b77748c2a..619a59f5b891 100644
@@ -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));
+			}
 		}
 	}
 
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Stephen Hemminger

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")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Stephen Hemminger
Quoted 8 lines · Stephen Hemminger

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: [email protected]

Quoted 38 lines
---
 app/test-pmd/testpmd.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
app/test-pmd/testpmd.c +4 -11
index 595b77748c2a..619a59f5b891 100644
@@ -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));

app/test-pmd/testpmd.c main(int argc, char** argv) · line 4755

Quoted 10 lines
app/test-pmd/testpmd.c +4 -6
-
-                       /* 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.

Signature · 1 line
David Marchand