commit 054e9cdec4226bc1c4d9225d28328c369a2274b1
parent 416175de671e057232d0c87aea1bfcf035cceb19
Author: hhvn <hayden@hhvn.uk>
Date: Mon, 24 May 2021 22:51:34 +0100
functions.sh: slurp stdin for timeout()
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/functions.sh b/functions.sh
@@ -52,6 +52,7 @@ match_raw(){
# timeout(time, command)
timeout(){
+ stdin=$(cat)
tmpfile="$tmpdir/$(printf '%s%s\n' "$(date +%s)" "$(head -n 1 /dev/urandom | base64 | head -n 1 | cut -c-10)" | tr '/' '%')"
time="$1"
shift
@@ -61,7 +62,7 @@ timeout(){
(
sleep 0.1 # for $!
- "$@"
+ printf '%s\n' "$stdin" | "$@"
ret=$?
rm "$tmpfile"
) &
@@ -72,7 +73,7 @@ timeout(){
# tmpfile hasn't been removed, should be
# safe to kill now..
- printf "Timeout, killing: %s\n" "$@"
+ printf "Timeout, killing: %s (%s)\n" "$pid" "$*"
kill -9 "$pid"
rm "$tmpfile"
return 1