diff options
author | Ron Yorston <rmy@pobox.com> | 2016-06-07 12:12:07 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-06-19 15:16:27 +0200 |
commit | ce824aecf216536beed00d7817a614ffb8572239 (patch) | |
tree | 2c511d4cfa1d7b62a26a032a152a9d8879b228e4 | |
parent | ba12081a9e9b2d90d1924546bc9097abf52cf2b5 (diff) | |
download | busybox-w32-ce824aecf216536beed00d7817a614ffb8572239.tar.gz busybox-w32-ce824aecf216536beed00d7817a614ffb8572239.tar.bz2 busybox-w32-ce824aecf216536beed00d7817a614ffb8572239.zip |
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 <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/appletlib.c | 21 |
2 files changed, 8 insertions, 15 deletions
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; | |||
1239 | 1239 | ||
1240 | #ifndef BUILD_INDIVIDUAL | 1240 | #ifndef BUILD_INDIVIDUAL |
1241 | extern int find_applet_by_name(const char *name) FAST_FUNC; | 1241 | extern int find_applet_by_name(const char *name) FAST_FUNC; |
1242 | /* Returns only if applet is not found. */ | ||
1243 | extern void run_applet_and_exit(const char *name, char **argv) FAST_FUNC; | ||
1244 | extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC; | 1242 | extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC; |
1245 | #endif | 1243 | #endif |
1246 | 1244 | ||
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 @@ | |||
52 | 52 | ||
53 | #include "usage_compressed.h" | 53 | #include "usage_compressed.h" |
54 | 54 | ||
55 | static void run_applet_and_exit(const char *name, char **argv) NORETURN; | ||
55 | 56 | ||
56 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE | 57 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE |
57 | static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; | 58 | static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; |
@@ -837,12 +838,6 @@ static int busybox_main(char **argv) | |||
837 | * "#!/bin/busybox"-style wrappers */ | 838 | * "#!/bin/busybox"-style wrappers */ |
838 | applet_name = bb_get_last_path_component_nostrip(argv[0]); | 839 | applet_name = bb_get_last_path_component_nostrip(argv[0]); |
839 | run_applet_and_exit(applet_name, argv); | 840 | run_applet_and_exit(applet_name, argv); |
840 | |||
841 | /*bb_error_msg_and_die("applet not found"); - sucks in printf */ | ||
842 | full_write2_str(applet_name); | ||
843 | full_write2_str(": applet not found\n"); | ||
844 | /* POSIX: "If a command is not found, the exit status shall be 127" */ | ||
845 | exit(127); | ||
846 | } | 841 | } |
847 | # endif | 842 | # endif |
848 | 843 | ||
@@ -884,7 +879,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | |||
884 | exit(applet_main[applet_no](argc, argv)); | 879 | exit(applet_main[applet_no](argc, argv)); |
885 | } | 880 | } |
886 | 881 | ||
887 | void FAST_FUNC run_applet_and_exit(const char *name, char **argv) | 882 | static NORETURN void run_applet_and_exit(const char *name, char **argv) |
888 | { | 883 | { |
889 | int applet; | 884 | int applet; |
890 | 885 | ||
@@ -896,6 +891,12 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv) | |||
896 | applet = find_applet_by_name(name); | 891 | applet = find_applet_by_name(name); |
897 | if (applet >= 0) | 892 | if (applet >= 0) |
898 | run_applet_no_and_exit(applet, argv); | 893 | run_applet_no_and_exit(applet, argv); |
894 | |||
895 | /*bb_error_msg_and_die("applet not found"); - links in printf */ | ||
896 | full_write2_str(applet_name); | ||
897 | full_write2_str(": applet not found\n"); | ||
898 | /* POSIX: "If a command is not found, the exit status shall be 127" */ | ||
899 | exit(127); | ||
899 | } | 900 | } |
900 | 901 | ||
901 | #endif /* !defined(SINGLE_APPLET_MAIN) */ | 902 | #endif /* !defined(SINGLE_APPLET_MAIN) */ |
@@ -968,11 +969,5 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
968 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ | 969 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ |
969 | 970 | ||
970 | run_applet_and_exit(applet_name, argv); | 971 | run_applet_and_exit(applet_name, argv); |
971 | |||
972 | /*bb_error_msg_and_die("applet not found"); - sucks in printf */ | ||
973 | full_write2_str(applet_name); | ||
974 | full_write2_str(": applet not found\n"); | ||
975 | /* POSIX: "If a command is not found, the exit status shall be 127" */ | ||
976 | exit(127); | ||
977 | #endif | 972 | #endif |
978 | } | 973 | } |