From 8e95068c7f28fe2a1e31b01636e3ed29eed09ef8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 May 2016 02:42:49 +0200 Subject: Make busybox an optional applet If it's disabled, code shrinks by about 900 bytes: function old new delta usr_bin 10 - -10 usr_sbin 11 - -11 install_dir 20 - -20 applet_install_loc 184 - -184 run_applet_and_exit 686 21 -665 ------------------------------------------------------------------------------ (add/remove: 0/4 grow/shrink: 0/1 up/down: 0/-890) Total: -890 bytes text data bss dec hex filename 911327 493 7336 919156 e0674 busybox_old 909848 493 7336 917677 e00ad busybox_unstripped but busybox executable by itself does not say anything useful: $ busybox busybox: applet not found Based on the patch by Ron Yorston Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libbb/appletlib.c') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index b682e6b85..281123c37 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -701,7 +701,7 @@ static void install_links(const char *busybox, int use_symbolic_links, continue; } } -# else +# elif ENABLE_BUSYBOX static void install_links(const char *busybox UNUSED_PARAM, int use_symbolic_links UNUSED_PARAM, char *custom_install_dir UNUSED_PARAM) @@ -709,6 +709,7 @@ static void install_links(const char *busybox UNUSED_PARAM, } # endif +# if ENABLE_BUSYBOX /* If we were called as "busybox..." */ static int busybox_main(char **argv) { @@ -784,10 +785,10 @@ static int busybox_main(char **argv) const char *a = applet_names; dup2(1, 2); while (*a) { -# if ENABLE_FEATURE_INSTALLER +# if ENABLE_FEATURE_INSTALLER if (argv[1][6]) /* --list-full? */ full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); -# endif +# endif full_write2_str(a); full_write2_str("\n"); i++; @@ -843,6 +844,7 @@ static int busybox_main(char **argv) /* POSIX: "If a command is not found, the exit status shall be 127" */ exit(127); } +# endif void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) { @@ -886,8 +888,10 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv) { int applet; +# if ENABLE_BUSYBOX if (is_prefixed_with(name, "busybox")) exit(busybox_main(argv)); +# endif /* find_applet_by_name() search is more expensive, so goes second */ applet = find_applet_by_name(name); if (applet >= 0) -- cgit v1.2.3-55-g6feb From ba12081a9e9b2d90d1924546bc9097abf52cf2b5 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 7 Jun 2016 10:26:24 +0100 Subject: Allow "busybox " to work when busybox is disabled A recent commit made it possible to disable BusyBox's --install and --list options. However it also stopped "busybox " from working. Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libbb/appletlib.c') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 281123c37..b6fe1dad2 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -956,6 +956,10 @@ int main(int argc UNUSED_PARAM, char **argv) #else lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); +#if !ENABLE_BUSYBOX + if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox")) + argv++; +#endif applet_name = argv[0]; if (applet_name[0] == '-') applet_name++; -- cgit v1.2.3-55-g6feb From ce824aecf216536beed00d7817a614ffb8572239 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 7 Jun 2016 12:12:07 +0100 Subject: libbb: move common code into run_applet_and_exit Both calls to run_applet_and_exit are followed by the same code to print an error message and return status 127. Remove this duplication and make run_applet_and_exit static. function old new delta run_applet_and_exit 675 667 -8 main 119 92 -27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-35) Total: -35 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- include/libbb.h | 2 -- libbb/appletlib.c | 21 ++++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) (limited to 'libbb/appletlib.c') diff --git a/include/libbb.h b/include/libbb.h index a21f4204a..e39021eb1 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1239,8 +1239,6 @@ const struct hwtype *get_hwntype(int type) FAST_FUNC; #ifndef BUILD_INDIVIDUAL extern int find_applet_by_name(const char *name) FAST_FUNC; -/* Returns only if applet is not found. */ -extern void run_applet_and_exit(const char *name, char **argv) FAST_FUNC; extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC; #endif diff --git a/libbb/appletlib.c b/libbb/appletlib.c index b6fe1dad2..480bf50fc 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -52,6 +52,7 @@ #include "usage_compressed.h" +static void run_applet_and_exit(const char *name, char **argv) NORETURN; #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; @@ -837,12 +838,6 @@ static int busybox_main(char **argv) * "#!/bin/busybox"-style wrappers */ applet_name = bb_get_last_path_component_nostrip(argv[0]); run_applet_and_exit(applet_name, argv); - - /*bb_error_msg_and_die("applet not found"); - sucks in printf */ - full_write2_str(applet_name); - full_write2_str(": applet not found\n"); - /* POSIX: "If a command is not found, the exit status shall be 127" */ - exit(127); } # endif @@ -884,7 +879,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) exit(applet_main[applet_no](argc, argv)); } -void FAST_FUNC run_applet_and_exit(const char *name, char **argv) +static NORETURN void run_applet_and_exit(const char *name, char **argv) { int applet; @@ -896,6 +891,12 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv) applet = find_applet_by_name(name); if (applet >= 0) run_applet_no_and_exit(applet, argv); + + /*bb_error_msg_and_die("applet not found"); - links in printf */ + full_write2_str(applet_name); + full_write2_str(": applet not found\n"); + /* POSIX: "If a command is not found, the exit status shall be 127" */ + exit(127); } #endif /* !defined(SINGLE_APPLET_MAIN) */ @@ -968,11 +969,5 @@ int main(int argc UNUSED_PARAM, char **argv) parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ run_applet_and_exit(applet_name, argv); - - /*bb_error_msg_and_die("applet not found"); - sucks in printf */ - full_write2_str(applet_name); - full_write2_str(": applet not found\n"); - /* POSIX: "If a command is not found, the exit status shall be 127" */ - exit(127); #endif } -- cgit v1.2.3-55-g6feb From 1b0dcc02dd5a101d1a62f2111892a41621be96cf Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 5 Jul 2016 14:07:50 +0100 Subject: libbb: suppress warning about run_applet_and_exit When busybox is configured to contain a single applet an unnecessary declaration of run_applet_and_exit results in a warning. Move the declaration to avoid this. Reported-by: Lauri Kasanen Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libbb/appletlib.c') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 480bf50fc..791b81c17 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -52,8 +52,6 @@ #include "usage_compressed.h" -static void run_applet_and_exit(const char *name, char **argv) NORETURN; - #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; #else @@ -711,6 +709,8 @@ static void install_links(const char *busybox UNUSED_PARAM, # endif # if ENABLE_BUSYBOX +static void run_applet_and_exit(const char *name, char **argv) NORETURN; + /* If we were called as "busybox..." */ static int busybox_main(char **argv) { -- cgit v1.2.3-55-g6feb From f4f8fe841cf2df761eaade204a13e6fde6639666 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 5 Jul 2016 21:43:28 +0200 Subject: build system: fix a few warnings for allnoconfig build Not that allnoconfig build is useful in any way... Signed-off-by: Denys Vlasenko --- applets/usage_pod.c | 2 ++ docs/busybox_footer.pod | 2 -- libbb/appletlib.c | 30 +++++++++++++++++------------- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'libbb/appletlib.c') diff --git a/applets/usage_pod.c b/applets/usage_pod.c index 0b1c4aadb..ccc166aed 100644 --- a/applets/usage_pod.c +++ b/applets/usage_pod.c @@ -90,6 +90,8 @@ int main(void) printf("%s\n\n", usage_array[i].aname); } } + printf("=back\n\n"); + return 0; } diff --git a/docs/busybox_footer.pod b/docs/busybox_footer.pod index c346c736b..92748eb72 100644 --- a/docs/busybox_footer.pod +++ b/docs/busybox_footer.pod @@ -1,5 +1,3 @@ -=back - =head1 LIBC NSS GNU Libc (glibc) uses the Name Service Switch (NSS) to configure the behavior diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 791b81c17..c341817e2 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -841,6 +841,7 @@ static int busybox_main(char **argv) } # endif +# if NUM_APPLETS > 0 void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) { int argc = 1; @@ -858,15 +859,15 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) * "true" and "false" are also special. */ if (1 -#if defined APPLET_NO_test +# if defined APPLET_NO_test && applet_no != APPLET_NO_test -#endif -#if defined APPLET_NO_true +# endif +# if defined APPLET_NO_true && applet_no != APPLET_NO_true -#endif -#if defined APPLET_NO_false +# endif +# if defined APPLET_NO_false && applet_no != APPLET_NO_false -#endif +# endif ) { if (argc == 2 && strcmp(argv[1], "--help") == 0) { /* Make "foo --help" exit with 0: */ @@ -878,19 +879,22 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) check_suid(applet_no); exit(applet_main[applet_no](argc, argv)); } +# endif /* NUM_APPLETS > 0 */ static NORETURN void run_applet_and_exit(const char *name, char **argv) { - int applet; - # if ENABLE_BUSYBOX if (is_prefixed_with(name, "busybox")) exit(busybox_main(argv)); # endif +# if NUM_APPLETS > 0 /* find_applet_by_name() search is more expensive, so goes second */ - applet = find_applet_by_name(name); - if (applet >= 0) - run_applet_no_and_exit(applet, argv); + { + int applet = find_applet_by_name(name); + if (applet >= 0) + run_applet_no_and_exit(applet, argv); + } +# endif /*bb_error_msg_and_die("applet not found"); - links in printf */ full_write2_str(applet_name); @@ -957,10 +961,10 @@ int main(int argc UNUSED_PARAM, char **argv) #else lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); -#if !ENABLE_BUSYBOX +# if !ENABLE_BUSYBOX if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox")) argv++; -#endif +# endif applet_name = argv[0]; if (applet_name[0] == '-') applet_name++; -- cgit v1.2.3-55-g6feb