[PATCH] libbb: '--help' handling in standalone shell mode

Ron Yorston rmy at pobox.com
Thu Feb 18 07:44:15 UTC 2021


Most BusyBox applets respond to the '--help' option by printing
a usage message.  This is normally handled by busybox_main() so
applet main routines don't have support for '--help'.

In standalone shell mode with FEATURE_SH_NOFORK enabled nofork
applets are invoked directly, bypassing busybox_main().  This
results in inconsistent handling of '--help':

- applets which call getopt() report "unrecognized option '--help'"
  and print help anyway;

- realpath says "--help: No such file or directory" and doesn't
  print help;

- usleep says "invalid number '--help'" and doesn't print help.

Avoid inconsistency by checking for '--help' in run_nofork_applet().

Signed-off-by: Ron Yorston <rmy at pobox.com>
---
 libbb/vfork_daemon_rexec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 65271e84f..a9ce280dd 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -109,6 +109,8 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
 		char *tmp_argv[argc+1];
 		memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0]));
 		applet_name = tmp_argv[0];
+		if (argc == 2 && strcmp(argv[1], "--help") == 0)
+			bb_show_usage();
 		/* Finally we can call NOFORK applet's main() */
 		rc = applet_main[applet_no](argc, tmp_argv);
 		/* Important for shells: `which CMD` was failing */
-- 
2.29.2



More information about the busybox mailing list