aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-03-01 11:48:04 +0000
committerRon Yorston <rmy@pobox.com>2021-03-01 11:48:04 +0000
commite2e8e16b465d34759678b8170c44ce62c5b74eb0 (patch)
treeabc31e3e2c1d0de089ae5e1e6d37672394757af9 /libbb/appletlib.c
parentb5cd41cdf4e6afd475fe34b755f99578e20b08ca (diff)
parent9b6bcfda0e11c0e73a966a77110f6c68425cff34 (diff)
downloadbusybox-w32-e2e8e16b465d34759678b8170c44ce62c5b74eb0.tar.gz
busybox-w32-e2e8e16b465d34759678b8170c44ce62c5b74eb0.tar.bz2
busybox-w32-e2e8e16b465d34759678b8170c44ce62c5b74eb0.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c70
1 files changed, 40 insertions, 30 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 1587cf36f..846417d59 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1034,6 +1034,34 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
1034# endif 1034# endif
1035 1035
1036# if NUM_APPLETS > 0 1036# if NUM_APPLETS > 0
1037void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv)
1038{
1039 /* Special case. POSIX says "test --help"
1040 * should be no different from e.g. "test --foo".
1041 * Thus for "test", we skip --help check.
1042 * "true" and "false" are also special.
1043 */
1044 if (1
1045# if defined APPLET_NO_test
1046 && applet_no != APPLET_NO_test
1047# endif
1048# if defined APPLET_NO_true
1049 && applet_no != APPLET_NO_true
1050# endif
1051# if defined APPLET_NO_false
1052 && applet_no != APPLET_NO_false
1053# endif
1054# if defined APPLET_NO_busybox
1055 && applet_no != APPLET_NO_busybox
1056# endif
1057 ) {
1058 if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) {
1059 /* Make "foo --help" exit with 0: */
1060 xfunc_error_retval = 0;
1061 bb_show_usage();
1062 }
1063 }
1064}
1037 1065
1038# if ENABLE_PLATFORM_MINGW32 1066# if ENABLE_PLATFORM_MINGW32
1039static int interp = 0; 1067static int interp = 0;
@@ -1043,11 +1071,13 @@ char bb_command_line[128];
1043 1071
1044void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) 1072void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
1045{ 1073{
1046 int argc = string_array_len(argv);
1047# if ENABLE_PLATFORM_MINGW32 1074# if ENABLE_PLATFORM_MINGW32
1075 int argc = string_array_len(argv);
1048 int i; 1076 int i;
1049 const char *vmask; 1077 const char *vmask;
1050 unsigned int mask; 1078 unsigned int mask;
1079# else
1080 int argc;
1051# endif 1081# endif
1052 1082
1053 /* 1083 /*
@@ -1055,6 +1085,12 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
1055 * "-/sbin/halt" -> "halt", for example. 1085 * "-/sbin/halt" -> "halt", for example.
1056 */ 1086 */
1057 applet_name = name; 1087 applet_name = name;
1088
1089 show_usage_if_dash_dash_help(applet_no, argv);
1090
1091 if (ENABLE_FEATURE_SUID)
1092 check_suid(applet_no);
1093
1058# if ENABLE_PLATFORM_MINGW32 1094# if ENABLE_PLATFORM_MINGW32
1059 safe_strncpy(bb_comm, 1095 safe_strncpy(bb_comm,
1060 interp ? bb_basename(argv[interp]) : applet_name, 1096 interp ? bb_basename(argv[interp]) : applet_name,
@@ -1069,37 +1105,11 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
1069 vmask = getenv("BB_UMASK"); 1105 vmask = getenv("BB_UMASK");
1070 if (vmask && sscanf(vmask, "%o", &mask) == 1) 1106 if (vmask && sscanf(vmask, "%o", &mask) == 1)
1071 umask((mode_t)(mask&0777)); 1107 umask((mode_t)(mask&0777));
1108# else
1109 argc = string_array_len(argv);
1072# endif 1110# endif
1073
1074 /* Special case. POSIX says "test --help"
1075 * should be no different from e.g. "test --foo".
1076 * Thus for "test", we skip --help check.
1077 * "true" and "false" are also special.
1078 */
1079 if (1
1080# if defined APPLET_NO_test
1081 && applet_no != APPLET_NO_test
1082# endif
1083# if defined APPLET_NO_true
1084 && applet_no != APPLET_NO_true
1085# endif
1086# if defined APPLET_NO_false
1087 && applet_no != APPLET_NO_false
1088# endif
1089# if defined APPLET_NO_busybox
1090 && applet_no != APPLET_NO_busybox
1091# endif
1092 ) {
1093 if (argc == 2 && strcmp(argv[1], "--help") == 0) {
1094 /* Make "foo --help" exit with 0: */
1095 xfunc_error_retval = 0;
1096 bb_show_usage();
1097 }
1098 }
1099 if (ENABLE_FEATURE_SUID)
1100 check_suid(applet_no);
1101
1102 xfunc_error_retval = applet_main[applet_no](argc, argv); 1111 xfunc_error_retval = applet_main[applet_no](argc, argv);
1112
1103 /* Note: applet_main() may also not return (die on a xfunc or such) */ 1113 /* Note: applet_main() may also not return (die on a xfunc or such) */
1104 xfunc_die(); 1114 xfunc_die();
1105} 1115}