]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools: share getting program name from argv for all tools
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Nov 2012 18:54:17 +0000 (16:54 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Nov 2012 18:55:00 +0000 (16:55 -0200)
tools/depmod.c
tools/insmod.c
tools/kmod.c
tools/kmod.h
tools/lsmod.c
tools/modinfo.c
tools/modprobe.c
tools/rmmod.c

index 410de3e859ed66b90e1de9b918c0e85b03312799..8fd0f12511b9704f4260c5905151d7d196f49690 100644 (file)
@@ -36,6 +36,8 @@
 #include <unistd.h>
 #include <ctype.h>
 
+#include "kmod.h"
+
 #define DEFAULT_VERBOSE LOG_WARNING
 static int verbose = DEFAULT_VERBOSE;
 
@@ -86,7 +88,7 @@ static const struct option cmdopts[] = {
        { }
 };
 
-static void help(const char *progname)
+static void help(void)
 {
        fprintf(stderr,
                "Usage:\n"
@@ -114,7 +116,7 @@ static void help(const char *progname)
                "\t                     current kernel symbols.\n"
                "\t-E, --symvers=FILE   Use Module.symvers file to check\n"
                "\t                     symbol versions.\n",
-               progname);
+               binname);
 }
 
 static inline void _show(const char *fmt, ...)
@@ -2623,7 +2625,7 @@ static int do_depmod(int argc, char *argv[])
 
                        break;
                case 'h':
-                       help(basename(argv[0]));
+                       help();
                        free(config_paths);
                        return EXIT_SUCCESS;
                case 'V':
@@ -2773,8 +2775,6 @@ cmdline_failed:
        return EXIT_FAILURE;
 }
 
-#include "kmod.h"
-
 const struct kmod_cmd kmod_cmd_compat_depmod = {
        .name = "depmod",
        .cmd = do_depmod,
index e7423c48473c01a390a775b161d92f305264ba79..bc7115f981be8cda1a2f288497bfee77dcc4556a 100644 (file)
@@ -24,6 +24,8 @@
 #include <string.h>
 #include "libkmod.h"
 
+#include "kmod.h"
+
 #define LOGPREFIX "insmod: "
 #define ERR(...) fprintf(stderr, LOGPREFIX "ERROR: " __VA_ARGS__)
 
@@ -34,7 +36,7 @@ static const struct option cmdopts[] = {
        {NULL, 0, 0, 0}
 };
 
-static void help(const char *progname)
+static void help(void)
 {
        fprintf(stderr,
                "Usage:\n"
@@ -42,7 +44,7 @@ static void help(const char *progname)
                "Options:\n"
                "\t-V, --version     show version\n"
                "\t-h, --help        show this help\n",
-               progname);
+               binname);
 }
 
 static const char *mod_strerror(int err)
@@ -83,7 +85,7 @@ static int do_insmod(int argc, char *argv[])
                        /* ignored, for compatibility only */
                        break;
                case 'h':
-                       help(basename(argv[0]));
+                       help();
                        return EXIT_SUCCESS;
                case 'V':
                        puts(PACKAGE " version " VERSION);
@@ -153,8 +155,6 @@ end:
        return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-#include "kmod.h"
-
 const struct kmod_cmd kmod_cmd_compat_insmod = {
        .name = "insmod",
        .cmd = do_insmod,
index 52b0c5da42d25047bee114b3815bd44000326d75..7de951112233053caa866c33f0b5d508e696cae3 100644 (file)
@@ -25,6 +25,9 @@
 #include <libkmod.h>
 #include "kmod.h"
 
+/* visible to all tools, compat or otherwise */
+const char *binname;
+
 static const char options_s[] = "+hV";
 static const struct option options[] = {
        { "help", no_argument, NULL, 'h' },
@@ -157,9 +160,10 @@ static int handle_kmod_compat_commands(int argc, char *argv[])
 
 int main(int argc, char *argv[])
 {
-       const char *binname = basename(argv[0]);
        int err;
 
+       binname = basename(argv[0]);
+
        if (strcmp(binname, "kmod") == 0)
                err = handle_kmod_commands(argc, argv);
        else
index 76a3426bb6d9215c37a3ca9687bca68990ec14ec..7bf6c4387381c38879232f07f967b7331a6e49a4 100644 (file)
@@ -35,3 +35,6 @@ extern const struct kmod_cmd kmod_cmd_compat_modprobe;
 extern const struct kmod_cmd kmod_cmd_compat_depmod;
 
 extern const struct kmod_cmd kmod_cmd_list;
+
+/* kmod.c */
+extern const char *binname;
index 96b340db07b289f82ef3c0305cf7c73695995aee..d62b188016c496921b809de6d17f146a88e80c6b 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include "libkmod.h"
 
+#include "kmod.h"
 
 static int do_lsmod(int argc, char *argv[])
 {
@@ -85,8 +86,6 @@ static int do_lsmod(int argc, char *argv[])
        return EXIT_SUCCESS;
 }
 
-#include "kmod.h"
-
 const struct kmod_cmd kmod_cmd_compat_lsmod = {
        .name = "lsmod",
        .cmd = do_lsmod,
index b52c6c902399f0f1bbd85f425030c213d492bd27..c6a12aee81ffbaf557d01cdaa59833c98d559c7b 100644 (file)
@@ -28,6 +28,8 @@
 #include <sys/stat.h>
 #include "libkmod.h"
 
+#include "kmod.h"
+
 #define LOGPREFIX "modinfo: "
 #define ERR(...) fprintf(stderr, LOGPREFIX "ERROR: " __VA_ARGS__)
 
@@ -326,7 +328,7 @@ static const struct option cmdopts[] = {
        {NULL, 0, 0, 0}
 };
 
-static void help(const char *progname)
+static void help(void)
 {
        fprintf(stderr,
                "Usage:\n"
@@ -343,7 +345,7 @@ static void help(const char *progname)
                "\t-b, --basedir=DIR           Use DIR as filesystem root for /lib/modules\n"
                "\t-V, --version               Show version\n"
                "\t-h, --help                  Show this help\n",
-               progname);
+               binname);
 }
 
 static bool is_module_filename(const char *name)
@@ -408,7 +410,7 @@ static int do_modinfo(int argc, char *argv[])
                        root = optarg;
                        break;
                case 'h':
-                       help(basename(argv[0]));
+                       help();
                        return EXIT_SUCCESS;
                case 'V':
                        puts(PACKAGE " version " VERSION);
@@ -466,8 +468,6 @@ static int do_modinfo(int argc, char *argv[])
        return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-#include "kmod.h"
-
 const struct kmod_cmd kmod_cmd_compat_modinfo = {
        .name = "modinfo",
        .cmd = do_modinfo,
index 58f6df9187cf266341811263d32a1eb8d9e8086d..7c8e2afee5a3f8f484c30a2f4ffd5b1790339d80 100644 (file)
@@ -36,6 +36,8 @@
 #include "libkmod-array.h"
 #include "macro.h"
 
+#include "kmod.h"
+
 static int log_priority = LOG_CRIT;
 static int use_syslog = 0;
 
@@ -89,7 +91,7 @@ static const struct option cmdopts[] = {
        {NULL, 0, 0, 0}
 };
 
-static void help(const char *progname)
+static void help(void)
 {
        fprintf(stderr,
                "Usage:\n"
@@ -136,7 +138,7 @@ static void help(const char *progname)
                "\t-v, --verbose               enables more messages\n"
                "\t-V, --version               show version\n"
                "\t-h, --help                  show this help\n",
-               progname, progname, progname, progname, progname, progname);
+               binname, binname, binname, binname, binname, binname);
 }
 
 static inline void _show(const char *fmt, ...)
@@ -938,7 +940,7 @@ static int do_modprobe(int argc, char **orig_argv)
                        err = 0;
                        goto done;
                case 'h':
-                       help(basename(argv[0]));
+                       help();
                        err = 0;
                        goto done;
                case '?':
@@ -1028,8 +1030,6 @@ done:
        return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-#include "kmod.h"
-
 const struct kmod_cmd kmod_cmd_compat_modprobe = {
        .name = "modprobe",
        .cmd = do_modprobe,
index 74982cdd67a8ec4f3e2eebbd13f1b505eacba384..1983f70fdfcd04a000c2107696d743dd21188828 100644 (file)
@@ -29,6 +29,8 @@
 #include "libkmod.h"
 #include "macro.h"
 
+#include "kmod.h"
+
 #define DEFAULT_VERBOSE LOG_ERR
 static int verbose = DEFAULT_VERBOSE;
 static int use_syslog;
@@ -44,7 +46,7 @@ static const struct option cmdopts[] = {
        {NULL, 0, 0, 0}
 };
 
-static void help(const char *progname)
+static void help(void)
 {
        fprintf(stderr,
                "Usage:\n"
@@ -57,7 +59,7 @@ static void help(const char *progname)
                "\t-v, --verbose     enables more messages\n"
                "\t-V, --version     show version\n"
                "\t-h, --help        show this help\n",
-               progname);
+               binname);
 }
 
 static _always_inline_ const char *prio_to_str(int prio)
@@ -212,7 +214,7 @@ static int do_rmmod(int argc, char *argv[])
                        flags &= ~KMOD_REMOVE_NOWAIT;
                        break;
                case 'h':
-                       help(basename(argv[0]));
+                       help();
                        return EXIT_SUCCESS;
                case 'V':
                        puts(PACKAGE " version " VERSION);
@@ -286,8 +288,6 @@ done:
        return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-#include "kmod.h"
-
 const struct kmod_cmd kmod_cmd_compat_rmmod = {
        .name = "rmmod",
        .cmd = do_rmmod,