Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/modutils/modinfo.c

    r3232 r3621  
    66 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    77 */
    8 
    9 //applet:IF_MODINFO(APPLET(modinfo, BB_DIR_SBIN, BB_SUID_DROP))
    10 
    11 //kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o
    12 
    138//config:config MODINFO
    149//config:   bool "modinfo"
     
    1813//config:     Show information about a Linux Kernel module
    1914
     15//applet:IF_MODINFO(APPLET(modinfo, BB_DIR_SBIN, BB_SUID_DROP))
     16
     17//kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o
     18
    2019#include <fnmatch.h>
    2120#include <sys/utsname.h> /* uname() */
     
    2322#include "modutils.h"
    2423
     24static const char *const shortcuts[] = {
     25    "filename", // -n
     26    "author",   // -a
     27    "description",  // -d
     28    "license",  // -l
     29    "parm",     // -p
     30    "version",  // the rest has no shortcut options
     31    "alias",
     32    "srcversion",
     33    "depends",
     34    "uts_release",
     35    "intree",
     36    "vermagic",
     37    "firmware",
     38};
    2539
    2640enum {
    27     OPT_TAGS = (1 << 12) - 1, /* shortcut count */
    28     OPT_F = (1 << 12), /* field name */
    29     OPT_0 = (1 << 13), /* \0 as separator */
     41    OPT_0 = (1 << 0), /* \0 as separator */
     42    OPT_F = (1 << 1), /* field name */
     43    /* first bits are for -nadlp options, the rest are for
     44     * fields not selectable with "shortcut" options
     45     */
     46    OPT_n = (1 << 2),
     47    OPT_TAGS = ((1 << ARRAY_SIZE(shortcuts)) - 1) << 2,
    3048};
    3149
    32 struct modinfo_env {
    33     char *field;
    34     int tags;
    35 };
    36 
    37 static int display(const char *data, const char *pattern, int flag)
     50static void display(const char *data, const char *pattern)
    3851{
    39     if (flag) {
     52    int flag = option_mask32 >> 1; /* shift out -0 bit */
     53    if (flag & (flag-1)) {
     54        /* more than one field to show: print "FIELD:" pfx */
    4055        int n = printf("%s:", pattern);
    4156        while (n++ < 16)
    4257            bb_putchar(' ');
    4358    }
    44     return printf("%s%c", data, (option_mask32 & OPT_0) ? '\0' : '\n');
     59    printf("%s%c", data, (option_mask32 & OPT_0) ? '\0' : '\n');
    4560}
    4661
    4762static void modinfo(const char *path, const char *version,
    48             const struct modinfo_env *env)
     63            const char *field)
    4964{
    50     static const char *const shortcuts[] = {
    51         "filename",
    52         "license",
    53         "author",
    54         "description",
    55         "version",
    56         "alias",
    57         "srcversion",
    58         "depends",
    59         "uts_release",
    60         "vermagic",
    61         "parm",
    62         "firmware",
    63     };
    6465    size_t len;
    65     int j, length;
     66    int j;
    6667    char *ptr, *the_module;
    67     const char *field = env->field;
    68     int tags = env->tags;
     68    char *allocated;
     69    int tags = option_mask32;
    6970
    70     if (tags & 1) { /* filename */
    71         display(path, shortcuts[0], 1 != tags);
    72     }
    73 
     71    allocated = NULL;
    7472    len = MAXINT(ssize_t);
    7573    the_module = xmalloc_open_zipped_read_close(path, &len);
     
    7876            return;
    7977        /* Newer depmod puts relative paths in modules.dep */
    80         path = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path);
     78        path = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path);
    8179        the_module = xmalloc_open_zipped_read_close(path, &len);
    82         free((char*)path);
    83         if (!the_module)
    84             return;
     80        if (!the_module) {
     81            bb_error_msg("module '%s' not found", path);
     82            goto ret;
     83        }
    8584    }
    8685
    87     if (field)
    88         tags |= OPT_F;
    89     for (j = 1; (1<<j) & (OPT_TAGS + OPT_F); j++) {
     86    for (j = 1; (1<<j) & (OPT_TAGS|OPT_F); j++) {
    9087        const char *pattern;
    9188
    9289        if (!((1<<j) & tags))
    9390            continue;
     91
    9492        pattern = field;
    9593        if ((1<<j) & OPT_TAGS)
    96             pattern = shortcuts[j];
    97         length = strlen(pattern);
     94            pattern = shortcuts[j-2];
     95
     96        if (strcmp(pattern, shortcuts[0]) == 0) {
     97            /* "-n" or "-F filename" */
     98            display(path, shortcuts[0]);
     99            continue;
     100        }
     101
    98102        ptr = the_module;
    99103        while (1) {
     104            char *after_pattern;
     105
    100106            ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
    101107            if (ptr == NULL) /* no occurance left, done */
    102108                break;
    103             if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') {
     109            after_pattern = is_prefixed_with(ptr, pattern);
     110            if (after_pattern && *after_pattern == '=') {
    104111                /* field prefixes are 0x80 or 0x00 */
    105                 if ((ptr[-1] & 0x7F) == '\0') {
    106                     ptr += length + 1;
    107                     ptr += display(ptr, pattern, (1<<j) != tags);
     112                if ((ptr[-1] & 0x7F) == 0x00) {
     113                    ptr = after_pattern + 1;
     114                    display(ptr, pattern);
     115                    ptr += strlen(ptr);
    108116                }
    109117            }
     
    112120    }
    113121    free(the_module);
     122 ret:
     123    free(allocated);
    114124}
    115125
    116126//usage:#define modinfo_trivial_usage
    117 //usage:       "[-adlp0] [-F keyword] MODULE"
     127//usage:       "[-adlpn0] [-F keyword] MODULE"
    118128//usage:#define modinfo_full_usage "\n\n"
    119129//usage:       "    -a      Shortcut for '-F author'"
     
    121131//usage:     "\n    -l      Shortcut for '-F license'"
    122132//usage:     "\n    -p      Shortcut for '-F parm'"
     133////usage:     "\n  -n      Shortcut for '-F filename'"
    123134//usage:     "\n    -F keyword  Keyword to look for"
    124135//usage:     "\n    -0      Separate output with NULs"
     
    129140int modinfo_main(int argc UNUSED_PARAM, char **argv)
    130141{
    131     struct modinfo_env env;
     142    const char *field;
    132143    char name[MODULE_NAME_LEN];
    133144    struct utsname uts;
     
    137148    unsigned i;
    138149
    139     env.field = NULL;
     150    field = NULL;
    140151    opt_complementary = "-1"; /* minimum one param */
    141     opts = getopt32(argv, "nladvAsDumpF:0", &env.field);
    142     env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
     152    opts = getopt32(argv, "0F:nadlp", &field);
     153    /* If no field selected, show all */
     154    if (!(opts & (OPT_TAGS|OPT_F)))
     155        option_mask32 |= OPT_TAGS;
    143156    argv += optind;
    144157
     
    154167            continue;
    155168        *colon = '\0';
    156         filename2modname(tokens[0], name);
     169        filename2modname(bb_basename(tokens[0]), name);
    157170        for (i = 0; argv[i]; i++) {
    158171            if (fnmatch(argv[i], name, 0) == 0) {
    159                 modinfo(tokens[0], uts.release, &env);
     172                modinfo(tokens[0], uts.release, field);
    160173                argv[i] = (char *) "";
    161174            }
     
    167180    for (i = 0; argv[i]; i++) {
    168181        if (argv[i][0]) {
    169             modinfo(argv[i], uts.release, &env);
     182            modinfo(argv[i], uts.release, field);
    170183        }
    171184    }
Note: See TracChangeset for help on using the changeset viewer.