Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/modutils


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/modutils
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/modutils/Config.src

    r2725 r3232  
    55
    66menu "Linux Module Utilities"
    7 depends on PLATFORM_LINUX
    87
    98INSERT
     
    1211    bool "Simplified modutils"
    1312    default y
     13    select PLATFORM_LINUX
    1414    help
    1515      Simplified modutils.
     
    4646    default y
    4747    depends on MODPROBE_SMALL
     48    select PLATFORM_LINUX
    4849    help
    4950      Allow insmod and modprobe take module options from command line.
     
    6061    default n
    6162    depends on !MODPROBE_SMALL
     63    select PLATFORM_LINUX
    6264    help
    6365      insmod is used to load specified modules in the running kernel.
     
    6769    default n
    6870    depends on !MODPROBE_SMALL
     71    select PLATFORM_LINUX
    6972    help
    7073      rmmod is used to unload specified modules from the kernel.
     
    7477    default n
    7578    depends on !MODPROBE_SMALL
     79    select PLATFORM_LINUX
    7680    help
    7781      lsmod is used to display a list of loaded modules.
     
    8185    default n
    8286    depends on LSMOD
     87    select PLATFORM_LINUX
    8388    help
    8489      This option makes output format of lsmod adjusted to
     
    9095    default n
    9196    depends on !MODPROBE_SMALL
     97    select PLATFORM_LINUX
    9298    help
    9399      Handle the loading of modules, and their dependencies on a high
     
    98104    default n
    99105    depends on MODPROBE
     106    select PLATFORM_LINUX
    100107    help
    101108      Say 'y' here to enable support for the 'blacklist' command in
     
    109116    default n
    110117    depends on !MODPROBE_SMALL
     118    select PLATFORM_LINUX
    111119    help
    112120      depmod generates modules.dep (and potentially modules.alias
     
    120128    default n
    121129    depends on INSMOD || RMMOD || LSMOD
     130    select PLATFORM_LINUX
    122131    help
    123132      Support module loading for 2.2.x and 2.4.x Linux kernels.
     
    129138    default n
    130139    depends on INSMOD || MODPROBE_SMALL
     140    select PLATFORM_LINUX
    131141    help
    132142      This option causes module loading code to try to mmap
     
    145155    default n
    146156    depends on FEATURE_2_4_MODULES && (INSMOD || MODPROBE)
     157    select PLATFORM_LINUX
    147158    help
    148159      Support checking of versions for modules. This is used to
     
    153164    default n
    154165    depends on FEATURE_2_4_MODULES && (INSMOD || MODPROBE)
     166    select PLATFORM_LINUX
    155167    help
    156168      By adding module symbols to the kernel symbol table, Oops messages
     
    164176    default n
    165177    depends on FEATURE_2_4_MODULES && (INSMOD || MODPROBE)
     178    select PLATFORM_LINUX
    166179    help
    167180      This is a special uClinux only memory optimization that lets insmod
     
    174187    default n
    175188    depends on FEATURE_2_4_MODULES && INSMOD
     189    select PLATFORM_LINUX
    176190    help
    177191      Enabling this, one would be able to get a load map
     
    185199    default y
    186200    depends on FEATURE_INSMOD_LOAD_MAP && !MODPROBE_SMALL
     201    select PLATFORM_LINUX
    187202    help
    188203      Without this option, -m will only output section
     
    194209    default y
    195210    depends on (LSMOD || FEATURE_2_4_MODULES) && !MODPROBE_SMALL
     211    select PLATFORM_LINUX
    196212    help
    197213      Support checking for tainted modules. These are usually binary
     
    204220    default y
    205221    depends on DEPMOD || MODPROBE
     222    select PLATFORM_LINUX
    206223    help
    207224      Generate and parse modules.alias containing aliases for bus
     
    220237    default y
    221238    depends on DEPMOD || MODPROBE
     239    select PLATFORM_LINUX
    222240    help
    223241      Generate and parse modules.symbols containing aliases for
  • branches/3.2/mindi-busybox/modutils/depmod.c

    r2725 r3232  
    99 */
    1010
    11 //applet:IF_DEPMOD(APPLET(depmod, _BB_DIR_SBIN, _BB_SUID_DROP))
    12 
    13 //usage:#if !ENABLE_MODPROBE_SMALL
    14 //usage:#define depmod_trivial_usage NOUSAGE_STR
    15 //usage:#define depmod_full_usage ""
    16 //usage:#endif
     11//applet:IF_DEPMOD(APPLET(depmod, BB_DIR_SBIN, BB_SUID_DROP))
    1712
    1813#include "libbb.h"
     
    3732
    3833static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM,
    39                   void *data, int depth UNUSED_PARAM)
     34                void *data, int depth UNUSED_PARAM)
    4035{
    4136    char modname[MODULE_NAME_LEN];
     
    10196
    10297static void order_dep_list(module_info *modules, module_info *start,
    103                llist_t *add)
     98            llist_t *add)
    10499{
    105100    module_info *m;
     
    132127}
    133128
    134 /* Usage:
     129//usage:#if !ENABLE_MODPROBE_SMALL
     130//usage:#define depmod_trivial_usage "[-n] [-b BASE] [VERSION] [MODFILES]..."
     131//usage:#define depmod_full_usage "\n\n"
     132//usage:       "Generate modules.dep, alias, and symbols files"
     133//usage:     "\n"
     134//usage:     "\n    -b BASE Use BASE/lib/modules/VERSION"
     135//usage:     "\n    -n  Dry run: print files to stdout"
     136//usage:#endif
     137
     138/* Upstream usage:
    135139 * [-aAenv] [-C FILE or DIR] [-b BASE] [-F System.map] [VERSION] [MODFILES]...
    136140 *  -a --all
     
    143147 *      Path to /etc/depmod.conf or /etc/depmod.d/
    144148 *  -e --errsyms
    145  *      When combined with the -F option, this reports any symbols which
     149 *      When combined with the -F option, this reports any symbols
    146150 *      which are not supplied by other modules or kernel.
    147151 *  -F --filesyms System.map
     
    155159 *  -q  No-op
    156160 *
    157  * So far we only support: [-rn] [-b BASE] [VERSION] [MODFILES]...
    158  * -aAeF are accepted but ignored. -vC are not accepted.
     161 * So far we only support: [-n] [-b BASE] [VERSION] [MODFILES]...
     162 * Accepted but ignored:
     163 * -aAe
     164 * -F System.map
     165 * -C FILE/DIR
     166 *
     167 * Not accepted: -v
    159168 */
    160169enum {
     
    208217    } else {
    209218        recursive_action(".", ACTION_RECURSE,
    210                  parse_module, NULL, &modules, 0);
     219                parse_module, NULL, &modules, 0);
    211220    }
    212221
  • branches/3.2/mindi-busybox/modutils/insmod.c

    r2725 r3232  
    88 */
    99
    10 //applet:IF_INSMOD(APPLET(insmod, _BB_DIR_SBIN, _BB_SUID_DROP))
     10//applet:IF_INSMOD(APPLET(insmod, BB_DIR_SBIN, BB_SUID_DROP))
    1111
    1212#include "libbb.h"
     
    2424//usage:       "Load the specified kernel modules into the kernel"
    2525//usage:    IF_FEATURE_2_4_MODULES( "\n"
    26 //usage:     "\nOptions:"
    2726//usage:     "\n    -f  Force module to load into the wrong kernel version"
    2827//usage:     "\n    -k  Make module autoclean-able"
     
    6059        bb_show_usage();
    6160
    62     rc = bb_init_module(filename, parse_cmdline_module_options(argv));
     61    rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
    6362    if (rc)
    6463        bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
  • branches/3.2/mindi-busybox/modutils/lsmod.c

    r2725 r3232  
    99 */
    1010
    11 //applet:IF_LSMOD(APPLET(lsmod, _BB_DIR_SBIN, _BB_SUID_DROP))
     11//applet:IF_LSMOD(APPLET(lsmod, BB_DIR_SBIN, BB_SUID_DROP))
    1212
    1313//usage:#if !ENABLE_MODPROBE_SMALL
     
    8888            // or comma-separated list ended by comma
    8989            // so trimming the trailing char is just what we need!
    90             token[3][strlen(token[3])-1] = '\0';
     90            if (token[3][0])
     91                token[3][strlen(token[3]) - 1] = '\0';
    9192# if ENABLE_UNICODE_SUPPORT
    9293            {
  • branches/3.2/mindi-busybox/modutils/modinfo.c

    r2725 r3232  
    77 */
    88
    9 //applet:IF_MODINFO(APPLET(modinfo, _BB_DIR_SBIN, _BB_SUID_DROP))
     9//applet:IF_MODINFO(APPLET(modinfo, BB_DIR_SBIN, BB_SUID_DROP))
    1010
    1111//kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o
     
    1414//config:   bool "modinfo"
    1515//config:   default y
     16//config:   select PLATFORM_LINUX
    1617//config:   help
    1718//config:     Show information about a Linux Kernel module
     
    2425
    2526enum {
    26     OPT_TAGS = (1 << 6) - 1,
    27     OPT_F = (1 << 6), /* field name */
    28     OPT_0 = (1 << 7), /* \0 as separator */
     27    OPT_TAGS = (1 << 12) - 1, /* shortcut count */
     28    OPT_F = (1 << 12), /* field name */
     29    OPT_0 = (1 << 13), /* \0 as separator */
    2930};
    3031
     
    4546
    4647static void modinfo(const char *path, const char *version,
    47             struct modinfo_env *env)
     48            const struct modinfo_env *env)
    4849{
    4950    static const char *const shortcuts[] = {
    5051        "filename",
     52        "license",
     53        "author",
    5154        "description",
    52         "author",
    53         "license",
     55        "version",
     56        "alias",
     57        "srcversion",
     58        "depends",
     59        "uts_release",
    5460        "vermagic",
    5561        "parm",
     62        "firmware",
    5663    };
    5764    size_t len;
     
    8188        tags |= OPT_F;
    8289    for (j = 1; (1<<j) & (OPT_TAGS + OPT_F); j++) {
    83         const char *pattern = field;
     90        const char *pattern;
     91
     92        if (!((1<<j) & tags))
     93            continue;
     94        pattern = field;
    8495        if ((1<<j) & OPT_TAGS)
    8596            pattern = shortcuts[j];
    86         if (!((1<<j) & tags))
    87             continue;
    8897        length = strlen(pattern);
    8998        ptr = the_module;
     
    93102                break;
    94103            if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') {
    95                 ptr += length + 1;
    96                 ptr += display(ptr, pattern, (1<<j) != tags);
     104                /* field prefixes are 0x80 or 0x00 */
     105                if ((ptr[-1] & 0x7F) == '\0') {
     106                    ptr += length + 1;
     107                    ptr += display(ptr, pattern, (1<<j) != tags);
     108                }
    97109            }
    98110            ++ptr;
     
    105117//usage:       "[-adlp0] [-F keyword] MODULE"
    106118//usage:#define modinfo_full_usage "\n\n"
    107 //usage:       "Options:"
    108 //usage:     "\n    -a      Shortcut for '-F author'"
     119//usage:       "    -a      Shortcut for '-F author'"
    109120//usage:     "\n    -d      Shortcut for '-F description'"
    110121//usage:     "\n    -l      Shortcut for '-F license'"
     
    128139    env.field = NULL;
    129140    opt_complementary = "-1"; /* minimum one param */
    130     opts = getopt32(argv, "fdalvpF:0", &env.field);
     141    opts = getopt32(argv, "nladvAsDumpF:0", &env.field);
    131142    env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
    132143    argv += optind;
  • branches/3.2/mindi-busybox/modutils/modprobe-small.c

    r2725 r3232  
    99 */
    1010
    11 //applet:IF_MODPROBE_SMALL(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP))
    12 //applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, _BB_DIR_SBIN, _BB_SUID_DROP, modprobe))
    13 //applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, _BB_DIR_SBIN, _BB_SUID_DROP, modprobe))
    14 //applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(lsmod, modprobe, _BB_DIR_SBIN, _BB_SUID_DROP, modprobe))
    15 //applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(rmmod, modprobe, _BB_DIR_SBIN, _BB_SUID_DROP, modprobe))
     11//applet:IF_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP))
     12//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, modprobe))
     13//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, modprobe))
     14//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(lsmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, modprobe))
     15//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(rmmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, modprobe))
    1616
    1717#include "libbb.h"
     
    595595            goto ret;
    596596        }
    597         /* N.B. we do not stop here -
     597
     598        if (applet_name[0] == 'r') {
     599            /* rmmod: do not remove dependencies, exit */
     600            goto ret;
     601        }
     602
     603        /* modprobe -r: we do not stop here -
    598604         * continue to unload modules on which the module depends:
    599605         * "-r --remove: option causes modprobe to remove a module.
    600606         * If the modules it depends on are also unused, modprobe
    601          * will try to remove them, too." */
     607         * will try to remove them, too."
     608         */
    602609    }
    603610
     
    697704//usage:#if ENABLE_MODPROBE_SMALL
    698705
     706//// Note: currently, help system shows modprobe --help text for all aliased cmds
     707//// (see APPLET_ODDNAME macro definition).
     708//// All other help texts defined below are not used. FIXME?
     709
    699710//usage:#define depmod_trivial_usage NOUSAGE_STR
    700711//usage:#define depmod_full_usage ""
     
    712723//usage:       "Load the specified kernel modules into the kernel"
    713724//usage:    IF_FEATURE_2_4_MODULES( "\n"
    714 //usage:     "\nOptions:"
    715725//usage:     "\n    -f  Force module to load into the wrong kernel version"
    716726//usage:     "\n    -k  Make module autoclean-able"
     
    728738//usage:#define rmmod_full_usage "\n\n"
    729739//usage:       "Unload kernel modules\n"
    730 //usage:     "\nOptions:"
    731740//usage:     "\n    -w  Wait until the module is no longer used"
    732741//usage:     "\n    -f  Force unload"
     
    739748//usage:    "[-qfwrsv] MODULE [symbol=value]..."
    740749//usage:#define modprobe_full_usage "\n\n"
    741 //usage:       "Options:"
    742 //usage:     "\n    -r  Remove MODULE (stacks) or do autoclean"
     750//usage:       "    -r  Remove MODULE (stacks) or do autoclean"
    743751//usage:     "\n    -q  Quiet"
    744752//usage:     "\n    -v  Verbose"
     
    809817    /* only -q (quiet) and -r (rmmod),
    810818     * the rest are accepted and ignored (compat) */
    811     getopt32(argv, "qrfsvw");
     819    getopt32(argv, "qrfsvwb");
    812820    argv += optind;
    813821
  • branches/3.2/mindi-busybox/modutils/modprobe.c

    r2725 r3232  
    99 */
    1010
    11 //applet:IF_MODPROBE(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP))
     11//applet:IF_MODPROBE(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP))
     12
     13#include "libbb.h"
     14#include "modutils.h"
     15#include <sys/utsname.h>
     16#include <fnmatch.h>
     17
     18//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
     19#define DBG(...) ((void)0)
     20
     21/* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t),
     22 * we expect the full dependency list to be specified in modules.dep.
     23 * Older versions would only export the direct dependency list.
     24 */
     25
    1226
    1327//usage:#if !ENABLE_MODPROBE_SMALL
     
    7387//usage:
    7488//usage:#define modprobe_trivial_usage
    75 //usage:    "[-alrqvs"
    76 //usage:    IF_FEATURE_MODPROBE_BLACKLIST("b")
    77 //usage:    "] MODULE [symbol=value]..."
     89//usage:    "[-alrqvsD" IF_FEATURE_MODPROBE_BLACKLIST("b") "]"
     90//usage:    " MODULE [symbol=value]..."
    7891//usage:#define modprobe_full_usage "\n\n"
    79 //usage:       "Options:"
    80 //usage:     "\n    -a  Load multiple MODULEs"
     92//usage:       "    -a  Load multiple MODULEs"
    8193//usage:     "\n    -l  List (MODULE is a pattern)"
    8294//usage:     "\n    -r  Remove MODULE (stacks) or do autoclean"
     
    8496//usage:     "\n    -v  Verbose"
    8597//usage:     "\n    -s  Log to syslog"
     98//usage:     "\n    -D  Show dependencies"
    8699//usage:    IF_FEATURE_MODPROBE_BLACKLIST(
    87100//usage:     "\n    -b  Apply blacklist to module names too"
     
    89102//usage:#endif /* !ENABLE_MODPROBE_SMALL */
    90103
    91 #include "libbb.h"
    92 #include "modutils.h"
    93 #include <sys/utsname.h>
    94 #include <fnmatch.h>
    95 
    96 //#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
    97 #define DBG(...) ((void)0)
    98 
    99 /* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t),
    100  * we expect the full dependency list to be specified in modules.dep.
    101  * Older versions would only export the direct dependency list.
     104/* Note: usage text doesn't document various 2.4 options
     105 * we pull in through INSMOD_OPTS define
     106 * Note2: -b is always accepted, but if !FEATURE_MODPROBE_BLACKLIST,
     107 * it is a no-op.
    102108 */
    103 
    104 /* Note that usage text doesn't document various 2.4 options
    105  * we pull in through INSMOD_OPTS define */
    106 
    107 #define MODPROBE_COMPLEMENTARY "q-v:v-q:l--ar:a--lr:r--al"
    108 #define MODPROBE_OPTS  "alr" IF_FEATURE_MODPROBE_BLACKLIST("b")
     109#define MODPROBE_OPTS  "alrDb"
     110/* -a and -D _are_ in fact compatible */
     111#define MODPROBE_COMPLEMENTARY ("q-v:v-q:l--arD:r--alD:a--lr:D--rl")
     112//#define MODPROBE_OPTS  "acd:lnrt:C:b"
    109113//#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al"
    110 //#define MODPROBE_OPTS  "acd:lnrt:C:" IF_FEATURE_MODPROBE_BLACKLIST("b")
    111114enum {
    112     MODPROBE_OPT_INSERT_ALL = (INSMOD_OPT_UNUSED << 0), /* a */
    113     //MODPROBE_OPT_DUMP_ONLY= (INSMOD_OPT_UNUSED << x), /* c */
    114     //MODPROBE_OPT_DIRNAME  = (INSMOD_OPT_UNUSED << x), /* d */
    115     MODPROBE_OPT_LIST_ONLY  = (INSMOD_OPT_UNUSED << 1), /* l */
    116     //MODPROBE_OPT_SHOW_ONLY= (INSMOD_OPT_UNUSED << x), /* n */
    117     MODPROBE_OPT_REMOVE     = (INSMOD_OPT_UNUSED << 2), /* r */
    118     //MODPROBE_OPT_RESTRICT = (INSMOD_OPT_UNUSED << x), /* t */
    119     //MODPROBE_OPT_VERONLY  = (INSMOD_OPT_UNUSED << x), /* V */
    120     //MODPROBE_OPT_CONFIGFILE=(INSMOD_OPT_UNUSED << x), /* C */
    121     MODPROBE_OPT_BLACKLIST  = (INSMOD_OPT_UNUSED << 3) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
     115    OPT_INSERT_ALL   = (INSMOD_OPT_UNUSED << 0), /* a */
     116    //OPT_DUMP_ONLY  = (INSMOD_OPT_UNUSED << x), /* c */
     117    //OPT_DIRNAME    = (INSMOD_OPT_UNUSED << x), /* d */
     118    OPT_LIST_ONLY    = (INSMOD_OPT_UNUSED << 1), /* l */
     119    //OPT_SHOW_ONLY  = (INSMOD_OPT_UNUSED << x), /* n */
     120    OPT_REMOVE       = (INSMOD_OPT_UNUSED << 2), /* r */
     121    //OPT_RESTRICT   = (INSMOD_OPT_UNUSED << x), /* t */
     122    //OPT_VERONLY    = (INSMOD_OPT_UNUSED << x), /* V */
     123    //OPT_CONFIGFILE = (INSMOD_OPT_UNUSED << x), /* C */
     124    OPT_SHOW_DEPS    = (INSMOD_OPT_UNUSED << 3), /* D */
     125    OPT_BLACKLIST    = (INSMOD_OPT_UNUSED << 4) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
    122126};
     127#if ENABLE_LONG_OPTS
     128static const char modprobe_longopts[] ALIGN1 =
     129    /* nobody asked for long opts (yet) */
     130    // "all\0"          No_argument "a"
     131    // "list\0"         No_argument "l"
     132    // "remove\0"       No_argument "r"
     133    // "quiet\0"        No_argument "q"
     134    // "verbose\0"      No_argument "v"
     135    // "syslog\0"       No_argument "s"
     136    /* module-init-tools 3.11.1 has only long opt --show-depends
     137     * but no short -D, we provide long opt for scripts which
     138     * were written for 3.11.1: */
     139    "show-depends\0"     No_argument "D"
     140    // "use-blacklist\0" No_argument "b"
     141    ;
     142#endif
    123143
    124144#define MODULE_FLAG_LOADED              0x0001
     
    139159};
    140160
     161#define DB_HASH_SIZE 256
     162
    141163struct globals {
    142     llist_t *db; /* MEs of all modules ever seen (caching for speed) */
    143164    llist_t *probes; /* MEs of module(s) requested on cmdline */
    144165    char *cmdline_mopts; /* module options from cmdline */
     
    146167    /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */
    147168    smallint need_symbols;
     169    struct utsname uts;
     170    llist_t *db[DB_HASH_SIZE]; /* MEs of all modules ever seen (caching for speed) */
    148171} FIX_ALIASING;
    149 #define G (*(struct globals*)&bb_common_bufsiz1)
    150 #define INIT_G() do { } while (0)
     172#define G (*ptr_to_globals)
     173#define INIT_G() do { \
     174        SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
     175} while (0)
    151176
    152177
     
    168193}
    169194
     195/* These three functions called many times, optimizing for speed.
     196 * Users reported minute-long delays when they runn iptables repeatedly
     197 * (iptables use modprobe to install needed kernel modules).
     198 */
    170199static struct module_entry *helper_get_module(const char *module, int create)
    171200{
     
    173202    struct module_entry *e;
    174203    llist_t *l;
     204    unsigned i;
     205    unsigned hash;
    175206
    176207    filename2modname(module, modname);
    177     for (l = G.db; l != NULL; l = l->link) {
     208
     209    hash = 0;
     210    for (i = 0; modname[i]; i++)
     211        hash = ((hash << 5) + hash) + modname[i];
     212    hash %= DB_HASH_SIZE;
     213
     214    for (l = G.db[hash]; l; l = l->link) {
    178215        e = (struct module_entry *) l->data;
    179216        if (strcmp(e->modname, modname) == 0)
     
    185222    e = xzalloc(sizeof(*e));
    186223    e->modname = xstrdup(modname);
    187     llist_add_to(&G.db, e);
     224    llist_add_to(&G.db[hash], e);
    188225
    189226    return e;
    190227}
    191 static struct module_entry *get_or_add_modentry(const char *module)
     228static ALWAYS_INLINE struct module_entry *get_or_add_modentry(const char *module)
    192229{
    193230    return helper_get_module(module, 1);
    194231}
    195 static struct module_entry *get_modentry(const char *module)
     232static ALWAYS_INLINE struct module_entry *get_modentry(const char *module)
    196233{
    197234    return helper_get_module(module, 0);
     
    203240
    204241    m = get_or_add_modentry(name);
    205     if (!(option_mask32 & MODPROBE_OPT_REMOVE)
     242    if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
    206243     && (m->flags & MODULE_FLAG_LOADED)
    207244    ) {
     
    253290            filename2modname(tokens[1], wildcard);
    254291
    255             for (l = G.probes; l != NULL; l = l->link) {
     292            for (l = G.probes; l; l = l->link) {
    256293                m = (struct module_entry *) l->data;
    257294                if (fnmatch(wildcard, m->modname, 0) != 0)
     
    354391static int do_modprobe(struct module_entry *m)
    355392{
    356     struct module_entry *m2 = m2; /* for compiler */
    357     char *fn, *options;
    358393    int rc, first;
    359     llist_t *l;
    360394
    361395    if (!(m->flags & MODULE_FLAG_FOUND_IN_MODDEP)) {
     
    367401    DBG("do_modprob'ing %s", m->modname);
    368402
    369     if (!(option_mask32 & MODPROBE_OPT_REMOVE))
     403    if (!(option_mask32 & OPT_REMOVE))
    370404        m->deps = llist_rev(m->deps);
    371405
    372     for (l = m->deps; l != NULL; l = l->link)
    373         DBG("dep: %s", l->data);
     406    if (0) {
     407        llist_t *l;
     408        for (l = m->deps; l; l = l->link)
     409            DBG("dep: %s", l->data);
     410    }
    374411
    375412    first = 1;
    376413    rc = 0;
    377414    while (m->deps) {
     415        struct module_entry *m2;
     416        char *fn, *options;
     417
    378418        rc = 0;
    379419        fn = llist_pop(&m->deps); /* we leak it */
    380420        m2 = get_or_add_modentry(fn);
    381421
    382         if (option_mask32 & MODPROBE_OPT_REMOVE) {
     422        if (option_mask32 & OPT_REMOVE) {
    383423            /* modprobe -r */
    384424            if (m2->flags & MODULE_FLAG_LOADED) {
     
    400440        }
    401441
    402         if (m2->flags & MODULE_FLAG_LOADED) {
    403             DBG("%s is already loaded, skipping", fn);
    404             continue;
    405         }
    406 
    407442        options = m2->options;
    408443        m2->options = NULL;
     
    410445        if (m == m2)
    411446            options = gather_options_str(options, G.cmdline_mopts);
     447
     448        if (option_mask32 & OPT_SHOW_DEPS) {
     449            printf(options ? "insmod %s/%s/%s %s\n"
     450                    : "insmod %s/%s/%s\n",
     451                CONFIG_DEFAULT_MODULES_DIR, G.uts.release, fn,
     452                options);
     453            free(options);
     454            continue;
     455        }
     456
     457        if (m2->flags & MODULE_FLAG_LOADED) {
     458            DBG("%s is already loaded, skipping", fn);
     459            free(options);
     460            continue;
     461        }
     462
    412463        rc = bb_init_module(fn, options);
    413464        DBG("loaded %s '%s', rc:%d", fn, options, rc);
     
    457508        /* Optimization... */
    458509        if ((m->flags & MODULE_FLAG_LOADED)
    459          && !(option_mask32 & MODPROBE_OPT_REMOVE)
     510         && !(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
    460511        ) {
    461512            DBG("skip deps of %s, it's already loaded", tokens[0]);
     
    478529int modprobe_main(int argc UNUSED_PARAM, char **argv)
    479530{
    480     struct utsname uts;
    481531    int rc;
    482532    unsigned opt;
    483533    struct module_entry *me;
    484534
     535    INIT_G();
     536
     537    IF_LONG_OPTS(applet_long_options = modprobe_longopts;)
    485538    opt_complementary = MODPROBE_COMPLEMENTARY;
    486539    opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS);
     
    489542    /* Goto modules location */
    490543    xchdir(CONFIG_DEFAULT_MODULES_DIR);
    491     uname(&uts);
    492     xchdir(uts.release);
    493 
    494     if (opt & MODPROBE_OPT_LIST_ONLY) {
     544    uname(&G.uts);
     545    xchdir(G.uts.release);
     546
     547    if (opt & OPT_LIST_ONLY) {
     548        int i;
    495549        char name[MODULE_NAME_LEN];
    496550        char *colon, *tokens[2];
    497551        parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
     552
     553        for (i = 0; argv[i]; i++)
     554            replace(argv[i], '-', '_');
    498555
    499556        while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
     
    506563                puts(tokens[0]);
    507564            else {
    508                 int i;
    509565                for (i = 0; argv[i]; i++) {
    510566                    if (fnmatch(argv[i], name, 0) == 0) {
     
    522578
    523579    if (!argv[0]) {
    524         if (opt & MODPROBE_OPT_REMOVE) {
     580        if (opt & OPT_REMOVE) {
    525581            /* "modprobe -r" (w/o params).
    526582             * "If name is NULL, all unused modules marked
     
    542598    }
    543599
    544     if (opt & (MODPROBE_OPT_INSERT_ALL | MODPROBE_OPT_REMOVE)) {
     600    if (opt & (OPT_INSERT_ALL | OPT_REMOVE)) {
    545601        /* Each argument is a module name */
    546602        do {
     
    552608        DBG("probing just module %s", *argv);
    553609        add_probe(argv[0]);
    554         G.cmdline_mopts = parse_cmdline_module_options(argv);
     610        G.cmdline_mopts = parse_cmdline_module_options(argv, /*quote_spaces:*/ 1);
    555611    }
    556612
     
    576632             * only if '-b' is given.
    577633             */
    578             if (!(opt & MODPROBE_OPT_BLACKLIST)
     634            if (!(opt & OPT_BLACKLIST)
    579635             || !(me->flags & MODULE_FLAG_BLACKLISTED)
    580636            ) {
     
    593649            if (!(m2->flags & MODULE_FLAG_BLACKLISTED)
    594650             && (!(m2->flags & MODULE_FLAG_LOADED)
    595                 || (opt & MODPROBE_OPT_REMOVE))
     651                || (opt & (OPT_REMOVE | OPT_SHOW_DEPS)))
    596652            ) {
    597653//TODO: we can pass "me" as 2nd param to do_modprobe,
  • branches/3.2/mindi-busybox/modutils/modutils-24.c

    r2859 r3232  
    6161#include "libbb.h"
    6262#include "modutils.h"
    63 #include <libgen.h>
    6463#include <sys/utsname.h>
    6564
     
    24452444
    24462445        /* Number of parameters */
     2446        min = max = 1;
    24472447        if (isdigit(*pinfo)) {
    2448             min = strtoul(pinfo, &pinfo, 10);
     2448            min = max = strtoul(pinfo, &pinfo, 10);
    24492449            if (*pinfo == '-')
    24502450                max = strtoul(pinfo + 1, &pinfo, 10);
    2451             else
    2452                 max = min;
    2453         } else
    2454             min = max = 1;
     2451        }
    24552452
    24562453        contents = f->sections[sym->secidx]->contents;
     
    24742471        n = 0;
    24752472        p = val;
    2476         while (*p != 0) {
     2473        while (*p) {
    24772474            char sv_ch;
    24782475            char *endp;
     
    24852482                len = strcspn(p, ",");
    24862483                sv_ch = p[len];
    2487                 p[len] = 0;
     2484                p[len] = '\0';
    24882485                obj_string_patch(f, sym->secidx,
    24892486                         loc - contents, p);
     
    24952492                len = strcspn(p, ",");
    24962493                sv_ch = p[len];
    2497                 p[len] = 0;
     2494                p[len] = '\0';
    24982495                if (len >= charssize)
    24992496                    bb_error_msg_and_die("string too long for %s (max %ld)", param,
  • branches/3.2/mindi-busybox/modutils/modutils.c

    r2725 r3232  
    6363}
    6464
    65 char* FAST_FUNC parse_cmdline_module_options(char **argv)
     65char* FAST_FUNC parse_cmdline_module_options(char **argv, int quote_spaces)
    6666{
    6767    char *options;
     
    7171    optlen = 0;
    7272    while (*++argv) {
    73         options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
    74         /* Spaces handled by "" pairs, but no way of escaping quotes */
    75 //TODO: module-init-tools version 3.11.1 quotes only value:
    76 //it generates var="val with spaces", not "var=val with spaces"
    77 //(and it won't quote var *name* even if it has spaces)
    78         optlen += sprintf(options + optlen, (strchr(*argv, ' ') ? "\"%s\" " : "%s "), *argv);
    79     }
     73        const char *fmt;
     74        const char *var;
     75        const char *val;
     76
     77        var = *argv;
     78        options = xrealloc(options, optlen + 2 + strlen(var) + 2);
     79        fmt = "%.*s%s ";
     80        val = strchrnul(var, '=');
     81        if (quote_spaces) {
     82            /*
     83             * modprobe (module-init-tools version 3.11.1) compat:
     84             * quote only value:
     85             * var="val with spaces", not "var=val with spaces"
     86             * (note: var *name* is not checked for spaces!)
     87             */
     88            if (*val) { /* has var=val format. skip '=' */
     89                val++;
     90                if (strchr(val, ' '))
     91                    fmt = "%.*s\"%s\" ";
     92            }
     93        }
     94        optlen += sprintf(options + optlen, fmt, (int)(val - var), var, val);
     95    }
     96    /* Remove trailing space. Disabled */
     97    /* if (optlen != 0) options[optlen-1] = '\0'; */
    8098    return options;
    8199}
  • branches/3.2/mindi-busybox/modutils/modutils.h

    r2725 r3232  
    2222int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC;
    2323char *filename2modname(const char *filename, char *modname) FAST_FUNC;
    24 char *parse_cmdline_module_options(char **argv) FAST_FUNC;
     24char *parse_cmdline_module_options(char **argv, int quote_spaces) FAST_FUNC;
    2525
    2626/* insmod for 2.4 and modprobe's options (insmod 2.6 has no options at all): */
  • branches/3.2/mindi-busybox/modutils/rmmod.c

    r2725 r3232  
    99 */
    1010
    11 //applet:IF_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_DROP))
     11//applet:IF_RMMOD(APPLET(rmmod, BB_DIR_SBIN, BB_SUID_DROP))
    1212
    1313//usage:#if !ENABLE_MODPROBE_SMALL
     
    1616//usage:#define rmmod_full_usage "\n\n"
    1717//usage:       "Unload kernel modules\n"
    18 //usage:     "\nOptions:"
    1918//usage:     "\n    -w  Wait until the module is no longer used"
    2019//usage:     "\n    -f  Force unload"
     
    6261        if (bb_delete_module(modname, flags))
    6362            bb_error_msg_and_die("can't unload '%s': %s",
    64                          modname, moderror(errno));
     63                    modname, moderror(errno));
    6564    }
    6665
Note: See TracChangeset for help on using the changeset viewer.