Skip to content

Commit

Permalink
scripts: Use gtimeout instead of timeout when available (#260).
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
s3rvac authored and mbandzi committed Apr 9, 2018
1 parent 7dc2823 commit 7c6c000
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
17 changes: 1 addition & 16 deletions scripts/retdec-archive-decompiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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.
##
Expand Down Expand Up @@ -187,7 +172,7 @@ for ((INDEX=0; INDEX<FILE_COUNT; INDEX++)); do

# We have to use indexes instead of names because archives can contain multiple files with same name.
LOG_FILE="$LIBRARY_PATH.file_$FILE_INDEX.log.verbose" # Do not escape!
timeout $TIMEOUT "$DECOMPILE_SH" --ar-index="$INDEX" -o "$LIBRARY_PATH.file_$FILE_INDEX" "$LIBRARY_PATH" $DECOMPILE_SH_ARGS > "$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.
Expand Down
11 changes: 11 additions & 0 deletions scripts/retdec-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7c6c000

Please sign in to comment.