aboutsummaryrefslogtreecommitdiff
path: root/kernel/debug
diff options
context:
space:
mode:
authorTomas Glozar <tglozar@redhat.com>2026-06-02 14:55:06 +0200
committerTomas Glozar <tglozar@redhat.com>2026-06-04 10:53:25 +0200
commite9e41d3035032ed6053d8bad7b7077e1cb3a6540 (patch)
treecd24724fdd1825bc81ebde85730b0224987db9b4 /kernel/debug
parente43ffb69e0438cddd72aaa30898b4dc446f664f8 (diff)
rtla: Fix parsing of multi-character short options
A bug was reported where the parsing of multi-character short options, be it a short option with an argument specified without space (e.g. "-p100") or multiple short options in one argument (e.g. -un), ignores options specific to individual tools. Furthermore, if the rest of the option is supposed to be an argument, it gets reinterpreted as a string of options. For example, -p100 gets interpreted as -100, which is due to hackish implementation read as --no-thread --no-irq --no-irq with timerlat hist, causing rtla to error out: $ rtla timerlat hist -p100 no-irq and no-thread set, there is nothing to do here This behavior is caused by getopt_long() being called twice on each argument, once in common_parse_options(), once in [tool]_parse_args(): - common_parse_options() calls getopt_long() with an array of options common for all rtla tools, while suppressing errors (opterr = 0). - If the option fails to parse, common_parse_options() returns 0. - If 0 is returned from common_parse_options(), [tool]_parse_args() calls getopt_long() again, with its own set of options. * [tool] means one of {osnoise,timerlat}_{top,hist} At least in glibc, getopt_long() increments its internal nextchar variable even if the option is not recognized. That means that in the case of "-p100", common_parse_options() sets nextchar pointing to '1', and timerlat_hist_parse_args() sees '1', not 'p'; the same then repeats for the first and second '0'. As there is no way to restore the correct internal state of getopt_long() reliably, fix the issue by merging the common options back to the longopt array and option string of the [tool]_parse_args() functions using a macro; only the switch part is left in the original function, which is renamed to set_common_option(). Fixes: 850cd24cb6d6 ("tools/rtla: Add common_parse_options()") Reported-by: John Kacur <jkacur@redhat.com> Tested-by: John Kacur <jkacur@redhat.com> Link: https://lore.kernel.org/r/20260602125506.3325345-1-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Diffstat (limited to 'kernel/debug')
0 files changed, 0 insertions, 0 deletions