aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-07-07 14:28:08 +0100
committerRon Yorston <rmy@pobox.com>2016-07-07 14:58:55 +0100
commit613f46218c53c8cabdbf0435653e74e0e0e91e1c (patch)
treeca06a7e7a3e4c861441acb4ea20648d7827fa6ae /libbb/appletlib.c
parenta0c61c9492723dd31681f878f9c68c92817a476d (diff)
parent237bedd499c58034a1355484d6d4d906f0180308 (diff)
downloadbusybox-w32-613f46218c53c8cabdbf0435653e74e0e0e91e1c.tar.gz
busybox-w32-613f46218c53c8cabdbf0435653e74e0e0e91e1c.tar.bz2
busybox-w32-613f46218c53c8cabdbf0435653e74e0e0e91e1c.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index c528c8a2c..28adf2740 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -52,7 +52,6 @@
52 52
53#include "usage_compressed.h" 53#include "usage_compressed.h"
54 54
55
56#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE 55#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
57static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; 56static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
58#else 57#else
@@ -730,7 +729,7 @@ static void install_links(const char *busybox,
730 } 729 }
731} 730}
732# endif 731# endif
733# else 732# elif ENABLE_BUSYBOX
734static void install_links(const char *busybox UNUSED_PARAM, 733static void install_links(const char *busybox UNUSED_PARAM,
735 int use_symbolic_links UNUSED_PARAM, 734 int use_symbolic_links UNUSED_PARAM,
736 char *custom_install_dir UNUSED_PARAM) 735 char *custom_install_dir UNUSED_PARAM)
@@ -738,6 +737,9 @@ static void install_links(const char *busybox UNUSED_PARAM,
738} 737}
739# endif 738# endif
740 739
740# if ENABLE_BUSYBOX
741static void run_applet_and_exit(const char *name, char **argv) NORETURN;
742
741/* If we were called as "busybox..." */ 743/* If we were called as "busybox..." */
742static int busybox_main(char **argv) 744static int busybox_main(char **argv)
743{ 745{
@@ -828,10 +830,10 @@ static int busybox_main(char **argv)
828 const char *a = applet_names; 830 const char *a = applet_names;
829 dup2(1, 2); 831 dup2(1, 2);
830 while (*a) { 832 while (*a) {
831# if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 833# if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32
832 if (argv[1][6]) /* --list-full? */ 834 if (argv[1][6]) /* --list-full? */
833 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); 835 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
834# endif 836# endif
835 full_write2_str(a); 837 full_write2_str(a);
836 full_write2_str("\n"); 838 full_write2_str("\n");
837 i++; 839 i++;
@@ -889,14 +891,10 @@ static int busybox_main(char **argv)
889 * "#!/bin/busybox"-style wrappers */ 891 * "#!/bin/busybox"-style wrappers */
890 applet_name = bb_get_last_path_component_nostrip(argv[0]); 892 applet_name = bb_get_last_path_component_nostrip(argv[0]);
891 run_applet_and_exit(applet_name, argv); 893 run_applet_and_exit(applet_name, argv);
892
893 /*bb_error_msg_and_die("applet not found"); - sucks in printf */
894 full_write2_str(applet_name);
895 full_write2_str(": applet not found\n");
896 /* POSIX: "If a command is not found, the exit status shall be 127" */
897 exit(127);
898} 894}
895# endif
899 896
897# if NUM_APPLETS > 0
900void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) 898void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
901{ 899{
902 int argc = 1; 900 int argc = 1;
@@ -914,15 +912,15 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
914 * "true" and "false" are also special. 912 * "true" and "false" are also special.
915 */ 913 */
916 if (1 914 if (1
917#if defined APPLET_NO_test 915# if defined APPLET_NO_test
918 && applet_no != APPLET_NO_test 916 && applet_no != APPLET_NO_test
919#endif 917# endif
920#if defined APPLET_NO_true 918# if defined APPLET_NO_true
921 && applet_no != APPLET_NO_true 919 && applet_no != APPLET_NO_true
922#endif 920# endif
923#if defined APPLET_NO_false 921# if defined APPLET_NO_false
924 && applet_no != APPLET_NO_false 922 && applet_no != APPLET_NO_false
925#endif 923# endif
926 ) { 924 ) {
927 if (argc == 2 && strcmp(argv[1], "--help") == 0) { 925 if (argc == 2 && strcmp(argv[1], "--help") == 0) {
928 /* Make "foo --help" exit with 0: */ 926 /* Make "foo --help" exit with 0: */
@@ -934,17 +932,28 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
934 check_suid(applet_no); 932 check_suid(applet_no);
935 exit(applet_main[applet_no](argc, argv)); 933 exit(applet_main[applet_no](argc, argv));
936} 934}
935# endif /* NUM_APPLETS > 0 */
937 936
938void FAST_FUNC run_applet_and_exit(const char *name, char **argv) 937static NORETURN void run_applet_and_exit(const char *name, char **argv)
939{ 938{
940 int applet; 939# if ENABLE_BUSYBOX
941
942 if (is_prefixed_with(name, "busybox")) 940 if (is_prefixed_with(name, "busybox"))
943 exit(busybox_main(argv)); 941 exit(busybox_main(argv));
942# endif
943# if NUM_APPLETS > 0
944 /* find_applet_by_name() search is more expensive, so goes second */ 944 /* find_applet_by_name() search is more expensive, so goes second */
945 applet = find_applet_by_name(name); 945 {
946 if (applet >= 0) 946 int applet = find_applet_by_name(name);
947 run_applet_no_and_exit(applet, argv); 947 if (applet >= 0)
948 run_applet_no_and_exit(applet, argv);
949 }
950# endif
951
952 /*bb_error_msg_and_die("applet not found"); - links in printf */
953 full_write2_str(applet_name);
954 full_write2_str(": applet not found\n");
955 /* POSIX: "If a command is not found, the exit status shall be 127" */
956 exit(127);
948} 957}
949 958
950#endif /* !defined(SINGLE_APPLET_MAIN) */ 959#endif /* !defined(SINGLE_APPLET_MAIN) */
@@ -1017,6 +1026,10 @@ int main(int argc UNUSED_PARAM, char **argv)
1017#else 1026#else
1018 lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); 1027 lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));
1019 1028
1029# if !ENABLE_BUSYBOX
1030 if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox"))
1031 argv++;
1032# endif
1020 applet_name = argv[0]; 1033 applet_name = argv[0];
1021 if (applet_name[0] == '-') 1034 if (applet_name[0] == '-')
1022 applet_name++; 1035 applet_name++;
@@ -1048,11 +1061,5 @@ int main(int argc UNUSED_PARAM, char **argv)
1048 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ 1061 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
1049 1062
1050 run_applet_and_exit(applet_name, argv); 1063 run_applet_and_exit(applet_name, argv);
1051
1052 /*bb_error_msg_and_die("applet not found"); - sucks in printf */
1053 full_write2_str(applet_name);
1054 full_write2_str(": applet not found\n");
1055 /* POSIX: "If a command is not found, the exit status shall be 127" */
1056 exit(127);
1057#endif 1064#endif
1058} 1065}