aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-05-26 12:01:49 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-05-26 12:01:49 +0000
commit55e547eb6fad0d3ced00a62f04160016d90baabe (patch)
treeecfd0a9d9a662c807ecb881d8e683fc22e7d6d17
parenta0e17f7df6d4c65ecab7339e9899b294ff8bc04e (diff)
downloadbusybox-w32-55e547eb6fad0d3ced00a62f04160016d90baabe.tar.gz
busybox-w32-55e547eb6fad0d3ced00a62f04160016d90baabe.tar.bz2
busybox-w32-55e547eb6fad0d3ced00a62f04160016d90baabe.zip
- add simple first-draft unoptimized depmod just to proove Vladimir Dronnikov wrong
text data bss dec hex filename 569 0 0 569 239 modutils/depmod.o
-rw-r--r--include/applets.h1
-rw-r--r--include/usage.h6
-rw-r--r--modutils/Config.in6
-rw-r--r--modutils/Kbuild1
-rw-r--r--modutils/depmod.c116
5 files changed, 130 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h
index 4797e1dd5..17113dfe7 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -115,6 +115,7 @@ USE_DD(APPLET_NOEXEC(dd, dd, _BB_DIR_BIN, _BB_SUID_NEVER, dd))
115USE_DEALLOCVT(APPLET(deallocvt, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 115USE_DEALLOCVT(APPLET(deallocvt, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
116USE_DELGROUP(APPLET_ODDNAME(delgroup, deluser, _BB_DIR_BIN, _BB_SUID_NEVER, delgroup)) 116USE_DELGROUP(APPLET_ODDNAME(delgroup, deluser, _BB_DIR_BIN, _BB_SUID_NEVER, delgroup))
117USE_DELUSER(APPLET(deluser, _BB_DIR_BIN, _BB_SUID_NEVER)) 117USE_DELUSER(APPLET(deluser, _BB_DIR_BIN, _BB_SUID_NEVER))
118USE_DEPMOD(APPLET(depmod, _BB_DIR_SBIN, _BB_SUID_NEVER))
118USE_DEVFSD(APPLET(devfsd, _BB_DIR_SBIN, _BB_SUID_NEVER)) 119USE_DEVFSD(APPLET(devfsd, _BB_DIR_SBIN, _BB_SUID_NEVER))
119USE_DF(APPLET(df, _BB_DIR_BIN, _BB_SUID_NEVER)) 120USE_DF(APPLET(df, _BB_DIR_BIN, _BB_SUID_NEVER))
120USE_APP_DHCPRELAY(APPLET(dhcprelay, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) 121USE_APP_DHCPRELAY(APPLET(dhcprelay, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
diff --git a/include/usage.h b/include/usage.h
index a4fe6a7e0..e9943d539 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -692,6 +692,12 @@
692#define deluser_full_usage "\n\n" \ 692#define deluser_full_usage "\n\n" \
693 "Delete user USER from the system" 693 "Delete user USER from the system"
694 694
695#define depmod_trivial_usage \
696 ""
697#define depmod_full_usage \
698 "\n" \
699 "\n"
700
695#define devfsd_trivial_usage \ 701#define devfsd_trivial_usage \
696 "mntpnt [-v]" USE_DEVFSD_FG_NP("[-fg][-np]") 702 "mntpnt [-v]" USE_DEVFSD_FG_NP("[-fg][-np]")
697#define devfsd_full_usage "\n\n" \ 703#define devfsd_full_usage "\n\n" \
diff --git a/modutils/Config.in b/modutils/Config.in
index c5e596d1d..bffb521c4 100644
--- a/modutils/Config.in
+++ b/modutils/Config.in
@@ -5,6 +5,12 @@
5 5
6menu "Linux Module Utilities" 6menu "Linux Module Utilities"
7 7
8config DEPMOD
9 bool "depmod"
10 default n
11 help
12 depmod generates modules.dep (FIXME: elaborate)
13
8config INSMOD 14config INSMOD
9 bool "insmod" 15 bool "insmod"
10 default n 16 default n
diff --git a/modutils/Kbuild b/modutils/Kbuild
index cff02b4f2..40ea0efbe 100644
--- a/modutils/Kbuild
+++ b/modutils/Kbuild
@@ -5,6 +5,7 @@
5# Licensed under the GPL v2, see the file LICENSE in this tarball. 5# Licensed under the GPL v2, see the file LICENSE in this tarball.
6 6
7lib-y:= 7lib-y:=
8lib-$(CONFIG_DEPMOD) += depmod.o
8lib-$(CONFIG_INSMOD) += insmod.o 9lib-$(CONFIG_INSMOD) += insmod.o
9lib-$(CONFIG_LSMOD) += lsmod.o 10lib-$(CONFIG_LSMOD) += lsmod.o
10lib-$(CONFIG_MODPROBE) += modprobe.o 11lib-$(CONFIG_MODPROBE) += modprobe.o
diff --git a/modutils/depmod.c b/modutils/depmod.c
new file mode 100644
index 000000000..9131dc1ab
--- /dev/null
+++ b/modutils/depmod.c
@@ -0,0 +1,116 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * depmod - generate modules.dep
4 * Copyright (c) 2008 Bernhard Fischer
5 *
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */
8
9#undef _GNU_SOURCE
10#define _GNU_SOURCE
11#include <libbb.h>
12#include <sys/utsname.h> /* uname() */
13
14struct globals {
15 llist_t *lst;
16};
17#define G (*(struct globals*)&bb_common_bufsiz1)
18/* We have to zero it out because of NOEXEC */
19#define INIT_G() memset(&G, 0, sizeof(G))
20
21static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb,
22 void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth)
23{
24 llist_add_to_end(&G.lst, strdup(modulename));
25 return TRUE;
26}
27
28static int fileAction(const char *fname, struct stat ATTRIBUTE_UNUSED *sb,
29 void *data, int ATTRIBUTE_UNUSED depth)
30{
31 size_t seen = 0;
32 size_t len = MAXINT(ssize_t);
33 void *the_module = xmalloc_open_read_close(fname, &len), *ptr = the_module;
34 const char *deps;
35 RESERVE_CONFIG_BUFFER(depends, 512);
36 RESERVE_CONFIG_BUFFER(buf1, 512);
37
38 memset(buf1, 0, sizeof(buf1));
39 memset(depends, 0, sizeof(depends));
40 sprintf(buf1, "\n%s:", fname);
41
42 if (last_char_is(fname, 'o') == NULL) /* not a module */
43 goto done;
44 write((int)data, buf1, strlen(buf1));
45//bb_info_msg("[%d] fname='%s'", (int)data, fname);
46 do {
47 /* search for a 'd' */
48 ptr = memchr(ptr, 'd', len - seen);
49 if (ptr == NULL) /* no d left, done */
50 break;
51 if (sscanf(ptr, "depends=%s", depends) == 1)
52 break;
53 seen = ++ptr - the_module;
54 } while (1);
55//bb_info_msg(" depends='%s'", depends);
56 deps = depends;
57 while (*deps) {
58 llist_t * _lst = G.lst;
59 ptr = memchr(deps, ',', strlen(deps));
60 if (ptr != NULL)
61 *(char*)ptr = '\0';
62 /* remember the length of the current dependency plus eventual 0 byte */
63 len = strlen(deps) + (ptr != NULL);
64 sprintf(buf1, "/%s.", deps); /* make sure we match the correct file */
65 while (_lst) {
66 ptr = strstr(_lst->data, buf1);
67 if (ptr != NULL)
68 break; /* found it */
69 _lst = _lst->link;
70 }
71 if (_lst && _lst->data) {
72 const char separator = ' ';
73//bb_info_msg("[%s] -> '%s'", deps, _lst->data);
74 write((int)data, &separator, 1);
75 write((int)data, _lst->data, strlen(_lst->data));
76
77 deps += len;
78 }
79 }
80done:
81 RELEASE_CONFIG_BUFFER(depends);
82 RELEASE_CONFIG_BUFFER(buf1);
83 free(the_module);
84 return TRUE;
85}
86
87int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
88int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
89{
90 int retval = EXIT_SUCCESS;
91// static const char moddir_base[] ALIGN1 = "/lib/modules/%s";
92
93 int fd = xopen3("/tmp/modules.dep", O_CREAT|O_WRONLY|O_TRUNC,
94 S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH);
95 argv++;
96 do {
97 if (!recursive_action(*argv,
98 ACTION_RECURSE, /* flags */
99 fill_lst, /* file action */
100 NULL, /* dir action */
101 NULL, /* user data */
102 0) || /* depth */
103 !recursive_action(*argv,
104 ACTION_RECURSE, /* flags */
105 fileAction, /* file action */
106 NULL, /* dir action */
107 (void*)fd, /* user data */
108 0)) { /* depth */
109 retval = EXIT_FAILURE;
110 }
111 } while (*++argv);
112
113 if (ENABLE_FEATURE_CLEAN_UP)
114 close(fd);
115 return retval;
116}