[git commit branch/1_36_stable] ash: sleep builtin with no arguments should not exit
Denys Vlasenko
vda.linux at googlemail.com
Tue Apr 25 14:47:22 UTC 2023
commit: https://git.busybox.net/busybox/commit/?id=d661cb1977def8215c50ae3eed1f9beb2877b862
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable
function old new delta
sleep_main 116 143 +27
.rodata 105245 105268 +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0) Total: 50 bytes
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
coreutils/sleep.c | 15 ++++++++++++++-
procps/kill.c | 2 +-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/coreutils/sleep.c b/coreutils/sleep.c
index 442841210..667db558d 100644
--- a/coreutils/sleep.c
+++ b/coreutils/sleep.c
@@ -65,15 +65,28 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
{
duration_t duration;
+ /* Note: sleep_main may be directly called from ash as a builtin.
+ * This brings some complications:
+ * + we can't use xfunc here
+ * + we can't use bb_show_usage
+ * + applet_name can be the name of the shell
+ */
++argv;
- if (!*argv)
+ if (!*argv) {
+ /* Without this, bare "sleep" in ash shows _ash_ --help */
+ if (ENABLE_ASH_SLEEP && applet_name[0] != 's') {
+ bb_simple_error_msg("sleep: missing operand");
+ return EXIT_FAILURE;
+ }
bb_show_usage();
+ }
/* GNU sleep accepts "inf", "INF", "infinity" and "INFINITY" */
if (strncasecmp(argv[0], "inf", 3) == 0)
for (;;)
sleep(INT_MAX);
+//FIXME: in ash, "sleep 123qwerty" as a builtin aborts the shell
#if ENABLE_FEATURE_FANCY_SLEEP
duration = 0;
do {
diff --git a/procps/kill.c b/procps/kill.c
index 8f10e21ab..208efebde 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -85,8 +85,8 @@
* This brings some complications:
*
* + we can't use xfunc here
- * + we can't use applet_name
* + we can't use bb_show_usage
+ * + applet_name can be the name of the shell
* (doesn't apply for killall[5], still should be careful b/c NOFORK)
*
* kill %n gets translated into kill ' -<process group>' by shell (note space!)
More information about the busybox-cvs
mailing list