From: Takashi Sakamoto Date: Mon, 3 Dec 2018 21:33:42 +0000 (+0900) Subject: axfer: truncate parsed arguments before operating subcommand X-Git-Tag: v1.1.8~23 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=b8833717bb9b7a392a37abf1671d2ff55575926e;p=alsa-utils.git axfer: truncate parsed arguments before operating subcommand When subcommands are operated, top-most two arguments are already parsed in renewed command system, thus they're useless. Besides, they're possible to be parsed by getopt_long(3). This commit truncates these options before entering subcommand operation. Signed-off-by: Takashi Sakamoto Signed-off-by: Takashi Iwai --- diff --git a/axfer/main.c b/axfer/main.c index 954dd5e..f9ee44e 100644 --- a/axfer/main.c +++ b/axfer/main.c @@ -251,8 +251,14 @@ int main(int argc, char *const *argv) // The second option should be either 'capture' or 'direction' // if subcommand is neither 'version' nor 'help'. if (subcmd != SUBCMD_VERSION && subcmd != SUBCMD_HELP) { - if (!detect_direction(argc, argv, &direction)) + if (!detect_direction(argc, argv, &direction)) { subcmd = SUBCMD_HELP; + } else { + // argv[0] is needed for unparsed option to use + // getopt_long(3). + argc -= 2; + argv += 2; + } } } diff --git a/axfer/subcmd-list.c b/axfer/subcmd-list.c index f8f0952..1ea9669 100644 --- a/axfer/subcmd-list.c +++ b/axfer/subcmd-list.c @@ -233,11 +233,11 @@ static int detect_operation(int argc, char *const *argv, enum list_op *op) }; int i; - if (strcmp(argv[1], "list") || argc < 3) + if (argc < 2) return false; for (i = 0; i < ARRAY_SIZE(ops); ++i) { - if (!strcmp(argv[2], ops[i])) { + if (!strcmp(argv[1], ops[i])) { *op = i; return true; } @@ -252,11 +252,9 @@ int subcmd_list(int argc, char *const *argv, snd_pcm_stream_t direction) int err = 0; // Renewed command system. - if (argc > 1) { - if (!detect_operation(argc, argv, &op) && - !decide_operation(argc, argv, &op)) - err = -EINVAL; - } + if (!detect_operation(argc, argv, &op) && + !decide_operation(argc, argv, &op)) + err = -EINVAL; if (op == LIST_OP_DEVICE) err = list_devices(direction); diff --git a/axfer/subcmd-transfer.c b/axfer/subcmd-transfer.c index d5f16cb..3ca745a 100644 --- a/axfer/subcmd-transfer.c +++ b/axfer/subcmd-transfer.c @@ -435,13 +435,6 @@ int subcmd_transfer(int argc, char *const *argv, snd_pcm_stream_t direction) uint64_t actual_frame_count = 0; int err = 0; - // Renewed command system. - if (argc > 2 && !strcmp(argv[1], "transfer")) { - // Go ahead to parse file paths properly. - --argc; - ++argv; - } - err = prepare_signal_handler(&ctx); if (err < 0) return err;