diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index fdfa37225..6e045a1c4 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -308,40 +308,67 @@ function waitforlisten() { local rpc_addr="${2:-$DEFAULT_RPC_ADDR}" + if hash ip; then + local have_ip_cmd=true + else + local have_ip_cmd=false + fi + + if hash ss; then + local have_ss_cmd=true + else + local have_ss_cmd=false + fi + echo "Waiting for process to start up and listen on UNIX domain socket $rpc_addr..." # turn off trace for this loop local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )" set +x local ret=0 - while true; do + local i + for (( i = 40; i != 0; i-- )); do # if the process is no longer running, then exit the script # since it means the application crashed if ! kill -s 0 $1; then + echo "ERROR: process (pid: $1) is no longer running" ret=1 break fi - namespace=$(ip netns identify $1) - if [ -n "$namespace" ]; then - ns_cmd="ip netns exec $namespace" + # FIXME: don't know how to fix this for FreeBSD + if $have_ip_cmd; then + namespace=$(ip netns identify $1) + if [ -n "$namespace" ]; then + ns_cmd="ip netns exec $namespace" + fi fi - if hash ss; then + if $have_ss_cmd; then if $ns_cmd ss -ln | egrep -q "\s+$rpc_addr\s+"; then break fi - else - # if system doesn't have ss, just assume it has netstat + elif [[ "$(uname -s)" == "Linux" ]]; then + # For Linux, if system doesn't have ss, just assume it has netstat if $ns_cmd netstat -an | grep -iw LISTENING | egrep -q "\s+$rpc_addr\$"; then break fi + else + # On FreeBSD netstat output 'State' column is missing for Unix sockets. + # To workaround this issue just try to use provided address. + # XXX: This solution could be used for other distros. + if $rootdir/scripts/rpc.py -t 1 -s "$rpc_addr" get_rpc_methods 1>&2 2>/dev/null; then + break + fi fi + sleep 0.5 done $shell_restore_x - if [ $ret -ne 0 ]; then - exit 1 + if (( i == 0 )); then + echo "ERROR: timeout while waiting for process (pid: $1) to start listening on '$rpc_addr'" + ret=1 fi + return $ret } function waitfornbd() {