]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pipesz: merge help/version getopt loop into main loop
authorKarel Zak <kzak@redhat.com>
Mon, 25 May 2026 11:33:34 +0000 (13:33 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 25 May 2026 11:33:34 +0000 (13:33 +0200)
The main() function scanned command-line options in two passes: the
first pass checked for --help/--version, and the second processed
normal options. When getopt_long encountered an unknown option in the
first pass, it printed an error message. The same error was then
printed again during the second pass, resulting in a duplicate
"unrecognized option" message.

Fix this by merging the first getopt_long loop into the main one,
following the standard util-linux convention.

Fixes: https://github.com/util-linux/util-linux/issues/3817
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/pipesz.c

index a84eb807dcb2d449e8bb4df244a751dce568cdd1..243b702e20c37da23c77d8abb0b568d98681076d 100644 (file)
@@ -227,18 +227,6 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        close_stdout_atexit();
 
-       /* check for --help or --version */
-       while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
-               switch (c) {
-               case 'h':
-                       usage();
-               case 'V':
-                       print_version(EXIT_SUCCESS);
-               }
-       }
-
-       /* gather normal options */
-       optind = 1;
        while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
                err_exclusive_options(c, longopts, excl, excl_st);
 
@@ -276,6 +264,11 @@ int main(int argc, char **argv)
                case 'v':
                        opt_verbose = TRUE;
                        break;
+
+               case 'V':
+                       print_version(EXIT_SUCCESS);
+               case 'h':
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }