mirror of
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
synced 2024-11-27 05:43:50 +08:00
tools: mass convert with clang-format
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/118 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
parent
4c760f7edd
commit
f34d115d09
449
tools/depmod.c
449
tools/depmod.c
File diff suppressed because it is too large
Load Diff
@ -30,15 +30,15 @@ static const struct option cmdopts[] = {
|
|||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
printf("Usage:\n"
|
printf("Usage:\n"
|
||||||
"\t%s [options] filename [args]\n"
|
"\t%s [options] filename [args]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-f, --force DANGEROUS: forces a module load, may cause\n"
|
"\t-f, --force DANGEROUS: forces a module load, may cause\n"
|
||||||
"\t data corruption and crash your machine\n"
|
"\t data corruption and crash your machine\n"
|
||||||
"\t-s, --syslog print to syslog, not stderr\n"
|
"\t-s, --syslog print to syslog, not stderr\n"
|
||||||
"\t-v, --verbose enables more messages\n"
|
"\t-v, --verbose enables more messages\n"
|
||||||
"\t-V, --version show version\n"
|
"\t-V, --version show version\n"
|
||||||
"\t-h, --help show this help\n",
|
"\t-h, --help show this help\n",
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *mod_strerror(int err)
|
static const char *mod_strerror(int err)
|
||||||
@ -95,8 +95,7 @@ static int do_insmod(int argc, char *argv[])
|
|||||||
case '?':
|
case '?':
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
default:
|
default:
|
||||||
ERR("unexpected getopt_long() value '%c'.\n",
|
ERR("unexpected getopt_long() value '%c'.\n", c);
|
||||||
c);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,16 +144,14 @@ static int do_insmod(int argc, char *argv[])
|
|||||||
|
|
||||||
err = kmod_module_new_from_path(ctx, filename, &mod);
|
err = kmod_module_new_from_path(ctx, filename, &mod);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ERR("could not load module %s: %s\n", filename,
|
ERR("could not load module %s: %s\n", filename, strerror(-err));
|
||||||
strerror(-err));
|
|
||||||
r++;
|
r++;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kmod_module_insert_module(mod, flags, opts);
|
err = kmod_module_insert_module(mod, flags, opts);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ERR("could not insert module %s: %s\n", filename,
|
ERR("could not insert module %s: %s\n", filename, mod_strerror(-err));
|
||||||
mod_strerror(-err));
|
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
kmod_module_unref(mod);
|
kmod_module_unref(mod);
|
||||||
|
22
tools/kmod.c
22
tools/kmod.c
@ -47,17 +47,17 @@ static int kmod_help(int argc, char *argv[])
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
printf("kmod - Manage kernel modules: list, load, unload, etc\n"
|
printf("kmod - Manage kernel modules: list, load, unload, etc\n"
|
||||||
"Usage:\n"
|
"Usage:\n"
|
||||||
"\t%s [options] command [command_options]\n\n"
|
"\t%s [options] command [command_options]\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-V, --version show version\n"
|
"\t-V, --version show version\n"
|
||||||
"\t-h, --help show this help\n\n"
|
"\t-h, --help show this help\n\n"
|
||||||
"Commands:\n", basename(argv[0]));
|
"Commands:\n",
|
||||||
|
basename(argv[0]));
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) {
|
for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) {
|
||||||
if (kmod_cmds[i]->help != NULL) {
|
if (kmod_cmds[i]->help != NULL) {
|
||||||
printf(" %-12s %s\n", kmod_cmds[i]->name,
|
printf(" %-12s %s\n", kmod_cmds[i]->name, kmod_cmds[i]->help);
|
||||||
kmod_cmds[i]->help);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ static int kmod_help(int argc, char *argv[])
|
|||||||
for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
|
for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
|
||||||
if (kmod_compat_cmds[i]->help != NULL) {
|
if (kmod_compat_cmds[i]->help != NULL) {
|
||||||
printf(" %-12s %s\n", kmod_compat_cmds[i]->name,
|
printf(" %-12s %s\n", kmod_compat_cmds[i]->name,
|
||||||
kmod_compat_cmds[i]->help);
|
kmod_compat_cmds[i]->help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,8 @@ static int handle_kmod_commands(int argc, char *argv[])
|
|||||||
case '?':
|
case '?':
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n", c);
|
fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n",
|
||||||
|
c);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +134,6 @@ fail:
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int handle_kmod_compat_commands(int argc, char *argv[])
|
static int handle_kmod_compat_commands(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
|
22
tools/log.c
22
tools/log.c
@ -48,9 +48,9 @@ static const char *prio_to_str(char buf[static PRIO_MAX_SIZE], int prio)
|
|||||||
return prioname;
|
return prioname;
|
||||||
}
|
}
|
||||||
|
|
||||||
_printf_format_(6, 0)
|
_printf_format_(6, 0) static void log_kmod(void *data, int priority, const char *file,
|
||||||
static void log_kmod(void *data, int priority, const char *file, int line,
|
int line, const char *fn, const char *format,
|
||||||
const char *fn, const char *format, va_list args)
|
va_list args)
|
||||||
{
|
{
|
||||||
char buf[PRIO_MAX_SIZE];
|
char buf[PRIO_MAX_SIZE];
|
||||||
const char *prioname;
|
const char *prioname;
|
||||||
@ -63,19 +63,17 @@ static void log_kmod(void *data, int priority, const char *file, int line,
|
|||||||
|
|
||||||
if (log_use_syslog) {
|
if (log_use_syslog) {
|
||||||
#ifdef ENABLE_DEBUG
|
#ifdef ENABLE_DEBUG
|
||||||
syslog(priority, "%s: %s:%d %s() %s", prioname, file, line,
|
syslog(priority, "%s: %s:%d %s() %s", prioname, file, line, fn, str);
|
||||||
fn, str);
|
|
||||||
#else
|
#else
|
||||||
syslog(priority, "%s: %s", prioname, str);
|
syslog(priority, "%s: %s", prioname, str);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#ifdef ENABLE_DEBUG
|
#ifdef ENABLE_DEBUG
|
||||||
fprintf(stderr, "%s: %s: %s:%d %s() %s",
|
fprintf(stderr, "%s: %s: %s:%d %s() %s", program_invocation_short_name,
|
||||||
program_invocation_short_name, prioname, file, line,
|
prioname, file, line, fn, str);
|
||||||
fn, str);
|
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "%s: %s: %s", program_invocation_short_name,
|
fprintf(stderr, "%s: %s: %s", program_invocation_short_name, prioname,
|
||||||
prioname, str);
|
str);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +116,8 @@ void log_printf(int prio, const char *fmt, ...)
|
|||||||
if (log_use_syslog)
|
if (log_use_syslog)
|
||||||
syslog(prio, "%s: %s", prioname, msg);
|
syslog(prio, "%s: %s", prioname, msg);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%s: %s: %s", program_invocation_short_name,
|
fprintf(stderr, "%s: %s: %s", program_invocation_short_name, prioname,
|
||||||
prioname, msg);
|
msg);
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
||||||
if (prio <= LOG_CRIT)
|
if (prio <= LOG_CRIT)
|
||||||
|
@ -29,13 +29,13 @@ static const struct option cmdopts[] = {
|
|||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
printf("Usage:\n"
|
printf("Usage:\n"
|
||||||
"\t%s [options]\n"
|
"\t%s [options]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-s, --syslog print to syslog, not stderr\n"
|
"\t-s, --syslog print to syslog, not stderr\n"
|
||||||
"\t-v, --verbose enables more messages\n"
|
"\t-v, --verbose enables more messages\n"
|
||||||
"\t-V, --version show version\n"
|
"\t-V, --version show version\n"
|
||||||
"\t-h, --help show this help\n",
|
"\t-h, --help show this help\n",
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_lsmod(int argc, char *argv[])
|
static int do_lsmod(int argc, char *argv[])
|
||||||
|
121
tools/modinfo.c
121
tools/modinfo.c
@ -34,13 +34,14 @@ struct param {
|
|||||||
int typelen;
|
int typelen;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct param *add_param(const char *name, int namelen, const char *param, int paramlen, const char *type, int typelen, struct param **list)
|
static struct param *add_param(const char *name, int namelen, const char *param,
|
||||||
|
int paramlen, const char *type, int typelen,
|
||||||
|
struct param **list)
|
||||||
{
|
{
|
||||||
struct param *it;
|
struct param *it;
|
||||||
|
|
||||||
for (it = *list; it != NULL; it = it->next) {
|
for (it = *list; it != NULL; it = it->next) {
|
||||||
if (it->namelen == namelen &&
|
if (it->namelen == namelen && memcmp(it->name, name, namelen) == 0)
|
||||||
memcmp(it->name, name, namelen) == 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +79,7 @@ static int process_parm(const char *key, const char *value, struct param **param
|
|||||||
struct param *it;
|
struct param *it;
|
||||||
const char *colon = strchr(value, ':');
|
const char *colon = strchr(value, ':');
|
||||||
if (colon == NULL) {
|
if (colon == NULL) {
|
||||||
ERR("Found invalid \"%s=%s\": missing ':'\n",
|
ERR("Found invalid \"%s=%s\": missing ':'\n", key, value);
|
||||||
key, value);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,19 +128,13 @@ static int modinfo_params_do(const struct kmod_list *list)
|
|||||||
params = p->next;
|
params = p->next;
|
||||||
|
|
||||||
if (p->param == NULL)
|
if (p->param == NULL)
|
||||||
printf("%.*s: (%.*s)%c",
|
printf("%.*s: (%.*s)%c", p->namelen, p->name, p->typelen, p->type,
|
||||||
p->namelen, p->name, p->typelen, p->type,
|
|
||||||
separator);
|
separator);
|
||||||
else if (p->type != NULL)
|
else if (p->type != NULL)
|
||||||
printf("%.*s:%.*s (%.*s)%c",
|
printf("%.*s:%.*s (%.*s)%c", p->namelen, p->name, p->paramlen,
|
||||||
p->namelen, p->name,
|
p->param, p->typelen, p->type, separator);
|
||||||
p->paramlen, p->param,
|
|
||||||
p->typelen, p->type,
|
|
||||||
separator);
|
|
||||||
else
|
else
|
||||||
printf("%.*s:%.*s%c",
|
printf("%.*s:%.*s%c", p->namelen, p->name, p->paramlen, p->param,
|
||||||
p->namelen, p->name,
|
|
||||||
p->paramlen, p->param,
|
|
||||||
separator);
|
separator);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
@ -167,8 +161,7 @@ static int modinfo_do(struct kmod_module *mod)
|
|||||||
|
|
||||||
if (is_builtin) {
|
if (is_builtin) {
|
||||||
if (field == NULL)
|
if (field == NULL)
|
||||||
printf("%-16s%s%c", "name:",
|
printf("%-16s%s%c", "name:", kmod_module_get_name(mod), separator);
|
||||||
kmod_module_get_name(mod), separator);
|
|
||||||
else if (field != NULL && streq(field, "name"))
|
else if (field != NULL && streq(field, "name"))
|
||||||
printf("%s%c", kmod_module_get_name(mod), separator);
|
printf("%s%c", kmod_module_get_name(mod), separator);
|
||||||
filename = "(builtin)";
|
filename = "(builtin)";
|
||||||
@ -178,8 +171,7 @@ static int modinfo_do(struct kmod_module *mod)
|
|||||||
printf("%s%c", filename, separator);
|
printf("%s%c", filename, separator);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (field == NULL) {
|
} else if (field == NULL) {
|
||||||
printf("%-16s%s%c", "filename:",
|
printf("%-16s%s%c", "filename:", filename, separator);
|
||||||
filename, separator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kmod_module_get_info(mod, &list);
|
err = kmod_module_get_info(mod, &list);
|
||||||
@ -191,8 +183,8 @@ static int modinfo_do(struct kmod_module *mod)
|
|||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ERR("could not get modinfo from '%s': %s\n",
|
ERR("could not get modinfo from '%s': %s\n", kmod_module_get_name(mod),
|
||||||
kmod_module_get_name(mod), strerror(-err));
|
strerror(-err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,21 +230,14 @@ static int modinfo_do(struct kmod_module *mod)
|
|||||||
params = p->next;
|
params = p->next;
|
||||||
|
|
||||||
if (p->param == NULL)
|
if (p->param == NULL)
|
||||||
printf("%-16s%.*s:%.*s%c", "parm:",
|
printf("%-16s%.*s:%.*s%c", "parm:", p->namelen, p->name,
|
||||||
p->namelen, p->name, p->typelen, p->type,
|
p->typelen, p->type, separator);
|
||||||
separator);
|
|
||||||
else if (p->type != NULL)
|
else if (p->type != NULL)
|
||||||
printf("%-16s%.*s:%.*s (%.*s)%c", "parm:",
|
printf("%-16s%.*s:%.*s (%.*s)%c", "parm:", p->namelen, p->name,
|
||||||
p->namelen, p->name,
|
p->paramlen, p->param, p->typelen, p->type, separator);
|
||||||
p->paramlen, p->param,
|
|
||||||
p->typelen, p->type,
|
|
||||||
separator);
|
|
||||||
else
|
else
|
||||||
printf("%-16s%.*s:%.*s%c",
|
printf("%-16s%.*s:%.*s%c", "parm:", p->namelen, p->name,
|
||||||
"parm:",
|
p->paramlen, p->param, separator);
|
||||||
p->namelen, p->name,
|
|
||||||
p->paramlen, p->param,
|
|
||||||
separator);
|
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
@ -298,7 +283,6 @@ static int modinfo_name_do(struct kmod_ctx *ctx, const char *name)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias)
|
static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias)
|
||||||
{
|
{
|
||||||
struct kmod_list *l, *list = NULL;
|
struct kmod_list *l, *list = NULL;
|
||||||
@ -326,39 +310,40 @@ static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias)
|
|||||||
|
|
||||||
static const char cmdopts_s[] = "adlpn0mF:k:b:Vh";
|
static const char cmdopts_s[] = "adlpn0mF:k:b:Vh";
|
||||||
static const struct option cmdopts[] = {
|
static const struct option cmdopts[] = {
|
||||||
{"author", no_argument, 0, 'a'},
|
{ "author", no_argument, 0, 'a' },
|
||||||
{"description", no_argument, 0, 'd'},
|
{ "description", no_argument, 0, 'd' },
|
||||||
{"license", no_argument, 0, 'l'},
|
{ "license", no_argument, 0, 'l' },
|
||||||
{"parameters", no_argument, 0, 'p'},
|
{ "parameters", no_argument, 0, 'p' },
|
||||||
{"filename", no_argument, 0, 'n'},
|
{ "filename", no_argument, 0, 'n' },
|
||||||
{"null", no_argument, 0, '0'},
|
{ "null", no_argument, 0, '0' },
|
||||||
{"modname", no_argument, 0, 'm'},
|
{ "modname", no_argument, 0, 'm' },
|
||||||
{"field", required_argument, 0, 'F'},
|
{ "field", required_argument, 0, 'F' },
|
||||||
{"set-version", required_argument, 0, 'k'},
|
{ "set-version", required_argument, 0, 'k' },
|
||||||
{"basedir", required_argument, 0, 'b'},
|
{ "basedir", required_argument, 0, 'b' },
|
||||||
{"version", no_argument, 0, 'V'},
|
{ "version", no_argument, 0, 'V' },
|
||||||
{"help", no_argument, 0, 'h'},
|
{ "help", no_argument, 0, 'h' },
|
||||||
{NULL, 0, 0, 0},
|
{ NULL, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
printf("Usage:\n"
|
printf("Usage:\n"
|
||||||
"\t%s [options] <modulename|filename> [args]\n"
|
"\t%s [options] <modulename|filename> [args]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-a, --author Print only 'author'\n"
|
"\t-a, --author Print only 'author'\n"
|
||||||
"\t-d, --description Print only 'description'\n"
|
"\t-d, --description Print only 'description'\n"
|
||||||
"\t-l, --license Print only 'license'\n"
|
"\t-l, --license Print only 'license'\n"
|
||||||
"\t-p, --parameters Print only 'parm'\n"
|
"\t-p, --parameters Print only 'parm'\n"
|
||||||
"\t-n, --filename Print only 'filename'\n"
|
"\t-n, --filename Print only 'filename'\n"
|
||||||
"\t-0, --null Use \\0 instead of \\n\n"
|
"\t-0, --null Use \\0 instead of \\n\n"
|
||||||
"\t-m, --modname Handle argument as module name instead of alias or filename\n"
|
"\t-m, --modname Handle argument as module name instead of alias or filename\n"
|
||||||
"\t-F, --field=FIELD Print only provided FIELD\n"
|
"\t-F, --field=FIELD Print only provided FIELD\n"
|
||||||
"\t-k, --set-version=VERSION Use VERSION instead of `uname -r`\n"
|
"\t-k, --set-version=VERSION Use VERSION instead of `uname -r`\n"
|
||||||
"\t-b, --basedir=DIR Use DIR as filesystem root for " MODULE_DIRECTORY "\n"
|
"\t-b, --basedir=DIR Use DIR as filesystem root for " MODULE_DIRECTORY
|
||||||
"\t-V, --version Show version\n"
|
"\n"
|
||||||
"\t-h, --help Show this help\n",
|
"\t-V, --version Show version\n"
|
||||||
program_invocation_short_name);
|
"\t-h, --help Show this help\n",
|
||||||
|
program_invocation_short_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_module_filename(const char *name)
|
static bool is_module_filename(const char *name)
|
||||||
@ -366,8 +351,8 @@ static bool is_module_filename(const char *name)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
|
if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
|
||||||
path_ends_with_kmod_ext(name, strlen(name)))
|
path_ends_with_kmod_ext(name, strlen(name)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -452,10 +437,10 @@ static int do_modinfo(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = snprintf(dirname_buf, sizeof(dirname_buf),
|
n = snprintf(dirname_buf, sizeof(dirname_buf),
|
||||||
"%s" MODULE_DIRECTORY "/%s", root, kversion);
|
"%s" MODULE_DIRECTORY "/%s", root, kversion);
|
||||||
if (n >= (int)sizeof(dirname_buf)) {
|
if (n >= (int)sizeof(dirname_buf)) {
|
||||||
ERR("bad directory %s" MODULE_DIRECTORY
|
ERR("bad directory %s" MODULE_DIRECTORY "/%s: path too long\n",
|
||||||
"/%s: path too long\n", root, kversion);
|
root, kversion);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
dirname = dirname_buf;
|
dirname = dirname_buf;
|
||||||
|
240
tools/modprobe.c
240
tools/modprobe.c
@ -49,102 +49,102 @@ static int quiet_inuse = 0;
|
|||||||
|
|
||||||
static const char cmdopts_s[] = "arw:RibfDcnC:d:S:sqvVh";
|
static const char cmdopts_s[] = "arw:RibfDcnC:d:S:sqvVh";
|
||||||
static const struct option cmdopts[] = {
|
static const struct option cmdopts[] = {
|
||||||
{"all", no_argument, 0, 'a'},
|
{ "all", no_argument, 0, 'a' },
|
||||||
|
|
||||||
{"remove", no_argument, 0, 'r'},
|
{ "remove", no_argument, 0, 'r' },
|
||||||
{"remove-dependencies", no_argument, 0, 5},
|
{ "remove-dependencies", no_argument, 0, 5 },
|
||||||
{"remove-holders", no_argument, 0, 5},
|
{ "remove-holders", no_argument, 0, 5 },
|
||||||
{"wait", required_argument, 0, 'w'},
|
{ "wait", required_argument, 0, 'w' },
|
||||||
|
|
||||||
{"resolve-alias", no_argument, 0, 'R'},
|
{ "resolve-alias", no_argument, 0, 'R' },
|
||||||
{"first-time", no_argument, 0, 3},
|
{ "first-time", no_argument, 0, 3 },
|
||||||
{"ignore-install", no_argument, 0, 'i'},
|
{ "ignore-install", no_argument, 0, 'i' },
|
||||||
{"ignore-remove", no_argument, 0, 'i'},
|
{ "ignore-remove", no_argument, 0, 'i' },
|
||||||
{"use-blacklist", no_argument, 0, 'b'},
|
{ "use-blacklist", no_argument, 0, 'b' },
|
||||||
{"force", no_argument, 0, 'f'},
|
{ "force", no_argument, 0, 'f' },
|
||||||
{"force-modversion", no_argument, 0, 2},
|
{ "force-modversion", no_argument, 0, 2 },
|
||||||
{"force-vermagic", no_argument, 0, 1},
|
{ "force-vermagic", no_argument, 0, 1 },
|
||||||
|
|
||||||
{"show-depends", no_argument, 0, 'D'},
|
{ "show-depends", no_argument, 0, 'D' },
|
||||||
{"showconfig", no_argument, 0, 'c'},
|
{ "showconfig", no_argument, 0, 'c' },
|
||||||
{"show-config", no_argument, 0, 'c'},
|
{ "show-config", no_argument, 0, 'c' },
|
||||||
{"show-modversions", no_argument, 0, 4},
|
{ "show-modversions", no_argument, 0, 4 },
|
||||||
{"dump-modversions", no_argument, 0, 4},
|
{ "dump-modversions", no_argument, 0, 4 },
|
||||||
{"show-exports", no_argument, 0, 6},
|
{ "show-exports", no_argument, 0, 6 },
|
||||||
|
|
||||||
{"dry-run", no_argument, 0, 'n'},
|
{ "dry-run", no_argument, 0, 'n' },
|
||||||
{"show", no_argument, 0, 'n'},
|
{ "show", no_argument, 0, 'n' },
|
||||||
|
|
||||||
{"config", required_argument, 0, 'C'},
|
{ "config", required_argument, 0, 'C' },
|
||||||
{"dirname", required_argument, 0, 'd'},
|
{ "dirname", required_argument, 0, 'd' },
|
||||||
{"set-version", required_argument, 0, 'S'},
|
{ "set-version", required_argument, 0, 'S' },
|
||||||
|
|
||||||
{"syslog", no_argument, 0, 's'},
|
{ "syslog", no_argument, 0, 's' },
|
||||||
{"quiet", no_argument, 0, 'q'},
|
{ "quiet", no_argument, 0, 'q' },
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{ "verbose", no_argument, 0, 'v' },
|
||||||
{"version", no_argument, 0, 'V'},
|
{ "version", no_argument, 0, 'V' },
|
||||||
{"help", no_argument, 0, 'h'},
|
{ "help", no_argument, 0, 'h' },
|
||||||
{NULL, 0, 0, 0},
|
{ NULL, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
printf("Usage:\n"
|
printf("Usage:\n"
|
||||||
"\t%s [options] [-i] [-b] modulename\n"
|
"\t%s [options] [-i] [-b] modulename\n"
|
||||||
"\t%s [options] -a [-i] [-b] modulename [modulename...]\n"
|
"\t%s [options] -a [-i] [-b] modulename [modulename...]\n"
|
||||||
"\t%s [options] -r [-i] modulename\n"
|
"\t%s [options] -r [-i] modulename\n"
|
||||||
"\t%s [options] -r -a [-i] modulename [modulename...]\n"
|
"\t%s [options] -r -a [-i] modulename [modulename...]\n"
|
||||||
"\t%s [options] -c\n"
|
"\t%s [options] -c\n"
|
||||||
"\t%s [options] --dump-modversions filename\n"
|
"\t%s [options] --dump-modversions filename\n"
|
||||||
"Management Options:\n"
|
"Management Options:\n"
|
||||||
"\t-a, --all Consider every non-argument to\n"
|
"\t-a, --all Consider every non-argument to\n"
|
||||||
"\t be a module name to be inserted\n"
|
"\t be a module name to be inserted\n"
|
||||||
"\t or removed (-r)\n"
|
"\t or removed (-r)\n"
|
||||||
"\t-r, --remove Remove modules instead of inserting\n"
|
"\t-r, --remove Remove modules instead of inserting\n"
|
||||||
"\t --remove-dependencies Deprecated: use --remove-holders\n"
|
"\t --remove-dependencies Deprecated: use --remove-holders\n"
|
||||||
"\t --remove-holders Also remove module holders (use together with -r)\n"
|
"\t --remove-holders Also remove module holders (use together with -r)\n"
|
||||||
"\t-w, --wait <MSEC> When removing a module, wait up to MSEC for\n"
|
"\t-w, --wait <MSEC> When removing a module, wait up to MSEC for\n"
|
||||||
"\t module's refcount to become 0 so it can be\n"
|
"\t module's refcount to become 0 so it can be\n"
|
||||||
"\t removed (use together with -r)\n"
|
"\t removed (use together with -r)\n"
|
||||||
"\t --first-time Fail if module already inserted or removed\n"
|
"\t --first-time Fail if module already inserted or removed\n"
|
||||||
"\t-i, --ignore-install Ignore install commands\n"
|
"\t-i, --ignore-install Ignore install commands\n"
|
||||||
"\t-i, --ignore-remove Ignore remove commands\n"
|
"\t-i, --ignore-remove Ignore remove commands\n"
|
||||||
"\t-b, --use-blacklist Apply blacklist to resolved alias.\n"
|
"\t-b, --use-blacklist Apply blacklist to resolved alias.\n"
|
||||||
"\t-f, --force Force module insertion or removal.\n"
|
"\t-f, --force Force module insertion or removal.\n"
|
||||||
"\t implies --force-modversions and\n"
|
"\t implies --force-modversions and\n"
|
||||||
"\t --force-vermagic\n"
|
"\t --force-vermagic\n"
|
||||||
"\t --force-modversion Ignore module's version\n"
|
"\t --force-modversion Ignore module's version\n"
|
||||||
"\t --force-vermagic Ignore module's version magic\n"
|
"\t --force-vermagic Ignore module's version magic\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Query Options:\n"
|
"Query Options:\n"
|
||||||
"\t-R, --resolve-alias Only lookup and print alias and exit\n"
|
"\t-R, --resolve-alias Only lookup and print alias and exit\n"
|
||||||
"\t-D, --show-depends Only print module dependencies and exit\n"
|
"\t-D, --show-depends Only print module dependencies and exit\n"
|
||||||
"\t-c, --showconfig Print out known configuration and exit\n"
|
"\t-c, --showconfig Print out known configuration and exit\n"
|
||||||
"\t-c, --show-config Same as --showconfig\n"
|
"\t-c, --show-config Same as --showconfig\n"
|
||||||
"\t --show-modversions Dump module symbol version and exit\n"
|
"\t --show-modversions Dump module symbol version and exit\n"
|
||||||
"\t --dump-modversions Same as --show-modversions\n"
|
"\t --dump-modversions Same as --show-modversions\n"
|
||||||
"\t --show-exports Only print module exported symbol versions and exit\n"
|
"\t --show-exports Only print module exported symbol versions and exit\n"
|
||||||
"\n"
|
"\n"
|
||||||
"General Options:\n"
|
"General Options:\n"
|
||||||
"\t-n, --dry-run Do not execute operations, just print out\n"
|
"\t-n, --dry-run Do not execute operations, just print out\n"
|
||||||
"\t-n, --show Same as --dry-run\n"
|
"\t-n, --show Same as --dry-run\n"
|
||||||
|
|
||||||
"\t-C, --config=FILE Use FILE instead of default search paths\n"
|
"\t-C, --config=FILE Use FILE instead of default search paths\n"
|
||||||
"\t-d, --dirname=DIR Use DIR as filesystem root for " MODULE_DIRECTORY "\n"
|
"\t-d, --dirname=DIR Use DIR as filesystem root for " MODULE_DIRECTORY
|
||||||
"\t-S, --set-version=VERSION Use VERSION instead of `uname -r`\n"
|
"\n"
|
||||||
|
"\t-S, --set-version=VERSION Use VERSION instead of `uname -r`\n"
|
||||||
|
|
||||||
"\t-s, --syslog print to syslog, not stderr\n"
|
"\t-s, --syslog print to syslog, not stderr\n"
|
||||||
"\t-q, --quiet disable messages\n"
|
"\t-q, --quiet disable messages\n"
|
||||||
"\t-v, --verbose enables more messages\n"
|
"\t-v, --verbose enables more messages\n"
|
||||||
"\t-V, --version show version\n"
|
"\t-V, --version show version\n"
|
||||||
"\t-h, --help show this help\n",
|
"\t-h, --help show this help\n",
|
||||||
program_invocation_short_name, program_invocation_short_name,
|
program_invocation_short_name, program_invocation_short_name,
|
||||||
program_invocation_short_name, program_invocation_short_name,
|
program_invocation_short_name, program_invocation_short_name,
|
||||||
program_invocation_short_name, program_invocation_short_name);
|
program_invocation_short_name, program_invocation_short_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
_printf_format_(1, 2)
|
_printf_format_(1, 2) static inline void _show(const char *fmt, ...)
|
||||||
static inline void _show(const char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ static int show_config(struct kmod_ctx *ctx)
|
|||||||
};
|
};
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(ci); i++) {
|
for (i = 0; i < ARRAY_SIZE(ci); i++) {
|
||||||
struct kmod_config_iter *iter = ci[i].get_iter(ctx);
|
struct kmod_config_iter *iter = ci[i].get_iter(ctx);
|
||||||
|
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
@ -183,8 +183,7 @@ static int show_config(struct kmod_ctx *ctx)
|
|||||||
while (kmod_config_iter_next(iter)) {
|
while (kmod_config_iter_next(iter)) {
|
||||||
const char *val;
|
const char *val;
|
||||||
|
|
||||||
printf("%s %s", ci[i].name,
|
printf("%s %s", ci[i].name, kmod_config_iter_get_key(iter));
|
||||||
kmod_config_iter_get_key(iter));
|
|
||||||
val = kmod_config_iter_get_value(iter);
|
val = kmod_config_iter_get_value(iter);
|
||||||
if (val != NULL) {
|
if (val != NULL) {
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
@ -217,8 +216,7 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
|
|||||||
|
|
||||||
err = kmod_module_get_versions(mod, &list);
|
err = kmod_module_get_versions(mod, &list);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
LOG("could not get modversions of %s: %s\n",
|
LOG("could not get modversions of %s: %s\n", filename, strerror(-err));
|
||||||
filename, strerror(-err));
|
|
||||||
kmod_module_unref(mod);
|
kmod_module_unref(mod);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -226,7 +224,7 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
|
|||||||
kmod_list_foreach(l, list) {
|
kmod_list_foreach(l, list) {
|
||||||
const char *symbol = kmod_module_version_get_symbol(l);
|
const char *symbol = kmod_module_version_get_symbol(l);
|
||||||
uint64_t crc = kmod_module_version_get_crc(l);
|
uint64_t crc = kmod_module_version_get_crc(l);
|
||||||
printf("0x%08"PRIx64"\t%s\n", crc, symbol);
|
printf("0x%08" PRIx64 "\t%s\n", crc, symbol);
|
||||||
}
|
}
|
||||||
kmod_module_versions_free_list(list);
|
kmod_module_versions_free_list(list);
|
||||||
kmod_module_unref(mod);
|
kmod_module_unref(mod);
|
||||||
@ -245,8 +243,7 @@ static int show_exports(struct kmod_ctx *ctx, const char *filename)
|
|||||||
|
|
||||||
err = kmod_module_get_symbols(mod, &list);
|
err = kmod_module_get_symbols(mod, &list);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
LOG("could not get symbols of %s: %s\n",
|
LOG("could not get symbols of %s: %s\n", filename, strerror(-err));
|
||||||
filename, strerror(-err));
|
|
||||||
kmod_module_unref(mod);
|
kmod_module_unref(mod);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -254,15 +251,15 @@ static int show_exports(struct kmod_ctx *ctx, const char *filename)
|
|||||||
kmod_list_foreach(l, list) {
|
kmod_list_foreach(l, list) {
|
||||||
const char *symbol = kmod_module_symbol_get_symbol(l);
|
const char *symbol = kmod_module_symbol_get_symbol(l);
|
||||||
uint64_t crc = kmod_module_symbol_get_crc(l);
|
uint64_t crc = kmod_module_symbol_get_crc(l);
|
||||||
printf("0x%08"PRIx64"\t%s\n", crc, symbol);
|
printf("0x%08" PRIx64 "\t%s\n", crc, symbol);
|
||||||
}
|
}
|
||||||
kmod_module_symbols_free_list(list);
|
kmod_module_symbols_free_list(list);
|
||||||
kmod_module_unref(mod);
|
kmod_module_unref(mod);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int command_do(struct kmod_module *module, const char *type,
|
static int command_do(struct kmod_module *module, const char *type, const char *command,
|
||||||
const char *command, const char *cmdline_opts)
|
const char *cmdline_opts)
|
||||||
{
|
{
|
||||||
const char *modname = kmod_module_get_name(module);
|
const char *modname = kmod_module_get_name(module);
|
||||||
char *p, *cmd = NULL;
|
char *p, *cmd = NULL;
|
||||||
@ -319,8 +316,7 @@ end:
|
|||||||
static int rmmod_do_remove_module(struct kmod_module *mod)
|
static int rmmod_do_remove_module(struct kmod_module *mod)
|
||||||
{
|
{
|
||||||
const char *modname = kmod_module_get_name(mod);
|
const char *modname = kmod_module_get_name(mod);
|
||||||
unsigned long long interval_msec = 0, t0_msec = 0,
|
unsigned long long interval_msec = 0, t0_msec = 0, tend_msec = 0;
|
||||||
tend_msec = 0;
|
|
||||||
int flags = 0, err;
|
int flags = 0, err;
|
||||||
|
|
||||||
SHOW("rmmod %s\n", modname);
|
SHOW("rmmod %s\n", modname);
|
||||||
@ -352,7 +348,7 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
until_msec = get_backoff_delta_msec(t0_msec, tend_msec,
|
until_msec = get_backoff_delta_msec(t0_msec, tend_msec,
|
||||||
&interval_msec);
|
&interval_msec);
|
||||||
err = sleep_until_msec(until_msec);
|
err = sleep_until_msec(until_msec);
|
||||||
|
|
||||||
if (!t0_msec)
|
if (!t0_msec)
|
||||||
@ -374,8 +370,8 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RMMOD_FLAG_REMOVE_HOLDERS 0x1
|
#define RMMOD_FLAG_REMOVE_HOLDERS 0x1
|
||||||
#define RMMOD_FLAG_IGNORE_BUILTIN 0x2
|
#define RMMOD_FLAG_IGNORE_BUILTIN 0x2
|
||||||
static int rmmod_do_module(struct kmod_module *mod, int flags);
|
static int rmmod_do_module(struct kmod_module *mod, int flags);
|
||||||
|
|
||||||
/* Remove modules in reverse order */
|
/* Remove modules in reverse order */
|
||||||
@ -405,8 +401,8 @@ static int rmmod_do_module(struct kmod_module *mod, int flags)
|
|||||||
if (!ignore_commands) {
|
if (!ignore_commands) {
|
||||||
err = kmod_module_get_softdeps(mod, &pre, &post);
|
err = kmod_module_get_softdeps(mod, &pre, &post);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
WRN("could not get softdeps of '%s': %s\n",
|
WRN("could not get softdeps of '%s': %s\n", modname,
|
||||||
modname, strerror(-err));
|
strerror(-err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,14 +531,12 @@ static int rmmod_all(struct kmod_ctx *ctx, char **args, int nargs)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_action(struct kmod_module *m, bool install,
|
static void print_action(struct kmod_module *m, bool install, const char *options)
|
||||||
const char *options)
|
|
||||||
{
|
{
|
||||||
const char *path;
|
const char *path;
|
||||||
|
|
||||||
if (install) {
|
if (install) {
|
||||||
printf("install %s %s\n", kmod_module_get_install_commands(m),
|
printf("install %s %s\n", kmod_module_get_install_commands(m), options);
|
||||||
options);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,12 +553,10 @@ static void print_action(struct kmod_module *m, bool install,
|
|||||||
printf("insmod %s %s\n", kmod_module_get_path(m), options);
|
printf("insmod %s %s\n", kmod_module_get_path(m), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int insmod_insert(struct kmod_module *mod, int flags,
|
static int insmod_insert(struct kmod_module *mod, int flags, const char *extra_options)
|
||||||
const char *extra_options)
|
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
void (*show)(struct kmod_module *m, bool install,
|
void (*show)(struct kmod_module *m, bool install, const char *options) = NULL;
|
||||||
const char *options) = NULL;
|
|
||||||
|
|
||||||
if (do_show || verbose > DEFAULT_VERBOSE)
|
if (do_show || verbose > DEFAULT_VERBOSE)
|
||||||
show = &print_action;
|
show = &print_action;
|
||||||
@ -572,8 +564,8 @@ static int insmod_insert(struct kmod_module *mod, int flags,
|
|||||||
if (lookup_only)
|
if (lookup_only)
|
||||||
printf("%s\n", kmod_module_get_name(mod));
|
printf("%s\n", kmod_module_get_name(mod));
|
||||||
else
|
else
|
||||||
err = kmod_module_probe_insert_module(mod, flags,
|
err = kmod_module_probe_insert_module(mod, flags, extra_options, NULL,
|
||||||
extra_options, NULL, NULL, show);
|
NULL, show);
|
||||||
|
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
/* ignore flag return values such as a mod being blacklisted */
|
/* ignore flag return values such as a mod being blacklisted */
|
||||||
@ -582,17 +574,16 @@ static int insmod_insert(struct kmod_module *mod, int flags,
|
|||||||
switch (err) {
|
switch (err) {
|
||||||
case -EEXIST:
|
case -EEXIST:
|
||||||
ERR("could not insert '%s': Module already in kernel\n",
|
ERR("could not insert '%s': Module already in kernel\n",
|
||||||
kmod_module_get_name(mod));
|
kmod_module_get_name(mod));
|
||||||
break;
|
break;
|
||||||
case -ENOENT:
|
case -ENOENT:
|
||||||
ERR("could not insert '%s': Unknown symbol in module, "
|
ERR("could not insert '%s': Unknown symbol in module, "
|
||||||
"or unknown parameter (see dmesg)\n",
|
"or unknown parameter (see dmesg)\n",
|
||||||
kmod_module_get_name(mod));
|
kmod_module_get_name(mod));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERR("could not insert '%s': %s\n",
|
ERR("could not insert '%s': %s\n", kmod_module_get_name(mod),
|
||||||
kmod_module_get_name(mod),
|
strerror(-err));
|
||||||
strerror(-err));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,8 +591,7 @@ static int insmod_insert(struct kmod_module *mod, int flags,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int insmod(struct kmod_ctx *ctx, const char *alias,
|
static int insmod(struct kmod_ctx *ctx, const char *alias, const char *extra_options)
|
||||||
const char *extra_options)
|
|
||||||
{
|
{
|
||||||
struct kmod_list *l, *list = NULL;
|
struct kmod_list *l, *list = NULL;
|
||||||
struct kmod_module *mod = NULL;
|
struct kmod_module *mod = NULL;
|
||||||
@ -611,14 +601,14 @@ static int insmod(struct kmod_ctx *ctx, const char *alias,
|
|||||||
err = kmod_module_new_from_path(ctx, alias, &mod);
|
err = kmod_module_new_from_path(ctx, alias, &mod);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
LOG("Failed to get module from path %s: %s\n", alias,
|
LOG("Failed to get module from path %s: %s\n", alias,
|
||||||
strerror(-err));
|
strerror(-err));
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = kmod_module_new_from_lookup(ctx, alias, &list);
|
err = kmod_module_new_from_lookup(ctx, alias, &list);
|
||||||
if (list == NULL || err < 0) {
|
if (list == NULL || err < 0) {
|
||||||
LOG("Module %s not found in directory %s\n", alias,
|
LOG("Module %s not found in directory %s\n", alias,
|
||||||
ctx ? kmod_get_dirname(ctx) : "(missing)");
|
ctx ? kmod_get_dirname(ctx) : "(missing)");
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -766,7 +756,7 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
new_argv[0] = orig_argv[0];
|
new_argv[0] = orig_argv[0];
|
||||||
str = (char *) (new_argv + argc + space_count + 3);
|
str = (char *)(new_argv + argc + space_count + 3);
|
||||||
memcpy(str, env, envlen + 1);
|
memcpy(str, env, envlen + 1);
|
||||||
|
|
||||||
str_end = str + envlen;
|
str_end = str + envlen;
|
||||||
@ -959,9 +949,7 @@ static int do_modprobe(int argc, char **orig_argv)
|
|||||||
nargs = argc - optind;
|
nargs = argc - optind;
|
||||||
|
|
||||||
if (!use_syslog &&
|
if (!use_syslog &&
|
||||||
(!stderr ||
|
(!stderr || fileno(stderr) == -1 || fstat(fileno(stderr), &stat_buf)))
|
||||||
fileno(stderr) == -1 ||
|
|
||||||
fstat(fileno(stderr), &stat_buf)))
|
|
||||||
use_syslog = 1;
|
use_syslog = 1;
|
||||||
|
|
||||||
log_open(use_syslog);
|
log_open(use_syslog);
|
||||||
@ -988,10 +976,10 @@ static int do_modprobe(int argc, char **orig_argv)
|
|||||||
kversion = u.release;
|
kversion = u.release;
|
||||||
}
|
}
|
||||||
n = snprintf(dirname_buf, sizeof(dirname_buf),
|
n = snprintf(dirname_buf, sizeof(dirname_buf),
|
||||||
"%s" MODULE_DIRECTORY "/%s", root, kversion);
|
"%s" MODULE_DIRECTORY "/%s", root, kversion);
|
||||||
if (n >= (int)sizeof(dirname_buf)) {
|
if (n >= (int)sizeof(dirname_buf)) {
|
||||||
ERR("bad directory %s" MODULE_DIRECTORY
|
ERR("bad directory %s" MODULE_DIRECTORY "/%s: path too long\n",
|
||||||
"/%s: path too long\n", root, kversion);
|
root, kversion);
|
||||||
err = -1;
|
err = -1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -35,18 +35,19 @@ static const struct option cmdopts[] = {
|
|||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
printf("Usage:\n"
|
printf("Usage:\n"
|
||||||
"\t%s [options] modulename ...\n"
|
"\t%s [options] modulename ...\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-f, --force DANGEROUS: forces a module unload and may\n"
|
"\t-f, --force DANGEROUS: forces a module unload and may\n"
|
||||||
"\t crash your machine\n"
|
"\t crash your machine\n"
|
||||||
"\t-s, --syslog print to syslog, not stderr\n"
|
"\t-s, --syslog print to syslog, not stderr\n"
|
||||||
"\t-v, --verbose enables more messages\n"
|
"\t-v, --verbose enables more messages\n"
|
||||||
"\t-V, --version show version\n"
|
"\t-V, --version show version\n"
|
||||||
"\t-h, --help show this help\n",
|
"\t-h, --help show this help\n",
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_module_inuse(struct kmod_module *mod) {
|
static int check_module_inuse(struct kmod_module *mod)
|
||||||
|
{
|
||||||
struct kmod_list *holders;
|
struct kmod_list *holders;
|
||||||
int state, ret;
|
int state, ret;
|
||||||
|
|
||||||
@ -56,8 +57,7 @@ static int check_module_inuse(struct kmod_module *mod) {
|
|||||||
ERR("Module %s is builtin.\n", kmod_module_get_name(mod));
|
ERR("Module %s is builtin.\n", kmod_module_get_name(mod));
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
} else if (state < 0) {
|
} else if (state < 0) {
|
||||||
ERR("Module %s is not currently loaded\n",
|
ERR("Module %s is not currently loaded\n", kmod_module_get_name(mod));
|
||||||
kmod_module_get_name(mod));
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,8 +154,7 @@ static int do_rmmod(int argc, char *argv[])
|
|||||||
err = kmod_module_new_from_name(ctx, arg, &mod);
|
err = kmod_module_new_from_name(ctx, arg, &mod);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ERR("could not use module %s: %s\n", arg,
|
ERR("could not use module %s: %s\n", arg, strerror(-err));
|
||||||
strerror(-err));
|
|
||||||
r = EXIT_FAILURE;
|
r = EXIT_FAILURE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -167,8 +166,7 @@ static int do_rmmod(int argc, char *argv[])
|
|||||||
|
|
||||||
err = kmod_module_remove_module(mod, flags);
|
err = kmod_module_remove_module(mod, flags);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ERR("could not remove module %s: %s\n", arg,
|
ERR("could not remove module %s: %s\n", arg, strerror(-err));
|
||||||
strerror(-err));
|
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
next:
|
next:
|
||||||
|
@ -41,24 +41,24 @@ static const struct static_nodes_format *static_nodes_formats[] = {
|
|||||||
|
|
||||||
static const char cmdopts_s[] = "o:f:h";
|
static const char cmdopts_s[] = "o:f:h";
|
||||||
static const struct option cmdopts[] = {
|
static const struct option cmdopts[] = {
|
||||||
{ "output", required_argument, 0, 'o'},
|
{ "output", required_argument, 0, 'o' },
|
||||||
{ "format", required_argument, 0, 'f'},
|
{ "format", required_argument, 0, 'f' },
|
||||||
{ "help", no_argument, 0, 'h'},
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ },
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int write_human(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min)
|
static int write_human(FILE *out, char modname[], char devname[], char type,
|
||||||
|
unsigned int maj, unsigned int min)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = fprintf(out,
|
ret = fprintf(out,
|
||||||
"Module: %s\n"
|
"Module: %s\n"
|
||||||
"\tDevice node: /dev/%s\n"
|
"\tDevice node: /dev/%s\n"
|
||||||
"\t\tType: %s device\n"
|
"\t\tType: %s device\n"
|
||||||
"\t\tMajor: %u\n"
|
"\t\tMajor: %u\n"
|
||||||
"\t\tMinor: %u\n",
|
"\t\tMinor: %u\n",
|
||||||
modname, devname,
|
modname, devname, (type == 'c') ? "character" : "block", maj, min);
|
||||||
(type == 'c') ? "character" : "block", maj, min);
|
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
else
|
else
|
||||||
@ -71,21 +71,21 @@ static const struct static_nodes_format static_nodes_format_human = {
|
|||||||
.description = "(default) a human readable format. Do not parse.",
|
.description = "(default) a human readable format. Do not parse.",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int write_tmpfiles(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min)
|
static int write_tmpfiles(FILE *out, char modname[], char devname[], char type,
|
||||||
|
unsigned int maj, unsigned int min)
|
||||||
{
|
{
|
||||||
const char *dir;
|
const char *dir;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dir = strrchr(devname, '/');
|
dir = strrchr(devname, '/');
|
||||||
if (dir) {
|
if (dir) {
|
||||||
ret = fprintf(out, "d /dev/%.*s 0755 - - -\n",
|
ret = fprintf(out, "d /dev/%.*s 0755 - - -\n", (int)(dir - devname),
|
||||||
(int)(dir - devname), devname);
|
devname);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = fprintf(out, "%c! /dev/%s 0600 - - - %u:%u\n",
|
ret = fprintf(out, "%c! /dev/%s 0600 - - - %u:%u\n", type, devname, maj, min);
|
||||||
type, devname, maj, min);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
@ -98,7 +98,8 @@ static const struct static_nodes_format static_nodes_format_tmpfiles = {
|
|||||||
.description = "the tmpfiles.d(5) format used by systemd-tmpfiles.",
|
.description = "the tmpfiles.d(5) format used by systemd-tmpfiles.",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int write_devname(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min)
|
static int write_devname(FILE *out, char modname[], char devname[], char type,
|
||||||
|
unsigned int maj, unsigned int min)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ static void help(void)
|
|||||||
"\t-h, --help show this help\n"
|
"\t-h, --help show this help\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Formats:\n",
|
"Formats:\n",
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(static_nodes_formats); i++) {
|
for (i = 0; i < ARRAY_SIZE(static_nodes_formats); i++) {
|
||||||
if (static_nodes_formats[i]->description != NULL) {
|
if (static_nodes_formats[i]->description != NULL) {
|
||||||
@ -172,8 +173,7 @@ static int do_static_nodes(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
fprintf(stderr, "Unknown format: '%s'.\n",
|
fprintf(stderr, "Unknown format: '%s'.\n", optarg);
|
||||||
optarg);
|
|
||||||
help();
|
help();
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
@ -186,8 +186,7 @@ static int do_static_nodes(int argc, char *argv[])
|
|||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unexpected commandline option '%c'.\n",
|
fprintf(stderr, "Unexpected commandline option '%c'.\n", c);
|
||||||
c);
|
|
||||||
help();
|
help();
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
@ -200,9 +199,12 @@ static int do_static_nodes(int argc, char *argv[])
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = snprintf(modules, sizeof(modules), MODULE_DIRECTORY "/%s/modules.devname", kernel.release);
|
r = snprintf(modules, sizeof(modules), MODULE_DIRECTORY "/%s/modules.devname",
|
||||||
|
kernel.release);
|
||||||
if (r >= (int)sizeof(modules)) {
|
if (r >= (int)sizeof(modules)) {
|
||||||
fprintf(stderr, "Error: could not open " MODULE_DIRECTORY "/%s/modules.devname - path too long\n",
|
fprintf(stderr,
|
||||||
|
"Error: could not open " MODULE_DIRECTORY
|
||||||
|
"/%s/modules.devname - path too long\n",
|
||||||
kernel.release);
|
kernel.release);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
@ -210,11 +212,15 @@ static int do_static_nodes(int argc, char *argv[])
|
|||||||
in = fopen(modules, "re");
|
in = fopen(modules, "re");
|
||||||
if (in == NULL) {
|
if (in == NULL) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
fprintf(stderr, "Warning: " MODULE_DIRECTORY "/%s/modules.devname not found - ignoring\n",
|
fprintf(stderr,
|
||||||
|
"Warning: " MODULE_DIRECTORY
|
||||||
|
"/%s/modules.devname not found - ignoring\n",
|
||||||
kernel.release);
|
kernel.release);
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: could not open " MODULE_DIRECTORY "/%s/modules.devname - %m\n",
|
fprintf(stderr,
|
||||||
|
"Error: could not open " MODULE_DIRECTORY
|
||||||
|
"/%s/modules.devname - %m\n",
|
||||||
kernel.release);
|
kernel.release);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@ -223,7 +229,8 @@ static int do_static_nodes(int argc, char *argv[])
|
|||||||
|
|
||||||
r = mkdir_parents(output, 0755);
|
r = mkdir_parents(output, 0755);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
fprintf(stderr, "Error: could not create parent directory for %s - %m.\n", output);
|
fprintf(stderr, "Error: could not create parent directory for %s - %m.\n",
|
||||||
|
output);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
@ -245,8 +252,8 @@ static int do_static_nodes(int argc, char *argv[])
|
|||||||
if (buf[0] == '#')
|
if (buf[0] == '#')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
matches = sscanf(buf, "%s %s %c%u:%u", modname, devname,
|
matches =
|
||||||
&type, &maj, &min);
|
sscanf(buf, "%s %s %c%u:%u", modname, devname, &type, &maj, &min);
|
||||||
if (matches != 5 || (type != 'c' && type != 'b')) {
|
if (matches != 5 || (type != 'c' && type != 'b')) {
|
||||||
fprintf(stderr, "Error: invalid devname entry: %s", buf);
|
fprintf(stderr, "Error: invalid devname entry: %s", buf);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
|
Loading…
Reference in New Issue
Block a user