diff options
| author | Eric Andersen <andersen@codepoet.org> | 2002-05-03 15:48:26 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2002-05-03 15:48:26 +0000 |
| commit | 864b79791a8367d9f8ea2c18eba31fea65bf511a (patch) | |
| tree | b5653837256659fad4718f52f8690802396cc563 /modutils | |
| parent | 26920c6c94449a96bf4c0701300ff4474bc56515 (diff) | |
| download | busybox-w32-864b79791a8367d9f8ea2c18eba31fea65bf511a.tar.gz busybox-w32-864b79791a8367d9f8ea2c18eba31fea65bf511a.tar.bz2 busybox-w32-864b79791a8367d9f8ea2c18eba31fea65bf511a.zip | |
Patch from Robert Griebl <griebl@gmx.de> to support modprobe -r properly,
merged in with the latest and greatest.
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/modprobe.c | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index f9aa0aa55..2f797ec4a 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
| @@ -34,7 +34,7 @@ struct dep_t { | |||
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | static struct dep_t *build_dep ( ) | 37 | static struct dep_t *build_dep ( void ) |
| 38 | { | 38 | { |
| 39 | struct utsname un; | 39 | struct utsname un; |
| 40 | FILE *f; | 40 | FILE *f; |
| @@ -55,7 +55,7 @@ static struct dep_t *build_dep ( ) | |||
| 55 | return 0; | 55 | return 0; |
| 56 | 56 | ||
| 57 | while ( fgets ( buffer, sizeof( buffer), f )) { | 57 | while ( fgets ( buffer, sizeof( buffer), f )) { |
| 58 | int l = strlen ( buffer ); | 58 | int l = xstrlen ( buffer ); |
| 59 | char *p = 0; | 59 | char *p = 0; |
| 60 | 60 | ||
| 61 | if ( buffer [l-1] == '\n' ) { | 61 | if ( buffer [l-1] == '\n' ) { |
| @@ -74,6 +74,7 @@ static struct dep_t *build_dep ( ) | |||
| 74 | if ( col ) { | 74 | if ( col ) { |
| 75 | char *mods; | 75 | char *mods; |
| 76 | char *mod; | 76 | char *mod; |
| 77 | int ext = 0; | ||
| 77 | 78 | ||
| 78 | *col = 0; | 79 | *col = 0; |
| 79 | mods = strrchr ( buffer, '/' ); | 80 | mods = strrchr ( buffer, '/' ); |
| @@ -83,10 +84,11 @@ static struct dep_t *build_dep ( ) | |||
| 83 | else | 84 | else |
| 84 | mods++; | 85 | mods++; |
| 85 | 86 | ||
| 86 | mod = (char *) malloc ( col - mods + 1 ); | 87 | if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) |
| 87 | strncpy ( mod, mods, col - mods ); | 88 | ext = 2; |
| 88 | mod [col - mods] = 0; | 89 | |
| 89 | 90 | mod = xstrndup ( mods, col - mods - ext ); | |
| 91 | |||
| 90 | if ( !current ) { | 92 | if ( !current ) { |
| 91 | first = current = (struct dep_t *) malloc ( sizeof ( struct dep_t )); | 93 | first = current = (struct dep_t *) malloc ( sizeof ( struct dep_t )); |
| 92 | } | 94 | } |
| @@ -99,7 +101,7 @@ static struct dep_t *build_dep ( ) | |||
| 99 | current-> m_deparr = 0; | 101 | current-> m_deparr = 0; |
| 100 | current-> m_next = 0; | 102 | current-> m_next = 0; |
| 101 | 103 | ||
| 102 | /* printf ( "%s:\n", mod ); */ | 104 | //printf ( "%s:\n", mod ); |
| 103 | 105 | ||
| 104 | p = col + 1; | 106 | p = col + 1; |
| 105 | } | 107 | } |
| @@ -113,6 +115,7 @@ static struct dep_t *build_dep ( ) | |||
| 113 | char *end = &buffer [l-1]; | 115 | char *end = &buffer [l-1]; |
| 114 | char *deps = strrchr ( end, '/' ); | 116 | char *deps = strrchr ( end, '/' ); |
| 115 | char *dep; | 117 | char *dep; |
| 118 | int ext = 0; | ||
| 116 | 119 | ||
| 117 | while ( isblank ( *end ) || ( *end == '\\' )) | 120 | while ( isblank ( *end ) || ( *end == '\\' )) |
| 118 | end--; | 121 | end--; |
| @@ -128,15 +131,16 @@ static struct dep_t *build_dep ( ) | |||
| 128 | else | 131 | else |
| 129 | deps++; | 132 | deps++; |
| 130 | 133 | ||
| 131 | dep = (char *) malloc ( end - deps + 2 ); | 134 | if (( *(end-1) == '.' ) && ( *end == 'o' )) |
| 132 | strncpy ( dep, deps, end - deps + 1 ); | 135 | ext = 2; |
| 133 | dep [end - deps + 1] = 0; | 136 | |
| 137 | dep = xstrndup ( deps, end - deps - ext + 1 ); | ||
| 134 | 138 | ||
| 135 | current-> m_depcnt++; | 139 | current-> m_depcnt++; |
| 136 | current-> m_deparr = (char **) realloc ( current-> m_deparr, sizeof ( char *) * current-> m_depcnt ); | 140 | current-> m_deparr = (char **) xrealloc ( current-> m_deparr, sizeof ( char *) * current-> m_depcnt ); |
| 137 | current-> m_deparr [current-> m_depcnt - 1] = dep; | 141 | current-> m_deparr [current-> m_depcnt - 1] = dep; |
| 138 | 142 | ||
| 139 | /* printf ( " %d) %s\n", current-> m_depcnt, current-> m_deparr [current-> m_depcnt -1] ); */ | 143 | //printf ( " %d) %s\n", current-> m_depcnt, current-> m_deparr [current-> m_depcnt -1] ); |
| 140 | } | 144 | } |
| 141 | 145 | ||
| 142 | if ( buffer [l-1] == '\\' ) | 146 | if ( buffer [l-1] == '\\' ) |
| @@ -152,26 +156,33 @@ static struct dep_t *build_dep ( ) | |||
| 152 | 156 | ||
| 153 | static struct dep_t *find_dep ( struct dep_t *dt, char *mod ) | 157 | static struct dep_t *find_dep ( struct dep_t *dt, char *mod ) |
| 154 | { | 158 | { |
| 155 | int lm = strlen ( mod ); | 159 | int lm = xstrlen ( mod ); |
| 156 | int hasext = 0; | 160 | int extpos = 0; |
| 157 | 161 | ||
| 158 | if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' )) | 162 | if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' )) |
| 159 | hasext = 1; | 163 | extpos = 2; |
| 160 | 164 | ||
| 165 | if ( extpos > 0 ) | ||
| 166 | mod [lm - extpos] = 0; | ||
| 167 | |||
| 161 | while ( dt ) { | 168 | while ( dt ) { |
| 162 | if ( hasext && !strcmp ( dt-> m_module, mod )) | 169 | if ( !strcmp ( dt-> m_module, mod )) |
| 163 | break; | 170 | break; |
| 164 | else if ( !hasext && !strncmp ( dt-> m_module, mod, strlen ( dt-> m_module ) - 2 )) | 171 | |
| 165 | break; | ||
| 166 | |||
| 167 | dt = dt-> m_next; | 172 | dt = dt-> m_next; |
| 168 | } | 173 | } |
| 174 | if ( extpos > 0 ) | ||
| 175 | mod [lm - extpos] = '.'; | ||
| 176 | |||
| 169 | return dt; | 177 | return dt; |
| 170 | } | 178 | } |
| 171 | 179 | ||
| 180 | #define MODPROBE_EXECUTE 0x1 | ||
| 181 | #define MODPROBE_INSERT 0x2 | ||
| 182 | #define MODPROBE_REMOVE 0x4 | ||
| 172 | 183 | ||
| 173 | static void check_dep ( char *mod, int do_syslog, | 184 | static void check_dep ( char *mod, int do_syslog, |
| 174 | int show_only, int verbose, int recursing ) | 185 | int show_only, int verbose, int flags ) |
| 175 | { | 186 | { |
| 176 | static struct dep_t *depend = (struct dep_t *) -1; | 187 | static struct dep_t *depend = (struct dep_t *) -1; |
| 177 | struct dep_t *dt; | 188 | struct dep_t *dt; |
| @@ -179,24 +190,29 @@ static void check_dep ( char *mod, int do_syslog, | |||
| 179 | if ( depend == (struct dep_t *) -1 ) | 190 | if ( depend == (struct dep_t *) -1 ) |
| 180 | depend = build_dep ( ); | 191 | depend = build_dep ( ); |
| 181 | 192 | ||
| 182 | /* printf ( "CHECK: %s (%p)\n", mod, depend ); */ | ||
| 183 | |||
| 184 | if (( dt = find_dep ( depend, mod ))) { | 193 | if (( dt = find_dep ( depend, mod ))) { |
| 185 | int i; | 194 | int i; |
| 186 | 195 | ||
| 187 | for ( i = 0; i < dt-> m_depcnt; i++ ) | 196 | for ( i = 0; i < dt-> m_depcnt; i++ ) |
| 188 | check_dep ( dt-> m_deparr [i], do_syslog, | 197 | check_dep ( dt-> m_deparr [i], do_syslog, |
| 189 | show_only, verbose, 1); | 198 | show_only, verbose, flags|MODPROBE_EXECUTE); |
| 190 | } | 199 | } |
| 191 | if ( recursing ) { | 200 | if ( flags & MODPROBE_EXECUTE ) { |
| 192 | char lcmd [256]; | 201 | char lcmd [256]; |
| 193 | 202 | if ( flags & MODPROBE_INSERT ) { | |
| 194 | snprintf(lcmd, sizeof(lcmd)-1, "insmod %s -q -k %s 2>/dev/null", | 203 | snprintf(lcmd, sizeof(lcmd)-1, "insmod %s -q -k %s 2>/dev/null", |
| 195 | do_syslog ? "-s" : "", mod ); | 204 | do_syslog ? "-s" : "", mod ); |
| 196 | if (show_only || verbose) | 205 | } |
| 197 | printf("%s\n", lcmd); | 206 | if ( flags & MODPROBE_REMOVE ) { |
| 198 | if (!show_only) | 207 | snprintf(lcmd, sizeof(lcmd)-1, "insmod %s -q -k %s 2>/dev/null", |
| 199 | system ( lcmd ); | 208 | do_syslog ? "-s" : "", mod ); |
| 209 | } | ||
| 210 | if ( flags & (MODPROBE_REMOVE|MODPROBE_INSERT) ) { | ||
| 211 | if (verbose) | ||
| 212 | printf("%s\n", lcmd); | ||
| 213 | if (!show_only) | ||
| 214 | system ( lcmd ); | ||
| 215 | } | ||
| 200 | } | 216 | } |
| 201 | } | 217 | } |
| 202 | 218 | ||
| @@ -273,10 +289,15 @@ extern int modprobe_main(int argc, char** argv) | |||
| 273 | optind < argc ? argv[optind] : ""); | 289 | optind < argc ? argv[optind] : ""); |
| 274 | if (do_syslog) | 290 | if (do_syslog) |
| 275 | syslog(LOG_INFO, "%s", cmd); | 291 | syslog(LOG_INFO, "%s", cmd); |
| 276 | if (show_only || verbose) | 292 | if (verbose) |
| 277 | printf("%s\n", cmd); | 293 | printf("%s\n", cmd); |
| 278 | if (!show_only) | 294 | if (!show_only) |
| 279 | rc = system(cmd); | 295 | rc = system(cmd); |
| 296 | |||
| 297 | #ifdef CONFIG_MODPROBE_DEPEND | ||
| 298 | if ( optind < argc ) | ||
| 299 | check_dep ( argv [optind], do_syslog, show_only, verbose, MODPROBE_REMOVE); | ||
| 300 | #endif | ||
| 280 | } while (++optind < argc); | 301 | } while (++optind < argc); |
| 281 | exit(EXIT_SUCCESS); | 302 | exit(EXIT_SUCCESS); |
| 282 | } | 303 | } |
| @@ -292,7 +313,7 @@ extern int modprobe_main(int argc, char** argv) | |||
| 292 | autoclean ? "-k" : ""); | 313 | autoclean ? "-k" : ""); |
| 293 | 314 | ||
| 294 | #ifdef CONFIG_MODPROBE_DEPEND | 315 | #ifdef CONFIG_MODPROBE_DEPEND |
| 295 | check_dep ( argv [optind], do_syslog, show_only, verbose, 0); | 316 | check_dep ( argv [optind], do_syslog, show_only, verbose, MODPROBE_INSERT); |
| 296 | #endif | 317 | #endif |
| 297 | 318 | ||
| 298 | while (optind < argc) { | 319 | while (optind < argc) { |
| @@ -302,7 +323,7 @@ extern int modprobe_main(int argc, char** argv) | |||
| 302 | } | 323 | } |
| 303 | if (do_syslog) | 324 | if (do_syslog) |
| 304 | syslog(LOG_INFO, "%s", cmd); | 325 | syslog(LOG_INFO, "%s", cmd); |
| 305 | if (show_only || verbose) | 326 | if (verbose) |
| 306 | printf("%s\n", cmd); | 327 | printf("%s\n", cmd); |
| 307 | if (!show_only) | 328 | if (!show_only) |
| 308 | rc = system(cmd); | 329 | rc = system(cmd); |
