From f34d115d09a85766137399d8e894633ba55f23f1 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Wed, 11 Sep 2024 17:30:40 +0100 Subject: [PATCH] tools: mass convert with clang-format Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/118 Signed-off-by: Lucas De Marchi --- tools/depmod.c | 449 +++++++++++++++++++------------------------ tools/insmod.c | 27 ++- tools/kmod.c | 22 +-- tools/log.c | 22 +-- tools/lsmod.c | 14 +- tools/modinfo.c | 121 +++++------- tools/modprobe.c | 240 +++++++++++------------ tools/rmmod.c | 30 ++- tools/static-nodes.c | 67 ++++--- 9 files changed, 455 insertions(+), 537 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index daaa918..91bd191 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -68,43 +68,43 @@ static const struct option cmdopts[] = { { "warn", no_argument, 0, 'w' }, { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, - { }, + {}, }; static void help(void) { printf("Usage:\n" - "\t%s -[aA] [options] [forced_version]\n" - "\n" - "If no arguments (except options) are given, \"depmod -a\" is assumed\n" - "\n" - "depmod will output a dependency list suitable for the modprobe utility.\n" - "\n" - "Options:\n" - "\t-a, --all Probe all modules\n" - "\t-A, --quick Only does the work if there's a new module\n" - "\t-e, --errsyms Report not supplied symbols\n" - "\t-n, --show Write the dependency file on stdout only\n" - "\t-P, --symbol-prefix Architecture symbol prefix\n" - "\t-C, --config=PATH Read configuration from PATH\n" - "\t-v, --verbose Enable verbose mode\n" - "\t-w, --warn Warn on duplicates\n" - "\t-V, --version show version\n" - "\t-h, --help show this help\n" - "\n" - "The following options are useful for people managing distributions:\n" - "\t-b, --basedir=DIR Root path (default: /).\n" - "\t-m, --moduledir=DIR Module directory (default: " MODULE_DIRECTORY ").\n" - "\t-o, --outdir=DIR Output root path (default: same as ).\n" - "\t-F, --filesyms=FILE Use the file instead of the\n" - "\t current kernel symbols.\n" - "\t-E, --symvers=FILE Use Module.symvers file to check\n" - "\t symbol versions.\n", - program_invocation_short_name); + "\t%s -[aA] [options] [forced_version]\n" + "\n" + "If no arguments (except options) are given, \"depmod -a\" is assumed\n" + "\n" + "depmod will output a dependency list suitable for the modprobe utility.\n" + "\n" + "Options:\n" + "\t-a, --all Probe all modules\n" + "\t-A, --quick Only does the work if there's a new module\n" + "\t-e, --errsyms Report not supplied symbols\n" + "\t-n, --show Write the dependency file on stdout only\n" + "\t-P, --symbol-prefix Architecture symbol prefix\n" + "\t-C, --config=PATH Read configuration from PATH\n" + "\t-v, --verbose Enable verbose mode\n" + "\t-w, --warn Warn on duplicates\n" + "\t-V, --version show version\n" + "\t-h, --help show this help\n" + "\n" + "The following options are useful for people managing distributions:\n" + "\t-b, --basedir=DIR Root path (default: /).\n" + "\t-m, --moduledir=DIR Module directory (default: " MODULE_DIRECTORY + ").\n" + "\t-o, --outdir=DIR Output root path (default: same as ).\n" + "\t-F, --filesyms=FILE Use the file instead of the\n" + "\t current kernel symbols.\n" + "\t-E, --symvers=FILE Use Module.symvers file to check\n" + "\t symbol versions.\n", + 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; @@ -118,12 +118,11 @@ static inline void _show(const char *fmt, ...) } #define SHOW(...) _show(__VA_ARGS__) - /* see documentation in libkmod/libkmod-index.c */ #define INDEX_MAGIC 0xB007F457 #define INDEX_VERSION_MAJOR 0x0002 #define INDEX_VERSION_MINOR 0x0001 -#define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR) +#define INDEX_VERSION ((INDEX_VERSION_MAJOR << 16) | INDEX_VERSION_MINOR) #define INDEX_CHILDMAX 128 struct index_value { @@ -134,22 +133,21 @@ struct index_value { /* In-memory index (depmod only) */ struct index_node { - char *prefix; /* path compression */ + char *prefix; /* path compression */ struct index_value *values; - unsigned char first; /* range of child nodes */ + unsigned char first; /* range of child nodes */ unsigned char last; struct index_node *children[INDEX_CHILDMAX]; /* indexed by character */ }; - /* Format of node offsets within index file */ enum node_offset { - INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ - INDEX_NODE_PREFIX = 0x80000000, + INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ + INDEX_NODE_PREFIX = 0x80000000, INDEX_NODE_VALUES = 0x40000000, - INDEX_NODE_CHILDS = 0x20000000, + INDEX_NODE_CHILDS = 0x20000000, - INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ + INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ }; static noreturn void fatal_oom(void) @@ -211,12 +209,13 @@ static void index__checkstring(const char *str) if (ch >= INDEX_CHILDMAX) CRIT("Module index: bad character '%c'=0x%x - only 7-bit ASCII is supported:" - "\n%s\n", (char) ch, (int) ch, str); + "\n%s\n", + (char)ch, (int)ch, str); } } -static int index_add_value(struct index_value **values, - const char *value, unsigned int priority) +static int index_add_value(struct index_value **values, const char *value, + unsigned int priority) { struct index_value *v; int duplicate = 0; @@ -244,8 +243,8 @@ static int index_add_value(struct index_value **values, return duplicate; } -static int index_insert(struct index_node *node, const char *key, - const char *value, unsigned int priority) +static int index_insert(struct index_node *node, const char *key, const char *value, + unsigned int priority) { int i = 0; /* index within str */ int ch; @@ -253,7 +252,7 @@ static int index_insert(struct index_node *node, const char *key, index__checkstring(key); index__checkstring(value); - while(1) { + while (1) { int j; /* index within node->prefix */ /* Ensure node->prefix is a prefix of &str[i]. @@ -261,7 +260,7 @@ static int index_insert(struct index_node *node, const char *key, for (j = 0; node->prefix[j]; j++) { ch = node->prefix[j]; - if (ch != key[i+j]) { + if (ch != key[i + j]) { char *prefix = node->prefix; struct index_node *n; @@ -270,7 +269,7 @@ static int index_insert(struct index_node *node, const char *key, if (n == NULL) fatal_oom(); memcpy(n, node, sizeof(struct index_node)); - n->prefix = strdup(&prefix[j+1]); + n->prefix = strdup(&prefix[j + 1]); if (n->prefix == NULL) fatal_oom(); @@ -289,7 +288,7 @@ static int index_insert(struct index_node *node, const char *key, i += j; ch = key[i]; - if(ch == '\0') + if (ch == '\0') return index_add_value(&node->values, value, priority); if (!node->children[ch]) { @@ -304,7 +303,7 @@ static int index_insert(struct index_node *node, const char *key, fatal_oom(); child = node->children[ch]; - child->prefix = strdup(&key[i+1]); + child->prefix = strdup(&key[i + 1]); if (child->prefix == NULL) fatal_oom(); child->first = INDEX_CHILDMAX; @@ -525,8 +524,7 @@ static int cfg_override_add(struct cfg *cfg, const char *modname, const char *su size_t subdirlen = strlen(subdir); size_t i; - o = malloc(sizeof(struct cfg_override) + subdirlen + 1 - + modnamelen + 1); + o = malloc(sizeof(struct cfg_override) + subdirlen + 1 + modnamelen + 1); if (o == NULL) { ERR("override add: out of memory\n"); return -ENOMEM; @@ -613,7 +611,7 @@ static int cfg_kernel_matches(const struct cfg *cfg, const char *pattern) if (streq(pattern, "*")) return 1; - if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) + if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0) return 0; status = regexec(&re, cfg->kversion, 0, NULL, 0); @@ -656,13 +654,12 @@ static int cfg_file_parse(struct cfg *cfg, const char *filename) const char *version = strtok_r(NULL, "\t ", &saveptr); const char *subdir = strtok_r(NULL, "\t ", &saveptr); - if (modname == NULL || version == NULL || - subdir == NULL) + if (modname == NULL || version == NULL || subdir == NULL) goto syntax_error; if (!cfg_kernel_matches(cfg, version)) { - INF("%s:%u: override kernel did not match %s\n", - filename, linenum, version); + INF("%s:%u: override kernel did not match %s\n", filename, + linenum, version); goto done_next; } @@ -686,14 +683,13 @@ static int cfg_file_parse(struct cfg *cfg, const char *filename) while ((sp = strtok_r(NULL, "\t ", &saveptr)) != NULL) { cfg_exclude_add(cfg, sp); } - } else if (streq(cmd, "include") - || streq(cmd, "make_map_files")) { - INF("%s:%u: command %s not implemented yet\n", - filename, linenum, cmd); + } else if (streq(cmd, "include") || streq(cmd, "make_map_files")) { + INF("%s:%u: command %s not implemented yet\n", filename, linenum, + cmd); } else { syntax_error: - ERR("%s:%u: ignoring bad line starting with '%s'\n", - filename, linenum, cmd); + ERR("%s:%u: ignoring bad line starting with '%s'\n", filename, + linenum, cmd); } done_next: @@ -720,8 +716,8 @@ static int cfg_files_filter_out(DIR *d, const char *dir, const char *name) fstatat(dirfd(d), name, &st, 0); if (S_ISDIR(st.st_mode)) { - ERR("Directories inside directories are not supported: %s/%s\n", - dir, name); + ERR("Directories inside directories are not supported: %s/%s\n", dir, + name); return 1; } @@ -741,7 +737,7 @@ static void cfg_file_free(struct cfg_file *f) } static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files, - const char *dir, const char *name) + const char *dir, const char *name) { struct cfg_file **files, *f; size_t i, n_files, namelen, dirlen; @@ -761,8 +757,8 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files for (i = 0; i < n_files; i++) { int cmp = strcmp(name, files[i]->name); if (cmp == 0) { - DBG("Ignoring duplicate config file: %.*s/%s\n", - (int)dirlen, dir, name); + DBG("Ignoring duplicate config file: %.*s/%s\n", (int)dirlen, dir, + name); return -EEXIST; } else if (cmp < 0) break; @@ -803,8 +799,7 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files /* * Insert configuration files ignoring duplicates */ -static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files, - const char *path) +static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files, const char *path) { struct dirent *dent; DIR *d; @@ -840,7 +835,7 @@ static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files, return err; } -static int cfg_load(struct cfg *cfg, const char * const *cfg_paths) +static int cfg_load(struct cfg *cfg, const char *const *cfg_paths) { size_t i, n_files = 0; struct cfg_file **files = NULL; @@ -894,7 +889,6 @@ static void cfg_free(struct cfg *cfg) } } - /* depmod calculations ***********************************************/ struct vertex; struct mod { @@ -957,8 +951,8 @@ static int mod_add_dependency(struct mod *mod, struct symbol *sym) if (err == -EEXIST) return 0; if (err < 0) { - CRIT("failed to add symbol %s to module %s: %s\n", - sym->name, mod->path, strerror(-err)); + CRIT("failed to add symbol %s to module %s: %s\n", sym->name, mod->path, + strerror(-err)); return err; } @@ -974,8 +968,7 @@ static void symbol_free(struct symbol *sym) free(sym); } -static int depmod_init(struct depmod *depmod, struct cfg *cfg, - struct kmod_ctx *ctx) +static int depmod_init(struct depmod *depmod, struct cfg *cfg, struct kmod_ctx *ctx) { int err = 0; @@ -1059,7 +1052,7 @@ static int depmod_module_add(struct depmod *depmod, struct kmod_module *kmod) lastslash = strrchr(mod->path, '/'); mod->baselen = lastslash - mod->path; if (strncmp(mod->path, cfg->dirname, cfg->dirnamelen) == 0 && - mod->path[cfg->dirnamelen] == '/') + mod->path[cfg->dirnamelen] == '/') mod->relpath = mod->path + cfg->dirnamelen + 1; else mod->relpath = NULL; @@ -1071,15 +1064,13 @@ static int depmod_module_add(struct depmod *depmod, struct kmod_module *kmod) } if (mod->relpath != NULL) { - size_t uncrelpathlen = lastslash - mod->relpath + modnamesz - + strlen(KMOD_EXTENSION_UNCOMPRESSED); + size_t uncrelpathlen = lastslash - mod->relpath + modnamesz + + strlen(KMOD_EXTENSION_UNCOMPRESSED); mod->uncrelpath = memdup(mod->relpath, uncrelpathlen + 1); mod->uncrelpath[uncrelpathlen] = '\0'; - err = hash_add_unique(depmod->modules_by_uncrelpath, - mod->uncrelpath, mod); + err = hash_add_unique(depmod->modules_by_uncrelpath, mod->uncrelpath, mod); if (err < 0) { - ERR("hash_add_unique %s: %s\n", - mod->uncrelpath, strerror(-err)); + ERR("hash_add_unique %s: %s\n", mod->uncrelpath, strerror(-err)); hash_del(depmod->modules_by_name, mod->modname); goto fail; } @@ -1110,7 +1101,7 @@ static int depmod_module_del(struct depmod *depmod, struct mod *mod) static const char *search_to_string(const struct cfg_search *s) { - switch(s->type) { + switch (s->type) { case SEARCH_EXTERNAL: return "external"; case SEARCH_BUILTIN: @@ -1120,10 +1111,8 @@ static const char *search_to_string(const struct cfg_search *s) } } -static bool depmod_is_path_starts_with(const char *path, - size_t pathlen, - const char *prefix, - size_t prefix_len) +static bool depmod_is_path_starts_with(const char *path, size_t pathlen, + const char *prefix, size_t prefix_len) { if (pathlen <= prefix_len) return false; @@ -1138,7 +1127,10 @@ static bool depmod_is_path_starts_with(const char *path, /* returns if existing module @mod is higher priority than newpath. * note this is the inverse of module-init-tools is_higher_priority() */ -static int depmod_module_is_higher_priority(const struct depmod *depmod, const struct mod *mod, size_t baselen, size_t namelen, size_t modnamelen, const char *newpath) +static int depmod_module_is_higher_priority(const struct depmod *depmod, + const struct mod *mod, size_t baselen, + size_t namelen, size_t modnamelen, + const char *newpath) { const struct cfg *cfg = depmod->cfg; const struct cfg_override *ov; @@ -1157,8 +1149,7 @@ static int depmod_module_is_higher_priority(const struct depmod *depmod, const s const char *relnewpath = NULL; const char *reloldpath = NULL; - DBG("comparing priorities of %s and %s\n", - oldpath, newpath); + DBG("comparing priorities of %s and %s\n", oldpath, newpath); if (strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0) { relnewpath = newpath + cfg->dirnamelen + 1; @@ -1171,11 +1162,9 @@ static int depmod_module_is_higher_priority(const struct depmod *depmod, const s for (ov = cfg->overrides; ov != NULL; ov = ov->next) { DBG("override %s\n", ov->path); - if (relnewlen == ov->len && - memcmp(ov->path, relnewpath, relnewlen) == 0) + if (relnewlen == ov->len && memcmp(ov->path, relnewpath, relnewlen) == 0) return 0; - if (reloldlen == ov->len && - memcmp(ov->path, reloldpath, reloldlen) == 0) + if (reloldlen == ov->len && memcmp(ov->path, reloldpath, reloldlen) == 0) return 1; } @@ -1185,19 +1174,15 @@ static int depmod_module_is_higher_priority(const struct depmod *depmod, const s bprio = i; else if (se->type == SEARCH_EXTERNAL) { for (ext = cfg->externals; ext != NULL; ext = ext->next, i++) { - if (depmod_is_path_starts_with(newpath, - newlen, - ext->path, + if (depmod_is_path_starts_with(newpath, newlen, ext->path, ext->len)) newprio = i; - if (depmod_is_path_starts_with(oldpath, - oldlen, - ext->path, + if (depmod_is_path_starts_with(oldpath, oldlen, ext->path, ext->len)) oldprio = i; } } else if (relnewlen > se->len && relnewpath[se->len] == '/' && - memcmp(se->path, relnewpath, se->len) == 0) + memcmp(se->path, relnewpath, se->len) == 0) newprio = i; else if (reloldlen > se->len && reloldpath[se->len] == '/' && memcmp(se->path, reloldpath, se->len) == 0) @@ -1209,13 +1194,13 @@ static int depmod_module_is_higher_priority(const struct depmod *depmod, const s if (oldprio < 0) oldprio = bprio; - DBG("priorities: built-in: %d, old: %d, new: %d\n", - bprio, oldprio, newprio); + DBG("priorities: built-in: %d, old: %d, new: %d\n", bprio, oldprio, newprio); return newprio <= oldprio; } -static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, size_t namelen, const char *path) +static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, + size_t namelen, const char *path) { struct kmod_module *kmod; struct mod *mod; @@ -1239,15 +1224,13 @@ static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, siz if (mod == NULL) goto add; - if (depmod_module_is_higher_priority(depmod, mod, baselen, - namelen, modnamelen, path)) { - DBG("Ignored lower priority: %s, higher: %s\n", - path, mod->path); + if (depmod_module_is_higher_priority(depmod, mod, baselen, namelen, modnamelen, + path)) { + DBG("Ignored lower priority: %s, higher: %s\n", path, mod->path); return 0; } - DBG("Replace lower priority %s with new module %s\n", - mod->relpath, relpath); + DBG("Replace lower priority %s with new module %s\n", mod->relpath, relpath); err = depmod_module_del(depmod, mod); if (err < 0) { ERR("could not del module %s: %s\n", mod->path, strerror(-err)); @@ -1263,8 +1246,7 @@ add: err = depmod_module_add(depmod, kmod); if (err < 0) { - ERR("could not add module %s: %s\n", - path, strerror(-err)); + ERR("could not add module %s: %s\n", path, strerror(-err)); kmod_module_unref(kmod); return err; } @@ -1275,8 +1257,7 @@ static bool should_exclude_dir(const struct cfg *cfg, const char *name) { struct cfg_exclude *exc; - if (name[0] == '.' && (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))) + if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) return true; if (streq(name, "build") || streq(name, "source")) @@ -1290,7 +1271,8 @@ static bool should_exclude_dir(const struct cfg *cfg, const char *name) return false; } -static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t baselen, struct scratchbuf *s_path) +static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t baselen, + struct scratchbuf *s_path) { struct dirent *de; int err = 0, dfd = dirfd(d); @@ -1328,8 +1310,8 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t basel else if (S_ISDIR(st.st_mode)) is_dir = 1; else { - ERR("unsupported file type %s: %o\n", - path, st.st_mode & S_IFMT); + ERR("unsupported file type %s: %o\n", path, + st.st_mode & S_IFMT); continue; } } @@ -1339,8 +1321,7 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t basel DIR *subdir; fd = openat(dfd, name, O_RDONLY); if (fd < 0) { - ERR("openat(%d, %s, O_RDONLY): %m\n", - dfd, name); + ERR("openat(%d, %s, O_RDONLY): %m\n", dfd, name); continue; } subdir = fdopendir(fd); @@ -1352,12 +1333,10 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t basel path[baselen + namelen] = '/'; path[baselen + namelen + 1] = '\0'; err = depmod_modules_search_dir(depmod, subdir, - baselen + namelen + 1, - s_path); + baselen + namelen + 1, s_path); closedir(subdir); } else { - err = depmod_modules_search_file(depmod, baselen, - namelen, path); + err = depmod_modules_search_file(depmod, baselen, namelen, path); } if (err < 0) { @@ -1369,8 +1348,7 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t basel return err; } -static int depmod_modules_search_path(struct depmod *depmod, - const char *path) +static int depmod_modules_search_path(struct depmod *depmod, const char *path) { char buf[256]; _cleanup_(scratchbuf_release) struct scratchbuf s_path_buf = @@ -1425,7 +1403,8 @@ static int depmod_modules_search(struct depmod *depmod) return 0; } -static int mod_cmp(const void *pa, const void *pb) { +static int mod_cmp(const void *pa, const void *pb) +{ const struct mod *a = *(const struct mod **)pa; const struct mod *b = *(const struct mod **)pb; return a->sort_idx - b->sort_idx; @@ -1439,7 +1418,7 @@ static int depmod_modules_build_array(struct depmod *depmod) hash_iter_init(depmod->modules_by_name, &module_iter); while (hash_iter_next(&module_iter, NULL, &v)) { - struct mod *mod = (struct mod *) v; + struct mod *mod = (struct mod *)v; mod->idx = depmod->modules.count; err = array_append(&depmod->modules, mod); if (err < 0) @@ -1449,8 +1428,7 @@ static int depmod_modules_build_array(struct depmod *depmod) return 0; } -static FILE *dfdopen(const char *dname, const char *filename, int flags, - const char *mode) +static FILE *dfdopen(const char *dname, const char *filename, int flags, const char *mode) { int fd, dfd; FILE *ret; @@ -1476,8 +1454,6 @@ static FILE *dfdopen(const char *dname, const char *filename, int flags, return ret; } - - static void depmod_modules_sort(struct depmod *depmod) { char line[PATH_MAX]; @@ -1496,7 +1472,7 @@ static void depmod_modules_sort(struct depmod *depmod) continue; if (line[len - 1] != '\n') { ERR("%s/%s:%u corrupted line misses '\\n'\n", - depmod->cfg->dirname, order_file, idx); + depmod->cfg->dirname, order_file, idx); goto corrupted; } } @@ -1528,9 +1504,8 @@ corrupted: fclose(fp); } -static int depmod_symbol_add(struct depmod *depmod, const char *name, - bool prefix_skipped, uint64_t crc, - const struct mod *owner) +static int depmod_symbol_add(struct depmod *depmod, const char *name, bool prefix_skipped, + uint64_t crc, const struct mod *owner) { size_t namelen; int err; @@ -1560,8 +1535,7 @@ static int depmod_symbol_add(struct depmod *depmod, const char *name, return 0; } -static struct symbol *depmod_symbol_find(const struct depmod *depmod, - const char *name) +static struct symbol *depmod_symbol_find(const struct depmod *depmod, const char *name) { if (name[0] == '.') /* PPC64 needs this: .foo == foo */ name++; @@ -1586,8 +1560,8 @@ static int depmod_load_modules(struct depmod *depmod) if (err == -ENODATA) DBG("ignoring %s: no symbols\n", mod->path); else - ERR("failed to load symbols from %s: %s\n", - mod->path, strerror(-err)); + ERR("failed to load symbols from %s: %s\n", mod->path, + strerror(-err)); goto load_info; } kmod_list_foreach(l, list) { @@ -1599,14 +1573,13 @@ static int depmod_load_modules(struct depmod *depmod) load_info: kmod_module_get_info(mod->kmod, &mod->info_list); - kmod_module_get_dependency_symbols(mod->kmod, - &mod->dep_sym_list); + kmod_module_get_dependency_symbols(mod->kmod, &mod->dep_sym_list); kmod_module_unref(mod->kmod); mod->kmod = NULL; } - DBG("loaded symbols (%zd modules, %u symbols)\n", - depmod->modules.count, hash_get_count(depmod->symbols)); + DBG("loaded symbols (%zd modules, %u symbols)\n", depmod->modules.count, + hash_get_count(depmod->symbols)); return 0; } @@ -1627,16 +1600,15 @@ static int depmod_load_module_dependencies(struct depmod *depmod, struct mod *mo int err; if (sym == NULL) { - DBG("%s needs (%c) unknown symbol %s\n", - mod->path, bindtype, name); + DBG("%s needs (%c) unknown symbol %s\n", mod->path, bindtype, + name); if (cfg->print_unknown && !is_weak) - WRN("%s needs unknown symbol %s\n", - mod->path, name); + WRN("%s needs unknown symbol %s\n", mod->path, name); continue; } if (cfg->check_symvers && sym->crc != crc && !is_weak) { - DBG("symbol %s (%#"PRIx64") module %s (%#"PRIx64")\n", + DBG("symbol %s (%#" PRIx64 ") module %s (%#" PRIx64 ")\n", sym->name, sym->crc, mod->path, crc); if (cfg->print_unknown) WRN("%s disagrees about version of symbol %s\n", @@ -1656,8 +1628,8 @@ static int depmod_load_dependencies(struct depmod *depmod) struct mod **itr, **itr_end; int ret = 0; - DBG("load dependencies (%zd modules, %u symbols)\n", - depmod->modules.count, hash_get_count(depmod->symbols)); + DBG("load dependencies (%zd modules, %u symbols)\n", depmod->modules.count, + hash_get_count(depmod->symbols)); itr = (struct mod **)depmod->modules.array; itr_end = itr + depmod->modules.count; @@ -1675,8 +1647,8 @@ static int depmod_load_dependencies(struct depmod *depmod) ret = err; } - DBG("loaded dependencies (%zd modules, %u symbols)\n", - depmod->modules.count, hash_get_count(depmod->symbols)); + DBG("loaded dependencies (%zd modules, %u symbols)\n", depmod->modules.count, + hash_get_count(depmod->symbols)); return ret; } @@ -1726,10 +1698,8 @@ static void depmod_list_remove_data(struct kmod_list **list, void *data) *list = l; } -static int depmod_report_one_cycle(struct depmod *depmod, - struct vertex *vertex, - struct kmod_list **roots, - struct hash *loop_set) +static int depmod_report_one_cycle(struct depmod *depmod, struct vertex *vertex, + struct kmod_list **roots, struct hash *loop_set) { const char sep[] = " -> "; size_t sz; @@ -1743,10 +1713,7 @@ static int depmod_report_one_cycle(struct depmod *depmod, array_init(&reverse, 3); sz = 0; - for (v = vertex->parent, n = 0; - v != NULL; - v = v->parent, n++) { - + for (v = vertex->parent, n = 0; v != NULL; v = v->parent, n++) { sz += v->mod->modnamesz - 1; rc = array_append(&reverse, v); if (rc < 0) @@ -1783,12 +1750,9 @@ static int depmod_report_one_cycle(struct depmod *depmod, return 0; } -static int depmod_report_cycles_from_root(struct depmod *depmod, - struct mod *root_mod, - struct kmod_list **roots, - void **stack, - size_t stack_size, - struct hash *loop_set) +static int depmod_report_cycles_from_root(struct depmod *depmod, struct mod *root_mod, + struct kmod_list **roots, void **stack, + size_t stack_size, struct hash *loop_set) { struct kmod_list *free_list = NULL; /* struct vertex */ struct kmod_list *l; @@ -1825,8 +1789,7 @@ static int depmod_report_cycles_from_root(struct depmod *depmod, */ if (m->visited && m == root->mod) { int rc; - rc = depmod_report_one_cycle(depmod, vertex, - roots, loop_set); + rc = depmod_report_one_cycle(depmod, vertex, roots, loop_set); if (rc != 0) { ret = rc; goto out; @@ -1850,7 +1813,7 @@ static int depmod_report_cycles_from_root(struct depmod *depmod, continue; } - itr = (struct mod **) m->deps.array; + itr = (struct mod **)m->deps.array; itr_end = itr + m->deps.count; for (; itr < itr_end; itr++) { struct mod *dep = *itr; @@ -1868,7 +1831,6 @@ static int depmod_report_cycles_from_root(struct depmod *depmod, goto out; } free_list = l; - } } ret = 0; @@ -1884,8 +1846,7 @@ out: return ret; } -static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods, - uint16_t *users) +static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods, uint16_t *users) { int num_cyclic = 0; struct kmod_list *roots = NULL; /* struct mod */ @@ -1927,10 +1888,8 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods, root = roots->data; l = kmod_list_remove(roots); roots = l; - err = depmod_report_cycles_from_root(depmod, - root, - &roots, - stack, n_r, loop_set); + err = depmod_report_cycles_from_root(depmod, root, &roots, stack, n_r, + loop_set); if (err < 0) goto out_hash; } @@ -2044,7 +2003,9 @@ static size_t mod_count_all_dependencies(const struct mod *mod) return count; } -static int mod_fill_all_unique_dependencies(const struct mod *mod, const struct mod **deps, size_t n_deps, size_t *last) +static int mod_fill_all_unique_dependencies(const struct mod *mod, + const struct mod **deps, size_t n_deps, + size_t *last) { size_t i; int err = 0; @@ -2074,7 +2035,8 @@ static int mod_fill_all_unique_dependencies(const struct mod *mod, const struct return err; } -static const struct mod **mod_get_all_sorted_dependencies(const struct mod *mod, size_t *n_deps) +static const struct mod **mod_get_all_sorted_dependencies(const struct mod *mod, + size_t *n_deps) { const struct mod **deps; size_t last = 0; @@ -2129,7 +2091,7 @@ static int output_deps(struct depmod *depmod, FILE *out) fprintf(out, " %s", mod_get_compressed_path(d)); } free(deps); - end: +end: putc('\n', out); } @@ -2264,11 +2226,10 @@ static int output_aliases_bin(struct depmod *depmod, FILE *out) } alias = buf; - duplicate = index_insert(idx, alias, mod->modname, - mod->idx); + duplicate = index_insert(idx, alias, mod->modname, mod->idx); if (duplicate && depmod->cfg->warn_dups) - WRN("duplicate module alias:\n%s %s\n", - alias, mod->modname); + WRN("duplicate module alias:\n%s %s\n", alias, + mod->modname); } } @@ -2340,8 +2301,7 @@ static int output_symbols(struct depmod *depmod, FILE *out) if (sym->owner == NULL) continue; - fprintf(out, "alias symbol:%s %s\n", - sym->name, sym->owner->modname); + fprintf(out, "alias symbol:%s %s\n", sym->name, sym->owner->modname); } return 0; @@ -2384,12 +2344,11 @@ static int output_symbols_bin(struct depmod *depmod, FILE *out) goto err_scratchbuf; } memcpy(scratchbuf_str(&salias) + baselen, sym->name, len + 1); - duplicate = index_insert(idx, alias, sym->owner->modname, - sym->owner->idx); + duplicate = + index_insert(idx, alias, sym->owner->modname, sym->owner->idx); if (duplicate && depmod->cfg->warn_dups) - WRN("duplicate module syms:\n%s %s\n", - alias, sym->owner->modname); + WRN("duplicate module syms:\n%s %s\n", alias, sym->owner->modname); } index_write(idx, out); @@ -2444,9 +2403,7 @@ static int flush_stream(FILE *in, int endchar) size_t i = 0; int c; - for (c = fgetc(in); - c != EOF && c != endchar && c != '\0'; - c = fgetc(in)) + for (c = fgetc(in); c != EOF && c != endchar && c != '\0'; c = fgetc(in)) ; return c == endchar ? i : 0; @@ -2457,14 +2414,13 @@ static int flush_stream_to(FILE *in, int endchar, char *dst, size_t dst_sz) size_t i = 0; int c; - for (c = fgetc(in); - c != EOF && c != endchar && c != '\0' && i < dst_sz; + for (c = fgetc(in); c != EOF && c != endchar && c != '\0' && i < dst_sz; c = fgetc(in)) dst[i++] = c; if (i == dst_sz) { - WRN("Could not flush stream: %d. Partial content: %.*s\n", - ENOSPC, (int) dst_sz, dst); + WRN("Could not flush stream: %d. Partial content: %.*s\n", ENOSPC, + (int)dst_sz, dst); i--; } @@ -2558,13 +2514,11 @@ static int output_devname(struct depmod *depmod, FILE *out) if (strstartswith(value, "devname:")) devname = value + sizeof("devname:") - 1; - else if (sscanf(value, "char-major-%u-%u", - &maj, &min) == 2) { + else if (sscanf(value, "char-major-%u-%u", &maj, &min) == 2) { type = 'c'; major = maj; minor = min; - } else if (sscanf(value, "block-major-%u-%u", - &maj, &min) == 2) { + } else if (sscanf(value, "block-major-%u-%u", &maj, &min) == 2) { type = 'b'; major = maj; minor = min; @@ -2581,12 +2535,13 @@ static int output_devname(struct depmod *depmod, FILE *out) out); empty = false; } - fprintf(out, "%s %s %c%u:%u\n", mod->modname, - devname, type, major, minor); - } else + fprintf(out, "%s %s %c%u:%u\n", mod->modname, devname, + type, major, minor); + } else ERR("Module '%s' has devname (%s) but " "lacks major and minor information. " - "Ignoring.\n", mod->modname, devname); + "Ignoring.\n", + mod->modname, devname); } } @@ -2610,7 +2565,7 @@ static int depmod_output(struct depmod *depmod, FILE *out) { "modules.builtin.bin", output_builtin_bin }, { "modules.builtin.alias.bin", output_builtin_alias_bin }, { "modules.devname", output_devname }, - { }, + {}, }; const char *dname = depmod->cfg->outdirname; int dfd, err = 0; @@ -2645,18 +2600,19 @@ static int depmod_output(struct depmod *depmod, FILE *out) int fd; int n; - n = snprintf(tmp, sizeof(tmp), "%s.%i.%lli.%lli", itr->name, getpid(), - (long long)tv.tv_usec, (long long)tv.tv_sec); + n = snprintf(tmp, sizeof(tmp), "%s.%i.%lli.%lli", itr->name, + getpid(), (long long)tv.tv_usec, + (long long)tv.tv_sec); if (n >= (int)sizeof(tmp)) { ERR("bad filename: %s.%i.%lli.%lli: path too long\n", - itr->name, getpid(), (long long)tv.tv_usec, - (long long)tv.tv_sec); + itr->name, getpid(), (long long)tv.tv_usec, + (long long)tv.tv_sec); continue; } fd = openat(dfd, tmp, flags, mode); if (fd < 0) { - ERR("openat(%s, %s, %o, %o): %m\n", - dname, tmp, flags, mode); + ERR("openat(%s, %s, %o, %o): %m\n", dname, tmp, flags, + mode); continue; } fp = fdopen(fd, "wb"); @@ -2677,23 +2633,22 @@ static int depmod_output(struct depmod *depmod, FILE *out) if (unlinkat(dfd, tmp, 0) != 0) ERR("unlinkat(%s, %s): %m\n", dname, tmp); - ERR("Could not write index '%s': %s\n", itr->name, - strerror(-r)); + ERR("Could not write index '%s': %s\n", itr->name, strerror(-r)); err = -errno; break; } if (renameat(dfd, tmp, dfd, itr->name) != 0) { err = -errno; - CRIT("renameat(%s, %s, %s, %s): %m\n", - dname, tmp, dname, itr->name); + CRIT("renameat(%s, %s, %s, %s): %m\n", dname, tmp, dname, + itr->name); break; } if (ferr) { err = -ENOSPC; ERR("Could not create index '%s'. Output is truncated: %s\n", - itr->name, strerror(-err)); + itr->name, strerror(-err)); break; } } @@ -2748,8 +2703,8 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename) crc = strtoull(ver, &verend, 16); if (verend[0] != '\0') { - ERR("%s:%u Invalid symbol version %s: %m\n", - filename, linenum, ver); + ERR("%s:%u Invalid symbol version %s: %m\n", filename, linenum, + ver); continue; } @@ -2809,7 +2764,7 @@ static int depmod_load_system_map(struct depmod *depmod, const char *filename) depmod_symbol_add(depmod, p + ksymstr_len, true, 0, NULL); continue; - invalid_syntax: +invalid_syntax: ERR("%s:%u: invalid line: %s\n", filename, linenum, line); } depmod_add_fake_syms(depmod); @@ -2820,7 +2775,6 @@ static int depmod_load_system_map(struct depmod *depmod, const char *filename) return 0; } - static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *path) { struct dirent *de; @@ -2831,8 +2785,8 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa size_t namelen; struct stat st; - if (name[0] == '.' && (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))) + if (name[0] == '.' && + (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) continue; if (streq(name, "build") || streq(name, "source")) continue; @@ -2858,8 +2812,7 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa } fd = openat(dfd, name, O_RDONLY); if (fd < 0) { - ERR("openat(%d, %s, O_RDONLY): %m\n", - dfd, name); + ERR("openat(%d, %s, O_RDONLY): %m\n", dfd, name); continue; } subdir = fdopendir(fd); @@ -2870,8 +2823,7 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa } path[baselen + namelen] = '/'; path[baselen + namelen + 1] = '\0'; - err = depfile_up_to_date_dir(subdir, mtime, - baselen + namelen + 1, + err = depfile_up_to_date_dir(subdir, mtime, baselen + namelen + 1, path); closedir(subdir); } else if (S_ISREG(st.st_mode)) { @@ -2881,13 +2833,11 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa memcpy(path + baselen, name, namelen + 1); err = st.st_mtime <= mtime; if (err == 0) { - DBG("%s %"PRIu64" is newer than %"PRIu64"\n", - path, (uint64_t)st.st_mtime, - (uint64_t)mtime); + DBG("%s %" PRIu64 " is newer than %" PRIu64 "\n", path, + (uint64_t)st.st_mtime, (uint64_t)mtime); } } else { - ERR("unsupported file type %s: %o\n", - path, st.st_mode & S_IFMT); + ERR("unsupported file type %s: %o\n", path, st.st_mode & S_IFMT); continue; } @@ -3058,22 +3008,20 @@ static int do_depmod(int argc, char *argv[]) cfg.kversion = un.release; } - cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, - "%s%s/%s", - root ?: "", module_directory, cfg.kversion); + cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, "%s%s/%s", root ?: "", + module_directory, cfg.kversion); if (cfg.dirnamelen >= PATH_MAX) { - ERR("Bad directory %s" MODULE_DIRECTORY - "/%s: path too long\n", root ?: "", cfg.kversion); + ERR("Bad directory %s" MODULE_DIRECTORY "/%s: path too long\n", + root ?: "", cfg.kversion); goto cmdline_failed; } - cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX, - "%s%s/%s", - out_root ?: (root ?: ""), module_directory, cfg.kversion); + cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX, "%s%s/%s", + out_root ?: (root ?: ""), module_directory, + cfg.kversion); if (cfg.outdirnamelen >= PATH_MAX) { - ERR("Bad directory %s" MODULE_DIRECTORY - "/%s: path too long\n", out_root ?: (root ?: ""), - cfg.kversion); + ERR("Bad directory %s" MODULE_DIRECTORY "/%s: path too long\n", + out_root ?: (root ?: ""), cfg.kversion); goto cmdline_failed; } @@ -3107,15 +3055,13 @@ static int do_depmod(int argc, char *argv[]) if (module_symvers != NULL) { err = depmod_load_symvers(&depmod, module_symvers); if (err < 0) { - CRIT("could not load %s: %s\n", module_symvers, - strerror(-err)); + CRIT("could not load %s: %s\n", module_symvers, strerror(-err)); goto cmdline_failed; } } else if (system_map != NULL) { err = depmod_load_system_map(&depmod, system_map); if (err < 0) { - CRIT("could not load %s: %s\n", system_map, - strerror(-err)); + CRIT("could not load %s: %s\n", system_map, strerror(-err)); goto cmdline_failed; } } else if (cfg.print_unknown) { @@ -3148,15 +3094,15 @@ static int do_depmod(int argc, char *argv[]) err = kmod_module_new_from_path(depmod.ctx, path, &mod); if (err < 0) { - CRIT("could not create module %s: %s\n", - path, strerror(-err)); + CRIT("could not create module %s: %s\n", path, + strerror(-err)); goto cmdline_modules_failed; } err = depmod_module_add(&depmod, mod); if (err < 0) { - CRIT("could not add module %s: %s\n", - path, strerror(-err)); + CRIT("could not add module %s: %s\n", path, + strerror(-err)); kmod_module_unref(mod); goto cmdline_modules_failed; } @@ -3165,8 +3111,7 @@ static int do_depmod(int argc, char *argv[]) err = depmod_modules_build_array(&depmod); if (err < 0) { - CRIT("could not build module array: %s\n", - strerror(-err)); + CRIT("could not build module array: %s\n", strerror(-err)); goto cmdline_modules_failed; } diff --git a/tools/insmod.c b/tools/insmod.c index 0f58f42..f1a8d89 100644 --- a/tools/insmod.c +++ b/tools/insmod.c @@ -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); diff --git a/tools/kmod.c b/tools/kmod.c index 4d11580..835970b 100644 --- a/tools/kmod.c +++ b/tools/kmod.c @@ -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; diff --git a/tools/log.c b/tools/log.c index e2fe9a7..8bd6a59 100644 --- a/tools/log.c +++ b/tools/log.c @@ -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) diff --git a/tools/lsmod.c b/tools/lsmod.c index 6cbe70c..3d5a54a 100644 --- a/tools/lsmod.c +++ b/tools/lsmod.c @@ -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[]) diff --git a/tools/modinfo.c b/tools/modinfo.c index 68c7b94..865bbec 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -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] [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] [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; diff --git a/tools/modprobe.c b/tools/modprobe.c index 4070e55..26b252c 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -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 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 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; } diff --git a/tools/rmmod.c b/tools/rmmod.c index 5246bad..8316978 100644 --- a/tools/rmmod.c +++ b/tools/rmmod.c @@ -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: diff --git a/tools/static-nodes.c b/tools/static-nodes.c index 58c06cf..cb8afd3 100644 --- a/tools/static-nodes.c +++ b/tools/static-nodes.c @@ -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;