From e8b5440b6f160467173a1eadb9e29de00f8902f5 Mon Sep 17 00:00:00 2001 From: Tom Scavo Date: Sat, 12 Nov 2016 16:47:31 -0500 Subject: [PATCH] Relax constraints on timeout options --- bin/check_idp_error_urls.sh | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/bin/check_idp_error_urls.sh b/bin/check_idp_error_urls.sh index c3aacd3..9c2825e 100755 --- a/bin/check_idp_error_urls.sh +++ b/bin/check_idp_error_urls.sh @@ -30,7 +30,7 @@ display_help () { Given a list of entityIDs and a metadata source, for each IdP probe its errorURL in metadata (if any). - Usage: ${0##*/} [-hvq] [-d OUT_DIR] [-t CONNECT_TIME -m MAX_TIME] (-u MDQ_BASE_URL | -f MD_PATH) [ID ...] + Usage: ${0##*/} [-hvq] [-d OUT_DIR] [-t CONNECT_TIME [-m MAX_TIME]] (-u MDQ_BASE_URL | -f MD_PATH) [ID ...] The script optionally takes a sequence of identifiers on the command line. If none are given, the script takes its input from stdin. @@ -61,12 +61,16 @@ display_help () { consume all available TCP connect time. Thus the TCP connect time should be kept small (say, less than 10 seconds) since larger values will slow this script considerably. The default - value of this option argument is $connect_timeout_default secs. + value of this option is $connect_timeout_default secs. The argument of the -m option is the maximum total time (in secs) allotted to each probe. A reasonable value is a few seconds beyond the TCP connect time. Any value less than the TCP connect - time causes the script to immediately fail. + time causes the script to immediately fail. If the -m option is + present on the command line, then the -t option must also be + present. If the -m option is omitted, its value is set to the + TCP connect time plus 2 secs, whether or not the -t option is + present. Entity metadata is required to process each identifier. Metadata is obtained in one of two ways, by consulting a Metadata Query Server @@ -251,9 +255,8 @@ for lib_filename in $LIB_FILENAMES; do fi done -# default parameters +# default timeout option connect_timeout_default=2 -max_time_default=4 # output filenames NO_IDP_ROLE_FILENAME="entities-no-idp-role.txt" @@ -320,7 +323,7 @@ if $help_mode; then exit 0 fi -# report bootstrap operation +# report bootstrap operations if $verbose_mode; then printf "$script_name using source lib directory: %s\n" "$LIB_DIR" for lib_filename in $LIB_FILENAMES; do @@ -376,23 +379,32 @@ else fi fi -# check consistency of timeout options (both or neither are required) -if [ -z "$connect_timeout" -a -z "$max_time" ]; then +# check consistency of timeout options +if [ -n "$max_time" -a -z "$connect_timeout" ]; then + echo "ERROR: $script_name: the -m option requires the presence of the -t option" >&2 + exit 2 +fi + +# set default connect timeout if necessary +if [ -z "$connect_timeout" ]; then connect_timeout=$connect_timeout_default - max_time=$max_time_default -elif [ -n "$connect_timeout" -a -n "$max_time" ]; then - if [ ! "${connect_timeout}" -gt 0 ] ; then - echo "ERROR: $script_name: connect timeout must be a positive integer: ${connect_timeout}" >&2 +else + if [ "$connect_timeout" -le 0 ] ; then + echo "ERROR: $script_name: connect timeout ($connect_timeout) must be a positive integer" >&2 exit 2 fi - if [ ! "${max_time}" -gt "${connect_timeout}" ]; then - echo "ERROR: $script_name: max time must be greater than the connect timeout: ${max_time}" >&2 +fi + +# compute max time if necessary +if [ -z "$max_time" ]; then + max_time=$(( connect_timeout + 2 )) +else + if [ "$max_time" -le "$connect_timeout" ]; then + echo "ERROR: $script_name: max time ($max_time) must be greater than the connect timeout ($connect_timeout)" >&2 exit 2 fi -else - echo "ERROR: $script_name: both (or neither) options -t and -m are required" >&2 - exit 2 fi + if $verbose_mode; then printf "$script_name using connect timeout: %d secs\n" $connect_timeout printf "$script_name using max time: %d secs\n" $max_time