aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-14 17:07:32 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-14 17:07:32 +0000
commit14d354312a9d49a8b410516c20be57159af217a5 (patch)
tree9dabe9c71ebbdb67f1c56fb97b780a5a823d132f
parentcb378a52672d65885c96d6d4b7ed73deac0b967a (diff)
downloadbusybox-w32-14d354312a9d49a8b410516c20be57159af217a5.tar.gz
busybox-w32-14d354312a9d49a8b410516c20be57159af217a5.tar.bz2
busybox-w32-14d354312a9d49a8b410516c20be57159af217a5.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
-rw-r--r--Makefile2
-rw-r--r--include/libbb.h1
-rw-r--r--insmod.c93
-rw-r--r--libbb/check_wildcard_match.c141
-rw-r--r--libbb/libbb.h1
-rw-r--r--modutils/insmod.c93
6 files changed, 97 insertions, 234 deletions
diff --git a/Makefile b/Makefile
index cbaf05704..b35ffc72e 100644
--- a/Makefile
+++ b/Makefile
@@ -236,7 +236,7 @@ endif
236 236
237LIBBB = libbb 237LIBBB = libbb
238LIBBB_LIB = libbb.a 238LIBBB_LIB = libbb.a
239LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c \ 239LIBBB_CSRC= ask_confirmation.c chomp.c \
240concat_path_file.c copy_file.c copy_file_chunk.c create_path.c \ 240concat_path_file.c copy_file.c copy_file_chunk.c create_path.c \
241daemon.c deb_extract.c device_open.c error_msg.c error_msg_and_die.c \ 241daemon.c deb_extract.c device_open.c error_msg.c error_msg_and_die.c \
242find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \ 242find_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 fde58b0a6..02cf607a7 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -127,7 +127,6 @@ extern void mtab_read(void);
127extern char *mtab_first(void **iter); 127extern char *mtab_first(void **iter);
128extern char *mtab_next(void **iter); 128extern char *mtab_next(void **iter);
129extern char *mtab_getinfo(const char *match, const char which); 129extern char *mtab_getinfo(const char *match, const char which);
130extern int check_wildcard_match(const char* text, const char* pattern);
131extern long atoi_w_units (const char *cp); 130extern long atoi_w_units (const char *cp);
132extern pid_t* find_pid_by_name( char* pidName); 131extern pid_t* find_pid_by_name( char* pidName);
133extern int find_real_root_device_name(char* name); 132extern int find_real_root_device_name(char* name);
diff --git a/insmod.c b/insmod.c
index 27f4a50e2..bc7f6589a 100644
--- a/insmod.c
+++ b/insmod.c
@@ -124,7 +124,7 @@
124#ifndef MODUTILS_MODULE_H 124#ifndef MODUTILS_MODULE_H
125static const int MODUTILS_MODULE_H = 1; 125static 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
331static const int MODUTILS_OBJ_H = 1; 331static 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;
677struct external_module *ext_modules; 677struct external_module *ext_modules;
678int n_ext_modules; 678int n_ext_modules;
679int n_ext_modules_used; 679int n_ext_modules_used;
680
681
682extern int delete_module(const char *); 680extern int delete_module(const char *);
683 681
682static char m_filename[FILENAME_MAX + 1];
683static 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
696static char m_filename[BUFSIZ + 1];
697static char m_fullName[BUFSIZ + 1];
698 686
699/*======================================================================*/ 687/*======================================================================*/
700 688
701 689
702static int findNamedModule(const char *fileName, struct stat *statbuf, 690static 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");
diff --git a/libbb/check_wildcard_match.c b/libbb/check_wildcard_match.c
deleted file mode 100644
index ab856797b..000000000
--- a/libbb/check_wildcard_match.c
+++ /dev/null
@@ -1,141 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) tons of folks. Tracking down who wrote what
6 * isn't something I'm going to worry about... If you wrote something
7 * here, please feel free to acknowledge your work.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
24 * Permission has been granted to redistribute this code under the GPL.
25 *
26 */
27
28#include <stdio.h>
29#include <string.h>
30#include "libbb.h"
31
32
33/*
34 * Routine to see if a text string is matched by a wildcard pattern.
35 * Returns TRUE if the text is matched, or FALSE if it is not matched
36 * or if the pattern is invalid.
37 * * matches zero or more characters
38 * ? matches a single character
39 * [abc] matches 'a', 'b' or 'c'
40 * \c quotes character c
41 * Adapted from code written by Ingo Wilken, and
42 * then taken from sash, Copyright (c) 1999 by David I. Bell
43 * Permission is granted to use, distribute, or modify this source,
44 * provided that this copyright notice remains intact.
45 * Permission to distribute this code under the GPL has been granted.
46 */
47extern int check_wildcard_match(const char *text, const char *pattern)
48{
49 const char *retryPat;
50 const char *retryText;
51 int ch;
52 int found;
53 int len;
54
55 retryPat = NULL;
56 retryText = NULL;
57
58 while (*text || *pattern) {
59 ch = *pattern++;
60
61 switch (ch) {
62 case '*':
63 retryPat = pattern;
64 retryText = text;
65 break;
66
67 case '[':
68 found = FALSE;
69
70 while ((ch = *pattern++) != ']') {
71 if (ch == '\\')
72 ch = *pattern++;
73
74 if (ch == '\0')
75 return FALSE;
76
77 if (*text == ch)
78 found = TRUE;
79 }
80 len=strlen(text);
81 if (found == FALSE && len!=0) {
82 return FALSE;
83 }
84 if (found == TRUE) {
85 if (strlen(pattern)==0 && len==1) {
86 return TRUE;
87 }
88 if (len!=0) {
89 text++;
90 continue;
91 }
92 }
93
94 /* fall into next case */
95
96 case '?':
97 if (*text++ == '\0')
98 return FALSE;
99
100 break;
101
102 case '\\':
103 ch = *pattern++;
104
105 if (ch == '\0')
106 return FALSE;
107
108 /* fall into next case */
109
110 default:
111 if (*text == ch) {
112 if (*text)
113 text++;
114 break;
115 }
116
117 if (*text) {
118 pattern = retryPat;
119 text = ++retryText;
120 break;
121 }
122
123 return FALSE;
124 }
125
126 if (pattern == NULL)
127 return FALSE;
128 }
129
130 return TRUE;
131}
132
133
134/* END CODE */
135/*
136Local Variables:
137c-file-style: "linux"
138c-basic-offset: 4
139tab-width: 4
140End:
141*/
diff --git a/libbb/libbb.h b/libbb/libbb.h
index fde58b0a6..02cf607a7 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -127,7 +127,6 @@ extern void mtab_read(void);
127extern char *mtab_first(void **iter); 127extern char *mtab_first(void **iter);
128extern char *mtab_next(void **iter); 128extern char *mtab_next(void **iter);
129extern char *mtab_getinfo(const char *match, const char which); 129extern char *mtab_getinfo(const char *match, const char which);
130extern int check_wildcard_match(const char* text, const char* pattern);
131extern long atoi_w_units (const char *cp); 130extern long atoi_w_units (const char *cp);
132extern pid_t* find_pid_by_name( char* pidName); 131extern pid_t* find_pid_by_name( char* pidName);
133extern int find_real_root_device_name(char* name); 132extern int find_real_root_device_name(char* name);
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
125static const int MODUTILS_MODULE_H = 1; 125static 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
331static const int MODUTILS_OBJ_H = 1; 331static 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;
677struct external_module *ext_modules; 677struct external_module *ext_modules;
678int n_ext_modules; 678int n_ext_modules;
679int n_ext_modules_used; 679int n_ext_modules_used;
680
681
682extern int delete_module(const char *); 680extern int delete_module(const char *);
683 681
682static char m_filename[FILENAME_MAX + 1];
683static 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
696static char m_filename[BUFSIZ + 1];
697static char m_fullName[BUFSIZ + 1];
698 686
699/*======================================================================*/ 687/*======================================================================*/
700 688
701 689
702static int findNamedModule(const char *fileName, struct stat *statbuf, 690static 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");