tools: share getting program name from argv for all tools

This commit is contained in:
Lucas De Marchi 2012-11-06 16:54:17 -02:00
parent e6996c5c30
commit 4a2e20dfb3
8 changed files with 34 additions and 28 deletions

View 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,

View 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,

View 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

View 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;

View 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,

View 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,

View 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,

View 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,