diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-04-26 06:04:01 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-04-26 06:04:01 +0000 |
commit | 60e56f5292dfe525a28f321c2d7b9371ce639a86 (patch) | |
tree | fb760911189b22b1cb95212e25100c210a194cf9 /modutils/modprobe.c | |
parent | 54c14d7850e57503e872a659fd4125e041def652 (diff) | |
download | busybox-w32-60e56f5292dfe525a28f321c2d7b9371ce639a86.tar.gz busybox-w32-60e56f5292dfe525a28f321c2d7b9371ce639a86.tar.bz2 busybox-w32-60e56f5292dfe525a28f321c2d7b9371ce639a86.zip |
Reworked by Robert Griebl <griebl@gmx.de> to support proper
module dependancies.
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r-- | modutils/modprobe.c | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 35feaebf7..0b81142d5 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -2,6 +2,10 @@ | |||
2 | /* | 2 | /* |
3 | * really dumb modprobe implementation for busybox | 3 | * really dumb modprobe implementation for busybox |
4 | * Copyright (C) 2001 Lineo, davidm@lineo.com | 4 | * Copyright (C) 2001 Lineo, davidm@lineo.com |
5 | * | ||
6 | * CONFIG_MODPROBE_DEPEND stuff was added and is | ||
7 | * Copyright (C) 2002 Robert Griebl, griebl@gmx.de | ||
8 | * | ||
5 | */ | 9 | */ |
6 | 10 | ||
7 | #include <stdio.h> | 11 | #include <stdio.h> |
@@ -10,10 +14,189 @@ | |||
10 | #include <unistd.h> | 14 | #include <unistd.h> |
11 | #include <syslog.h> | 15 | #include <syslog.h> |
12 | #include <string.h> | 16 | #include <string.h> |
17 | #include <ctype.h> | ||
13 | #include "busybox.h" | 18 | #include "busybox.h" |
14 | 19 | ||
15 | static char cmd[128]; | 20 | static char cmd[128]; |
16 | 21 | ||
22 | #define CONFIG_MODPROBE_DEPEND | ||
23 | |||
24 | #ifdef CONFIG_MODPROBE_DEPEND | ||
25 | |||
26 | #include <sys/utsname.h> | ||
27 | |||
28 | struct dep_t { | ||
29 | char * m_module; | ||
30 | int m_depcnt; | ||
31 | char ** m_deparr; | ||
32 | |||
33 | struct dep_t * m_next; | ||
34 | }; | ||
35 | |||
36 | |||
37 | static struct dep_t *build_dep ( ) | ||
38 | { | ||
39 | struct utsname un; | ||
40 | FILE *f; | ||
41 | struct dep_t *first = 0; | ||
42 | struct dep_t *current = 0; | ||
43 | char buffer [4096]; | ||
44 | char *filename = buffer; | ||
45 | int continuation_line = 0; | ||
46 | |||
47 | if ( uname ( &un )) | ||
48 | return 0; | ||
49 | strcpy ( filename, "/lib/modules/" ); | ||
50 | strcat ( filename, un. release ); | ||
51 | strcat ( filename, "/modules.dep" ); | ||
52 | |||
53 | f = fopen ( filename, "r" ); | ||
54 | if ( !f ) | ||
55 | return 0; | ||
56 | |||
57 | while ( fgets ( buffer, sizeof( buffer), f )) { | ||
58 | int l = strlen ( buffer ); | ||
59 | char *p = 0; | ||
60 | |||
61 | if ( buffer [l-1] == '\n' ) { | ||
62 | buffer [l-1] = 0; | ||
63 | l--; | ||
64 | } | ||
65 | |||
66 | if ( l == 0 ) { | ||
67 | continuation_line = 0; | ||
68 | continue; | ||
69 | } | ||
70 | |||
71 | if ( !continuation_line ) { | ||
72 | char *col = strchr ( buffer, ':' ); | ||
73 | |||
74 | if ( col ) { | ||
75 | char *mods; | ||
76 | char *mod; | ||
77 | |||
78 | *col = 0; | ||
79 | mods = strrchr ( buffer, '/' ); | ||
80 | |||
81 | if ( !mods ) | ||
82 | mods = buffer; | ||
83 | else | ||
84 | mods++; | ||
85 | |||
86 | mod = (char *) malloc ( col - mods + 1 ); | ||
87 | strncpy ( mod, mods, col - mods ); | ||
88 | mod [col - mods] = 0; | ||
89 | |||
90 | if ( !current ) { | ||
91 | first = current = (struct dep_t *) malloc ( sizeof ( struct dep_t )); | ||
92 | } | ||
93 | else { | ||
94 | current-> m_next = (struct dep_t *) malloc ( sizeof ( struct dep_t )); | ||
95 | current = current-> m_next; | ||
96 | } | ||
97 | current-> m_module = mod; | ||
98 | current-> m_depcnt = 0; | ||
99 | current-> m_deparr = 0; | ||
100 | current-> m_next = 0; | ||
101 | |||
102 | /* printf ( "%s:\n", mod ); */ | ||
103 | |||
104 | p = col + 1; | ||
105 | } | ||
106 | else | ||
107 | p = 0; | ||
108 | } | ||
109 | else | ||
110 | p = buffer; | ||
111 | |||
112 | if ( p && *p ) { | ||
113 | char *end = &buffer [l-1]; | ||
114 | char *deps = strrchr ( end, '/' ); | ||
115 | char *dep; | ||
116 | |||
117 | while ( isblank ( *end ) || ( *end == '\\' )) | ||
118 | end--; | ||
119 | |||
120 | deps = strrchr ( p, '/' ); | ||
121 | |||
122 | if ( !deps || ( deps < p )) { | ||
123 | deps = p; | ||
124 | |||
125 | while ( isblank ( *deps )) | ||
126 | deps++; | ||
127 | } | ||
128 | else | ||
129 | deps++; | ||
130 | |||
131 | dep = (char *) malloc ( end - deps + 2 ); | ||
132 | strncpy ( dep, deps, end - deps + 1 ); | ||
133 | dep [end - deps + 1] = 0; | ||
134 | |||
135 | current-> m_depcnt++; | ||
136 | current-> m_deparr = (char **) realloc ( current-> m_deparr, sizeof ( char *) * current-> m_depcnt ); | ||
137 | current-> m_deparr [current-> m_depcnt - 1] = dep; | ||
138 | |||
139 | /* printf ( " %d) %s\n", current-> m_depcnt, current-> m_deparr [current-> m_depcnt -1] ); */ | ||
140 | } | ||
141 | |||
142 | if ( buffer [l-1] == '\\' ) | ||
143 | continuation_line = 1; | ||
144 | else | ||
145 | continuation_line = 0; | ||
146 | } | ||
147 | fclose ( f ); | ||
148 | |||
149 | return first; | ||
150 | } | ||
151 | |||
152 | |||
153 | static struct dep_t *find_dep ( struct dep_t *dt, char *mod ) | ||
154 | { | ||
155 | int lm = strlen ( mod ); | ||
156 | int hasext = 0; | ||
157 | |||
158 | if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' )) | ||
159 | hasext = 1; | ||
160 | |||
161 | while ( dt ) { | ||
162 | if ( hasext && !strcmp ( dt-> m_module, mod )) | ||
163 | break; | ||
164 | else if ( !hasext && !strncmp ( dt-> m_module, mod, strlen ( dt-> m_module ) - 2 )) | ||
165 | break; | ||
166 | |||
167 | dt = dt-> m_next; | ||
168 | } | ||
169 | return dt; | ||
170 | } | ||
171 | |||
172 | |||
173 | static void check_dep ( char *mod, int loadit ) | ||
174 | { | ||
175 | static struct dep_t *depend = (struct dep_t *) -1; | ||
176 | struct dep_t *dt; | ||
177 | |||
178 | if ( depend == (struct dep_t *) -1 ) | ||
179 | depend = build_dep ( ); | ||
180 | |||
181 | /* printf ( "CHECK: %s (%p)\n", mod, depend ); */ | ||
182 | |||
183 | if (( dt = find_dep ( depend, mod ))) { | ||
184 | int i; | ||
185 | |||
186 | for ( i = 0; i < dt-> m_depcnt; i++ ) | ||
187 | check_dep ( dt-> m_deparr [i], 1 ); | ||
188 | } | ||
189 | if ( loadit ) { | ||
190 | char lcmd [128]; | ||
191 | |||
192 | sprintf ( lcmd, "insmod -k %s 2>/dev/null", mod ); | ||
193 | system ( lcmd ); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | #endif | ||
198 | |||
199 | |||
17 | extern int modprobe_main(int argc, char** argv) | 200 | extern int modprobe_main(int argc, char** argv) |
18 | { | 201 | { |
19 | int ch, rc = 0; | 202 | int ch, rc = 0; |
@@ -101,6 +284,11 @@ extern int modprobe_main(int argc, char** argv) | |||
101 | do_syslog ? "-s" : "", | 284 | do_syslog ? "-s" : "", |
102 | quiet ? "-q" : "", | 285 | quiet ? "-q" : "", |
103 | autoclean ? "-k" : ""); | 286 | autoclean ? "-k" : ""); |
287 | |||
288 | #ifdef CONFIG_MODPROBE_DEPEND | ||
289 | check_dep ( argv [optind], 0 ); | ||
290 | #endif | ||
291 | |||
104 | while (optind < argc) { | 292 | while (optind < argc) { |
105 | strcat(cmd, " "); | 293 | strcat(cmd, " "); |
106 | strcat(cmd, argv[optind]); | 294 | strcat(cmd, argv[optind]); |