Was meaning to add a negative test or two to modinfo - where a invalid
option is passed into the program - only to notice that the default will
print the path, alongside the program name.
While fixing that, I've decided to pimp-up the reporting to also show
the help screen.
Eg. from this:
/usr/bin/insmod: unrecognized option '--versoin'
... to this
insmod: ERROR: unrecognised option '--versoin'
Usage:
insmod [options] filename [module options]
Options:
-f, --force DANGEROUS: forces a module load, may cause
data corruption and crash your machine.
implies --force-modversion and
--force-vermagic
--force-modversion Ignore module's version
--force-vermagic Ignore module's version magic
-s, --syslog print to syslog, not stderr
-v, --verbose enables more messages
-V, --version show version
-h, --help show this help
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/453
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
return -EINVAL;
}
+ opterr = 0;
while ((c = getopt_long(argc, argv, options_short, options, NULL)) != -1) {
switch (c) {
case 'l':
oneshot = 1;
break;
case '?':
+ TS_ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
return -1;
default:
TS_ERR("unexpected getopt_long() value %c\n", c);
memset(&cfg, 0, sizeof(cfg));
memset(&depmod, 0, sizeof(depmod));
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 'a':
kmod_version();
return EXIT_SUCCESS;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
goto cmdline_failed;
default:
ERR("unexpected getopt_long() value '%c'.\n", c);
const char *null_config = NULL;
unsigned int flags = 0;
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 'f':
kmod_version();
return EXIT_SUCCESS;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
return EXIT_FAILURE;
default:
ERR("unexpected getopt_long() value '%c'.\n", c);
int err = 0, c;
size_t i;
+ opterr = 0;
while ((c = getopt_long(argc, argv, options_s, options, NULL)) != -1) {
switch (c) {
case 'h':
kmod_version();
return EXIT_SUCCESS;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ kmod_help(argc, argv);
return EXIT_FAILURE;
default:
fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n",
bool use_syslog = false;
int err, c, r = 0;
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 's':
kmod_version();
return EXIT_SUCCESS;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
return EXIT_FAILURE;
default:
ERR("unexpected getopt_long() value '%c'.\n", c);
bool arg_is_modname = false;
int i, err, c;
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 'a':
kmod_version();
return EXIT_SUCCESS;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
return EXIT_FAILURE;
default:
ERR("unexpected getopt_long() value '%c'.\n", c);
return EXIT_FAILURE;
}
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 'a':
err = 0;
goto done;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
err = -1;
goto done;
default:
int flags = 0;
int i, c, r = 0;
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 'f':
kmod_version();
return EXIT_SUCCESS;
case '?':
+ ERR("unrecognised option \'%s\'\n\n", argv[optind - 1]);
+ help();
return EXIT_FAILURE;
default:
ERR("unexpected getopt_long() value '%c'.\n", c);
int r, ret = EXIT_SUCCESS;
int c, valid;
+ opterr = 0;
while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) {
switch (c) {
case 'o':
help();
goto finish;
case '?':
+ fprintf(stderr, "unrecognised option \'%s\'\n\n",
+ argv[optind - 1]);
+ help();
ret = EXIT_FAILURE;
goto finish;
default: