Skip to content

Commit 3cf21a8

Browse files
bruce-richardsontmonjalo
authored andcommitted
app/pdump: improve command line arguments 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. Signed-off-by: Bruce Richardson <[email protected]> Acked-by: Anatoly Burakov <[email protected]>
1 parent 4a8d8db commit 3cf21a8

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

app/pdump/main.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,8 @@ main(int argc, char **argv)
983983
int i;
984984

985985
char mp_flag[] = "--proc-type=secondary";
986-
char *argp[argc + 1];
986+
char *argp[argc + 2]; /* add proc-type, and final NULL entry */
987+
int n_argp = 0;
987988

988989
/* catch ctrl-c so we can cleanup on exit */
989990
sigemptyset(&action.sa_mask);
@@ -994,27 +995,27 @@ main(int argc, char **argv)
994995
if (origaction.sa_handler == SIG_DFL)
995996
sigaction(SIGHUP, &action, NULL);
996997

997-
argp[0] = argv[0];
998-
argp[1] = mp_flag;
998+
argp[n_argp++] = argv[0];
999+
argp[n_argp++] = mp_flag;
9991000

1000-
for (i = 1; i < argc; i++)
1001-
argp[i + 1] = argv[i];
1002-
1003-
argc += 1;
1001+
for (i = 1; i < argc; i++) {
1002+
argp[n_argp] = argv[i];
1003+
/* drop any user-provided proc-type to avoid dup flags */
1004+
if (strncmp(argv[i], mp_flag, strlen("--proc-type")) != 0)
1005+
n_argp++;
1006+
}
1007+
argp[n_argp] = NULL;
10041008

1005-
diag = rte_eal_init(argc, argp);
1009+
diag = rte_eal_init(n_argp, argp);
10061010
if (diag < 0)
10071011
rte_panic("Cannot init EAL\n");
10081012

10091013
if (rte_eth_dev_count_avail() == 0)
10101014
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
10111015

1012-
argc -= diag;
1013-
argv += (diag - 1);
1014-
10151016
/* parse app arguments */
1016-
if (argc > 1) {
1017-
ret = launch_args_parse(argc, argv, argp[0]);
1017+
if (n_argp - diag > 1) {
1018+
ret = launch_args_parse(n_argp - diag, argp + diag, argp[0]);
10181019
if (ret < 0)
10191020
rte_exit(EXIT_FAILURE, "Invalid argument\n");
10201021
}

0 commit comments

Comments
 (0)