diff options
author | Eric Andersen | 2001-05-14 17:07:32 +0000 |
---|---|---|
committer | Eric Andersen | 2001-05-14 17:07:32 +0000 |
commit | 14d354312a9d49a8b410516c20be57159af217a5 (patch) | |
tree | 9dabe9c71ebbdb67f1c56fb97b780a5a823d132f | |
parent | cb378a52672d65885c96d6d4b7ed73deac0b967a (diff) | |
download | busybox-14d354312a9d49a8b410516c20be57159af217a5.zip busybox-14d354312a9d49a8b410516c20be57159af217a5.tar.gz |
Per suggestion from Vladimir, eliminate check_wildcard_match(), which
was only being used by insmod these days.
Also, I spent a minute adjusting insmod so that it first searches
/lib/modules/`uname -r` and then (if that fails) searches /lib/modules,
which makes bb insmod behave much more like the real insmod, and should
avoid nasty surprises (such as the recent "Modutils vs. Busybox..."
thread).
-Erik
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | insmod.c | 93 | ||||
-rw-r--r-- | libbb/check_wildcard_match.c | 141 | ||||
-rw-r--r-- | libbb/libbb.h | 1 | ||||
-rw-r--r-- | modutils/insmod.c | 93 |
6 files changed, 97 insertions, 234 deletions
@@ -236,7 +236,7 @@ endif LIBBB = libbb LIBBB_LIB = libbb.a -LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c \ +LIBBB_CSRC= ask_confirmation.c chomp.c \ concat_path_file.c copy_file.c copy_file_chunk.c create_path.c \ daemon.c deb_extract.c device_open.c error_msg.c error_msg_and_die.c \ find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \ diff --git a/include/libbb.h b/include/libbb.h index fde58b0..02cf607 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -127,7 +127,6 @@ extern void mtab_read(void); extern char *mtab_first(void **iter); extern char *mtab_next(void **iter); extern char *mtab_getinfo(const char *match, const char which); -extern int check_wildcard_match(const char* text, const char* pattern); extern long atoi_w_units (const char *cp); extern pid_t* find_pid_by_name( char* pidName); extern int find_real_root_device_name(char* name); @@ -124,7 +124,7 @@ #ifndef MODUTILS_MODULE_H static const int MODUTILS_MODULE_H = 1; -#ident "$Id: insmod.c,v 1.60 2001/04/26 19:29:58 andersen Exp $" +#ident "$Id: insmod.c,v 1.61 2001/05/14 17:07:32 andersen Exp $" /* This file contains the structures used by the 2.0 and 2.1 kernels. We do not use the kernel headers directly because we do not wish @@ -330,7 +330,7 @@ int delete_module(const char *); #ifndef MODUTILS_OBJ_H static const int MODUTILS_OBJ_H = 1; -#ident "$Id: insmod.c,v 1.60 2001/04/26 19:29:58 andersen Exp $" +#ident "$Id: insmod.c,v 1.61 2001/05/14 17:07:32 andersen Exp $" /* The relocatable object is manipulated using elfin types. */ @@ -677,50 +677,35 @@ size_t nksyms; struct external_module *ext_modules; int n_ext_modules; int n_ext_modules_used; - - extern int delete_module(const char *); +static char m_filename[FILENAME_MAX + 1]; +static char m_fullName[FILENAME_MAX + 1]; -/* This is kind of troublesome. See, we don't actually support - the m68k or the arm the same way we support i386 and (now) - sh. In doing my SH patch, I just assumed that whatever works - for i386 also works for m68k and arm since currently insmod.c - does nothing special for them. If this isn't true, the below - line is rather misleading IMHO, and someone should either - change it or add more proper architecture-dependent support - for these boys. - -- Bryan Rittmeyer <bryan@ixiacom.com> */ - -static char m_filename[BUFSIZ + 1]; -static char m_fullName[BUFSIZ + 1]; /*======================================================================*/ -static int findNamedModule(const char *fileName, struct stat *statbuf, - void *userDate) +static int check_module_name_match(const char *filename, struct stat *statbuf, + void *userdata) { - char *fullName = (char *) userDate; - + char *fullname = (char *) userdata; - if (fullName[0] == '\0') + if (fullname[0] == '\0') return (FALSE); else { - char *tmp = strrchr((char *) fileName, '/'); - - if (tmp == NULL) - tmp = (char *) fileName; - else - tmp++; - if (check_wildcard_match(tmp, fullName) == TRUE) { + char *tmp, *tmp1 = strdup(filename); + tmp = get_last_path_component(tmp1); + if (strcmp(tmp, fullname) == 0) { + free(tmp1); /* Stop searching if we find a match */ - safe_strncpy(m_filename, fileName, sizeof(m_filename)); - return (FALSE); + safe_strncpy(m_filename, filename, sizeof(m_filename)); + return (TRUE); } + free(tmp1); } - return (TRUE); + return (FALSE); } @@ -3125,7 +3110,7 @@ extern int insmod_main( int argc, char **argv) FILE *fp; struct obj_file *f; struct stat st; - char m_name[BUFSIZ + 1] = "\0"; + char m_name[FILENAME_MAX + 1] = "\0"; int exit_status = EXIT_FAILURE; int m_has_modinfo; #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING @@ -3152,7 +3137,7 @@ extern int insmod_main( int argc, char **argv) flag_export = 0; break; case 'o': /* name the output module */ - strncpy(m_name, optarg, BUFSIZ); + strncpy(m_name, optarg, FILENAME_MAX); break; case 'L': /* Stub warning */ /* This is needed for compatibility with modprobe. @@ -3186,24 +3171,42 @@ extern int insmod_main( int argc, char **argv) } strcat(m_fullName, ".o"); - /* Get a filedesc for the module */ + /* Get a filedesc for the module. Check we we have a complete path */ if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) || (fp = fopen(argv[optind], "r")) == NULL) { - /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */ - if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE, - findNamedModule, 0, m_fullName) == FALSE) + struct utsname myuname; + + /* Hmm. Could not open it. First search under /lib/modules/`uname -r`, + * but do not error out yet if we fail to find it... */ + if (uname(&myuname) == 0) { + char module_dir[FILENAME_MAX]; + snprintf (module_dir, sizeof(module_dir), "%s/%s", + _PATH_MODULES, myuname.release); + recursive_action(module_dir, TRUE, FALSE, FALSE, + check_module_name_match, 0, m_fullName); + } + + /* Check if we have found anything yet */ + if (m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) { - if (m_filename[0] == '\0' - || ((fp = fopen(m_filename, "r")) == NULL)) + /* No module found under /lib/modules/`uname -r`, this + * time cast the net a bit wider. Search /lib/modules/ */ + if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE, + check_module_name_match, 0, m_fullName) == FALSE) { - error_msg("No module named '%s' found in '%s'", m_fullName, _PATH_MODULES); - return EXIT_FAILURE; - } - } else - error_msg_and_die("No module named '%s' found in '%s'", m_fullName, _PATH_MODULES); - } else + if (m_filename[0] == '\0' + || ((fp = fopen(m_filename, "r")) == NULL)) + { + error_msg("%s: no module by that name found", m_fullName); + return EXIT_FAILURE; + } + } else + error_msg_and_die("%s: no module by that name found", m_fullName); + } + } else safe_strncpy(m_filename, argv[optind], sizeof(m_filename)); + printf("Using %s\n", m_filename); if ((f = obj_load(fp)) == NULL) perror_msg_and_die("Could not load the module"); diff --git a/libbb/check_wildcard_match.c b/libbb/check_wildcard_match.c deleted file mode 100644 index ab85679..0000000 --- a/libbb/check_wildcard_match.c +++ /dev/null @@ -1,141 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) tons of folks. Tracking down who wrote what - * isn't something I'm going to worry about... If you wrote something - * here, please feel free to acknowledge your work. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Based in part on code from sash, Copyright (c) 1999 by David I. Bell - * Permission has been granted to redistribute this code under the GPL. - * - */ - -#include <stdio.h> -#include <string.h> -#include "libbb.h" - - -/* - * Routine to see if a text string is matched by a wildcard pattern. - * Returns TRUE if the text is matched, or FALSE if it is not matched - * or if the pattern is invalid. - * * matches zero or more characters - * ? matches a single character - * [abc] matches 'a', 'b' or 'c' - * \c quotes character c - * Adapted from code written by Ingo Wilken, and - * then taken from sash, Copyright (c) 1999 by David I. Bell - * Permission is granted to use, distribute, or modify this source, - * provided that this copyright notice remains intact. - * Permission to distribute this code under the GPL has been granted. - */ -extern int check_wildcard_match(const char *text, const char *pattern) -{ - const char *retryPat; - const char *retryText; - int ch; - int found; - int len; - - retryPat = NULL; - retryText = NULL; - - while (*text || *pattern) { - ch = *pattern++; - - switch (ch) { - case '*': - retryPat = pattern; - retryText = text; - break; - - case '[': - found = FALSE; - - while ((ch = *pattern++) != ']') { - if (ch == '\\') - ch = *pattern++; - - if (ch == '\0') - return FALSE; - - if (*text == ch) - found = TRUE; - } - len=strlen(text); - if (found == FALSE && len!=0) { - return FALSE; - } - if (found == TRUE) { - if (strlen(pattern)==0 && len==1) { - return TRUE; - } - if (len!=0) { - text++; - continue; - } - } - - /* fall into next case */ - - case '?': - if (*text++ == '\0') - return FALSE; - - break; - - case '\\': - ch = *pattern++; - - if (ch == '\0') - return FALSE; - - /* fall into next case */ - - default: - if (*text == ch) { - if (*text) - text++; - break; - } - - if (*text) { - pattern = retryPat; - text = ++retryText; - break; - } - - return FALSE; - } - - if (pattern == NULL) - return FALSE; - } - - return TRUE; -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/libbb.h b/libbb/libbb.h index fde58b0..02cf607 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h @@ -127,7 +127,6 @@ extern void mtab_read(void); extern char *mtab_first(void **iter); extern char *mtab_next(void **iter); extern char *mtab_getinfo(const char *match, const char which); -extern int check_wildcard_match(const char* text, const char* pattern); extern long atoi_w_units (const char *cp); extern pid_t* find_pid_by_name( char* pidName); extern int find_real_root_device_name(char* name); diff --git a/modutils/insmod.c b/modutils/insmod.c index 27f4a50..bc7f658 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c @@ -124,7 +124,7 @@ #ifndef MODUTILS_MODULE_H static const int MODUTILS_MODULE_H = 1; -#ident "$Id: insmod.c,v 1.60 2001/04/26 19:29:58 andersen Exp $" +#ident "$Id: insmod.c,v 1.61 2001/05/14 17:07:32 andersen Exp $" /* This file contains the structures used by the 2.0 and 2.1 kernels. We do not use the kernel headers directly because we do not wish @@ -330,7 +330,7 @@ int delete_module(const char *); #ifndef MODUTILS_OBJ_H static const int MODUTILS_OBJ_H = 1; -#ident "$Id: insmod.c,v 1.60 2001/04/26 19:29:58 andersen Exp $" +#ident "$Id: insmod.c,v 1.61 2001/05/14 17:07:32 andersen Exp $" /* The relocatable object is manipulated using elfin types. */ @@ -677,50 +677,35 @@ size_t nksyms; struct external_module *ext_modules; int n_ext_modules; int n_ext_modules_used; - - extern int delete_module(const char *); +static char m_filename[FILENAME_MAX + 1]; +static char m_fullName[FILENAME_MAX + 1]; -/* This is kind of troublesome. See, we don't actually support - the m68k or the arm the same way we support i386 and (now) - sh. In doing my SH patch, I just assumed that whatever works - for i386 also works for m68k and arm since currently insmod.c - does nothing special for them. If this isn't true, the below - line is rather misleading IMHO, and someone should either - change it or add more proper architecture-dependent support - for these boys. - -- Bryan Rittmeyer <bryan@ixiacom.com> */ - -static char m_filename[BUFSIZ + 1]; -static char m_fullName[BUFSIZ + 1]; /*======================================================================*/ -static int findNamedModule(const char *fileName, struct stat *statbuf, - void *userDate) +static int check_module_name_match(const char *filename, struct stat *statbuf, + void *userdata) { - char *fullName = (char *) userDate; - + char *fullname = (char *) userdata; - if (fullName[0] == '\0') + if (fullname[0] == '\0') return (FALSE); else { - char *tmp = strrchr((char *) fileName, '/'); - - if (tmp == NULL) - tmp = (char *) fileName; - else - tmp++; - if (check_wildcard_match(tmp, fullName) == TRUE) { + char *tmp, *tmp1 = strdup(filename); + tmp = get_last_path_component(tmp1); + if (strcmp(tmp, fullname) == 0) { + free(tmp1); /* Stop searching if we find a match */ - safe_strncpy(m_filename, fileName, sizeof(m_filename)); - return (FALSE); + safe_strncpy(m_filename, filename, sizeof(m_filename)); + return (TRUE); } + free(tmp1); } - return (TRUE); + return (FALSE); } @@ -3125,7 +3110,7 @@ extern int insmod_main( int argc, char **argv) FILE *fp; struct obj_file *f; struct stat st; - char m_name[BUFSIZ + 1] = "\0"; + char m_name[FILENAME_MAX + 1] = "\0"; int exit_status = EXIT_FAILURE; int m_has_modinfo; #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING @@ -3152,7 +3137,7 @@ extern int insmod_main( int argc, char **argv) flag_export = 0; break; case 'o': /* name the output module */ - strncpy(m_name, optarg, BUFSIZ); + strncpy(m_name, optarg, FILENAME_MAX); break; case 'L': /* Stub warning */ /* This is needed for compatibility with modprobe. @@ -3186,24 +3171,42 @@ extern int insmod_main( int argc, char **argv) } strcat(m_fullName, ".o"); - /* Get a filedesc for the module */ + /* Get a filedesc for the module. Check we we have a complete path */ if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) || (fp = fopen(argv[optind], "r")) == NULL) { - /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */ - if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE, - findNamedModule, 0, m_fullName) == FALSE) + struct utsname myuname; + + /* Hmm. Could not open it. First search under /lib/modules/`uname -r`, + * but do not error out yet if we fail to find it... */ + if (uname(&myuname) == 0) { + char module_dir[FILENAME_MAX]; + snprintf (module_dir, sizeof(module_dir), "%s/%s", + _PATH_MODULES, myuname.release); + recursive_action(module_dir, TRUE, FALSE, FALSE, + check_module_name_match, 0, m_fullName); + } + + /* Check if we have found anything yet */ + if (m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) { - if (m_filename[0] == '\0' - || ((fp = fopen(m_filename, "r")) == NULL)) + /* No module found under /lib/modules/`uname -r`, this + * time cast the net a bit wider. Search /lib/modules/ */ + if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE, + check_module_name_match, 0, m_fullName) == FALSE) { - error_msg("No module named '%s' found in '%s'", m_fullName, _PATH_MODULES); - return EXIT_FAILURE; - } - } else - error_msg_and_die("No module named '%s' found in '%s'", m_fullName, _PATH_MODULES); - } else + if (m_filename[0] == '\0' + || ((fp = fopen(m_filename, "r")) == NULL)) + { + error_msg("%s: no module by that name found", m_fullName); + return EXIT_FAILURE; + } + } else + error_msg_and_die("%s: no module by that name found", m_fullName); + } + } else safe_strncpy(m_filename, argv[optind], sizeof(m_filename)); + printf("Using %s\n", m_filename); if ((f = obj_load(fp)) == NULL) perror_msg_and_die("Could not load the module"); |