[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] libbb: move common code into run_applet_and_exit
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2016-06-19 13:16:56
Message-ID: CAK1hOcPYQZDmBzLMxOdLREyRKpq72WVZ9vNd4wUB7vCRDu8p8A () mail ! gmail ! com
[Download RAW message or body]
Applied, thanks!
On Tue, Jun 7, 2016 at 1:12 PM, Ron Yorston <rmy@pobox.com> wrote:
> 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 <rmy@pobox.com>
> ---
> include/libbb.h | 2 --
> libbb/appletlib.c | 21 ++++++++-------------
> 2 files changed, 8 insertions(+), 15 deletions(-)
>
> diff --git a/include/libbb.h b/include/libbb.h
> index a21f420..e39021e 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 281123c..55ea4de 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"); - 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 /* !defined(SINGLE_APPLET_MAIN) */
> @@ -964,11 +965,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
> }
> --
> 2.5.5
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic