diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2015-10-28 15:48:13 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2015-10-28 15:48:13 +0000 |
commit | e99310f967946358b74c86fa77143dbda6f630bf (patch) | |
tree | a74476b2f6629787918d8eb7fcbaf52dc0d41e29 /main/busybox | |
parent | ad3fc3792e72e273b78fd2c010e3a08c971d1b70 (diff) | |
download | aports-e99310f967946358b74c86fa77143dbda6f630bf.tar.bz2 aports-e99310f967946358b74c86fa77143dbda6f630bf.tar.xz |
main/busybox: fix comatibility with kmod
Diffstat (limited to 'main/busybox')
5 files changed, 1052 insertions, 11 deletions
diff --git a/main/busybox/2001-modutils-merge-module_entry-and-module_info-to-commo.patch b/main/busybox/2001-modutils-merge-module_entry-and-module_info-to-commo.patch new file mode 100644 index 000000000..d0ad5f852 --- /dev/null +++ b/main/busybox/2001-modutils-merge-module_entry-and-module_info-to-commo.patch @@ -0,0 +1,445 @@ +From e20b230f09522423c6f752d0d6914922fa0f8533 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> +Date: Sun, 25 Oct 2015 22:21:40 +0200 +Subject: [PATCH 2001/2003] modutils: merge module_entry and module_info to + common code +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This merges the in-memory module info structures of modprobe +and depmod. This allows sharing hashing by modulename code +improving depmod runtime with almost factor of 2x. + +Signed-off-by: Timo Teräs <timo.teras@iki.fi> +--- + modutils/depmod.c | 99 +++++++++++++++++++---------------------------------- + modutils/modprobe.c | 66 ++++------------------------------- + modutils/modutils.c | 43 +++++++++++++++++++++++ + modutils/modutils.h | 29 ++++++++++++++++ + 4 files changed, 114 insertions(+), 123 deletions(-) + +diff --git a/modutils/depmod.c b/modutils/depmod.c +index 9713aef..b8699ba 100644 +--- a/modutils/depmod.c ++++ b/modutils/depmod.c +@@ -14,6 +14,14 @@ + #include "modutils.h" + #include <sys/utsname.h> /* uname() */ + ++struct globals { ++ module_db db; ++} FIX_ALIASING; ++#define G (*ptr_to_globals) ++#define INIT_G() do { \ ++ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ ++} while (0) ++ + /* + * Theory of operation: + * - iterate over all modules and record their full path +@@ -21,21 +29,12 @@ + * for each depends, look through our list of full paths and emit if found + */ + +-typedef struct module_info { +- struct module_info *next; +- char *name, *modname; +- llist_t *dependencies; +- llist_t *aliases; +- llist_t *symbols; +- struct module_info *dnext, *dprev; +-} module_info; +- + static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, +- void *data, int depth UNUSED_PARAM) ++ void *data UNUSED_PARAM, int depth UNUSED_PARAM) + { +- module_info **first = (module_info **) data; + char *image, *ptr; +- module_info *info; ++ module_entry *e; ++ + /* Arbitrary. Was sb->st_size, but that breaks .gz etc */ + size_t len = (64*1024*1024 - 4096); + +@@ -43,17 +42,10 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA + return TRUE; + + image = xmalloc_open_zipped_read_close(fname, &len); +- info = xzalloc(sizeof(*info)); + +- info->next = *first; +- *first = info; ++ e = moddb_get(&G.db, bb_get_last_path_component_nostrip(fname), 1); ++ e->name = xstrdup(fname + 2); /* skip "./" */ + +- info->dnext = info->dprev = info; +- info->name = xstrdup(fname + 2); /* skip "./" */ +- info->modname = filename2modname( +- bb_get_last_path_component_nostrip(fname), +- NULL +- ); + for (ptr = image; ptr < image + len - 10; ptr++) { + if (is_prefixed_with(ptr, "depends=")) { + char *u; +@@ -62,11 +54,11 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA + for (u = ptr; *u; u++) + if (*u == '-') + *u = '_'; +- ptr += string_to_llist(ptr, &info->dependencies, ","); ++ ptr += string_to_llist(ptr, &e->deps, ","); + } else if (ENABLE_FEATURE_MODUTILS_ALIAS + && is_prefixed_with(ptr, "alias=") + ) { +- llist_add_to(&info->aliases, xstrdup(ptr + 6)); ++ llist_add_to(&e->aliases, xstrdup(ptr + 6)); + ptr += strlen(ptr); + } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS + && is_prefixed_with(ptr, "__ksymtab_") +@@ -77,7 +69,7 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA + ) { + continue; + } +- llist_add_to(&info->symbols, xstrdup(ptr)); ++ llist_add_to(&e->symbols, xstrdup(ptr)); + ptr += strlen(ptr); + } + } +@@ -86,24 +78,13 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA + return TRUE; + } + +-static module_info *find_module(module_info *modules, const char *modname) +-{ +- module_info *m; +- +- for (m = modules; m != NULL; m = m->next) +- if (strcmp(m->modname, modname) == 0) +- return m; +- return NULL; +-} +- +-static void order_dep_list(module_info *modules, module_info *start, +- llist_t *add) ++static void order_dep_list(module_entry *start, llist_t *add) + { +- module_info *m; ++ module_entry *m; + llist_t *n; + + for (n = add; n != NULL; n = n->link) { +- m = find_module(modules, n->data); ++ m = moddb_get(&G.db, n->data, 0); + if (m == NULL) + continue; + +@@ -118,7 +99,7 @@ static void order_dep_list(module_info *modules, module_info *start, + start->dprev = m; + + /* recurse */ +- order_dep_list(modules, start, m->dependencies); ++ order_dep_list(start, m->deps); + } + } + +@@ -184,12 +165,15 @@ enum { + int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; + int depmod_main(int argc UNUSED_PARAM, char **argv) + { +- module_info *modules, *m, *dep; ++ module_entry *m, *dep; + const char *moddir_base = "/"; + char *moddir, *version; + struct utsname uts; ++ unsigned i; + int tmp; + ++ INIT_G(); ++ + getopt32(argv, "aAb:eF:nruqC:", &moddir_base, NULL, NULL); + argv += optind; + +@@ -211,23 +195,23 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) + free(moddir); + + /* Scan modules */ +- modules = NULL; + if (*argv) { + do { +- parse_module(*argv, /*sb (unused):*/ NULL, &modules, 0); ++ parse_module(*argv, /*sb (unused):*/ NULL, NULL, 0); + } while (*++argv); + } else { + recursive_action(".", ACTION_RECURSE, +- parse_module, NULL, &modules, 0); ++ parse_module, NULL, NULL, 0); + } + + /* Generate dependency and alias files */ + if (!(option_mask32 & OPT_n)) + xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout); +- for (m = modules; m != NULL; m = m->next) { ++ ++ moddb_foreach_module(&G.db, m, i) { + printf("%s:", m->name); + +- order_dep_list(modules, m, m->dependencies); ++ order_dep_list(m, m->deps); + while (m->dnext != m) { + dep = m->dnext; + printf(" %s", dep->name); +@@ -243,10 +227,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) + #if ENABLE_FEATURE_MODUTILS_ALIAS + if (!(option_mask32 & OPT_n)) + xfreopen_write("modules.alias", stdout); +- for (m = modules; m != NULL; m = m->next) { +- char modname[MODULE_NAME_LEN]; +- const char *fname = bb_basename(m->name); +- filename2modname(fname, modname); ++ moddb_foreach_module(&G.db, m, i) { + while (m->aliases) { + /* + * Last word used to be a basename +@@ -256,34 +237,24 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) + */ + printf("alias %s %s\n", + (char*)llist_pop(&m->aliases), +- modname); ++ m->modname); + } + } + #endif + #if ENABLE_FEATURE_MODUTILS_SYMBOLS + if (!(option_mask32 & OPT_n)) + xfreopen_write("modules.symbols", stdout); +- for (m = modules; m != NULL; m = m->next) { +- char modname[MODULE_NAME_LEN]; +- const char *fname = bb_basename(m->name); +- filename2modname(fname, modname); ++ moddb_foreach_module(&G.db, m, i) { + while (m->symbols) { + printf("alias symbol:%s %s\n", + (char*)llist_pop(&m->symbols), +- modname); ++ m->modname); + } + } + #endif + +- if (ENABLE_FEATURE_CLEAN_UP) { +- while (modules) { +- module_info *old = modules; +- modules = modules->next; +- free(old->name); +- free(old->modname); +- free(old); +- } +- } ++ if (ENABLE_FEATURE_CLEAN_UP) ++ moddb_free(&G.db); + + return EXIT_SUCCESS; + } +diff --git a/modutils/modprobe.c b/modutils/modprobe.c +index 05bf02c..2f55ad2 100644 +--- a/modutils/modprobe.c ++++ b/modutils/modprobe.c +@@ -150,19 +150,6 @@ static const char modprobe_longopts[] ALIGN1 = + #define MODULE_FLAG_FOUND_IN_MODDEP 0x0004 + #define MODULE_FLAG_BLACKLISTED 0x0008 + +-struct module_entry { /* I'll call it ME. */ +- unsigned flags; +- char *modname; /* stripped of /path/, .ext and s/-/_/g */ +- const char *probed_name; /* verbatim as seen on cmdline */ +- char *options; /* options from config files */ +- llist_t *realnames; /* strings. if this module is an alias, */ +- /* real module name is one of these. */ +-//Can there really be more than one? Example from real kernel? +- llist_t *deps; /* strings. modules we depend on */ +-}; +- +-#define DB_HASH_SIZE 256 +- + struct globals { + llist_t *probes; /* MEs of module(s) requested on cmdline */ + char *cmdline_mopts; /* module options from cmdline */ +@@ -170,7 +157,7 @@ struct globals { + /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */ + smallint need_symbols; + struct utsname uts; +- llist_t *db[DB_HASH_SIZE]; /* MEs of all modules ever seen (caching for speed) */ ++ module_db db; + } FIX_ALIASING; + #define G (*ptr_to_globals) + #define INIT_G() do { \ +@@ -195,51 +182,9 @@ static char *gather_options_str(char *opts, const char *append) + return opts; + } + +-/* These three functions called many times, optimizing for speed. +- * Users reported minute-long delays when they runn iptables repeatedly +- * (iptables use modprobe to install needed kernel modules). +- */ +-static struct module_entry *helper_get_module(const char *module, int create) +-{ +- char modname[MODULE_NAME_LEN]; +- struct module_entry *e; +- llist_t *l; +- unsigned i; +- unsigned hash; +- +- filename2modname(module, modname); +- +- hash = 0; +- for (i = 0; modname[i]; i++) +- hash = ((hash << 5) + hash) + modname[i]; +- hash %= DB_HASH_SIZE; +- +- for (l = G.db[hash]; l; l = l->link) { +- e = (struct module_entry *) l->data; +- if (strcmp(e->modname, modname) == 0) +- return e; +- } +- if (!create) +- return NULL; +- +- e = xzalloc(sizeof(*e)); +- e->modname = xstrdup(modname); +- llist_add_to(&G.db[hash], e); +- +- return e; +-} +-static ALWAYS_INLINE struct module_entry *get_or_add_modentry(const char *module) ++static struct module_entry *get_or_add_modentry(const char *module) + { +- return helper_get_module(module, 1); +-} +-/* So far this function always gets a module pathname, never an alias name. +- * The crucial difference is that pathname needs dirname stripping, +- * while alias name must NOT do it! +- * Testcase where dirname stripping is likely to go wrong: "modprobe devname:snd/timer" +- */ +-static ALWAYS_INLINE struct module_entry *get_modentry(const char *pathname) +-{ +- return helper_get_module(bb_get_last_path_component_nostrip(pathname), 0); ++ return moddb_get(&G.db, module, 1); + } + + static void add_probe(const char *name) +@@ -536,7 +481,7 @@ static void load_modules_dep(void) + continue; + *colon = '\0'; + +- m = get_modentry(tokens[0]); ++ m = moddb_get(&G.db, bb_get_last_path_component_nostrip(tokens[0]), 0); + if (m == NULL) + continue; + +@@ -697,5 +642,8 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) + } while (me->realnames != NULL); + } + ++ if (ENABLE_FEATURE_CLEAN_UP) ++ moddb_free(&G.db); ++ + return (rc != 0); + } +diff --git a/modutils/modutils.c b/modutils/modutils.c +index ef4134a..05e0777 100644 +--- a/modutils/modutils.c ++++ b/modutils/modutils.c +@@ -16,6 +16,49 @@ extern int delete_module(const char *module, unsigned int flags); + # define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) + #endif + ++module_entry * FAST_FUNC moddb_get(module_db *db, const char *module, int create) ++{ ++ char modname[MODULE_NAME_LEN]; ++ struct module_entry *e; ++ unsigned i, hash; ++ ++ filename2modname(module, modname); ++ ++ hash = 0; ++ for (i = 0; modname[i]; i++) ++ hash = ((hash << 5) + hash) + modname[i]; ++ hash %= MODULE_HASH_SIZE; ++ ++ for (e = db->buckets[hash]; e; e = e->next) ++ if (strcmp(e->modname, modname) == 0) ++ return e; ++ if (!create) ++ return NULL; ++ ++ e = xzalloc(sizeof(*e)); ++ e->modname = xstrdup(modname); ++ e->next = db->buckets[hash]; ++ db->buckets[hash] = e; ++ e->dnext = e->dprev = e; ++ ++ return e; ++} ++ ++void FAST_FUNC moddb_free(module_db *db) ++{ ++ module_entry *e, *n; ++ unsigned i; ++ ++ for (i = 0; i < MODULE_HASH_SIZE; i++) { ++ for (e = db->buckets[i]; e; e = n) { ++ n = e->next; ++ free(e->name); ++ free(e->modname); ++ free(e); ++ } ++ } ++} ++ + void FAST_FUNC replace(char *s, char what, char with) + { + while (*s) { +diff --git a/modutils/modutils.h b/modutils/modutils.h +index 5f059c7..0c0cb46 100644 +--- a/modutils/modutils.h ++++ b/modutils/modutils.h +@@ -16,6 +16,35 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN + /* linux/include/linux/module.h has 64, but this is also used + * internally for the maximum alias name length, which can be quite long */ + #define MODULE_NAME_LEN 256 ++#define MODULE_HASH_SIZE 256 ++ ++typedef struct module_entry { ++ struct module_entry *next; ++ char *name, *modname; ++ llist_t *deps; ++ IF_MODPROBE( ++ llist_t *realnames; ++ unsigned flags; ++ const char *probed_name; /* verbatim as seen on cmdline */ ++ char *options; /* options from config files */ ++ ) ++ IF_DEPMOD( ++ llist_t *aliases; ++ llist_t *symbols; ++ struct module_entry *dnext, *dprev; ++ ) ++} module_entry; ++ ++typedef struct module_db { ++ module_entry *buckets[MODULE_HASH_SIZE]; ++} module_db; ++ ++#define moddb_foreach_module(db, module, index) \ ++ for ((index) = 0; (index) < MODULE_HASH_SIZE; (index)++) \ ++ for (module = (db)->buckets[index]; module; module = module->next) ++ ++module_entry *moddb_get(module_db *db, const char *s, int create) FAST_FUNC; ++void moddb_free(module_db *db) FAST_FUNC; + + void replace(char *s, char what, char with) FAST_FUNC; + char *replace_underscores(char *s) FAST_FUNC; +-- +2.6.1 + diff --git a/main/busybox/2002-depmod-support-generating-kmod-binary-index-files.patch b/main/busybox/2002-depmod-support-generating-kmod-binary-index-files.patch new file mode 100644 index 000000000..b758c35e4 --- /dev/null +++ b/main/busybox/2002-depmod-support-generating-kmod-binary-index-files.patch @@ -0,0 +1,495 @@ +From d8c1e5b77fd9fac9e03172a00bcd3f18aa20e2d9 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> +Date: Sun, 25 Oct 2015 22:21:41 +0200 +Subject: [PATCH 2002/2003] depmod: support generating kmod binary index files +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This allows to use busybox depmod, and run daemons +using libkmod (or even kmod modprobe if needed). + +About +1500 bytes when enabled. This patch merges some +depmod code paths, so when this is disabled it shrinks +the code size a little bit. + +Signed-off-by: Timo Teräs <timo.teras@iki.fi> +--- + modutils/Config.src | 10 ++ + modutils/depmod.c | 270 ++++++++++++++++++++++++++++++++++++++++++---------- + modutils/modprobe.c | 15 --- + modutils/modutils.c | 27 +++++- + modutils/modutils.h | 15 +++ + 5 files changed, 270 insertions(+), 67 deletions(-) + +diff --git a/modutils/Config.src b/modutils/Config.src +index 0b11832..09db515 100644 +--- a/modutils/Config.src ++++ b/modutils/Config.src +@@ -229,6 +229,16 @@ config FEATURE_MODUTILS_ALIAS + + Say Y if unsure. + ++config FEATURE_MODUTILS_BIN ++ bool "Support for the kmod .bin file format" ++ default n ++ depends on DEPMOD && !MODPROBE_SMALL ++ select PLATFORM_LINUX ++ help ++ Generate kmod compatible binary index files for .dep, .alias, ++ .symbols and .builtin files. Allows mixing use of busybox ++ modutils and kmod (binaries and library). ++ + config FEATURE_MODUTILS_SYMBOLS + bool "Support for module.symbols file" + default y +diff --git a/modutils/depmod.c b/modutils/depmod.c +index b8699ba..40f3c08 100644 +--- a/modutils/depmod.c ++++ b/modutils/depmod.c +@@ -2,7 +2,7 @@ + /* + * depmod - generate modules.dep + * Copyright (c) 2008 Bernhard Reutner-Fischer +- * Copyrihgt (c) 2008 Timo Teras <timo.teras@iki.fi> ++ * Copyrihgt (c) 2008-2015 Timo Teras <timo.teras@iki.fi> + * Copyright (c) 2008 Vladimir Dronnikov + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. +@@ -14,8 +14,18 @@ + #include "modutils.h" + #include <sys/utsname.h> /* uname() */ + ++#define INDEX_MINCHAR 32 ++#define INDEX_MAXCHAR 128 ++ ++typedef struct index_node { ++ char *prefix; ++ llist_t *values; ++ struct index_node *children[INDEX_MAXCHAR-INDEX_MINCHAR]; ++} index_node; ++ + struct globals { + module_db db; ++ index_node *root_node; + } FIX_ALIASING; + #define G (*ptr_to_globals) + #define INIT_G() do { \ +@@ -48,18 +58,12 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA + + for (ptr = image; ptr < image + len - 10; ptr++) { + if (is_prefixed_with(ptr, "depends=")) { +- char *u; +- + ptr += 8; +- for (u = ptr; *u; u++) +- if (*u == '-') +- *u = '_'; +- ptr += string_to_llist(ptr, &e->deps, ","); ++ string_to_llist(replace_underscores(ptr), &e->deps, ","); + } else if (ENABLE_FEATURE_MODUTILS_ALIAS + && is_prefixed_with(ptr, "alias=") + ) { +- llist_add_to(&e->aliases, xstrdup(ptr + 6)); +- ptr += strlen(ptr); ++ llist_add_to(&e->aliases, replace_underscores(xstrdup(ptr + 6))); + } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS + && is_prefixed_with(ptr, "__ksymtab_") + ) { +@@ -69,9 +73,10 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA + ) { + continue; + } +- llist_add_to(&e->symbols, xstrdup(ptr)); +- ptr += strlen(ptr); +- } ++ llist_add_to(&e->symbols, xasprintf("symbol:%s", ptr)); ++ } else ++ continue; ++ ptr += strlen(ptr); + } + free(image); + +@@ -103,12 +108,6 @@ static void order_dep_list(module_entry *start, llist_t *add) + } + } + +-static void xfreopen_write(const char *file, FILE *f) +-{ +- if (freopen(file, "w", f) == NULL) +- bb_perror_msg_and_die("can't open '%s'", file); +-} +- + //usage:#if !ENABLE_MODPROBE_SMALL + //usage:#define depmod_trivial_usage "[-n] [-b BASE] [VERSION] [MODFILES]..." + //usage:#define depmod_full_usage "\n\n" +@@ -162,6 +161,169 @@ enum { + OPT_C = (1 << 9), /* -C,--config etc_modules_conf: ignored */ + }; + ++/* Support for the mod binary index generation */ ++ ++static void index_init(const char *filename) ++{ ++ if (ENABLE_FEATURE_MODUTILS_BIN) { ++ index_node *n; ++ ++ n = xzalloc(sizeof(index_node)); ++ n->prefix = xstrdup(""); ++ G.root_node = n; ++ } ++ ++ if (filename && !(option_mask32 & OPT_n)) { ++ if (freopen(filename, "w", stdout) == NULL) ++ bb_perror_msg_and_die("can't open '%s'", filename); ++ } ++} ++ ++static void index_add(const char *key, char *value, const char *prefix) ++{ ++ if (prefix && *prefix) ++ printf("%s%s %s\n", prefix, key, value); ++ else if (prefix) ++ printf("%s\n", value); ++ ++ if (ENABLE_FEATURE_MODUTILS_BIN) { ++ index_node *cur = G.root_node, *n; ++ unsigned i = 0, j, ch; ++ ++ while (1) { ++ /* Ensure node->prefix is a prefix of &str[i]. ++ * If it is not already, then we must split node. */ ++ for (j = 0; cur->prefix[j]; j++) { ++ ch = cur->prefix[j]; ++ if (ch != key[i+j]) { ++ /* New child is copy of node with prefix[j+1..N] */ ++ n = xzalloc(sizeof(index_node)); ++ n->prefix = xstrdup(&cur->prefix[j+1]); ++ n->values = cur->values; ++ memcpy(n->children, cur->children, sizeof(n->children)); ++ ++ /* Parent has prefix[0..j], child at prefix[j] */ ++ cur->prefix[j] = '\0'; ++ cur->values = NULL; ++ memset(cur->children, 0, sizeof(cur->children)); ++ cur->children[ch-INDEX_MINCHAR] = n; ++ break; ++ } ++ } ++ i += j; ++ ++ ch = key[i]; ++ if (ch == 0) ++ break; ++ ++ if (ch < INDEX_MINCHAR || ch >= INDEX_MAXCHAR) ++ bb_error_msg_and_die("bad module name"); ++ ++ ch -= INDEX_MINCHAR; ++ if (!cur->children[ch]) { ++ n = xzalloc(sizeof(index_node)); ++ cur->children[ch] = n; ++ n->prefix = xstrdup(&key[i+1]); ++ cur = n; ++ break; ++ } ++ ++ /* Descend into child node and continue */ ++ cur = cur->children[ch]; ++ i++; ++ } ++ ++ llist_add_to(&cur->values, value); ++ } ++} ++ ++static uint32_t index_write_node(FILE *out, index_node *n, void (*freeit)(void *data)) ++{ ++ uint32_t child_offs[INDEX_MAXCHAR-INDEX_MINCHAR]; ++ uint32_t offset; ++ uint8_t first = 255, last = 0; ++ unsigned i; ++ ++ for (i = 0; i < INDEX_MAXCHAR-INDEX_MINCHAR; i++) { ++ child_offs[i] = 0; ++ if (!n->children[i]) ++ continue; ++ child_offs[i] = index_write_node(out, n->children[i], freeit); ++ if (first > INDEX_MAXCHAR) ++ first = i; ++ last = i; ++ } ++ ++ offset = ftell(out); ++ ++ if (n->prefix[0]) { ++ fputs(n->prefix, out); ++ fputc('\0', out); ++ offset |= INDEX_NODE_PREFIX; ++ } ++ ++ if (first < INDEX_MAXCHAR) { ++ fputc(first + INDEX_MINCHAR, out); ++ fputc(last + INDEX_MINCHAR, out); ++ fwrite(child_offs + first, sizeof(uint32_t), last - first + 1, out); ++ offset |= INDEX_NODE_CHILDS; ++ } ++ ++ if (n->values) { ++ const llist_t *v; ++ unsigned int cnt; ++ uint32_t u; ++ ++ n->values = llist_rev(n->values); ++ for (v = n->values, cnt = 0; v != NULL; v = v->link, cnt++); ++ u = htonl(cnt); ++ fwrite(&u, sizeof(u), 1, out); ++ for (v = n->values, cnt = 0; v != NULL; v = v->link, cnt++) { ++ u = htonl(cnt); ++ fwrite(&u, sizeof(u), 1, out); ++ fputs(v->data, out); ++ fputc('\0', out); ++ } ++ offset |= INDEX_NODE_VALUES; ++ } ++ ++ llist_free(n->values, freeit); ++ free(n->prefix); ++ free(n); ++ ++ return htonl(offset); ++} ++ ++static void index_dump(const char *filename, int deps_file) ++{ ++ if (ENABLE_FEATURE_MODUTILS_BIN) { ++ FILE *out; ++ uint32_t header[3] = { ++ htonl(INDEX_MAGIC), ++ htonl(INDEX_VERSION), ++ }; ++ ++ if (option_mask32 & OPT_n) ++ filename = "/dev/null"; ++ else ++ filename = xasprintf("tmp.%s.bin", filename); ++ ++ out = xfopen_for_write(filename); ++ fwrite(header, sizeof(uint32_t), 3, out); ++ header[2] = index_write_node(out, G.root_node, deps_file ? free : 0); ++ rewind(out); ++ G.root_node = NULL; ++ fwrite(header, sizeof(uint32_t), 3, out); ++ if (fclose(out)) { ++ remove(filename); ++ bb_error_msg_and_die(bb_msg_write_error); ++ } ++ /* .bin files are mmap'ed; not renaming it may crash ++ * long standing daemon using libkmod */ ++ rename_or_warn(filename, filename + 4); ++ } ++} ++ + int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; + int depmod_main(int argc UNUSED_PARAM, char **argv) + { +@@ -205,53 +367,59 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) + } + + /* Generate dependency and alias files */ +- if (!(option_mask32 & OPT_n)) +- xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout); +- ++ index_init(CONFIG_DEFAULT_DEPMOD_FILE); + moddb_foreach_module(&G.db, m, i) { +- printf("%s:", m->name); +- ++ char *buf = xasprintf("%s:", m->name); + order_dep_list(m, m->deps); + while (m->dnext != m) { + dep = m->dnext; +- printf(" %s", dep->name); +- ++ buf = gather_options_str(buf, dep->name); + /* unlink current entry */ + dep->dnext->dprev = dep->dprev; + dep->dprev->dnext = dep->dnext; + dep->dnext = dep->dprev = dep; + } +- bb_putchar('\n'); ++ index_add(m->modname, buf, ""); + } +- +-#if ENABLE_FEATURE_MODUTILS_ALIAS +- if (!(option_mask32 & OPT_n)) +- xfreopen_write("modules.alias", stdout); +- moddb_foreach_module(&G.db, m, i) { +- while (m->aliases) { +- /* +- * Last word used to be a basename +- * (filename with path and .ko.* stripped) +- * at the time of module-init-tools 3.4. +- * kmod v.12 uses module name, i.e., s/-/_/g. +- */ +- printf("alias %s %s\n", +- (char*)llist_pop(&m->aliases), +- m->modname); ++ index_dump(CONFIG_DEFAULT_DEPMOD_FILE, 1); ++ ++ if (ENABLE_FEATURE_MODUTILS_ALIAS) { ++ index_init("modules.alias"); ++ moddb_foreach_module(&G.db, m, i) { ++ while (m->aliases) { ++ /* ++ * Last word used to be a basename ++ * (filename with path and .ko.* stripped) ++ * at the time of module-init-tools 3.4. ++ * kmod v.12 uses module name, i.e., s/-/_/g. ++ */ ++ index_add((char*)llist_pop(&m->aliases), m->modname, "alias "); ++ } + } ++ index_dump("modules.alias", 0); + } +-#endif +-#if ENABLE_FEATURE_MODUTILS_SYMBOLS +- if (!(option_mask32 & OPT_n)) +- xfreopen_write("modules.symbols", stdout); +- moddb_foreach_module(&G.db, m, i) { +- while (m->symbols) { +- printf("alias symbol:%s %s\n", +- (char*)llist_pop(&m->symbols), +- m->modname); ++ if (ENABLE_FEATURE_MODUTILS_SYMBOLS) { ++ index_init("modules.symbols"); ++ moddb_foreach_module(&G.db, m, i) { ++ while (m->symbols) { ++ index_add((char*)llist_pop(&m->symbols), m->modname, "alias "); ++ } ++ } ++ index_dump("modules.symbols", 0); ++ } ++ if (ENABLE_FEATURE_MODUTILS_BIN) { ++ char line[PATH_MAX], modname[MODULE_NAME_LEN]; ++ FILE *in; ++ ++ index_init(NULL); ++ in = xfopen_for_read("modules.builtin"); ++ while (fgets(line, sizeof(line), in) != NULL) { ++ filename2modname(line, modname); ++ index_add(modname, (char *) "", 0); + } ++ fclose(in); ++ index_dump("modules.builtin", 0); + } +-#endif + + if (ENABLE_FEATURE_CLEAN_UP) + moddb_free(&G.db); +diff --git a/modutils/modprobe.c b/modutils/modprobe.c +index 2f55ad2..121bd56 100644 +--- a/modutils/modprobe.c ++++ b/modutils/modprobe.c +@@ -167,21 +167,6 @@ struct globals { + + static int read_config(const char *path); + +-static char *gather_options_str(char *opts, const char *append) +-{ +- /* Speed-optimized. We call gather_options_str many times. */ +- if (append) { +- if (opts == NULL) { +- opts = xstrdup(append); +- } else { +- int optlen = strlen(opts); +- opts = xrealloc(opts, optlen + strlen(append) + 2); +- sprintf(opts + optlen, " %s", append); +- } +- } +- return opts; +-} +- + static struct module_entry *get_or_add_modentry(const char *module) + { + return moddb_get(&G.db, module, 1); +diff --git a/modutils/modutils.c b/modutils/modutils.c +index 05e0777..9d5c8c4 100644 +--- a/modutils/modutils.c ++++ b/modutils/modutils.c +@@ -59,6 +59,21 @@ void FAST_FUNC moddb_free(module_db *db) + } + } + ++char * FAST_FUNC gather_options_str(char *opts, const char *append) ++{ ++ /* Speed-optimized. We call gather_options_str many times. */ ++ if (append) { ++ if (opts == NULL) { ++ opts = xstrdup(append); ++ } else { ++ int optlen = strlen(opts); ++ opts = xrealloc(opts, optlen + strlen(append) + 2); ++ sprintf(opts + optlen, " %s", append); ++ } ++ } ++ return opts; ++} ++ + void FAST_FUNC replace(char *s, char what, char with) + { + while (*s) { +@@ -70,7 +85,17 @@ void FAST_FUNC replace(char *s, char what, char with) + + char* FAST_FUNC replace_underscores(char *s) + { +- replace(s, '-', '_'); ++ int i; ++ for (i = 0; s[i]; i++) { ++ switch (s[i]) { ++ case '-': ++ s[i] = '_'; ++ break; ++ case '[': ++ i += strcspn(&s[i], "]"); ++ break; ++ } ++ } + return s; + } + +diff --git a/modutils/modutils.h b/modutils/modutils.h +index 0c0cb46..30a13e6 100644 +--- a/modutils/modutils.h ++++ b/modutils/modutils.h +@@ -18,6 +18,20 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN + #define MODULE_NAME_LEN 256 + #define MODULE_HASH_SIZE 256 + ++/* .bin index format definitions */ ++#define INDEX_MAGIC 0xB007F457 ++#define INDEX_VERSION_MAJOR 0x0002 ++#define INDEX_VERSION_MINOR 0x0001 ++#define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR) ++ ++enum node_offset { ++ INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ ++ INDEX_NODE_PREFIX = 0x80000000, ++ INDEX_NODE_VALUES = 0x40000000, ++ INDEX_NODE_CHILDS = 0x20000000, ++ INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ ++}; ++ + typedef struct module_entry { + struct module_entry *next; + char *name, *modname; +@@ -46,6 +60,7 @@ typedef struct module_db { + module_entry *moddb_get(module_db *db, const char *s, int create) FAST_FUNC; + void moddb_free(module_db *db) FAST_FUNC; + ++char *gather_options_str(char *opts, const char *append) FAST_FUNC; + void replace(char *s, char what, char with) FAST_FUNC; + char *replace_underscores(char *s) FAST_FUNC; + int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC; +-- +2.6.1 + diff --git a/main/busybox/2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch b/main/busybox/2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch new file mode 100644 index 000000000..434759d13 --- /dev/null +++ b/main/busybox/2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch @@ -0,0 +1,87 @@ +From a19967762fa8b8e6da7fcbcf7447131f33b0135b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> +Date: Wed, 28 Oct 2015 10:20:57 +0200 +Subject: [PATCH 2003/2003] modinfo: fix argument parsing, and printing of + firmware +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +getopt was missing a short option for 'firmware', thus the -F option +for specific keyword was flagged as last OPT_TAGS entry. This caused +"-F firmware" to print twice the firmware fields (once due to incorrectly +set OPT_TAGS and once for OPT_F) and incorrectly with the fieldname +prefix. + +This adds -f as shortcut for "-F firmware" so that OPT_TAGS and OPT_F +are now set properly by getopt32(). This allows removing the incorrect +and unneeded OPT_F setting based on the keyword field. + +function old new delta +modinfo_main 438 430 -8 +modinfo 457 438 -19 +------------------------------------------------------------------------------ +(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-27) Total: -27 bytes + text data bss dec hex filename + 787574 15136 3656 806366 c4dde busybox_old + 787547 15136 3656 806339 c4dc3 busybox_unstripped + +Fixes: 772f17a843 "modinfo: match more standard module fields and fix version field" +Signed-off-by: Timo Teräs <timo.teras@iki.fi> +Cc: Tanguy Pruvot <tanguy.pruvot@gmail.com> +--- + modutils/modinfo.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/modutils/modinfo.c b/modutils/modinfo.c +index 8e74b64..e2c9df3 100644 +--- a/modutils/modinfo.c ++++ b/modutils/modinfo.c +@@ -31,7 +31,7 @@ enum { + + struct modinfo_env { + char *field; +- int tags; ++ unsigned tags; + }; + + static void display(const char *data, const char *pattern, int flag) +@@ -62,11 +62,13 @@ static void modinfo(const char *path, const char *version, + "firmware", + }; + size_t len; +- int j; ++ unsigned j; + char *ptr, *the_module; + const char *field = env->field; +- int tags = env->tags; ++ unsigned tags = env->tags; + ++ if (!tags) ++ tags = OPT_TAGS; + if (tags & 1) { /* filename */ + display(path, shortcuts[0], 1 != tags); + } +@@ -84,8 +86,6 @@ static void modinfo(const char *path, const char *version, + return; + } + +- if (field) +- tags |= OPT_F; + for (j = 1; (1<<j) & (OPT_TAGS + OPT_F); j++) { + const char *pattern; + +@@ -141,8 +141,8 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv) + + env.field = NULL; + opt_complementary = "-1"; /* minimum one param */ +- opts = getopt32(argv, "nladvAsDumpF:0", &env.field); +- env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS; ++ opts = getopt32(argv, "nladvAsDumpfF:0", &env.field); ++ env.tags = opts & (OPT_TAGS + OPT_F); + argv += optind; + + uname(&uts); +-- +2.6.1 + diff --git a/main/busybox/APKBUILD b/main/busybox/APKBUILD index 0dc5b2f3c..eeabcda4d 100644 --- a/main/busybox/APKBUILD +++ b/main/busybox/APKBUILD @@ -2,7 +2,7 @@ # Maintainer: Natanael Copa <ncopa@alpinelinux.org> pkgname=busybox pkgver=1.24.1 -pkgrel=0 +pkgrel=1 pkgdesc="Size optimized toolbox of many common UNIX utilities" url=http://busybox.net arch="all" @@ -29,6 +29,10 @@ source="http://busybox.net/downloads/$pkgname-$pkgver.tar.bz2 1001-fbsplash-support-console-switching.patch 1002-fbsplash-support-image-and-bar-alignment-and-positio.patch + 2001-modutils-merge-module_entry-and-module_info-to-commo.patch + 2002-depmod-support-generating-kmod-binary-index-files.patch + 2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch + acpid.logrotate busyboxconfig glibc.patch" @@ -139,8 +143,11 @@ e1c183cbe1ca18a0fa0d9597314076c9 0001-ifupdown-use-x-hostname-NAME-with-udhcpc. 699ce5aa1095ba4419cd595cec8a8f75 1000-fbsplash-use-virtual-y-size-in-mmap-size-calculation.patch b56d306ccba574da78dff060b7330806 1001-fbsplash-support-console-switching.patch 4fe5f9e973674c7db3d07f295c363a7c 1002-fbsplash-support-image-and-bar-alignment-and-positio.patch +ad908fc45563148d9f22b50c6e78e0d4 2001-modutils-merge-module_entry-and-module_info-to-commo.patch +313fa7175333161c549af097d9f62a79 2002-depmod-support-generating-kmod-binary-index-files.patch +47987a0add3da5f2b1bac13c62120423 2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch 4046b78ee6a25259954797d73b94f4bd acpid.logrotate -3bcc0a7d9155d4439552ba3ff866692f busyboxconfig +08cc87d52169236c035e7a562d606514 busyboxconfig befaac2c59c380e36a452b3f1c1d4a3a glibc.patch" sha256sums="37d03132cc078937360b392170b7a1d0e5b322eee9f57c0b82292a8b1f0afe3d busybox-1.24.1.tar.bz2 81957f1fe0c386120dad1c8174ccc1fcfeed98c14d229db7d164d4fb4c938b3d bbsuid.c @@ -155,8 +162,11 @@ sha256sums="37d03132cc078937360b392170b7a1d0e5b322eee9f57c0b82292a8b1f0afe3d bu 043963183cad556bdae5d5608180f0cb76cf7eede175cd97aa002a787780500f 1000-fbsplash-use-virtual-y-size-in-mmap-size-calculation.patch b8b0b16ed67b0159256193b1d2108b8ef9aa8a334ab81e463bb970c71257da9a 1001-fbsplash-support-console-switching.patch e1f3fad8e21dfd72cfcae7ab3ba31d7938e964e0f9ec08b2da0b14d462435424 1002-fbsplash-support-image-and-bar-alignment-and-positio.patch +16ee3a66e5854adbcb7ea6b1ea5846bac49dcf6d874e167f57e88f2fbd5cd0a5 2001-modutils-merge-module_entry-and-module_info-to-commo.patch +dbddad67d6b6054b8ffe7159f7fd3189bf3b433ba8f179fb6915caeea20d1b4e 2002-depmod-support-generating-kmod-binary-index-files.patch +ea589dcd25037e3fefd2f3d6ac801a2a4a61a5cfd2d765785ea5558ed3937776 2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch f7cbeb5a5a47395ad30454ce8262abcd3e91c33ef803c2ae31a9258d7142dd48 acpid.logrotate -2c4987e8a7ef2b47e947a0067b6facfc687f8192c683dfe35beb264e8bff28d7 busyboxconfig +3c44bace3822cc83f1a68690775e7bf51a659565a50dfe5344b40bfca782b2ec busyboxconfig c604ef791c31d35a8c5ee4558d21428a46f37a6d762c4a7e29864f4037fc44a0 glibc.patch" sha512sums="3afc757ebaae61ae13c2c69097ee734717434f9e658eb77093a8b7b49af3326cbca2d723483ff84a1da99544b822fd2b47d9a97c68f09962e11754e5daf124ca busybox-1.24.1.tar.bz2 16b3dd6a8b76b062d51458351fcb44f84b49eb4bf898584c933df90fb2cb3966f9547865a4d7447589bb20b7c203beb04ff7512f76f85d29138d2cff4eb9ee81 bbsuid.c @@ -171,6 +181,9 @@ a35b66cd28b79ccc14b47315ac94677fdf8c14d8a6e8956707e71fb50d453dfc5b4b822832cd1fae 2a8e9360e1cedd26bdb70d8cc036ef0abc7588bf2eee147c1c7436d7a40763f8e31d346b980145a36649130a2f811d299e4f46f7e1b60a8165a60ae9e79727d5 1000-fbsplash-use-virtual-y-size-in-mmap-size-calculation.patch a181dd54e8e11cf1199edb1b1fcd4b7402bbf142593b6014f32c6815bb7093b56899ad0fcc9f73c382f56203ac5274fb3d51fa070feb541436f23c31680f1a69 1001-fbsplash-support-console-switching.patch c33073416f7da2805a20f3f456f869217171c8fbfdef85f4ae481307aeb1e1b5717084bbbc619010fa5500c3f3f49b6468d5c122024fcc49d637c82427a3f553 1002-fbsplash-support-image-and-bar-alignment-and-positio.patch +d94d17806f08ad54366ca623fbe8663b6397b28d68860239edc9305e6006f01d4ea1c1fd2033b30d302fd095145b018aa6a1707b07b7b4dfcaa8e0388b6737d0 2001-modutils-merge-module_entry-and-module_info-to-commo.patch +daadb1b255a8d30f2a13b84c2120427998d8173cf10754b9117e19a6fea8926d1820005f4d99a4a6999a559e731b5339c12ead22b3efbe1f0e752671363129a5 2002-depmod-support-generating-kmod-binary-index-files.patch +80589e03021fd0cb7bf29c3747e5396bf53dc99ecfecf78de86759e5c3939652d7f022f4534de0a35228bd782c1a44c4762f027d198790ec2c1bb76d6f7f102d 2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch dadb4c953ebc755b88ee95c1489feb0c2d352f6e44abc716166024e6eea11ab9d10c84fad62c081775834d205cb04aa1be3c994676c88f4284495c54b9188e8b acpid.logrotate -03aa02d9799d43d9aaa1675bc9a146ccdce58026b6f2775215b6017ae187d48df3a1033727c8569f835c55835919602662a7f674ed8147559b0c586181a415fe busyboxconfig +5d5a23dc4c6b808b62d888225ba79dc726c8c2776b86d85cc01206e7e861c72d8fe23434eef74b1cfa3e8054618fa87a81af05ca22264a1901fd52944ea8c30a busyboxconfig 1d2739379dab1deb3eae7cffd4845300eb7d30f7343b4a1209b21a5680860d55080ad45fdefe098b249ce3040c01951fa7f0a79cd447b2d7b260eb000099d9dc glibc.patch" diff --git a/main/busybox/busyboxconfig b/main/busybox/busyboxconfig index 4bb03545a..f49ee7762 100644 --- a/main/busybox/busyboxconfig +++ b/main/busybox/busyboxconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.24.1 -# Wed Oct 28 09:25:45 2015 +# Wed Oct 28 15:46:41 2015 # CONFIG_HAVE_DOT_CONFIG=y @@ -206,8 +206,8 @@ CONFIG_FEATURE_TR_EQUIV=y CONFIG_TRUNCATE=y CONFIG_UNLINK=y CONFIG_BASE64=y -CONFIG_WHO=y -CONFIG_USERS=y +# CONFIG_WHO is not set +# CONFIG_USERS is not set CONFIG_CAL=y CONFIG_CATV=y CONFIG_CHGRP=y @@ -543,6 +543,7 @@ CONFIG_DEPMOD=y # CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set CONFIG_FEATURE_CHECK_TAINTED_MODULE=y CONFIG_FEATURE_MODUTILS_ALIAS=y +CONFIG_FEATURE_MODUTILS_BIN=y CONFIG_FEATURE_MODUTILS_SYMBOLS=y CONFIG_DEFAULT_MODULES_DIR="/lib/modules" CONFIG_DEFAULT_DEPMOD_FILE="modules.dep" @@ -699,7 +700,7 @@ CONFIG_SETSERIAL=y # CONFIG_UBIRMVOL is not set # CONFIG_UBIRSVOL is not set # CONFIG_UBIUPDATEVOL is not set -CONFIG_WALL=y +# CONFIG_WALL is not set CONFIG_ADJTIMEX=y CONFIG_BBCONFIG=y CONFIG_FEATURE_COMPRESS_BBCONFIG=y @@ -733,8 +734,8 @@ CONFIG_FBSPLASH=y # CONFIG_FLASH_ERASEALL is not set CONFIG_IONICE=y CONFIG_INOTIFYD=y -CONFIG_LAST=y -CONFIG_FEATURE_LAST_SMALL=y +# CONFIG_LAST is not set +# CONFIG_FEATURE_LAST_SMALL is not set # CONFIG_FEATURE_LAST_FANCY is not set # CONFIG_HDPARM is not set # CONFIG_FEATURE_HDPARM_GET_IDENTITY is not set @@ -950,7 +951,7 @@ CONFIG_FEATURE_TOP_SMP_CPU=y CONFIG_FEATURE_TOP_SMP_PROCESS=y CONFIG_FEATURE_TOPMEM=y CONFIG_UPTIME=y -CONFIG_FEATURE_UPTIME_UTMP_SUPPORT=y +# CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set CONFIG_FREE=y CONFIG_FUSER=y CONFIG_KILL=y |