Add a non-busy path to safe_sleep for modern versions of bash #3870
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
safe_sleep.sh
is a busy wait.This seems to exist because
sleep
is not a shell builtin, and it can't be assumed all environments have the sleep binary.Bash 4 and above support the builtin
read
command, which can be used as a sleep with the timeout feature. This pattern is described here:https://github.com/dylanaraps/pure-bash-bible?tab=readme-ov-file#use-read-as-an-alternative-to-the-sleep-command
Despite Bash 4 shipping 16 years ago, bash 3.x is still the default shipped on MacOS due to 4+ being licensed as GPL3, so the busy wait was retained as a fallback.
Also the condition in the busy wait was switched from
!=
to-lt
, which is a safer comparison and avoids possibility of an infinite loop.Fixes #2380
#3143 has another similar approach, which relies on conditionally checking for sleep or ping binaries to provide a sleep functionality.