diff options
author | Denis Vlasenko | 2007-10-07 20:46:34 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-10-07 20:46:34 +0000 |
commit | d62fd84d4b309bc5fa6548288b82f21189d4f53f (patch) | |
tree | 323ecf50e92a496908b6749c1e0cc41a0669d8c3 /applets/applets.c | |
parent | 7930bcf7368e42b327b2a234f4e1be897fc25b1d (diff) | |
download | busybox-d62fd84d4b309bc5fa6548288b82f21189d4f53f.zip busybox-d62fd84d4b309bc5fa6548288b82f21189d4f53f.tar.gz |
libbusybox: move (possibly compressed) help stuff into libbusybox.
Makes individual binaries much smaller.
Diffstat (limited to 'applets/applets.c')
-rw-r--r-- | applets/applets.c | 116 |
1 files changed, 3 insertions, 113 deletions
diff --git a/applets/applets.c b/applets/applets.c index f91884b..49ad859 100644 --- a/applets/applets.c +++ b/applets/applets.c @@ -15,6 +15,7 @@ #include <assert.h> #include "busybox.h" + /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ #if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__) #warning Static linking against glibc produces buggy executables @@ -27,32 +28,8 @@ #endif -/* Declare <applet>_main() */ -#define PROTOTYPES -#include "applets.h" -#undef PROTOTYPES - -#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE -/* Define usage_messages[] */ -static const char usage_messages[] ALIGN1 = "" -#define MAKE_USAGE -#include "usage.h" -#include "applets.h" -; -#undef MAKE_USAGE -#else -#define usage_messages 0 -#endif /* SHOW_USAGE */ - -/* Define struct bb_applet applets[] */ -#include "applets.h" -/* The -1 arises because of the {0,NULL,0,-1} entry. */ - -#if ENABLE_FEATURE_SH_STANDALONE -const unsigned short NUM_APPLETS = ARRAY_SIZE(applets); -#endif const struct bb_applet *current_applet; -const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; +const char *applet_name; #if !BB_MMU bool re_execed; #endif @@ -419,82 +396,6 @@ static void check_suid(const struct bb_applet *applet) #endif /* FEATURE_SUID */ -#if ENABLE_FEATURE_COMPRESS_USAGE - -#include "usage_compressed.h" -#include "unarchive.h" - -static const char *unpack_usage_messages(void) -{ - char *outbuf = NULL; - bunzip_data *bd; - int i; - - i = start_bunzip(&bd, - /* src_fd: */ -1, - /* inbuf: */ packed_usage, - /* len: */ sizeof(packed_usage)); - /* read_bunzip can longjmp to start_bunzip, and ultimately - * end up here with i != 0 on read data errors! Not trivial */ - if (!i) { - /* Cannot use xmalloc: will leak bd in NOFORK case! */ - outbuf = malloc_or_warn(SIZEOF_usage_messages); - if (outbuf) - read_bunzip(bd, outbuf, SIZEOF_usage_messages); - } - dealloc_bunzip(bd); - return outbuf; -} -#define dealloc_usage_messages(s) free(s) - -#else - -#define unpack_usage_messages() usage_messages -#define dealloc_usage_messages(s) ((void)(s)) - -#endif /* FEATURE_COMPRESS_USAGE */ - - -void bb_show_usage(void) -{ - if (ENABLE_SHOW_USAGE) { - const char *format_string; - const char *p; - const char *usage_string = p = unpack_usage_messages(); - int i; - - i = current_applet - applets; - while (i) { - while (*p++) continue; - i--; - } - - fprintf(stderr, "%s multi-call binary\n", bb_banner); - format_string = "\nUsage: %s %s\n\n"; - if (*p == '\b') - format_string = "\nNo help available.\n\n"; - fprintf(stderr, format_string, applet_name, p); - dealloc_usage_messages((char*)usage_string); - } - xfunc_die(); -} - - -static int applet_name_compare(const void *name, const void *vapplet) -{ - const struct bb_applet *applet = vapplet; - - return strcmp(name, applet->name); -} - -const struct bb_applet *find_applet_by_name(const char *name) -{ - /* Do a binary search to find the applet entry given the name. */ - return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]), - applet_name_compare); -} - - #if ENABLE_FEATURE_INSTALLER /* create (sym)links for each applet */ static void install_links(const char *busybox, int use_symbolic_links) @@ -635,16 +536,9 @@ void run_applet_and_exit(const char *name, char **argv) } -#ifdef __GLIBC__ -/* Make it reside in R/W memory: */ -int *const bb_errno __attribute__ ((section (".data"))); -#endif - int main(int argc, char **argv) { -#ifdef __GLIBC__ - (*(int **)&bb_errno) = __errno_location(); -#endif + bbox_prepare_main(); #if !BB_MMU /* NOMMU re-exec trick sets high-order bit in first byte of name */ @@ -660,10 +554,6 @@ int main(int argc, char **argv) parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ - /* Set locale for everybody except 'init' */ - if (ENABLE_LOCALE_SUPPORT && getpid() != 1) - setlocale(LC_ALL, ""); - run_applet_and_exit(applet_name, argv); bb_error_msg_and_die("applet not found"); } |