diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-07 20:46:34 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-07 20:46:34 +0000 |
| commit | d62fd84d4b309bc5fa6548288b82f21189d4f53f (patch) | |
| tree | 323ecf50e92a496908b6749c1e0cc41a0669d8c3 /applets | |
| parent | 7930bcf7368e42b327b2a234f4e1be897fc25b1d (diff) | |
| download | busybox-w32-d62fd84d4b309bc5fa6548288b82f21189d4f53f.tar.gz busybox-w32-d62fd84d4b309bc5fa6548288b82f21189d4f53f.tar.bz2 busybox-w32-d62fd84d4b309bc5fa6548288b82f21189d4f53f.zip | |
libbusybox: move (possibly compressed) help stuff into libbusybox.
Makes individual binaries much smaller.
Diffstat (limited to 'applets')
| -rw-r--r-- | applets/Kbuild | 6 | ||||
| -rw-r--r-- | applets/applets.c | 116 |
2 files changed, 6 insertions, 116 deletions
diff --git a/applets/Kbuild b/applets/Kbuild index cf7d29751..289c5def4 100644 --- a/applets/Kbuild +++ b/applets/Kbuild | |||
| @@ -4,13 +4,13 @@ | |||
| 4 | # | 4 | # |
| 5 | # Licensed under the GPL v2, see the file LICENSE in this tarball. | 5 | # Licensed under the GPL v2, see the file LICENSE in this tarball. |
| 6 | 6 | ||
| 7 | obj-y:= | 7 | obj-y := |
| 8 | obj-y += applets.o | 8 | obj-y += applets.o |
| 9 | 9 | ||
| 10 | hostprogs-y:= | 10 | hostprogs-y:= |
| 11 | hostprogs-y += usage | 11 | hostprogs-y += usage |
| 12 | 12 | ||
| 13 | always:= $(hostprogs-y) | 13 | always:= $(hostprogs-y) |
| 14 | 14 | ||
| 15 | # Generated files need additional love | 15 | # Generated files need additional love |
| 16 | 16 | ||
diff --git a/applets/applets.c b/applets/applets.c index f91884b13..49ad8599f 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include <assert.h> | 15 | #include <assert.h> |
| 16 | #include "busybox.h" | 16 | #include "busybox.h" |
| 17 | 17 | ||
| 18 | |||
| 18 | /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ | 19 | /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ |
| 19 | #if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__) | 20 | #if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__) |
| 20 | #warning Static linking against glibc produces buggy executables | 21 | #warning Static linking against glibc produces buggy executables |
| @@ -27,32 +28,8 @@ | |||
| 27 | #endif | 28 | #endif |
| 28 | 29 | ||
| 29 | 30 | ||
| 30 | /* Declare <applet>_main() */ | ||
| 31 | #define PROTOTYPES | ||
| 32 | #include "applets.h" | ||
| 33 | #undef PROTOTYPES | ||
| 34 | |||
| 35 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE | ||
| 36 | /* Define usage_messages[] */ | ||
| 37 | static const char usage_messages[] ALIGN1 = "" | ||
| 38 | #define MAKE_USAGE | ||
| 39 | #include "usage.h" | ||
| 40 | #include "applets.h" | ||
| 41 | ; | ||
| 42 | #undef MAKE_USAGE | ||
| 43 | #else | ||
| 44 | #define usage_messages 0 | ||
| 45 | #endif /* SHOW_USAGE */ | ||
| 46 | |||
| 47 | /* Define struct bb_applet applets[] */ | ||
| 48 | #include "applets.h" | ||
| 49 | /* The -1 arises because of the {0,NULL,0,-1} entry. */ | ||
| 50 | |||
| 51 | #if ENABLE_FEATURE_SH_STANDALONE | ||
| 52 | const unsigned short NUM_APPLETS = ARRAY_SIZE(applets); | ||
| 53 | #endif | ||
| 54 | const struct bb_applet *current_applet; | 31 | const struct bb_applet *current_applet; |
| 55 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; | 32 | const char *applet_name; |
| 56 | #if !BB_MMU | 33 | #if !BB_MMU |
| 57 | bool re_execed; | 34 | bool re_execed; |
| 58 | #endif | 35 | #endif |
| @@ -419,82 +396,6 @@ static void check_suid(const struct bb_applet *applet) | |||
| 419 | #endif /* FEATURE_SUID */ | 396 | #endif /* FEATURE_SUID */ |
| 420 | 397 | ||
| 421 | 398 | ||
| 422 | #if ENABLE_FEATURE_COMPRESS_USAGE | ||
| 423 | |||
| 424 | #include "usage_compressed.h" | ||
| 425 | #include "unarchive.h" | ||
| 426 | |||
| 427 | static const char *unpack_usage_messages(void) | ||
| 428 | { | ||
| 429 | char *outbuf = NULL; | ||
| 430 | bunzip_data *bd; | ||
| 431 | int i; | ||
| 432 | |||
| 433 | i = start_bunzip(&bd, | ||
| 434 | /* src_fd: */ -1, | ||
| 435 | /* inbuf: */ packed_usage, | ||
| 436 | /* len: */ sizeof(packed_usage)); | ||
| 437 | /* read_bunzip can longjmp to start_bunzip, and ultimately | ||
| 438 | * end up here with i != 0 on read data errors! Not trivial */ | ||
| 439 | if (!i) { | ||
| 440 | /* Cannot use xmalloc: will leak bd in NOFORK case! */ | ||
| 441 | outbuf = malloc_or_warn(SIZEOF_usage_messages); | ||
| 442 | if (outbuf) | ||
| 443 | read_bunzip(bd, outbuf, SIZEOF_usage_messages); | ||
| 444 | } | ||
| 445 | dealloc_bunzip(bd); | ||
| 446 | return outbuf; | ||
| 447 | } | ||
| 448 | #define dealloc_usage_messages(s) free(s) | ||
| 449 | |||
| 450 | #else | ||
| 451 | |||
| 452 | #define unpack_usage_messages() usage_messages | ||
| 453 | #define dealloc_usage_messages(s) ((void)(s)) | ||
| 454 | |||
| 455 | #endif /* FEATURE_COMPRESS_USAGE */ | ||
| 456 | |||
| 457 | |||
| 458 | void bb_show_usage(void) | ||
| 459 | { | ||
| 460 | if (ENABLE_SHOW_USAGE) { | ||
| 461 | const char *format_string; | ||
| 462 | const char *p; | ||
| 463 | const char *usage_string = p = unpack_usage_messages(); | ||
| 464 | int i; | ||
| 465 | |||
| 466 | i = current_applet - applets; | ||
| 467 | while (i) { | ||
| 468 | while (*p++) continue; | ||
| 469 | i--; | ||
| 470 | } | ||
| 471 | |||
| 472 | fprintf(stderr, "%s multi-call binary\n", bb_banner); | ||
| 473 | format_string = "\nUsage: %s %s\n\n"; | ||
| 474 | if (*p == '\b') | ||
| 475 | format_string = "\nNo help available.\n\n"; | ||
| 476 | fprintf(stderr, format_string, applet_name, p); | ||
| 477 | dealloc_usage_messages((char*)usage_string); | ||
| 478 | } | ||
| 479 | xfunc_die(); | ||
| 480 | } | ||
| 481 | |||
| 482 | |||
| 483 | static int applet_name_compare(const void *name, const void *vapplet) | ||
| 484 | { | ||
| 485 | const struct bb_applet *applet = vapplet; | ||
| 486 | |||
| 487 | return strcmp(name, applet->name); | ||
| 488 | } | ||
| 489 | |||
| 490 | const struct bb_applet *find_applet_by_name(const char *name) | ||
| 491 | { | ||
| 492 | /* Do a binary search to find the applet entry given the name. */ | ||
| 493 | return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]), | ||
| 494 | applet_name_compare); | ||
| 495 | } | ||
| 496 | |||
| 497 | |||
| 498 | #if ENABLE_FEATURE_INSTALLER | 399 | #if ENABLE_FEATURE_INSTALLER |
| 499 | /* create (sym)links for each applet */ | 400 | /* create (sym)links for each applet */ |
| 500 | static void install_links(const char *busybox, int use_symbolic_links) | 401 | 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) | |||
| 635 | } | 536 | } |
| 636 | 537 | ||
| 637 | 538 | ||
| 638 | #ifdef __GLIBC__ | ||
| 639 | /* Make it reside in R/W memory: */ | ||
| 640 | int *const bb_errno __attribute__ ((section (".data"))); | ||
| 641 | #endif | ||
| 642 | |||
| 643 | int main(int argc, char **argv) | 539 | int main(int argc, char **argv) |
| 644 | { | 540 | { |
| 645 | #ifdef __GLIBC__ | 541 | bbox_prepare_main(); |
| 646 | (*(int **)&bb_errno) = __errno_location(); | ||
| 647 | #endif | ||
| 648 | 542 | ||
| 649 | #if !BB_MMU | 543 | #if !BB_MMU |
| 650 | /* NOMMU re-exec trick sets high-order bit in first byte of name */ | 544 | /* NOMMU re-exec trick sets high-order bit in first byte of name */ |
| @@ -660,10 +554,6 @@ int main(int argc, char **argv) | |||
| 660 | 554 | ||
| 661 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ | 555 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ |
| 662 | 556 | ||
| 663 | /* Set locale for everybody except 'init' */ | ||
| 664 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) | ||
| 665 | setlocale(LC_ALL, ""); | ||
| 666 | |||
| 667 | run_applet_and_exit(applet_name, argv); | 557 | run_applet_and_exit(applet_name, argv); |
| 668 | bb_error_msg_and_die("applet not found"); | 558 | bb_error_msg_and_die("applet not found"); |
| 669 | } | 559 | } |
