Skip to content

Commit

Permalink
Update bits-info.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ale5000-git authored Nov 1, 2024
1 parent 7633133 commit 50bd51d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tools/bits-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -954,14 +954,15 @@ detect_bits_of_cut_b()
printf '%s\n' "${_dbcb_max}"
}

detect_bits_of_cut_b_timeout()
code_timeout()
{
local _sec_limit _pid _bg_status
local _func_name _sec_limit _pid _bg_status

_sec_limit="${1}"
shift
_func_name="${1}"
_sec_limit="${2}"
shift 2

detect_bits_of_cut_b "${@}" &
"${_func_name}" 2>&3 "${@}" &
_pid="${!}"
if test -z "${_pid}" || test "${_pid}" = "${$}" || test "${_pid}" -le 1; then return 126; fi # Seriously broken shell

Expand All @@ -971,8 +972,8 @@ detect_bits_of_cut_b_timeout()
: # Still running
else
_bg_status=0
wait 1>&2 "${_pid}" || _bg_status="${?}"
test "${_bg_status}" != 127 || return 0 # On some shells wait does NOT work correctly and return 127
wait 1>&3 2>&3 "${_pid}" || _bg_status="${?}"
test "${_bg_status}" != 127 || return 0 # On some shells "wait" misbehave and return 127 even on success
return "${_bg_status}"
fi
done
Expand Down Expand Up @@ -1242,7 +1243,7 @@ main()
case "${cut_version}" in
# The "cut" of "GNU textutils 1.5" does NOT freeze (so no timeout needed) but shells that come with this old "cut" may NOT support background processes
*'GNU textutils'*) _max="$(detect_bits_of_cut_b "${limits_s_u}" "${operative_system}")" || _max='-1' ;;
*) _max="$(detect_bits_of_cut_b_timeout 1 "${limits_s_u}" "${operative_system}")" || _max='-1' ;;
*) _max="$(code_timeout 3>&2 2>/dev/null detect_bits_of_cut_b 1 "${limits_s_u}" "${operative_system}")" || _max='-1' ;;
esac
cut_b_bit="$(convert_max_unsigned_int_to_bit "${_max}" 'true' || :)"

Expand Down

0 comments on commit 50bd51d

Please sign in to comment.