Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1348803

[PATCH] perf subcmd: Bugfix exactly compare long name of options to avoid repeat output.

From Taeung Song <treeze.taeung@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] perf subcmd: Bugfix exactly compare long name of options to avoid repeat output.
Date 2016-03-03 07:10 +0100
Message-ID <r8uCt-2Tn-1@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


In parse_options_usage(), check whether short option
is used and there is a option that has same name with
a specific option string (optstr) or not
before printing usage of options by print_option_help().

But using prefixcmp() has a problem when comparing long name
of options with a specific option string(optstr).
If two options has similar long name that is same prefix
of each name, repeat printing usage of options i.e.

'list' and 'list-all' among perf-config options
has a option flag 'PARSE_OPT_EXCLUSIVE'
but there was a problem when handling the error as below.

    # perf config --list-all --list
    Error: option `list' cannot be used with list-all
    Usage: perf config [<file-option>] [options]

        -l, --list            show current config variables
        -a, --list-all        show current and all possible config variables with default values
        -a, --list-all        show current and all possible config variables with default values

But if using short name of them,
this problem(repeat output) didn't occur i.e.
That is why two names are compared by prefixcmp().

    # perf config -a -l
    Error: switch `l' cannot be used with switch `a'
    Usage: perf config [<file-option>] [options]

        -l, --list            show current config variables
        -a, --list-all        show current and all possible config variables with default values

And perf-probe or perf-record hasn't this problem.
Because them hasn't two simliar long name of each option.
But I found this problem developing perf-config to add
a option 'list-all'. Current perf-config hasn't 'list-all' option yet
but I think this problem might occur by other sub-command in future.
So I fix it changing prefixcmp() into strcmp() in order to
exactly compare long name of options with a spefic option string.
After applied, other problems didn't occur as below.

Before:

    # perf probe --list --funcs
    Error: option `funcs' cannot be used with list
    Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
       or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
       or: perf probe [<options>] --del '[GROUP:]EVENT' ...
       or: perf probe --list [GROUP:]EVENT ...
       or: perf probe [<options>] --line 'LINEDESC'
       or: perf probe [<options>] --vars 'PROBEPOINT'
       or: perf probe [<options>] --funcs

       -F, --funcs <[FILTER]>
                             Show potential probe-able functions.
       -l, --list <[GROUP:]EVENT>
                             list up probe events

    # perf config --list-all --list
    Error: option `list' cannot be used with list-all
    Usage: perf config [<file-option>] [options]

        -l, --list            show current config variables
        -a, --list-all        show current and all possible config variables with default values
        -a, --list-all        show current and all possible config variables with default values

After:

    # perf probe --list --funcs
    Error: option `funcs' cannot be used with list
    Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
       or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
       or: perf probe [<options>] --del '[GROUP:]EVENT' ...
       or: perf probe --list [GROUP:]EVENT ...
       or: perf probe [<options>] --line 'LINEDESC'
       or: perf probe [<options>] --vars 'PROBEPOINT'
       or: perf probe [<options>] --funcs

       -F, --funcs <[FILTER]>
                             Show potential probe-able functions.
       -l, --list <[GROUP:]EVENT>
                             list up probe events

    # perf config --list-all --list
    Error: option `list' cannot be used with list-all
    Usage: perf config [<file-option>] [options]

        -l, --list            show current config variables
        -a, --list-all        show current and all possible config variables with default values

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/lib/subcmd/parse-options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 981bb44..b217b90 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -911,7 +911,7 @@ opt:
 		if (opts->long_name == NULL)
 			continue;
 
-		if (!prefixcmp(opts->long_name, optstr))
+		if (!strcmp(opts->long_name, optstr))
 			print_option_help(opts, 0);
 		if (!prefixcmp("no-", optstr) &&
 		    !prefixcmp(opts->long_name, optstr + 3))
-- 
2.5.0

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] perf subcmd: Bugfix exactly compare long name of options to avoid repeat output. Taeung Song <treeze.taeung@gmail.com> - 2016-03-03 07:10 +0100

csiph-web