diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-02-18 23:30:24 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-02-18 23:30:24 +0100 |
commit | 6bdfbc4cb5470f63d4905e89f89a9829af354316 (patch) | |
tree | 573f2b655d4944d4e5e9e7627f18c8a4bb1ebeaa /libbb/vfork_daemon_rexec.c | |
parent | 33745b1fc8cc6d41f4e708d67800d296668af2ce (diff) | |
download | busybox-w32-6bdfbc4cb5470f63d4905e89f89a9829af354316.tar.gz busybox-w32-6bdfbc4cb5470f63d4905e89f89a9829af354316.tar.bz2 busybox-w32-6bdfbc4cb5470f63d4905e89f89a9829af354316.zip |
libbb: fix '--help' handling in FEATURE_SH_NOFORK=y
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().
Bug found by Ron Yorston.
function old new delta
show_usage_if_dash_dash_help - 70 +70
run_nofork_applet 347 362 +15
run_applet_no_and_exit 432 365 -67
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 85/-67) Total: 18 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 65271e84f..a49fe8e01 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -109,8 +109,13 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) | |||
109 | char *tmp_argv[argc+1]; | 109 | char *tmp_argv[argc+1]; |
110 | memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0])); | 110 | memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0])); |
111 | applet_name = tmp_argv[0]; | 111 | applet_name = tmp_argv[0]; |
112 | |||
113 | /* longjmp's (instead of returning) if --help is seen */ | ||
114 | show_usage_if_dash_dash_help(applet_no, argv); | ||
115 | |||
112 | /* Finally we can call NOFORK applet's main() */ | 116 | /* Finally we can call NOFORK applet's main() */ |
113 | rc = applet_main[applet_no](argc, tmp_argv); | 117 | rc = applet_main[applet_no](argc, tmp_argv); |
118 | |||
114 | /* Important for shells: `which CMD` was failing */ | 119 | /* Important for shells: `which CMD` was failing */ |
115 | fflush_all(); | 120 | fflush_all(); |
116 | } else { | 121 | } else { |