From e387209c108b232ca625ce227ecea3a41f1db7ef Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Thu, 26 Mar 2026 14:43:12 +0100 Subject: [PATCH] busy can properly exit, pattern can not inject code --- profile.d/fun.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/profile.d/fun.sh b/profile.d/fun.sh index 530c758..33c75c8 100644 --- a/profile.d/fun.sh +++ b/profile.d/fun.sh @@ -88,19 +88,23 @@ busy() esac done - # If a pattern was provided as a positional argument (e.g., 'busy "ff 00"'), - # it is captured here. - [[ -n "$1" ]] && pattern="$1" - # Convert milliseconds to seconds for 'sleep' - local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }") + local delay_s=$(awk "BEGIN{ + printf \"%.3f\", $delay_ms / 1000 }") # Monitor /dev/urandom - cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \ - while read -r line; do - echo "$line" - [[ $delay_ms -gt 0 ]] && sleep "$delay_s" - done + ( + hexdump -C < /dev/urandom | grep -iF --line-buffered "$pattern" | \ + while read -r line; do + echo "$line" + [[ $delay_ms -gt 0 ]] && sleep "$delay_s" + done + ) & local sub_pid=$! + + IFS= read -r -n 1 -s _ /dev/null || kill "$sub_pid" 2>/dev/null + wait "$sub_pid" 2>/dev/null + return 0 } # ------------------------------------------------------------------------------