]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools/insmod: minor getopt tweaks
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 19 Oct 2024 17:11:17 +0000 (18:11 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 22 Oct 2024 15:37:11 +0000 (10:37 -0500)
Pull the unistd.h for optind and adjust the loop to follow the
in-documentation example.

Namely, we don't need the unused idx and removing the seemingly
infinite loop helps static analysers better reason about the code flow.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/195
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/insmod.c

index b3d01c6a1fcdde0782438ec6dca3f2fdd5004bd3..74669a93b414ae2e0a1575f413730c8c4e4e5d5f 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <shared/util.h>
 
@@ -66,15 +67,11 @@ static int do_insmod(int argc, char *argv[])
        size_t optslen = 0;
        int verbose = LOG_ERR;
        int use_syslog = 0;
-       int i, r = 0;
+       int i, c, r = 0;
        const char *null_config = NULL;
        unsigned int flags = 0;
 
-       for (;;) {
-               int c, idx = 0;
-               c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
-               if (c == -1)
-                       break;
+       while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
                switch (c) {
                case 'f':
                        flags |= KMOD_PROBE_FORCE_MODVERSION;