{ "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 <basedir>).\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, ...)
+ "\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 <basedir>).\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, ...)
{
va_list args;
}
#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 {
/* 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)
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;
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;
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].
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;
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();
i += j;
ch = key[i];
- if(ch == '\0')
+ if (ch == '\0')
return index_add_value(&node->values, value, priority);
if (!node->children[ch]) {
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;
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;
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);
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;
}
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:
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;
}
}
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;
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;
/*
* 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;
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;
}
}
-
/* depmod calculations ***********************************************/
struct vertex;
struct mod {
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;
}
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;
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;
}
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;
}
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:
}
}
-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;
/* 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;
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;
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;
}
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)
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;
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));
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;
}
{
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"))
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);
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;
}
}
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);
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) {
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 =
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;
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)
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;
return ret;
}
-
-
static void depmod_modules_sort(struct depmod *depmod)
{
char line[PATH_MAX];
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;
}
}
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;
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++;
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) {
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;
}
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",
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;
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;
}
*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;
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)
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;
*/
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;
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;
goto out;
}
free_list = l;
-
}
}
ret = 0;
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 */
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;
}
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;
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;
fprintf(out, " %s", mod_get_compressed_path(d));
}
free(deps);
- end:
+end:
putc('\n', 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);
}
}
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;
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);
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;
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--;
}
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;
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);
}
}
{ "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;
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");
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;
}
}
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;
}
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);
return 0;
}
-
static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *path)
{
struct dirent *de;
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;
}
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);
}
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)) {
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;
}
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;
}
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) {
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;
}
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;
}
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)
case '?':
return EXIT_FAILURE;
default:
- ERR("unexpected getopt_long() value '%c'.\n",
- c);
+ ERR("unexpected getopt_long() value '%c'.\n", c);
return EXIT_FAILURE;
}
}
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);
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);
}
}
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);
}
}
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;
}
}
return EXIT_FAILURE;
}
-
static int handle_kmod_compat_commands(int argc, char *argv[])
{
const char *cmd;
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;
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
}
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)
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[])
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;
}
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;
}
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);
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)";
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);
*/
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;
}
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);
}
return err;
}
-
static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias)
{
struct kmod_list *l, *list = NULL;
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)
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;
}
}
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;
static const char cmdopts_s[] = "arw:RibfDcnC:d:S:sqvVh";
static const struct option cmdopts[] = {
- {"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'},
-
- {"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},
-
- {"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'},
-
- {"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},
+ { "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' },
+
+ { "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 },
+
+ { "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' },
+
+ { "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-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 [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-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;
};
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)
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(' ');
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;
}
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);
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;
}
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;
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);
}
until_msec = get_backoff_delta_msec(t0_msec, tend_msec,
- &interval_msec);
+ &interval_msec);
err = sleep_until_msec(until_msec);
if (!t0_msec)
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 */
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;
}
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;
}
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;
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 */
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;
}
}
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;
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;
}
}
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;
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);
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;
}
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;
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;
}
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;
}
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:
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
.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;
.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;
"\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) {
}
if (!valid) {
- fprintf(stderr, "Unknown format: '%s'.\n",
- optarg);
+ fprintf(stderr, "Unknown format: '%s'.\n", optarg);
help();
ret = EXIT_FAILURE;
goto finish;
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;
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;
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;
}
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;
}
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;