diff options
| author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-05-14 17:07:32 +0000 |
|---|---|---|
| committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-05-14 17:07:32 +0000 |
| commit | 5e4b2db3dbdf0ff1ef8e0bfa817b7588015e412c (patch) | |
| tree | 9dabe9c71ebbdb67f1c56fb97b780a5a823d132f /modutils | |
| parent | a22cdd2b4b32287b1e486cd80381e9edce438cc9 (diff) | |
| download | busybox-w32-5e4b2db3dbdf0ff1ef8e0bfa817b7588015e412c.tar.gz busybox-w32-5e4b2db3dbdf0ff1ef8e0bfa817b7588015e412c.tar.bz2 busybox-w32-5e4b2db3dbdf0ff1ef8e0bfa817b7588015e412c.zip | |
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
git-svn-id: svn://busybox.net/trunk/busybox@2634 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/insmod.c | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c index 27f4a50e2..bc7f6589a 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
| @@ -124,7 +124,7 @@ | |||
| 124 | #ifndef MODUTILS_MODULE_H | 124 | #ifndef MODUTILS_MODULE_H |
| 125 | static const int MODUTILS_MODULE_H = 1; | 125 | static const int MODUTILS_MODULE_H = 1; |
| 126 | 126 | ||
| 127 | #ident "$Id: insmod.c,v 1.60 2001/04/26 19:29:58 andersen Exp $" | 127 | #ident "$Id: insmod.c,v 1.61 2001/05/14 17:07:32 andersen Exp $" |
| 128 | 128 | ||
| 129 | /* This file contains the structures used by the 2.0 and 2.1 kernels. | 129 | /* This file contains the structures used by the 2.0 and 2.1 kernels. |
| 130 | We do not use the kernel headers directly because we do not wish | 130 | We do not use the kernel headers directly because we do not wish |
| @@ -330,7 +330,7 @@ int delete_module(const char *); | |||
| 330 | #ifndef MODUTILS_OBJ_H | 330 | #ifndef MODUTILS_OBJ_H |
| 331 | static const int MODUTILS_OBJ_H = 1; | 331 | static const int MODUTILS_OBJ_H = 1; |
| 332 | 332 | ||
| 333 | #ident "$Id: insmod.c,v 1.60 2001/04/26 19:29:58 andersen Exp $" | 333 | #ident "$Id: insmod.c,v 1.61 2001/05/14 17:07:32 andersen Exp $" |
| 334 | 334 | ||
| 335 | /* The relocatable object is manipulated using elfin types. */ | 335 | /* The relocatable object is manipulated using elfin types. */ |
| 336 | 336 | ||
| @@ -677,50 +677,35 @@ size_t nksyms; | |||
| 677 | struct external_module *ext_modules; | 677 | struct external_module *ext_modules; |
| 678 | int n_ext_modules; | 678 | int n_ext_modules; |
| 679 | int n_ext_modules_used; | 679 | int n_ext_modules_used; |
| 680 | |||
| 681 | |||
| 682 | extern int delete_module(const char *); | 680 | extern int delete_module(const char *); |
| 683 | 681 | ||
| 682 | static char m_filename[FILENAME_MAX + 1]; | ||
| 683 | static char m_fullName[FILENAME_MAX + 1]; | ||
| 684 | 684 | ||
| 685 | /* This is kind of troublesome. See, we don't actually support | ||
| 686 | the m68k or the arm the same way we support i386 and (now) | ||
| 687 | sh. In doing my SH patch, I just assumed that whatever works | ||
| 688 | for i386 also works for m68k and arm since currently insmod.c | ||
| 689 | does nothing special for them. If this isn't true, the below | ||
| 690 | line is rather misleading IMHO, and someone should either | ||
| 691 | change it or add more proper architecture-dependent support | ||
| 692 | for these boys. | ||
| 693 | 685 | ||
| 694 | -- Bryan Rittmeyer <bryan@ixiacom.com> */ | ||
| 695 | |||
| 696 | static char m_filename[BUFSIZ + 1]; | ||
| 697 | static char m_fullName[BUFSIZ + 1]; | ||
| 698 | 686 | ||
| 699 | /*======================================================================*/ | 687 | /*======================================================================*/ |
| 700 | 688 | ||
| 701 | 689 | ||
| 702 | static int findNamedModule(const char *fileName, struct stat *statbuf, | 690 | static int check_module_name_match(const char *filename, struct stat *statbuf, |
| 703 | void *userDate) | 691 | void *userdata) |
| 704 | { | 692 | { |
| 705 | char *fullName = (char *) userDate; | 693 | char *fullname = (char *) userdata; |
| 706 | |||
| 707 | 694 | ||
| 708 | if (fullName[0] == '\0') | 695 | if (fullname[0] == '\0') |
| 709 | return (FALSE); | 696 | return (FALSE); |
| 710 | else { | 697 | else { |
| 711 | char *tmp = strrchr((char *) fileName, '/'); | 698 | char *tmp, *tmp1 = strdup(filename); |
| 712 | 699 | tmp = get_last_path_component(tmp1); | |
| 713 | if (tmp == NULL) | 700 | if (strcmp(tmp, fullname) == 0) { |
| 714 | tmp = (char *) fileName; | 701 | free(tmp1); |
| 715 | else | ||
| 716 | tmp++; | ||
| 717 | if (check_wildcard_match(tmp, fullName) == TRUE) { | ||
| 718 | /* Stop searching if we find a match */ | 702 | /* Stop searching if we find a match */ |
| 719 | safe_strncpy(m_filename, fileName, sizeof(m_filename)); | 703 | safe_strncpy(m_filename, filename, sizeof(m_filename)); |
| 720 | return (FALSE); | 704 | return (TRUE); |
| 721 | } | 705 | } |
| 706 | free(tmp1); | ||
| 722 | } | 707 | } |
| 723 | return (TRUE); | 708 | return (FALSE); |
| 724 | } | 709 | } |
| 725 | 710 | ||
| 726 | 711 | ||
| @@ -3125,7 +3110,7 @@ extern int insmod_main( int argc, char **argv) | |||
| 3125 | FILE *fp; | 3110 | FILE *fp; |
| 3126 | struct obj_file *f; | 3111 | struct obj_file *f; |
| 3127 | struct stat st; | 3112 | struct stat st; |
| 3128 | char m_name[BUFSIZ + 1] = "\0"; | 3113 | char m_name[FILENAME_MAX + 1] = "\0"; |
| 3129 | int exit_status = EXIT_FAILURE; | 3114 | int exit_status = EXIT_FAILURE; |
| 3130 | int m_has_modinfo; | 3115 | int m_has_modinfo; |
| 3131 | #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING | 3116 | #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING |
| @@ -3152,7 +3137,7 @@ extern int insmod_main( int argc, char **argv) | |||
| 3152 | flag_export = 0; | 3137 | flag_export = 0; |
| 3153 | break; | 3138 | break; |
| 3154 | case 'o': /* name the output module */ | 3139 | case 'o': /* name the output module */ |
| 3155 | strncpy(m_name, optarg, BUFSIZ); | 3140 | strncpy(m_name, optarg, FILENAME_MAX); |
| 3156 | break; | 3141 | break; |
| 3157 | case 'L': /* Stub warning */ | 3142 | case 'L': /* Stub warning */ |
| 3158 | /* This is needed for compatibility with modprobe. | 3143 | /* This is needed for compatibility with modprobe. |
| @@ -3186,24 +3171,42 @@ extern int insmod_main( int argc, char **argv) | |||
| 3186 | } | 3171 | } |
| 3187 | strcat(m_fullName, ".o"); | 3172 | strcat(m_fullName, ".o"); |
| 3188 | 3173 | ||
| 3189 | /* Get a filedesc for the module */ | 3174 | /* Get a filedesc for the module. Check we we have a complete path */ |
| 3190 | if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) || | 3175 | if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) || |
| 3191 | (fp = fopen(argv[optind], "r")) == NULL) { | 3176 | (fp = fopen(argv[optind], "r")) == NULL) { |
| 3192 | /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */ | 3177 | struct utsname myuname; |
| 3193 | if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE, | 3178 | |
| 3194 | findNamedModule, 0, m_fullName) == FALSE) | 3179 | /* Hmm. Could not open it. First search under /lib/modules/`uname -r`, |
| 3180 | * but do not error out yet if we fail to find it... */ | ||
| 3181 | if (uname(&myuname) == 0) { | ||
| 3182 | char module_dir[FILENAME_MAX]; | ||
| 3183 | snprintf (module_dir, sizeof(module_dir), "%s/%s", | ||
| 3184 | _PATH_MODULES, myuname.release); | ||
| 3185 | recursive_action(module_dir, TRUE, FALSE, FALSE, | ||
| 3186 | check_module_name_match, 0, m_fullName); | ||
| 3187 | } | ||
| 3188 | |||
| 3189 | /* Check if we have found anything yet */ | ||
| 3190 | if (m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) | ||
| 3195 | { | 3191 | { |
| 3196 | if (m_filename[0] == '\0' | 3192 | /* No module found under /lib/modules/`uname -r`, this |
| 3197 | || ((fp = fopen(m_filename, "r")) == NULL)) | 3193 | * time cast the net a bit wider. Search /lib/modules/ */ |
| 3194 | if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE, | ||
| 3195 | check_module_name_match, 0, m_fullName) == FALSE) | ||
| 3198 | { | 3196 | { |
| 3199 | error_msg("No module named '%s' found in '%s'", m_fullName, _PATH_MODULES); | 3197 | if (m_filename[0] == '\0' |
| 3200 | return EXIT_FAILURE; | 3198 | || ((fp = fopen(m_filename, "r")) == NULL)) |
| 3201 | } | 3199 | { |
| 3202 | } else | 3200 | error_msg("%s: no module by that name found", m_fullName); |
| 3203 | error_msg_and_die("No module named '%s' found in '%s'", m_fullName, _PATH_MODULES); | 3201 | return EXIT_FAILURE; |
| 3204 | } else | 3202 | } |
| 3203 | } else | ||
| 3204 | error_msg_and_die("%s: no module by that name found", m_fullName); | ||
| 3205 | } | ||
| 3206 | } else | ||
| 3205 | safe_strncpy(m_filename, argv[optind], sizeof(m_filename)); | 3207 | safe_strncpy(m_filename, argv[optind], sizeof(m_filename)); |
| 3206 | 3208 | ||
| 3209 | printf("Using %s\n", m_filename); | ||
| 3207 | 3210 | ||
| 3208 | if ((f = obj_load(fp)) == NULL) | 3211 | if ((f = obj_load(fp)) == NULL) |
| 3209 | perror_msg_and_die("Could not load the module"); | 3212 | perror_msg_and_die("Could not load the module"); |
