From f5d5e77321ad32b3952dcdf21d14fd0ef3d4c1a9 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 24 Jan 2001 23:34:48 +0000 Subject: [PATCH] more bugs fixed -- found doing regression testing -Erik --- Config.h | 28 ++++++++--------- applets/busybox.c | 63 +++++++++++++++++++-------------------- busybox.c | 63 +++++++++++++++++++-------------------- coreutils/ls.c | 8 +++-- insmod.c | 22 ++++++-------- ls.c | 8 +++-- lsmod.c | 10 ++----- modutils/insmod.c | 22 ++++++-------- modutils/lsmod.c | 10 ++----- tests/busybox.REGRESS.sh | Bin 4068 -> 4078 bytes utility.c | 6 ++-- 11 files changed, 114 insertions(+), 126 deletions(-) diff --git a/Config.h b/Config.h index 22882b6c2..1df72f301 100644 --- a/Config.h +++ b/Config.h @@ -258,17 +258,11 @@ //Turn on fbset readmode support //#define BB_FEATURE_FBSET_READMODE // -// You must enable one or both of these features -// Support installing modules from pre 2.1 kernels -//#define BB_FEATURE_INSMOD_OLD_KERNEL -// Support installing modules from kernel versions after 2.1.18 -#define BB_FEATURE_INSMOD_NEW_KERNEL +// Support insmod/lsmod/rmmod for post 2.1 kernels +//#define BB_FEATURE_NEW_MODULE_INTERFACE // -// You must enable one or both of these features -// Support modules status from pre 2.1 kernels -//#define BB_FEATURE_LSMOD_OLD_KERNEL -// Support modules status from kernel versions after 2.1.18 -#define BB_FEATURE_LSMOD_NEW_KERNEL +// Support insmod/lsmod/rmmod for pre 2.1 kernels +//#define BB_FEATURE_OLD_MODULE_INTERFACE // // Support module version checking //#define BB_FEATURE_INSMOD_VERSION_CHECKING @@ -308,7 +302,9 @@ #ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT #define BB_MTAB #endif -#endif +#else +#undef BB_MTAB +#endif // #if defined BB_FEATURE_SH_COMMAND_EDITING && defined BB_SH #define BB_CMDEDIT @@ -320,12 +316,14 @@ #endif #endif // -#ifdef BB_FEATURE_LINUXRC +#if defined BB_FEATURE_LINUXRC || defined BB_LINUXRC #ifndef BB_INIT #define BB_INIT #endif +#ifndef BB_LINUXRC #define BB_LINUXRC #endif +#endif // #ifdef BB_GZIP #ifndef BB_GUNZIP @@ -369,8 +367,8 @@ #endif #endif // -#if defined BB_INSMOD -#ifndef BB_FEATURE_INSMOD_OLD_KERNEL -#define BB_FEATURE_INSMOD_NEW_KERNEL +#if defined BB_INSMOD || defined BB_LSMOD +#ifndef BB_FEATURE_NEW_MODULE_INTERFACE +#define BB_FEATURE_NEW_MODULE_INTERFACE #endif #endif diff --git a/applets/busybox.c b/applets/busybox.c index 0439fb566..5eb9dfa64 100644 --- a/applets/busybox.c +++ b/applets/busybox.c @@ -89,7 +89,37 @@ int main(int argc, char **argv) { struct BB_applet search_applet, *applet; const char *s; - applet_name = "busybox"; + + for (s = applet_name = argv[0]; *s != '\0';) { + if (*s++ == '/') + applet_name = s; + } + +#ifdef BB_SH + /* Add in a special case hack -- whenever **argv == '-' + * (i.e. '-su' or '-sh') always invoke the shell */ + if (**argv == '-' && *(*argv+1)!= '-') { + exit(((*(shell_main)) (argc, argv))); + } +#endif + + /* Do a binary search to find the applet entry given the name. */ + search_applet.name = applet_name; + applet = bsearch(&search_applet, applets, NUM_APPLETS, + sizeof(struct BB_applet), applet_name_compare); + if (applet != NULL) { + if (applet->usage && argv[1] && strcmp(argv[1], "--help") == 0) + usage(applet->usage); + exit((*(applet->main)) (argc, argv)); + } + + error_msg_and_die("applet not found\n"); +} + + +int busybox_main(int argc, char **argv) +{ + int col = 0, len, i; #ifdef BB_FEATURE_INSTALLER /* @@ -121,37 +151,6 @@ int main(int argc, char **argv) } #endif /* BB_FEATURE_INSTALLER */ - for (s = applet_name = argv[0]; *s != '\0';) { - if (*s++ == '/') - applet_name = s; - } - -#ifdef BB_SH - /* Add in a special case hack -- whenever **argv == '-' - * (i.e. '-su' or '-sh') always invoke the shell */ - if (**argv == '-' && *(*argv+1)!= '-') { - exit(((*(shell_main)) (argc, argv))); - } -#endif - - /* Do a binary search to find the applet entry given the name. */ - search_applet.name = applet_name; - applet = bsearch(&search_applet, applets, NUM_APPLETS, - sizeof(struct BB_applet), applet_name_compare); - if (applet != NULL) { - if (applet->usage && argv[1] && strcmp(argv[1], "--help") == 0) - usage(applet->usage); - exit((*(applet->main)) (argc, argv)); - } - - return(busybox_main(argc, argv)); -} - - -int busybox_main(int argc, char **argv) -{ - int col = 0, len, i; - argc--; /* If we've already been here once, exit now */ diff --git a/busybox.c b/busybox.c index 0439fb566..5eb9dfa64 100644 --- a/busybox.c +++ b/busybox.c @@ -89,7 +89,37 @@ int main(int argc, char **argv) { struct BB_applet search_applet, *applet; const char *s; - applet_name = "busybox"; + + for (s = applet_name = argv[0]; *s != '\0';) { + if (*s++ == '/') + applet_name = s; + } + +#ifdef BB_SH + /* Add in a special case hack -- whenever **argv == '-' + * (i.e. '-su' or '-sh') always invoke the shell */ + if (**argv == '-' && *(*argv+1)!= '-') { + exit(((*(shell_main)) (argc, argv))); + } +#endif + + /* Do a binary search to find the applet entry given the name. */ + search_applet.name = applet_name; + applet = bsearch(&search_applet, applets, NUM_APPLETS, + sizeof(struct BB_applet), applet_name_compare); + if (applet != NULL) { + if (applet->usage && argv[1] && strcmp(argv[1], "--help") == 0) + usage(applet->usage); + exit((*(applet->main)) (argc, argv)); + } + + error_msg_and_die("applet not found\n"); +} + + +int busybox_main(int argc, char **argv) +{ + int col = 0, len, i; #ifdef BB_FEATURE_INSTALLER /* @@ -121,37 +151,6 @@ int main(int argc, char **argv) } #endif /* BB_FEATURE_INSTALLER */ - for (s = applet_name = argv[0]; *s != '\0';) { - if (*s++ == '/') - applet_name = s; - } - -#ifdef BB_SH - /* Add in a special case hack -- whenever **argv == '-' - * (i.e. '-su' or '-sh') always invoke the shell */ - if (**argv == '-' && *(*argv+1)!= '-') { - exit(((*(shell_main)) (argc, argv))); - } -#endif - - /* Do a binary search to find the applet entry given the name. */ - search_applet.name = applet_name; - applet = bsearch(&search_applet, applets, NUM_APPLETS, - sizeof(struct BB_applet), applet_name_compare); - if (applet != NULL) { - if (applet->usage && argv[1] && strcmp(argv[1], "--help") == 0) - usage(applet->usage); - exit((*(applet->main)) (argc, argv)); - } - - return(busybox_main(argc, argv)); -} - - -int busybox_main(int argc, char **argv) -{ - int col = 0, len, i; - argc--; /* If we've already been here once, exit now */ diff --git a/coreutils/ls.c b/coreutils/ls.c index 080768027..64e5bf828 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -171,6 +171,8 @@ static unsigned short column = 0; static unsigned short terminal_width; static unsigned short column_width; static unsigned short tabstops; +#else +# define column_width COLUMN_WIDTH #endif static int status = EXIT_SUCCESS; @@ -236,7 +238,7 @@ static void nexttabstop( void ) column++; } } - nexttab= column + column_width + COLUMN_GAP ; + nexttab= column + column_width + COLUMN_GAP; } /*----------------------------------------------------------------------*/ @@ -429,8 +431,10 @@ void showfiles(struct dnode **dn, int nfiles) ; if (column_width < len) column_width= len; } -#endif ncols= (int)(terminal_width / (column_width + COLUMN_GAP)); +#else + ncols= TERMINAL_WIDTH; +#endif switch (style_fmt) { case STYLE_LONG: /* one record per line, extended info */ case STYLE_SINGLE: /* one record per line */ diff --git a/insmod.c b/insmod.c index a134fea87..e52da91e4 100644 --- a/insmod.c +++ b/insmod.c @@ -78,7 +78,7 @@ #ifndef MODUTILS_MODULE_H static const int MODUTILS_MODULE_H = 1; -#ident "$Id: insmod.c,v 1.37 2001/01/24 19:07:09 andersen Exp $" +#ident "$Id: insmod.c,v 1.38 2001/01/24 23:34:48 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 @@ -284,7 +284,7 @@ int delete_module(const char *); #ifndef MODUTILS_OBJ_H static const int MODUTILS_OBJ_H = 1; -#ident "$Id: insmod.c,v 1.37 2001/01/24 19:07:09 andersen Exp $" +#ident "$Id: insmod.c,v 1.38 2001/01/24 23:34:48 andersen Exp $" /* The relocatable object is manipulated using elfin types. */ @@ -519,10 +519,6 @@ int arch_init_module (struct obj_file *f, struct new_module *); #define _PATH_MODULES "/lib/modules" static const int STRVERSIONLEN = 32; -#if !defined(BB_FEATURE_INSMOD_NEW_KERNEL) && !defined(BB_FEATURE_INSMOD_OLD_KERNEL) -#error "Must have ether BB_FEATURE_INSMOD_NEW_KERNEL or BB_FEATURE_INSMOD_OLD_KERNEL defined" -#endif - /*======================================================================*/ int flag_force_load = 0; @@ -615,7 +611,7 @@ extern int delete_module(const char *); -- Bryan Rittmeyer */ -#ifdef BB_FEATURE_INSMOD_OLD_KERNEL +#ifdef BB_FEATURE_OLD_MODULE_INTERFACE _syscall1(int, get_kernel_syms, struct old_kernel_sym *, ks) #endif @@ -1549,7 +1545,7 @@ old_get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ -#ifdef BB_FEATURE_INSMOD_OLD_KERNEL +#ifdef BB_FEATURE_OLD_MODULE_INTERFACE /* Fetch all the symbols and divvy them up as appropriate for the modules. */ @@ -1757,7 +1753,7 @@ old_init_module(const char *m_name, struct obj_file *f, #define old_create_mod_use_count(x) TRUE #define old_init_module(x, y, z) TRUE -#endif /* BB_FEATURE_INSMOD_OLD_KERNEL */ +#endif /* BB_FEATURE_OLD_MODULE_INTERFACE */ @@ -2036,7 +2032,7 @@ new_get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ -#ifdef BB_FEATURE_INSMOD_NEW_KERNEL +#ifdef BB_FEATURE_NEW_MODULE_INTERFACE /* Fetch the loaded modules, and all currently exported symbols. */ @@ -2310,7 +2306,7 @@ new_init_module(const char *m_name, struct obj_file *f, #define new_create_module_ksymtab(x) #define query_module(v, w, x, y, z) -1 -#endif /* BB_FEATURE_INSMOD_NEW_KERNEL */ +#endif /* BB_FEATURE_NEW_MODULE_INTERFACE */ /*======================================================================*/ @@ -2997,7 +2993,7 @@ extern int insmod_main( int argc, char **argv) k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL); if (k_new_syscalls) { -#ifdef BB_FEATURE_INSMOD_NEW_KERNEL +#ifdef BB_FEATURE_NEW_MODULE_INTERFACE if (!new_get_kernel_symbols()) goto out; k_crcs = new_is_kernel_checksummed(); @@ -3006,7 +3002,7 @@ extern int insmod_main( int argc, char **argv) goto out; #endif } else { -#ifdef BB_FEATURE_INSMOD_OLD_KERNEL +#ifdef BB_FEATURE_OLD_MODULE_INTERFACE if (!old_get_kernel_symbols(m_name)) goto out; k_crcs = old_is_kernel_checksummed(); diff --git a/ls.c b/ls.c index 080768027..64e5bf828 100644 --- a/ls.c +++ b/ls.c @@ -171,6 +171,8 @@ static unsigned short column = 0; static unsigned short terminal_width; static unsigned short column_width; static unsigned short tabstops; +#else +# define column_width COLUMN_WIDTH #endif static int status = EXIT_SUCCESS; @@ -236,7 +238,7 @@ static void nexttabstop( void ) column++; } } - nexttab= column + column_width + COLUMN_GAP ; + nexttab= column + column_width + COLUMN_GAP; } /*----------------------------------------------------------------------*/ @@ -429,8 +431,10 @@ void showfiles(struct dnode **dn, int nfiles) ; if (column_width < len) column_width= len; } -#endif ncols= (int)(terminal_width / (column_width + COLUMN_GAP)); +#else + ncols= TERMINAL_WIDTH; +#endif switch (style_fmt) { case STYLE_LONG: /* one record per line, extended info */ case STYLE_SINGLE: /* one record per line */ diff --git a/lsmod.c b/lsmod.c index 586920d63..41575585f 100644 --- a/lsmod.c +++ b/lsmod.c @@ -40,11 +40,7 @@ -#if !defined(BB_FEATURE_LSMOD_NEW_KERNEL) && !defined(BB_FEATURE_LSMOD_OLD_KERNEL) -#error "Must have ether BB_FEATURE_LSMOD_NEW_KERNEL or BB_FEATURE_LSMOD_OLD_KERNEL defined" -#endif - -#ifdef BB_FEATURE_LSMOD_NEW_KERNEL +#ifdef BB_FEATURE_NEW_MODULE_INTERFACE struct module_info { @@ -132,7 +128,7 @@ extern int lsmod_main(int argc, char **argv) return( 0); } -#else /*BB_FEATURE_LSMOD_OLD_KERNEL*/ +#else /*BB_FEATURE_OLD_MODULE_INTERFACE*/ #if ! defined BB_FEATURE_USE_PROCFS #error Sorry, I depend on the /proc filesystem right now. @@ -157,4 +153,4 @@ extern int lsmod_main(int argc, char **argv) return 1; } -#endif /*BB_FEATURE_LSMOD_OLD_KERNEL*/ +#endif /*BB_FEATURE_OLD_MODULE_INTERFACE*/ diff --git a/modutils/insmod.c b/modutils/insmod.c index a134fea87..e52da91e4 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c @@ -78,7 +78,7 @@ #ifndef MODUTILS_MODULE_H static const int MODUTILS_MODULE_H = 1; -#ident "$Id: insmod.c,v 1.37 2001/01/24 19:07:09 andersen Exp $" +#ident "$Id: insmod.c,v 1.38 2001/01/24 23:34:48 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 @@ -284,7 +284,7 @@ int delete_module(const char *); #ifndef MODUTILS_OBJ_H static const int MODUTILS_OBJ_H = 1; -#ident "$Id: insmod.c,v 1.37 2001/01/24 19:07:09 andersen Exp $" +#ident "$Id: insmod.c,v 1.38 2001/01/24 23:34:48 andersen Exp $" /* The relocatable object is manipulated using elfin types. */ @@ -519,10 +519,6 @@ int arch_init_module (struct obj_file *f, struct new_module *); #define _PATH_MODULES "/lib/modules" static const int STRVERSIONLEN = 32; -#if !defined(BB_FEATURE_INSMOD_NEW_KERNEL) && !defined(BB_FEATURE_INSMOD_OLD_KERNEL) -#error "Must have ether BB_FEATURE_INSMOD_NEW_KERNEL or BB_FEATURE_INSMOD_OLD_KERNEL defined" -#endif - /*======================================================================*/ int flag_force_load = 0; @@ -615,7 +611,7 @@ extern int delete_module(const char *); -- Bryan Rittmeyer */ -#ifdef BB_FEATURE_INSMOD_OLD_KERNEL +#ifdef BB_FEATURE_OLD_MODULE_INTERFACE _syscall1(int, get_kernel_syms, struct old_kernel_sym *, ks) #endif @@ -1549,7 +1545,7 @@ old_get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ -#ifdef BB_FEATURE_INSMOD_OLD_KERNEL +#ifdef BB_FEATURE_OLD_MODULE_INTERFACE /* Fetch all the symbols and divvy them up as appropriate for the modules. */ @@ -1757,7 +1753,7 @@ old_init_module(const char *m_name, struct obj_file *f, #define old_create_mod_use_count(x) TRUE #define old_init_module(x, y, z) TRUE -#endif /* BB_FEATURE_INSMOD_OLD_KERNEL */ +#endif /* BB_FEATURE_OLD_MODULE_INTERFACE */ @@ -2036,7 +2032,7 @@ new_get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ -#ifdef BB_FEATURE_INSMOD_NEW_KERNEL +#ifdef BB_FEATURE_NEW_MODULE_INTERFACE /* Fetch the loaded modules, and all currently exported symbols. */ @@ -2310,7 +2306,7 @@ new_init_module(const char *m_name, struct obj_file *f, #define new_create_module_ksymtab(x) #define query_module(v, w, x, y, z) -1 -#endif /* BB_FEATURE_INSMOD_NEW_KERNEL */ +#endif /* BB_FEATURE_NEW_MODULE_INTERFACE */ /*======================================================================*/ @@ -2997,7 +2993,7 @@ extern int insmod_main( int argc, char **argv) k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL); if (k_new_syscalls) { -#ifdef BB_FEATURE_INSMOD_NEW_KERNEL +#ifdef BB_FEATURE_NEW_MODULE_INTERFACE if (!new_get_kernel_symbols()) goto out; k_crcs = new_is_kernel_checksummed(); @@ -3006,7 +3002,7 @@ extern int insmod_main( int argc, char **argv) goto out; #endif } else { -#ifdef BB_FEATURE_INSMOD_OLD_KERNEL +#ifdef BB_FEATURE_OLD_MODULE_INTERFACE if (!old_get_kernel_symbols(m_name)) goto out; k_crcs = old_is_kernel_checksummed(); diff --git a/modutils/lsmod.c b/modutils/lsmod.c index 586920d63..41575585f 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c @@ -40,11 +40,7 @@ -#if !defined(BB_FEATURE_LSMOD_NEW_KERNEL) && !defined(BB_FEATURE_LSMOD_OLD_KERNEL) -#error "Must have ether BB_FEATURE_LSMOD_NEW_KERNEL or BB_FEATURE_LSMOD_OLD_KERNEL defined" -#endif - -#ifdef BB_FEATURE_LSMOD_NEW_KERNEL +#ifdef BB_FEATURE_NEW_MODULE_INTERFACE struct module_info { @@ -132,7 +128,7 @@ extern int lsmod_main(int argc, char **argv) return( 0); } -#else /*BB_FEATURE_LSMOD_OLD_KERNEL*/ +#else /*BB_FEATURE_OLD_MODULE_INTERFACE*/ #if ! defined BB_FEATURE_USE_PROCFS #error Sorry, I depend on the /proc filesystem right now. @@ -157,4 +153,4 @@ extern int lsmod_main(int argc, char **argv) return 1; } -#endif /*BB_FEATURE_LSMOD_OLD_KERNEL*/ +#endif /*BB_FEATURE_OLD_MODULE_INTERFACE*/ diff --git a/tests/busybox.REGRESS.sh b/tests/busybox.REGRESS.sh index a5a31ad7735782648222e89a6af2271d862699dc..00deaf26ff1b8df2fe405317d474e31ed38f3ee9 100755 GIT binary patch delta 20 bcmaDN|4x3xR(=l7)QZd!1w-q}oB0g^R(1zs delta 11 ScmaDS|3rSnR{qKR`Sk%JrUexM diff --git a/utility.c b/utility.c index 6b637de04..50bf507b8 100644 --- a/utility.c +++ b/utility.c @@ -137,7 +137,7 @@ extern void perror_msg_and_die(const char *s, ...) exit(EXIT_FAILURE); } -#if defined BB_INIT || defined BB_MKSWAP || defined BB_MOUNT +#if defined BB_INIT || defined BB_MKSWAP || defined BB_MOUNT || defined BB_NFSMOUNT /* Returns kernel version encoded as major*65536 + minor*256 + patch, * so, for example, to check if the kernel is greater than 2.2.11: * if (get_kernel_revision() <= 2*65536+2*256+11) { } @@ -1386,7 +1386,7 @@ extern void *xcalloc(size_t nmemb, size_t size) } #endif -#if defined BB_FEATURE_NFSMOUNT || defined BB_LS || defined BB_SH || defined BB_WGET +#if defined BB_NFSMOUNT || defined BB_LS || defined BB_SH || defined BB_WGET # ifndef DMALLOC extern char * xstrdup (const char *s) { char *t; @@ -1404,7 +1404,7 @@ extern char * xstrdup (const char *s) { # endif #endif -#if defined BB_FEATURE_NFSMOUNT +#if defined BB_NFSMOUNT extern char * xstrndup (const char *s, int n) { char *t;