* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
+#include "busybox.h"
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
-#include "busybox.h"
+#include <fnmatch.h>
struct mod_opt_t { /* one-way list of options to pass to a module */
char * m_opt_val;
if ( p )
*p = 0;
- l = bb_strlen ( buffer );
+ l = strlen ( buffer );
while ( l && isspace ( buffer [l-1] )) {
buffer [l-1] = 0;
}
/*
- * This function builds a list of dependency rules from /lib/modules/`uname -r\modules.dep.
- * It then fills every modules and aliases with their default options, found by parsing
+ * This function builds a list of dependency rules from /lib/modules/`uname -r`\modules.dep.
+ * It then fills every modules and aliases with their default options, found by parsing
* modprobe.conf (or modules.conf, or conf.modules).
*/
static struct dep_t *build_dep ( void )
}
filename = bb_xasprintf("/lib/modules/%s/modules.dep", un.release );
-
- if (( fd = open ( filename, O_RDONLY )) < 0 ) {
-
+ fd = open ( filename, O_RDONLY );
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(filename);
+ if (fd < 0) {
/* Ok, that didn't work. Fall back to looking in /lib/modules */
if (( fd = open ( "/lib/modules/modules.dep", O_RDONLY )) < 0 ) {
return 0;
}
}
- free(filename);
while ( reads ( fd, buffer, sizeof( buffer ))) {
- int l = bb_strlen ( buffer );
+ int l = strlen ( buffer );
char *p = 0;
while ( l > 0 && isspace ( buffer [l-1] )) {
include_conf (&first, ¤t, buffer, sizeof(buffer), fd);
close(fd);
- filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release );
-
- if (( fd = open ( filename, O_RDONLY )) < 0 ) {
-
+ filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release);
+ fd = open ( filename, O_RDONLY );
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(filename);
+ if (fd < 0) {
/* Ok, that didn't work. Fall back to looking in /lib/modules */
if (( fd = open ( "/lib/modules/modules.alias", O_RDONLY )) < 0 ) {
return first;
}
}
- free(filename);
include_conf (&first, ¤t, buffer, sizeof(buffer), fd);
close(fd);
struct mod_opt_t *opt = 0;
char *path = 0;
- // check dependencies
+ /* Search for the given module name amongst all dependency rules.
+ * The module name in a dependency rule can be a shell pattern,
+ * so try to match the given module name against such a pattern.
+ * Of course if the name in the dependency rule is a plain string,
+ * then we consider it a pattern, and matching will still work. */
for ( dt = depend; dt; dt = dt-> m_next ) {
- if ( strcmp ( dt-> m_name, mod ) == 0) {
+ if ( fnmatch ( dt-> m_name, mod, 0 ) == 0) {
break;
}
}
depend = build_dep ( );
if ( !depend )
- bb_error_msg_and_die ( "could not parse modules.dep\n" );
+ bb_error_msg_and_die ( "could not parse modules.dep" );
if (remove_opt) {
do {
} while ( ++optind < argc );
} else {
if (optind >= argc)
- bb_error_msg_and_die ( "No module or pattern provided\n" );
+ bb_error_msg_and_die ( "No module or pattern provided" );
if ( mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 ))
bb_error_msg_and_die ( "failed to load module %s", argv [optind] );