diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2012-11-06 16:54:17 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2012-11-06 16:55:00 -0200 |
commit | 4a2e20dfb3f94b0c5f0b8269b0dd84974a5dac56 (patch) | |
tree | dfa043682702bc7d617c66e389ec063867b63d20 | |
parent | e6996c5c30454574d392aac8cbff879e90004e02 (diff) | |
download | kmod-4a2e20dfb3f94b0c5f0b8269b0dd84974a5dac56.tar.gz kmod-4a2e20dfb3f94b0c5f0b8269b0dd84974a5dac56.tar.bz2 kmod-4a2e20dfb3f94b0c5f0b8269b0dd84974a5dac56.zip |
tools: share getting program name from argv for all tools
-rw-r--r-- | tools/depmod.c | 10 | ||||
-rw-r--r-- | tools/insmod.c | 10 | ||||
-rw-r--r-- | tools/kmod.c | 6 | ||||
-rw-r--r-- | tools/kmod.h | 3 | ||||
-rw-r--r-- | tools/lsmod.c | 3 | ||||
-rw-r--r-- | tools/modinfo.c | 10 | ||||
-rw-r--r-- | tools/modprobe.c | 10 | ||||
-rw-r--r-- | tools/rmmod.c | 10 |
8 files changed, 34 insertions, 28 deletions
diff --git a/tools/depmod.c b/tools/depmod.c index 410de3e..8fd0f12 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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, diff --git a/tools/insmod.c b/tools/insmod.c index e7423c4..bc7115f 100644 --- a/tools/insmod.c +++ b/tools/insmod.c @@ -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, diff --git a/tools/kmod.c b/tools/kmod.c index 52b0c5d..7de9511 100644 --- a/tools/kmod.c +++ b/tools/kmod.c @@ -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 diff --git a/tools/kmod.h b/tools/kmod.h index 76a3426..7bf6c43 100644 --- a/tools/kmod.h +++ b/tools/kmod.h @@ -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; diff --git a/tools/lsmod.c b/tools/lsmod.c index 96b340d..d62b188 100644 --- a/tools/lsmod.c +++ b/tools/lsmod.c @@ -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, diff --git a/tools/modinfo.c b/tools/modinfo.c index b52c6c9..c6a12ae 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -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, diff --git a/tools/modprobe.c b/tools/modprobe.c index 58f6df9..7c8e2af 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -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, diff --git a/tools/rmmod.c b/tools/rmmod.c index 74982cd..1983f70 100644 --- a/tools/rmmod.c +++ b/tools/rmmod.c @@ -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, |