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:
Emil Velikov 2024-09-11 17:30:40 +01:00 committed by Lucas De Marchi
parent 4c760f7edd
commit f34d115d09
9 changed files with 455 additions and 537 deletions

File diff suppressed because it is too large Load Diff

View File

@ -30,15 +30,15 @@ static const struct option cmdopts[] = {
static void help(void)
{
printf("Usage:\n"
"\t%s [options] filename [args]\n"
"Options:\n"
"\t-f, --force DANGEROUS: forces a module load, may cause\n"
"\t data corruption and crash your machine\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n",
program_invocation_short_name);
"\t%s [options] filename [args]\n"
"Options:\n"
"\t-f, --force DANGEROUS: forces a module load, may cause\n"
"\t data corruption and crash your machine\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n",
program_invocation_short_name);
}
static const char *mod_strerror(int err)
@ -95,8 +95,7 @@ static int do_insmod(int argc, char *argv[])
case '?':
return EXIT_FAILURE;
default:
ERR("unexpected getopt_long() value '%c'.\n",
c);
ERR("unexpected getopt_long() value '%c'.\n", c);
return EXIT_FAILURE;
}
}
@ -145,16 +144,14 @@ static int do_insmod(int argc, char *argv[])
err = kmod_module_new_from_path(ctx, filename, &mod);
if (err < 0) {
ERR("could not load module %s: %s\n", filename,
strerror(-err));
ERR("could not load module %s: %s\n", filename, strerror(-err));
r++;
goto end;
}
err = kmod_module_insert_module(mod, flags, opts);
if (err < 0) {
ERR("could not insert module %s: %s\n", filename,
mod_strerror(-err));
ERR("could not insert module %s: %s\n", filename, mod_strerror(-err));
r++;
}
kmod_module_unref(mod);

View File

@ -47,17 +47,17 @@ static int kmod_help(int argc, char *argv[])
size_t i;
printf("kmod - Manage kernel modules: list, load, unload, etc\n"
"Usage:\n"
"\t%s [options] command [command_options]\n\n"
"Options:\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n\n"
"Commands:\n", basename(argv[0]));
"Usage:\n"
"\t%s [options] command [command_options]\n\n"
"Options:\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n\n"
"Commands:\n",
basename(argv[0]));
for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) {
if (kmod_cmds[i]->help != NULL) {
printf(" %-12s %s\n", kmod_cmds[i]->name,
kmod_cmds[i]->help);
printf(" %-12s %s\n", kmod_cmds[i]->name, 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++) {
if (kmod_compat_cmds[i]->help != NULL) {
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 '?':
return EXIT_FAILURE;
default:
fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n", c);
fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n",
c);
return EXIT_FAILURE;
}
}
@ -133,7 +134,6 @@ fail:
return EXIT_FAILURE;
}
static int handle_kmod_compat_commands(int argc, char *argv[])
{
const char *cmd;

View File

@ -48,9 +48,9 @@ static const char *prio_to_str(char buf[static PRIO_MAX_SIZE], int prio)
return prioname;
}
_printf_format_(6, 0)
static void log_kmod(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args)
_printf_format_(6, 0) static void log_kmod(void *data, int priority, const char *file,
int line, const char *fn, const char *format,
va_list args)
{
char buf[PRIO_MAX_SIZE];
const char *prioname;
@ -63,19 +63,17 @@ static void log_kmod(void *data, int priority, const char *file, int line,
if (log_use_syslog) {
#ifdef ENABLE_DEBUG
syslog(priority, "%s: %s:%d %s() %s", prioname, file, line,
fn, str);
syslog(priority, "%s: %s:%d %s() %s", prioname, file, line, fn, str);
#else
syslog(priority, "%s: %s", prioname, str);
#endif
} else {
#ifdef ENABLE_DEBUG
fprintf(stderr, "%s: %s: %s:%d %s() %s",
program_invocation_short_name, prioname, file, line,
fn, str);
fprintf(stderr, "%s: %s: %s:%d %s() %s", program_invocation_short_name,
prioname, file, line, fn, str);
#else
fprintf(stderr, "%s: %s: %s", program_invocation_short_name,
prioname, str);
fprintf(stderr, "%s: %s: %s", program_invocation_short_name, prioname,
str);
#endif
}
@ -118,8 +116,8 @@ void log_printf(int prio, const char *fmt, ...)
if (log_use_syslog)
syslog(prio, "%s: %s", prioname, msg);
else
fprintf(stderr, "%s: %s: %s", program_invocation_short_name,
prioname, msg);
fprintf(stderr, "%s: %s: %s", program_invocation_short_name, prioname,
msg);
free(msg);
if (prio <= LOG_CRIT)

View File

@ -29,13 +29,13 @@ static const struct option cmdopts[] = {
static void help(void)
{
printf("Usage:\n"
"\t%s [options]\n"
"Options:\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n",
program_invocation_short_name);
"\t%s [options]\n"
"Options:\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n",
program_invocation_short_name);
}
static int do_lsmod(int argc, char *argv[])

View File

@ -34,13 +34,14 @@ struct param {
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;
for (it = *list; it != NULL; it = it->next) {
if (it->namelen == namelen &&
memcmp(it->name, name, namelen) == 0)
if (it->namelen == namelen && memcmp(it->name, name, namelen) == 0)
break;
}
@ -78,8 +79,7 @@ static int process_parm(const char *key, const char *value, struct param **param
struct param *it;
const char *colon = strchr(value, ':');
if (colon == NULL) {
ERR("Found invalid \"%s=%s\": missing ':'\n",
key, value);
ERR("Found invalid \"%s=%s\": missing ':'\n", key, value);
return 0;
}
@ -128,19 +128,13 @@ static int modinfo_params_do(const struct kmod_list *list)
params = p->next;
if (p->param == NULL)
printf("%.*s: (%.*s)%c",
p->namelen, p->name, p->typelen, p->type,
printf("%.*s: (%.*s)%c", p->namelen, p->name, p->typelen, p->type,
separator);
else if (p->type != NULL)
printf("%.*s:%.*s (%.*s)%c",
p->namelen, p->name,
p->paramlen, p->param,
p->typelen, p->type,
separator);
printf("%.*s:%.*s (%.*s)%c", p->namelen, p->name, p->paramlen,
p->param, p->typelen, p->type, separator);
else
printf("%.*s:%.*s%c",
p->namelen, p->name,
p->paramlen, p->param,
printf("%.*s:%.*s%c", p->namelen, p->name, p->paramlen, p->param,
separator);
free(p);
@ -167,8 +161,7 @@ static int modinfo_do(struct kmod_module *mod)
if (is_builtin) {
if (field == NULL)
printf("%-16s%s%c", "name:",
kmod_module_get_name(mod), separator);
printf("%-16s%s%c", "name:", kmod_module_get_name(mod), separator);
else if (field != NULL && streq(field, "name"))
printf("%s%c", kmod_module_get_name(mod), separator);
filename = "(builtin)";
@ -178,8 +171,7 @@ static int modinfo_do(struct kmod_module *mod)
printf("%s%c", filename, separator);
return 0;
} else if (field == NULL) {
printf("%-16s%s%c", "filename:",
filename, separator);
printf("%-16s%s%c", "filename:", filename, separator);
}
err = kmod_module_get_info(mod, &list);
@ -191,8 +183,8 @@ static int modinfo_do(struct kmod_module *mod)
*/
return 0;
}
ERR("could not get modinfo from '%s': %s\n",
kmod_module_get_name(mod), strerror(-err));
ERR("could not get modinfo from '%s': %s\n", kmod_module_get_name(mod),
strerror(-err));
return err;
}
@ -238,21 +230,14 @@ static int modinfo_do(struct kmod_module *mod)
params = p->next;
if (p->param == NULL)
printf("%-16s%.*s:%.*s%c", "parm:",
p->namelen, p->name, p->typelen, p->type,
separator);
printf("%-16s%.*s:%.*s%c", "parm:", p->namelen, p->name,
p->typelen, p->type, separator);
else if (p->type != NULL)
printf("%-16s%.*s:%.*s (%.*s)%c", "parm:",
p->namelen, p->name,
p->paramlen, p->param,
p->typelen, p->type,
separator);
printf("%-16s%.*s:%.*s (%.*s)%c", "parm:", p->namelen, p->name,
p->paramlen, p->param, p->typelen, p->type, separator);
else
printf("%-16s%.*s:%.*s%c",
"parm:",
p->namelen, p->name,
p->paramlen, p->param,
separator);
printf("%-16s%.*s:%.*s%c", "parm:", p->namelen, p->name,
p->paramlen, p->param, separator);
free(p);
}
@ -298,7 +283,6 @@ static int modinfo_name_do(struct kmod_ctx *ctx, const char *name)
return err;
}
static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias)
{
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 struct option cmdopts[] = {
{"author", no_argument, 0, 'a'},
{"description", no_argument, 0, 'd'},
{"license", no_argument, 0, 'l'},
{"parameters", no_argument, 0, 'p'},
{"filename", no_argument, 0, 'n'},
{"null", no_argument, 0, '0'},
{"modname", no_argument, 0, 'm'},
{"field", required_argument, 0, 'F'},
{"set-version", required_argument, 0, 'k'},
{"basedir", required_argument, 0, 'b'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{NULL, 0, 0, 0},
{ "author", no_argument, 0, 'a' },
{ "description", no_argument, 0, 'd' },
{ "license", no_argument, 0, 'l' },
{ "parameters", no_argument, 0, 'p' },
{ "filename", no_argument, 0, 'n' },
{ "null", no_argument, 0, '0' },
{ "modname", no_argument, 0, 'm' },
{ "field", required_argument, 0, 'F' },
{ "set-version", required_argument, 0, 'k' },
{ "basedir", required_argument, 0, 'b' },
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ NULL, 0, 0, 0 },
};
static void help(void)
{
printf("Usage:\n"
"\t%s [options] <modulename|filename> [args]\n"
"Options:\n"
"\t-a, --author Print only 'author'\n"
"\t-d, --description Print only 'description'\n"
"\t-l, --license Print only 'license'\n"
"\t-p, --parameters Print only 'parm'\n"
"\t-n, --filename Print only 'filename'\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-F, --field=FIELD Print only provided FIELD\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-V, --version Show version\n"
"\t-h, --help Show this help\n",
program_invocation_short_name);
"\t%s [options] <modulename|filename> [args]\n"
"Options:\n"
"\t-a, --author Print only 'author'\n"
"\t-d, --description Print only 'description'\n"
"\t-l, --license Print only 'license'\n"
"\t-p, --parameters Print only 'parm'\n"
"\t-n, --filename Print only 'filename'\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-F, --field=FIELD Print only provided FIELD\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-V, --version Show version\n"
"\t-h, --help Show this help\n",
program_invocation_short_name);
}
static bool is_module_filename(const char *name)
@ -366,8 +351,8 @@ static bool is_module_filename(const char *name)
struct stat st;
if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
path_ends_with_kmod_ext(name, strlen(name)))
return true;
path_ends_with_kmod_ext(name, strlen(name)))
return true;
return false;
}
@ -452,10 +437,10 @@ static int do_modinfo(int argc, char *argv[])
}
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)) {
ERR("bad directory %s" MODULE_DIRECTORY
"/%s: path too long\n", root, kversion);
ERR("bad directory %s" MODULE_DIRECTORY "/%s: path too long\n",
root, kversion);
return EXIT_FAILURE;
}
dirname = dirname_buf;

View File

@ -49,102 +49,102 @@ static int quiet_inuse = 0;
static const char cmdopts_s[] = "arw:RibfDcnC:d:S:sqvVh";
static const struct option cmdopts[] = {
{"all", no_argument, 0, 'a'},
{ "all", no_argument, 0, 'a' },
{"remove", no_argument, 0, 'r'},
{"remove-dependencies", no_argument, 0, 5},
{"remove-holders", no_argument, 0, 5},
{"wait", required_argument, 0, 'w'},
{ "remove", no_argument, 0, 'r' },
{ "remove-dependencies", no_argument, 0, 5 },
{ "remove-holders", no_argument, 0, 5 },
{ "wait", required_argument, 0, 'w' },
{"resolve-alias", no_argument, 0, 'R'},
{"first-time", no_argument, 0, 3},
{"ignore-install", no_argument, 0, 'i'},
{"ignore-remove", no_argument, 0, 'i'},
{"use-blacklist", no_argument, 0, 'b'},
{"force", no_argument, 0, 'f'},
{"force-modversion", no_argument, 0, 2},
{"force-vermagic", no_argument, 0, 1},
{ "resolve-alias", no_argument, 0, 'R' },
{ "first-time", no_argument, 0, 3 },
{ "ignore-install", no_argument, 0, 'i' },
{ "ignore-remove", no_argument, 0, 'i' },
{ "use-blacklist", no_argument, 0, 'b' },
{ "force", no_argument, 0, 'f' },
{ "force-modversion", no_argument, 0, 2 },
{ "force-vermagic", no_argument, 0, 1 },
{"show-depends", no_argument, 0, 'D'},
{"showconfig", no_argument, 0, 'c'},
{"show-config", no_argument, 0, 'c'},
{"show-modversions", no_argument, 0, 4},
{"dump-modversions", no_argument, 0, 4},
{"show-exports", no_argument, 0, 6},
{ "show-depends", no_argument, 0, 'D' },
{ "showconfig", no_argument, 0, 'c' },
{ "show-config", no_argument, 0, 'c' },
{ "show-modversions", no_argument, 0, 4 },
{ "dump-modversions", no_argument, 0, 4 },
{ "show-exports", no_argument, 0, 6 },
{"dry-run", no_argument, 0, 'n'},
{"show", no_argument, 0, 'n'},
{ "dry-run", no_argument, 0, 'n' },
{ "show", no_argument, 0, 'n' },
{"config", required_argument, 0, 'C'},
{"dirname", required_argument, 0, 'd'},
{"set-version", required_argument, 0, 'S'},
{ "config", required_argument, 0, 'C' },
{ "dirname", required_argument, 0, 'd' },
{ "set-version", required_argument, 0, 'S' },
{"syslog", no_argument, 0, 's'},
{"quiet", no_argument, 0, 'q'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{NULL, 0, 0, 0},
{ "syslog", no_argument, 0, 's' },
{ "quiet", no_argument, 0, 'q' },
{ "verbose", no_argument, 0, 'v' },
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ NULL, 0, 0, 0 },
};
static void help(void)
{
printf("Usage:\n"
"\t%s [options] [-i] [-b] modulename\n"
"\t%s [options] -a [-i] [-b] modulename [modulename...]\n"
"\t%s [options] -r [-i] modulename\n"
"\t%s [options] -r -a [-i] modulename [modulename...]\n"
"\t%s [options] -c\n"
"\t%s [options] --dump-modversions filename\n"
"Management Options:\n"
"\t-a, --all Consider every non-argument to\n"
"\t be a module name to be inserted\n"
"\t or removed (-r)\n"
"\t-r, --remove Remove modules instead of inserting\n"
"\t --remove-dependencies Deprecated: use --remove-holders\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 module's refcount to become 0 so it can be\n"
"\t removed (use together with -r)\n"
"\t --first-time Fail if module already inserted or removed\n"
"\t-i, --ignore-install Ignore install commands\n"
"\t-i, --ignore-remove Ignore remove commands\n"
"\t-b, --use-blacklist Apply blacklist to resolved alias.\n"
"\t-f, --force Force module insertion or removal.\n"
"\t implies --force-modversions and\n"
"\t --force-vermagic\n"
"\t --force-modversion Ignore module's version\n"
"\t --force-vermagic Ignore module's version magic\n"
"\n"
"Query Options:\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-c, --showconfig Print out known configuration and exit\n"
"\t-c, --show-config Same as --showconfig\n"
"\t --show-modversions Dump module symbol version and exit\n"
"\t --dump-modversions Same as --show-modversions\n"
"\t --show-exports Only print module exported symbol versions and exit\n"
"\n"
"General Options:\n"
"\t-n, --dry-run Do not execute operations, just print out\n"
"\t-n, --show Same as --dry-run\n"
"\t%s [options] [-i] [-b] modulename\n"
"\t%s [options] -a [-i] [-b] modulename [modulename...]\n"
"\t%s [options] -r [-i] modulename\n"
"\t%s [options] -r -a [-i] modulename [modulename...]\n"
"\t%s [options] -c\n"
"\t%s [options] --dump-modversions filename\n"
"Management Options:\n"
"\t-a, --all Consider every non-argument to\n"
"\t be a module name to be inserted\n"
"\t or removed (-r)\n"
"\t-r, --remove Remove modules instead of inserting\n"
"\t --remove-dependencies Deprecated: use --remove-holders\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 module's refcount to become 0 so it can be\n"
"\t removed (use together with -r)\n"
"\t --first-time Fail if module already inserted or removed\n"
"\t-i, --ignore-install Ignore install commands\n"
"\t-i, --ignore-remove Ignore remove commands\n"
"\t-b, --use-blacklist Apply blacklist to resolved alias.\n"
"\t-f, --force Force module insertion or removal.\n"
"\t implies --force-modversions and\n"
"\t --force-vermagic\n"
"\t --force-modversion Ignore module's version\n"
"\t --force-vermagic Ignore module's version magic\n"
"\n"
"Query Options:\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-c, --showconfig Print out known configuration and exit\n"
"\t-c, --show-config Same as --showconfig\n"
"\t --show-modversions Dump module symbol version and exit\n"
"\t --dump-modversions Same as --show-modversions\n"
"\t --show-exports Only print module exported symbol versions and exit\n"
"\n"
"General Options:\n"
"\t-n, --dry-run Do not execute operations, just print out\n"
"\t-n, --show Same as --dry-run\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-S, --set-version=VERSION Use VERSION instead of `uname -r`\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-S, --set-version=VERSION Use VERSION instead of `uname -r`\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-q, --quiet disable messages\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\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);
"\t-s, --syslog print to syslog, not stderr\n"
"\t-q, --quiet disable messages\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\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);
}
_printf_format_(1, 2)
static inline void _show(const char *fmt, ...)
_printf_format_(1, 2) static inline void _show(const char *fmt, ...)
{
va_list args;
@ -174,7 +174,7 @@ static int show_config(struct kmod_ctx *ctx)
};
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);
if (iter == NULL)
@ -183,8 +183,7 @@ static int show_config(struct kmod_ctx *ctx)
while (kmod_config_iter_next(iter)) {
const char *val;
printf("%s %s", ci[i].name,
kmod_config_iter_get_key(iter));
printf("%s %s", ci[i].name, kmod_config_iter_get_key(iter));
val = kmod_config_iter_get_value(iter);
if (val != NULL) {
putchar(' ');
@ -217,8 +216,7 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
err = kmod_module_get_versions(mod, &list);
if (err < 0) {
LOG("could not get modversions of %s: %s\n",
filename, strerror(-err));
LOG("could not get modversions of %s: %s\n", filename, strerror(-err));
kmod_module_unref(mod);
return err;
}
@ -226,7 +224,7 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
kmod_list_foreach(l, list) {
const char *symbol = kmod_module_version_get_symbol(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_unref(mod);
@ -245,8 +243,7 @@ static int show_exports(struct kmod_ctx *ctx, const char *filename)
err = kmod_module_get_symbols(mod, &list);
if (err < 0) {
LOG("could not get symbols of %s: %s\n",
filename, strerror(-err));
LOG("could not get symbols of %s: %s\n", filename, strerror(-err));
kmod_module_unref(mod);
return err;
}
@ -254,15 +251,15 @@ static int show_exports(struct kmod_ctx *ctx, const char *filename)
kmod_list_foreach(l, list) {
const char *symbol = kmod_module_symbol_get_symbol(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_unref(mod);
return 0;
}
static int command_do(struct kmod_module *module, const char *type,
const char *command, const char *cmdline_opts)
static int command_do(struct kmod_module *module, const char *type, const char *command,
const char *cmdline_opts)
{
const char *modname = kmod_module_get_name(module);
char *p, *cmd = NULL;
@ -319,8 +316,7 @@ end:
static int rmmod_do_remove_module(struct kmod_module *mod)
{
const char *modname = kmod_module_get_name(mod);
unsigned long long interval_msec = 0, t0_msec = 0,
tend_msec = 0;
unsigned long long interval_msec = 0, t0_msec = 0, tend_msec = 0;
int flags = 0, err;
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,
&interval_msec);
&interval_msec);
err = sleep_until_msec(until_msec);
if (!t0_msec)
@ -374,8 +370,8 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
return err;
}
#define RMMOD_FLAG_REMOVE_HOLDERS 0x1
#define RMMOD_FLAG_IGNORE_BUILTIN 0x2
#define RMMOD_FLAG_REMOVE_HOLDERS 0x1
#define RMMOD_FLAG_IGNORE_BUILTIN 0x2
static int rmmod_do_module(struct kmod_module *mod, int flags);
/* Remove modules in reverse order */
@ -405,8 +401,8 @@ static int rmmod_do_module(struct kmod_module *mod, int flags)
if (!ignore_commands) {
err = kmod_module_get_softdeps(mod, &pre, &post);
if (err < 0) {
WRN("could not get softdeps of '%s': %s\n",
modname, strerror(-err));
WRN("could not get softdeps of '%s': %s\n", modname,
strerror(-err));
return err;
}
@ -535,14 +531,12 @@ static int rmmod_all(struct kmod_ctx *ctx, char **args, int nargs)
return err;
}
static void print_action(struct kmod_module *m, bool install,
const char *options)
static void print_action(struct kmod_module *m, bool install, const char *options)
{
const char *path;
if (install) {
printf("install %s %s\n", kmod_module_get_install_commands(m),
options);
printf("install %s %s\n", kmod_module_get_install_commands(m), options);
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);
}
static int insmod_insert(struct kmod_module *mod, int flags,
const char *extra_options)
static int insmod_insert(struct kmod_module *mod, int flags, const char *extra_options)
{
int err = 0;
void (*show)(struct kmod_module *m, bool install,
const char *options) = NULL;
void (*show)(struct kmod_module *m, bool install, const char *options) = NULL;
if (do_show || verbose > DEFAULT_VERBOSE)
show = &print_action;
@ -572,8 +564,8 @@ static int insmod_insert(struct kmod_module *mod, int flags,
if (lookup_only)
printf("%s\n", kmod_module_get_name(mod));
else
err = kmod_module_probe_insert_module(mod, flags,
extra_options, NULL, NULL, show);
err = kmod_module_probe_insert_module(mod, flags, extra_options, NULL,
NULL, show);
if (err >= 0)
/* 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) {
case -EEXIST:
ERR("could not insert '%s': Module already in kernel\n",
kmod_module_get_name(mod));
kmod_module_get_name(mod));
break;
case -ENOENT:
ERR("could not insert '%s': Unknown symbol in module, "
"or unknown parameter (see dmesg)\n",
kmod_module_get_name(mod));
"or unknown parameter (see dmesg)\n",
kmod_module_get_name(mod));
break;
default:
ERR("could not insert '%s': %s\n",
kmod_module_get_name(mod),
strerror(-err));
ERR("could not insert '%s': %s\n", kmod_module_get_name(mod),
strerror(-err));
break;
}
}
@ -600,8 +591,7 @@ static int insmod_insert(struct kmod_module *mod, int flags,
return err;
}
static int insmod(struct kmod_ctx *ctx, const char *alias,
const char *extra_options)
static int insmod(struct kmod_ctx *ctx, const char *alias, const char *extra_options)
{
struct kmod_list *l, *list = 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);
if (err < 0) {
LOG("Failed to get module from path %s: %s\n", alias,
strerror(-err));
strerror(-err));
return -ENOENT;
}
} else {
err = kmod_module_new_from_lookup(ctx, alias, &list);
if (list == NULL || err < 0) {
LOG("Module %s not found in directory %s\n", alias,
ctx ? kmod_get_dirname(ctx) : "(missing)");
ctx ? kmod_get_dirname(ctx) : "(missing)");
return -ENOENT;
}
}
@ -766,7 +756,7 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv)
return NULL;
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);
str_end = str + envlen;
@ -959,9 +949,7 @@ static int do_modprobe(int argc, char **orig_argv)
nargs = argc - optind;
if (!use_syslog &&
(!stderr ||
fileno(stderr) == -1 ||
fstat(fileno(stderr), &stat_buf)))
(!stderr || fileno(stderr) == -1 || fstat(fileno(stderr), &stat_buf)))
use_syslog = 1;
log_open(use_syslog);
@ -988,10 +976,10 @@ static int do_modprobe(int argc, char **orig_argv)
kversion = u.release;
}
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)) {
ERR("bad directory %s" MODULE_DIRECTORY
"/%s: path too long\n", root, kversion);
ERR("bad directory %s" MODULE_DIRECTORY "/%s: path too long\n",
root, kversion);
err = -1;
goto done;
}

View File

@ -35,18 +35,19 @@ static const struct option cmdopts[] = {
static void help(void)
{
printf("Usage:\n"
"\t%s [options] modulename ...\n"
"Options:\n"
"\t-f, --force DANGEROUS: forces a module unload and may\n"
"\t crash your machine\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n",
program_invocation_short_name);
"\t%s [options] modulename ...\n"
"Options:\n"
"\t-f, --force DANGEROUS: forces a module unload and may\n"
"\t crash your machine\n"
"\t-s, --syslog print to syslog, not stderr\n"
"\t-v, --verbose enables more messages\n"
"\t-V, --version show version\n"
"\t-h, --help show this help\n",
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;
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));
return -ENOENT;
} else if (state < 0) {
ERR("Module %s is not currently loaded\n",
kmod_module_get_name(mod));
ERR("Module %s is not currently loaded\n", kmod_module_get_name(mod));
return -ENOENT;
}
@ -154,8 +154,7 @@ static int do_rmmod(int argc, char *argv[])
err = kmod_module_new_from_name(ctx, arg, &mod);
if (err < 0) {
ERR("could not use module %s: %s\n", arg,
strerror(-err));
ERR("could not use module %s: %s\n", arg, strerror(-err));
r = EXIT_FAILURE;
break;
}
@ -167,8 +166,7 @@ static int do_rmmod(int argc, char *argv[])
err = kmod_module_remove_module(mod, flags);
if (err < 0) {
ERR("could not remove module %s: %s\n", arg,
strerror(-err));
ERR("could not remove module %s: %s\n", arg, strerror(-err));
r++;
}
next:

View File

@ -41,24 +41,24 @@ static const struct static_nodes_format *static_nodes_formats[] = {
static const char cmdopts_s[] = "o:f:h";
static const struct option cmdopts[] = {
{ "output", required_argument, 0, 'o'},
{ "format", required_argument, 0, 'f'},
{ "help", no_argument, 0, 'h'},
{ },
{ "output", required_argument, 0, 'o' },
{ "format", required_argument, 0, 'f' },
{ "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;
ret = fprintf(out,
"Module: %s\n"
"\tDevice node: /dev/%s\n"
"\t\tType: %s device\n"
"\t\tMajor: %u\n"
"\t\tMinor: %u\n",
modname, devname,
(type == 'c') ? "character" : "block", maj, min);
"Module: %s\n"
"\tDevice node: /dev/%s\n"
"\t\tType: %s device\n"
"\t\tMajor: %u\n"
"\t\tMinor: %u\n",
modname, devname, (type == 'c') ? "character" : "block", maj, min);
if (ret >= 0)
return EXIT_SUCCESS;
else
@ -71,21 +71,21 @@ static const struct static_nodes_format static_nodes_format_human = {
.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;
int ret;
dir = strrchr(devname, '/');
if (dir) {
ret = fprintf(out, "d /dev/%.*s 0755 - - -\n",
(int)(dir - devname), devname);
ret = fprintf(out, "d /dev/%.*s 0755 - - -\n", (int)(dir - devname),
devname);
if (ret < 0)
return EXIT_FAILURE;
}
ret = fprintf(out, "%c! /dev/%s 0600 - - - %u:%u\n",
type, devname, maj, min);
ret = fprintf(out, "%c! /dev/%s 0600 - - - %u:%u\n", type, devname, maj, min);
if (ret < 0)
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.",
};
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;
@ -130,7 +131,7 @@ static void help(void)
"\t-h, --help show this help\n"
"\n"
"Formats:\n",
program_invocation_short_name);
program_invocation_short_name);
for (i = 0; i < ARRAY_SIZE(static_nodes_formats); i++) {
if (static_nodes_formats[i]->description != NULL) {
@ -172,8 +173,7 @@ static int do_static_nodes(int argc, char *argv[])
}
if (!valid) {
fprintf(stderr, "Unknown format: '%s'.\n",
optarg);
fprintf(stderr, "Unknown format: '%s'.\n", optarg);
help();
ret = EXIT_FAILURE;
goto finish;
@ -186,8 +186,7 @@ static int do_static_nodes(int argc, char *argv[])
ret = EXIT_FAILURE;
goto finish;
default:
fprintf(stderr, "Unexpected commandline option '%c'.\n",
c);
fprintf(stderr, "Unexpected commandline option '%c'.\n", c);
help();
ret = EXIT_FAILURE;
goto finish;
@ -200,9 +199,12 @@ static int do_static_nodes(int argc, char *argv[])
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)) {
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);
ret = EXIT_FAILURE;
goto finish;
@ -210,11 +212,15 @@ static int do_static_nodes(int argc, char *argv[])
in = fopen(modules, "re");
if (in == NULL) {
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);
ret = EXIT_SUCCESS;
} 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);
ret = EXIT_FAILURE;
}
@ -223,7 +229,8 @@ static int do_static_nodes(int argc, char *argv[])
r = mkdir_parents(output, 0755);
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;
goto finish;
}
@ -245,8 +252,8 @@ static int do_static_nodes(int argc, char *argv[])
if (buf[0] == '#')
continue;
matches = sscanf(buf, "%s %s %c%u:%u", modname, devname,
&type, &maj, &min);
matches =
sscanf(buf, "%s %s %c%u:%u", modname, devname, &type, &maj, &min);
if (matches != 5 || (type != 'c' && type != 'b')) {
fprintf(stderr, "Error: invalid devname entry: %s", buf);
ret = EXIT_FAILURE;