wok view busybox/stuff/busybox-1.12.0-modinfo.u @ rev 1305

Fix: Typo in claws-mail. Sorry guys.
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Mon Aug 25 09:51:40 2008 +0200 (2008-08-25)
parents
children 85fbd04c1fd6
line source
1 --- busybox-1.12.0/include/applets.h
2 +++ busybox-1.12.0/include/applets.h
3 @@ -251,6 +251,7 @@ USE_MKFS_MINIX(APPLET_ODDNAME(mkfs.minix
4 USE_MKNOD(APPLET(mknod, _BB_DIR_BIN, _BB_SUID_NEVER))
5 USE_MKSWAP(APPLET(mkswap, _BB_DIR_SBIN, _BB_SUID_NEVER))
6 USE_MKTEMP(APPLET(mktemp, _BB_DIR_BIN, _BB_SUID_NEVER))
7 +USE_MODINFO(APPLET(modinfo, _BB_DIR_SBIN, _BB_SUID_NEVER))
8 USE_MODPROBE(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER))
9 USE_MODPROBE_SMALL(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER))
10 USE_MORE(APPLET(more, _BB_DIR_BIN, _BB_SUID_NEVER))
12 --- busybox-1.12.0/include/usage.h
13 +++ busybox-1.12.0/include/usage.h
14 @@ -2629,6 +2629,20 @@
15 " which are the default for alias 'tulip2' overridden by the options 'irq=2 io=0x210'\n\n" \
16 " from the command line\n"
18 +#define modinfo_trivial_usage \
19 + "[-adlp0] [-F keyword] MODULE"
20 +#define modinfo_full_usage "\n\n" \
21 + "Options:" \
22 + "\n -a Shortcut for '-F author'" \
23 + "\n -d Shortcut for '-F description'" \
24 + "\n -l Shortcut for '-F license'" \
25 + "\n -p Shortcut for '-F parm'" \
26 + "\n -F keyword Keyword to look for" \
27 + "\n -0 Use \\0 string separator. Not \\n" \
28 +
29 +#define modinfo_example_usage \
30 + "$ modinfo -F vermagic loop\n"
31 +
32 #define more_trivial_usage \
33 "[FILE...]"
34 #define more_full_usage "\n\n" \
36 --- busybox-1.12.0/modutils/Config.in
37 +++ busybox-1.12.0/modutils/Config.in
38 @@ -213,6 +213,12 @@ config FEATURE_MODPROBE_BLACKLIST
39 hardware autodetection scripts to load modules like evdev, frame
40 buffer drivers etc.
42 +config MODINFO
43 + bool "modinfo"
44 + default n
45 + help
46 + Show information about a Linux Kernel module
47 +
48 comment "Options common to multiple modutils"
49 depends on INSMOD || RMMOD || MODPROBE || LSMOD || DEPMOD
52 --- busybox-1.12.0/modutils/Kbuild
53 +++ busybox-1.12.0/modutils/Kbuild
54 @@ -11,3 +11,4 @@ lib-$(CONFIG_LSMOD) += lsmod
55 lib-$(CONFIG_MODPROBE) += modprobe.o
56 lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o
57 lib-$(CONFIG_RMMOD) += rmmod.o
58 +lib-$(CONFIG_MODINFO) += modinfo.o
60 --- busybox-1.12.0/modutils/modinfo.c
61 +++ busybox-1.12.0/modutils/modinfo.c
62 @@ -0,0 +1,91 @@
63 +/* vi: set sw=4 ts=4: */
64 +/*
65 + * modinfo - retrieve module info
66 + * Copyright (c) 2008 Pascal Bellard
67 + *
68 + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
69 + */
70 +
71 +#undef _GNU_SOURCE
72 +#define _GNU_SOURCE
73 +#include <libbb.h>
74 +#include <sys/utsname.h> /* uname() */
75 +
76 +int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
77 +int modinfo_main(int argc UNUSED_PARAM, char **argv)
78 +{
79 + static const char *shortcuts[] = {
80 + "author",
81 + "description",
82 + "license",
83 + "parm"
84 + };
85 + size_t len;
86 + int i, length;
87 + char *field = NULL;
88 + char *ptr, *the_module, *depends, *filename;
89 + struct utsname un;
90 + enum {
91 + ARG_F = (1<<4), /* field name */
92 + ARG_0 = (1<<5) /* \0 as separator */
93 + };
94 + extern void *xalloc_load_module(const char filename[], size_t *len);
95 +
96 + getopt32(argv, "adlpF:0", &field);
97 + argv += optind;
98 +
99 + for (i = 0; i < sizeof(shortcuts)/sizeof(shortcuts[0]); i++)
100 + if (option_mask32 & (1 << i))
101 + field = (char *) shortcuts[i];
102 +
103 + if (!field || !*argv)
104 + bb_show_usage();
105 +
106 + /* get module path from modules.dep */
107 + uname(&un); /* never fails */
108 + filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/"CONFIG_DEFAULT_DEPMOD_FILE, un.release);
109 + len = MAXINT(ssize_t);
110 + the_module = xalloc_load_module(*argv, &len);
111 + if (the_module == NULL) {
112 + len = MAXINT(ssize_t);
113 + ptr = depends = xmalloc_open_read_close(filename, &len);
114 + depends[len-1] = 0;
115 + if (ENABLE_FEATURE_CLEAN_UP)
116 + free(filename);
117 + do {
118 + ptr = strstr(ptr,*argv);
119 + length = strlen(*argv);
120 + if (!ptr)
121 + bb_show_usage();
122 + if (ptr[length] == '.' && ptr[-1] == '/') {
123 + while (ptr[++length] != ':')
124 + if (ptr[length] == ' ') goto next;
125 + ptr[length] = 0;
126 + while (ptr > depends && ptr[-1] != '\n') ptr--;
127 + break;
128 + }
129 + next:
130 + ptr++;
131 + } while (1);
132 + if (ENABLE_FEATURE_CLEAN_UP)
133 + free(depends);
134 +
135 + len = MAXINT(ssize_t);
136 + the_module = xalloc_load_module(ptr, &len);
137 + }
138 + ptr = the_module;
139 + length = strlen(field);
140 + do {
141 + ptr = memchr(ptr, *field, len - (ptr - (char*)the_module));
142 + if (ptr == NULL) /* no occurance left, done */
143 + break;
144 + if (!strncmp(ptr, field, length) && ptr[length] == '=') {
145 + ptr += length + 1;
146 + ptr += printf("%s%c",ptr,(option_mask32 & ARG_0) ? '\0' : '\n');
147 + }
148 + ++ptr;
149 + } while (1);
150 + if (ENABLE_FEATURE_CLEAN_UP)
151 + free(the_module);
152 + return 0;
153 +}