From 7c6c000ff53586b14fa22050587b2d86fb6b48a3 Mon Sep 17 00:00:00 2001 From: Petr Zemek Date: Sat, 31 Mar 2018 10:47:36 +0200 Subject: [PATCH] scripts: Use gtimeout instead of timeout when available (#260). Before this commit, retdec-archive-decompiler.sh on macOS failed with the following error: $ retdec-archive-decompiler.sh error: The `timeout` command is required but it is not available. Aborting. The reason for this is that on macOS, timeout from GNU coreutils is installed as gtimeout (unless you have installed coreutils with `brew install coreutils --with-default-names`). The present commit updates the script so it uses gtimeout when available (we already do the same for e.g. greadlink and gha256sum). --- scripts/retdec-archive-decompiler.sh | 17 +---------------- scripts/retdec-utils.sh | 11 +++++++++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/retdec-archive-decompiler.sh b/scripts/retdec-archive-decompiler.sh index d86f5c2d1..2469924f7 100644 --- a/scripts/retdec-archive-decompiler.sh +++ b/scripts/retdec-archive-decompiler.sh @@ -3,10 +3,6 @@ # Runs the decompilation script with the given arguments over all files in the # given static library. # -# Requirements: -# - bash -# - the `timeout` command -# # On macOS, we want the GNU version of 'readlink', which is available under # 'greadlink': @@ -27,17 +23,6 @@ fi . "$DECOMPILER_UTILS" -## -## Check that all script requirements are satisfied. -## -for CMD in "timeout"; do - command -v $CMD > /dev/null 2>&1 || { - echo "error: The \`$CMD\` command is required but it is not" \ - "available. Aborting." >&2 - exit 1 - } -done - ## ## Configuration. ## @@ -187,7 +172,7 @@ for ((INDEX=0; INDEX "$LOG_FILE" 2>&1 + gnutimeout $TIMEOUT "$DECOMPILE_SH" --ar-index="$INDEX" -o "$LIBRARY_PATH.file_$FILE_INDEX" "$LIBRARY_PATH" $DECOMPILE_SH_ARGS > "$LOG_FILE" 2>&1 RC=$? # Print status. diff --git a/scripts/retdec-utils.sh b/scripts/retdec-utils.sh index efaf39c18..82ee7ddbd 100644 --- a/scripts/retdec-utils.sh +++ b/scripts/retdec-utils.sh @@ -22,6 +22,17 @@ fi . "$DECOMPILER_CONFIG" +# On macOS, 'timeout' from GNU coreutils is by default available under +# 'gtimeout'. +gnutimeout() +{ + if hash gtimeout 2> /dev/null; then + gtimeout "$@" + else + timeout "$@" + fi +} + # # Prints the real, physical location of a directory or file, relative or # absolute.