aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2021-03-09 08:43:43 +0300
committerCem Keylan <cem@ckyln.com>2021-03-09 08:43:43 +0300
commit7ccc9c2432a847b85da5f445977d09f014cbc75b (patch)
tree8067d45ebeea60f1ddaa8167cb1398e2b6631473 /libbb/appletlib.c
parentfef526c380e35cbdc0bdb8375487756c42659a75 (diff)
parent307cd26e9893ed0cf6ee88e7fca2d61d3da0e139 (diff)
downloadbusybox-master.tar.gz
Merge remote-tracking branch 'upstream/master'HEADmaster
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 542211255..67c540abb 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -905,16 +905,8 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
# endif
# if NUM_APPLETS > 0
-void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
+void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv)
{
- int argc = string_array_len(argv);
-
- /*
- * We do not use argv[0]: do not want to repeat massaging of
- * "-/sbin/halt" -> "halt", for example.
- */
- applet_name = name;
-
/* Special case. POSIX says "test --help"
* should be no different from e.g. "test --foo".
* Thus for "test", we skip --help check.
@@ -931,15 +923,32 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
&& applet_no != APPLET_NO_false
# endif
) {
- if (argc == 2 && strcmp(argv[1], "--help") == 0) {
+ if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) {
/* Make "foo --help" exit with 0: */
xfunc_error_retval = 0;
bb_show_usage();
}
}
+}
+
+void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
+{
+ int argc;
+
+ /*
+ * We do not use argv[0]: do not want to repeat massaging of
+ * "-/sbin/halt" -> "halt", for example.
+ */
+ applet_name = name;
+
+ show_usage_if_dash_dash_help(applet_no, argv);
+
if (ENABLE_FEATURE_SUID)
check_suid(applet_no);
+
+ argc = string_array_len(argv);
xfunc_error_retval = applet_main[applet_no](argc, argv);
+
/* Note: applet_main() may also not return (die on a xfunc or such) */
xfunc_die();
}