aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-01 14:47:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-01 14:47:57 +0000
commit468aea2d8800cc0496383616d82d7c957ae8bc50 (patch)
tree8a2f3d80dc2440dd007caed4cfa235b3858c9170 /libbb/appletlib.c
parent165f5b394fa337e71e08435b51108f4394199b2b (diff)
downloadbusybox-w32-468aea2d8800cc0496383616d82d7c957ae8bc50.tar.gz
busybox-w32-468aea2d8800cc0496383616d82d7c957ae8bc50.tar.bz2
busybox-w32-468aea2d8800cc0496383616d82d7c957ae8bc50.zip
shells: do not frocibly enable test, echo and kill _applets_,
just build relevant source and use xxx_main functions. build system: add a special case when we have exactly one applet enabled (makes "true", "false", "basename" REALLY tiny). getopt32: do not use stdio. function old new delta getopt32 1385 1412 +27 make_device 1187 1200 +13 basename_main 120 127 +7 tcpudpsvd_main 1922 1926 +4 testcmd 5 - -5 echocmd 5 - -5 fuser_main 1243 1231 -12 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 4/1 up/down: 51/-22) Total: 29 bytes
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index e2bb37868..a48a26003 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -36,6 +36,13 @@ static const char usage_messages[] ALIGN1 = ""
36 36
37/* Include generated applet names, pointers to <applet>_main, etc */ 37/* Include generated applet names, pointers to <applet>_main, etc */
38#include "applet_tables.h" 38#include "applet_tables.h"
39/* ...and if applet_tables generator says we have only one applet... */
40#ifdef SINGLE_APPLET_MAIN
41#undef ENABLE_FEATURE_INDIVIDUAL
42#define ENABLE_FEATURE_INDIVIDUAL 1
43#undef USE_FEATURE_INDIVIDUAL
44#define USE_FEATURE_INDIVIDUAL(...) __VA_ARGS__
45#endif
39 46
40 47
41#if ENABLE_FEATURE_COMPRESS_USAGE 48#if ENABLE_FEATURE_COMPRESS_USAGE
@@ -77,6 +84,23 @@ static const char *unpack_usage_messages(void)
77void bb_show_usage(void) 84void bb_show_usage(void)
78{ 85{
79 if (ENABLE_SHOW_USAGE) { 86 if (ENABLE_SHOW_USAGE) {
87#ifdef SINGLE_APPLET_STR
88 /* Imagine that this applet is "true". Dont suck in printf! */
89 const char *p;
90 const char *usage_string = p = unpack_usage_messages();
91
92 if (*p == '\b') {
93 write(2, "\nNo help available.\n\n",
94 sizeof("\nNo help available.\n\n") - 1);
95 } else {
96 write(2, "\nUsage: "SINGLE_APPLET_STR" ",
97 sizeof("\nUsage: "SINGLE_APPLET_STR" ") - 1);
98 write(2, p, strlen(p));
99 write(2, "\n\n", 2);
100 }
101 dealloc_usage_messages((char*)usage_string);
102#else
103// TODO: in this case, stdio is sucked in by busybox_main() anyway...
80 const char *format_string; 104 const char *format_string;
81 const char *p; 105 const char *p;
82 const char *usage_string = p = unpack_usage_messages(); 106 const char *usage_string = p = unpack_usage_messages();
@@ -84,18 +108,17 @@ void bb_show_usage(void)
84 108
85 if (ap < 0) /* never happens, paranoia */ 109 if (ap < 0) /* never happens, paranoia */
86 xfunc_die(); 110 xfunc_die();
87
88 while (ap) { 111 while (ap) {
89 while (*p++) continue; 112 while (*p++) continue;
90 ap--; 113 ap--;
91 } 114 }
92
93 fprintf(stderr, "%s multi-call binary\n", bb_banner); 115 fprintf(stderr, "%s multi-call binary\n", bb_banner);
94 format_string = "\nUsage: %s %s\n\n"; 116 format_string = "\nUsage: %s %s\n\n";
95 if (*p == '\b') 117 if (*p == '\b')
96 format_string = "\nNo help available.\n\n"; 118 format_string = "\nNo help available.\n\n";
97 fprintf(stderr, format_string, applet_name, p); 119 fprintf(stderr, format_string, applet_name, p);
98 dealloc_usage_messages((char*)usage_string); 120 dealloc_usage_messages((char*)usage_string);
121#endif
99 } 122 }
100 xfunc_die(); 123 xfunc_die();
101} 124}
@@ -125,6 +148,9 @@ int *const bb_errno __attribute__ ((section (".data")));
125 148
126void lbb_prepare(const char *applet 149void lbb_prepare(const char *applet
127 USE_FEATURE_INDIVIDUAL(, char **argv)) 150 USE_FEATURE_INDIVIDUAL(, char **argv))
151 MAIN_EXTERNALLY_VISIBLE;
152void lbb_prepare(const char *applet
153 USE_FEATURE_INDIVIDUAL(, char **argv))
128{ 154{
129#ifdef __GLIBC__ 155#ifdef __GLIBC__
130 (*(int **)&bb_errno) = __errno_location(); 156 (*(int **)&bb_errno) = __errno_location();
@@ -158,6 +184,9 @@ const char *applet_name;
158bool re_execed; 184bool re_execed;
159#endif 185#endif
160 186
187
188#if !ENABLE_FEATURE_INDIVIDUAL
189
161USE_FEATURE_SUID(static uid_t ruid;) /* real uid */ 190USE_FEATURE_SUID(static uid_t ruid;) /* real uid */
162 191
163#if ENABLE_FEATURE_SUID_CONFIG 192#if ENABLE_FEATURE_SUID_CONFIG
@@ -660,6 +689,9 @@ void run_applet_and_exit(const char *name, char **argv)
660 exit(busybox_main(argv)); 689 exit(busybox_main(argv));
661} 690}
662 691
692#endif /* !ENABLE_FEATURE_INDIVIDUAL */
693
694
663 695
664#if ENABLE_BUILD_LIBBUSYBOX 696#if ENABLE_BUILD_LIBBUSYBOX
665int lbb_main(char **argv) 697int lbb_main(char **argv)
@@ -667,6 +699,11 @@ int lbb_main(char **argv)
667int main(int argc ATTRIBUTE_UNUSED, char **argv) 699int main(int argc ATTRIBUTE_UNUSED, char **argv)
668#endif 700#endif
669{ 701{
702#if ENABLE_FEATURE_INDIVIDUAL
703 /* Only one applet is selected by the user! */
704 lbb_prepare(SINGLE_APPLET_STR USE_FEATURE_INDIVIDUAL(, argv));
705 return SINGLE_APPLET_MAIN(argc, argv);
706#else
670 lbb_prepare("busybox" USE_FEATURE_INDIVIDUAL(, argv)); 707 lbb_prepare("busybox" USE_FEATURE_INDIVIDUAL(, argv));
671 708
672#if !BB_MMU 709#if !BB_MMU
@@ -685,4 +722,5 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv)
685 722
686 run_applet_and_exit(applet_name, argv); 723 run_applet_and_exit(applet_name, argv);
687 bb_error_msg_and_die("applet not found"); 724 bb_error_msg_and_die("applet not found");
725#endif
688} 726}