From 376ddfbd22f3ca6bed4fb80f2a5eb1ee9c89e3d9 Mon Sep 17 00:00:00 2001 From: Mete Durlu Date: Tue, 17 Feb 2026 09:02:34 +0100 Subject: [PATCH] hyptop/opts: Replace sort_field option with sort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hyptop's "--sort_field" command line option has always been documented as "--sort", while the code _only_ explicitly has "--sort_field". Specifying the shorter "--sort" happened to work due to an unnoticed getopt() behavior. From getopt(3) man page: """ Long option names may be abbreviated if the abbreviation is unique or is an exact match for some defined option. """ With the addition of "--sort-field" as another unique identifier via commit c5695e43c4cd ("hyptop/opts: Replace long option formats for consistency") "--sort" is no longer unique. getopt() won't be able to use that as an abbreviation, since there is ambiguity between "--sort_field" and new "--sort-field" as they are defined as separate options. Replace "--sort-field" and "--sort_field" with plain "--sort" to adhere to the documented hyptop command line argument specification and resolve the broken behavior. Fixes: c5695e43c4cd ("hyptop/opts: Replace long option formats for consistency") Reported-by: Gorkem Kilinc Reviewed-by: Jan Höppner Signed-off-by: Mete Durlu Signed-off-by: Jan Höppner --- hyptop/opts.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hyptop/opts.c b/hyptop/opts.c index ca182069..a8829683 100644 --- a/hyptop/opts.c +++ b/hyptop/opts.c @@ -58,9 +58,8 @@ static char HELP_TEXT[] = * Options with underscore to keep compatibility */ #define OPT_BATCH_MODE 257 /* --batch_mode */ -#define OPT_SORT_FIELD 258 /* --sort | --sort_field */ -#define OPT_CPU_TYPES 259 /* --cpu_types */ -#define OPT_SMT_FACTOR 260 /* --smt_factor */ +#define OPT_CPU_TYPES 258 /* --cpu_types */ +#define OPT_SMT_FACTOR 259 /* --smt_factor */ /* * Initialize default settings @@ -224,7 +223,7 @@ static void l_fields_set(char *str) } /* - * Set the "--sort_field" option + * Set the "--sort" option */ static void l_sort_field_set(char *str) { @@ -371,8 +370,7 @@ void opts_parse(int argc, char *argv[]) { "sys", required_argument, NULL, 's'}, { "iterations", required_argument, NULL, 'n'}, { "fields", required_argument, NULL, 'f'}, - { "sort-field", required_argument, NULL, 'S'}, - { "sort_field", required_argument, NULL, OPT_SORT_FIELD}, + { "sort", required_argument, NULL, 'S'}, { "cpu-types", required_argument, NULL, 't'}, { "cpu_types", required_argument, NULL, OPT_CPU_TYPES}, { "format", required_argument, NULL, OPT_FORMAT }, @@ -420,7 +418,6 @@ void opts_parse(int argc, char *argv[]) case 'f': l_fields_set(optarg); break; - case OPT_SORT_FIELD: case 'S': l_sort_field_set(optarg); break;