aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
Diffstat (limited to 'applets')
-rw-r--r--applets/Kbuild6
-rw-r--r--applets/applets.c116
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
7obj-y:= 7obj-y :=
8obj-y += applets.o 8obj-y += applets.o
9 9
10hostprogs-y:= 10hostprogs-y:=
11hostprogs-y += usage 11hostprogs-y += usage
12 12
13always:= $(hostprogs-y) 13always:= $(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[] */
37static 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
52const unsigned short NUM_APPLETS = ARRAY_SIZE(applets);
53#endif
54const struct bb_applet *current_applet; 31const struct bb_applet *current_applet;
55const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; 32const char *applet_name;
56#if !BB_MMU 33#if !BB_MMU
57bool re_execed; 34bool 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
427static 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
458void 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
483static 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
490const 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 */
500static void install_links(const char *busybox, int use_symbolic_links) 401static 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: */
640int *const bb_errno __attribute__ ((section (".data")));
641#endif
642
643int main(int argc, char **argv) 539int 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}