Skip to content

Commit

Permalink
app/testpmd: fix early exit from signal
Browse files Browse the repository at this point in the history
[ upstream commit a996cd04aeeaeca88e6313174101a1229349fb47 ]

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>
Reviewed-by: David Marchand <david.marchand@redhat.com>
  • Loading branch information
shemminger authored and bluca committed Nov 8, 2023
1 parent 6821f2a commit 14d0084
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions app/test-pmd/testpmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <time.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/types.h>
#include <errno.h>
#include <stdbool.h>
Expand Down Expand Up @@ -4059,25 +4058,17 @@ main(int argc, char** argv)
}
} else {
char c;
fd_set fds;

printf("Press enter to exit\n");

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",
while (f_quit == 0) {
/* end-of-file or any character exits loop */
if (read(0, &c, 1) >= 0)
break;
if (errno == EINTR)
continue;
rte_exit(EXIT_FAILURE, "Read failed: %s\n",
strerror(errno));
}
}
}

Expand Down

0 comments on commit 14d0084

Please sign in to comment.