From 468aea2d8800cc0496383616d82d7c957ae8bc50 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Tue, 1 Apr 2008 14:47:57 +0000 Subject: 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 --- libbb/appletlib.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'libbb/appletlib.c') 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 = "" /* Include generated applet names, pointers to _main, etc */ #include "applet_tables.h" +/* ...and if applet_tables generator says we have only one applet... */ +#ifdef SINGLE_APPLET_MAIN +#undef ENABLE_FEATURE_INDIVIDUAL +#define ENABLE_FEATURE_INDIVIDUAL 1 +#undef USE_FEATURE_INDIVIDUAL +#define USE_FEATURE_INDIVIDUAL(...) __VA_ARGS__ +#endif #if ENABLE_FEATURE_COMPRESS_USAGE @@ -77,6 +84,23 @@ static const char *unpack_usage_messages(void) void bb_show_usage(void) { if (ENABLE_SHOW_USAGE) { +#ifdef SINGLE_APPLET_STR + /* Imagine that this applet is "true". Dont suck in printf! */ + const char *p; + const char *usage_string = p = unpack_usage_messages(); + + if (*p == '\b') { + write(2, "\nNo help available.\n\n", + sizeof("\nNo help available.\n\n") - 1); + } else { + write(2, "\nUsage: "SINGLE_APPLET_STR" ", + sizeof("\nUsage: "SINGLE_APPLET_STR" ") - 1); + write(2, p, strlen(p)); + write(2, "\n\n", 2); + } + dealloc_usage_messages((char*)usage_string); +#else +// TODO: in this case, stdio is sucked in by busybox_main() anyway... const char *format_string; const char *p; const char *usage_string = p = unpack_usage_messages(); @@ -84,18 +108,17 @@ void bb_show_usage(void) if (ap < 0) /* never happens, paranoia */ xfunc_die(); - while (ap) { while (*p++) continue; ap--; } - 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); +#endif } xfunc_die(); } @@ -123,6 +146,9 @@ int find_applet_by_name(const char *name) int *const bb_errno __attribute__ ((section (".data"))); #endif +void lbb_prepare(const char *applet + USE_FEATURE_INDIVIDUAL(, char **argv)) + MAIN_EXTERNALLY_VISIBLE; void lbb_prepare(const char *applet USE_FEATURE_INDIVIDUAL(, char **argv)) { @@ -158,6 +184,9 @@ const char *applet_name; bool re_execed; #endif + +#if !ENABLE_FEATURE_INDIVIDUAL + USE_FEATURE_SUID(static uid_t ruid;) /* real uid */ #if ENABLE_FEATURE_SUID_CONFIG @@ -660,6 +689,9 @@ void run_applet_and_exit(const char *name, char **argv) exit(busybox_main(argv)); } +#endif /* !ENABLE_FEATURE_INDIVIDUAL */ + + #if ENABLE_BUILD_LIBBUSYBOX int lbb_main(char **argv) @@ -667,6 +699,11 @@ int lbb_main(char **argv) int main(int argc ATTRIBUTE_UNUSED, char **argv) #endif { +#if ENABLE_FEATURE_INDIVIDUAL + /* Only one applet is selected by the user! */ + lbb_prepare(SINGLE_APPLET_STR USE_FEATURE_INDIVIDUAL(, argv)); + return SINGLE_APPLET_MAIN(argc, argv); +#else lbb_prepare("busybox" USE_FEATURE_INDIVIDUAL(, argv)); #if !BB_MMU @@ -685,4 +722,5 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv) run_applet_and_exit(applet_name, argv); bb_error_msg_and_die("applet not found"); +#endif } -- cgit v1.2.3