Skip to contentSkip to conversation

app/pdump: remove hard-coded memory channels EAL arg

PATCH In review Bruce Richardson 3 participants 5 messages Oct 17, 2025 – Nov 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 app/pdump: remove hard-coded memory channels EAL arg

The pdump main function modifies argc/argv before calling EAL init function. It needs to do so in order to add the proc-type=secondary flag, but also adds in "-n4" as parameter. This parameter is unnecessary and also causes duplicate parameter errors if the user also passes in -n flag on the commandline. Just remove this flag.

Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")
---
 app/pdump/main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
app/pdump/main.c +5 -7
index fa85859703..f3ac81cb80 100644
@@ -982,9 +982,8 @@ main(int argc, char **argv)
 	int ret;
 	int i;
 
-	char n_flag[] = "-n4";
 	char mp_flag[] = "--proc-type=secondary";
-	char *argp[argc + 2];
+	char *argp[argc + 1];
 
 	/* catch ctrl-c so we can cleanup on exit */
 	sigemptyset(&action.sa_mask);
@@ -996,13 +995,12 @@ main(int argc, char **argv)
 		sigaction(SIGHUP, &action, NULL);
 
 	argp[0] = argv[0];
-	argp[1] = n_flag;
-	argp[2] = mp_flag;
+	argp[1] = mp_flag;
 
 	for (i = 1; i < argc; i++)
-		argp[i + 2] = argv[i];
+		argp[i + 1] = argv[i];
 
-	argc += 2;
+	argc += 1;
 
 	diag = rte_eal_init(argc, argp);
 	if (diag < 0)
@@ -1012,7 +1010,7 @@ main(int argc, char **argv)
 		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
 
 	argc -= diag;
-	argv += (diag - 2);
+	argv += (diag - 1);
 
 	/* parse app arguments */
 	if (argc > 1) {
Signature · 1 line
2.48.1
#1 lore raw

PATCH 2/2 app/pdump: improve cmdline argument handling

Rework the argc/argv handling in pdump a little to improve things. Issues with the original implementation:
* assumed user would never pass proc-type parameter on the commandline
* did not null-terminate the argv array (generally harmless but not in spec)
* did not handle case where arg processing in eal_init would reorder non-flag args to the end to be handled by the app.

Fix these - all-be-it minor issues, by having a separate count value for the number of arguments we put in the argp array, rather than assuming that its argc + 1 (for proc-type flag). Properly set the last argv entry to NULL, and when processing app args, reuse the argp array passed to eal_init rather than reverting back to the original argv array.

---
 app/pdump/main.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
app/pdump/main.c +14 -13
index f3ac81cb80..89347d70dc 100644
@@ -983,7 +983,8 @@ main(int argc, char **argv)
 	int i;
 
 	char mp_flag[] = "--proc-type=secondary";
-	char *argp[argc + 1];
+	char *argp[argc + 2];  /* add proc-type, and final NULL entry */
+	int n_argp = 0;
 
 	/* catch ctrl-c so we can cleanup on exit */
 	sigemptyset(&action.sa_mask);
@@ -994,27 +995,27 @@ main(int argc, char **argv)
 	if (origaction.sa_handler == SIG_DFL)
 		sigaction(SIGHUP, &action, NULL);
 
-	argp[0] = argv[0];
-	argp[1] = mp_flag;
+	argp[n_argp++] = argv[0];
+	argp[n_argp++] = mp_flag;
 
-	for (i = 1; i < argc; i++)
-		argp[i + 1] = argv[i];
-
-	argc += 1;
+	for (i = 1; i < argc; i++) {
+		argp[n_argp] = argv[i];
+		/* drop any user-provided proc-type to avoid dup flags */
+		if (strncmp(argv[i], mp_flag, strlen("--proc-type")) != 0)
+			n_argp++;
+	}
+	argp[n_argp] = NULL;
 
-	diag = rte_eal_init(argc, argp);
+	diag = rte_eal_init(n_argp, argp);
 	if (diag < 0)
 		rte_panic("Cannot init EAL\n");
 
 	if (rte_eth_dev_count_avail() == 0)
 		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
 
-	argc -= diag;
-	argv += (diag - 1);
-
 	/* parse app arguments */
-	if (argc > 1) {
-		ret = launch_args_parse(argc, argv, argp[0]);
+	if (n_argp - diag > 1) {
+		ret = launch_args_parse(n_argp - diag, argp + diag, argp[0]);
 		if (ret < 0)
 			rte_exit(EXIT_FAILURE, "Invalid argument\n");
 	}
Signature · 1 line
2.48.1
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] app/pdump: improve cmdline argument handling

Quoted 16 lines · Bruce Richardson

Rework the argc/argv handling in pdump a little to improve things. Issues with the original implementation:
* assumed user would never pass proc-type parameter on the commandline
* did not null-terminate the argv array (generally harmless but not in spec)
* did not handle case where arg processing in eal_init would reorder non-flag args to the end to be handled by the app.

Fix these - all-be-it minor issues, by having a separate count value for the number of arguments we put in the argp array, rather than assuming that its argc + 1 (for proc-type flag). Properly set the last argv entry to NULL, and when processing app args, reuse the argp array passed to eal_init rather than reverting back to the original argv array.

---

<snip>

Quoted 5 lines
app/pdump/main.c +2 -2
-	argp[0] = argv[0];
-	argp[1] = mp_flag;
+	argp[n_argp++] = argv[0];
+	argp[n_argp++] = mp_flag;

app/pdump/main.c main(int argc, char **argv) · line 1005

Quoted 10 lines
app/pdump/main.c +5 -4
 
-	for (i = 1; i < argc; i++)
-		argp[i + 1] = argv[i];
-
-	argc += 1;
+	for (i = 1; i < argc; i++) {
+		argp[n_argp] = argv[i];
+		/* drop any user-provided proc-type to avoid dup flags */
+		if (strncmp(argv[i], mp_flag, strlen("--proc-type")) != 0)
+			n_argp++;

Feels a little odd to assign the value and then overwrite it in next iteration, but same end result so no biggie

Signature · 2 lines
Thanks,
Anatoly
Acked-by on v1 1/2
#3 lore raw
In reply to Bruce Richardson
Quoted 11 lines · Bruce Richardson

The pdump main function modifies argc/argv before calling EAL init function. It needs to do so in order to add the proc-type=secondary flag, but also adds in "-n4" as parameter. This parameter is unnecessary and also causes duplicate parameter errors if the user also passes in -n flag on the commandline. Just remove this flag.

Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")

---

Signature · 2 lines
Thanks,
Anatoly
#4 lore raw

07/11/2025 17:10, Burakov, Anatoly:

Quoted 7 lines · Bruce Richardson
Quoted 6 lines

The pdump main function modifies argc/argv before calling EAL init function. It needs to do so in order to add the proc-type=secondary flag, but also adds in "-n4" as parameter. This parameter is unnecessary and also causes duplicate parameter errors if the user also passes in -n flag on the commandline. Just remove this flag.

Quoted 6 lines
Quoted 5 lines
Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")

---

Series applied, thanks.