diff options
author | Mark Wielaard <mjw@redhat.com> | 2009-03-17 16:58:35 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2009-03-17 16:58:35 +0100 |
commit | bf33ee46c8fff4d181b7f28521f12175bd32ec77 (patch) | |
tree | 5e0a9e1047af60389eee36da54182b52d3d53ee7 /stap-find-servers | |
parent | 524c6f82b0a3c010d0fd6a67b1afcfbf55b789a6 (diff) | |
parent | 30cb532a560ed152b86506b80490e99195970271 (diff) | |
download | systemtap-steved-bf33ee46c8fff4d181b7f28521f12175bd32ec77.tar.gz systemtap-steved-bf33ee46c8fff4d181b7f28521f12175bd32ec77.tar.xz systemtap-steved-bf33ee46c8fff4d181b7f28521f12175bd32ec77.zip |
Merge branch 'master' into pr6866
Resolved conflicts:
runtime/task_finder.c: name vs path.
Diffstat (limited to 'stap-find-servers')
-rwxr-xr-x | stap-find-servers | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/stap-find-servers b/stap-find-servers index 3038c54e..fde7d9ef 100755 --- a/stap-find-servers +++ b/stap-find-servers @@ -2,7 +2,7 @@ # Find compile servers for systemtap # -# Copyright (C) 2008 Red Hat Inc. +# Copyright (C) 2008, 2009 Red Hat Inc. # # This file is part of systemtap, and is free software. You can # redistribute it and/or modify it under the terms of the GNU General @@ -18,6 +18,7 @@ # function: configuration function configuration { avahi_service_tag=_stap._tcp + timeout=10 # seconds } # function: initialization @@ -30,13 +31,32 @@ function initialization { fi } -# function: find_and_connect_to_server +# function: find_servers # -# Find and establish connection with a compatibale stap server. +# Find and establish connection with a compatible stap server. function find_servers { - # Find a server - avahi-browse $avahi_service_tag --terminate -r 2>/dev/null | match_server - rc=$? + # Create a temp file for the list of servers. We do this instead + # of using a pipe so that we can kill avahi-browse if it + # takes more than a minute. + tmpfile=`mktemp -t stap-serversXXXXXX` || \ + fatal "Cannot create temporary file " $tmpfile + + # Find servers + avahi-browse $avahi_service_tag --terminate -r 2>/dev/null > $tmpfile & + + for ((attempt=0; $attempt < $timeout; ++attempt)) + do + if ! jobs '%avahi-browse' >/dev/null 2>&1; then + break + fi + sleep 1 + done + + # Kill avahi-browse, if it's still running + test $attempt = $timeout && kill -s SIGTERM '%avahi-browse' 2>/dev/null + + match_server < $tmpfile + rm -fr $tmpfile } # function: match_server @@ -47,10 +67,11 @@ function match_server { local server_name local server_sysinfo local server_port - local rc=1 # not found yet + + rc=1 # not found yet # Loop over the avahi service descriptors. - read || exit $rc + read -t $timeout || return while test "X$REPLY" != "X" do server_name= @@ -61,14 +82,14 @@ function match_server { # Examine the next service descriptor # Is it a stap server? if ! echo $REPLY | grep -q "=.* .* IPv4 .*_stap"; then - read || exit $rc + read -t $timeout || return continue fi REPLY= # Get the details of the service local service_tag equal service_data - while read service_tag equal service_data + while read -t $timeout service_tag equal service_data do case $service_tag in hostname ) @@ -113,8 +134,6 @@ function match_server { echo "$server_name $server_ip $server_port '$server_sysinfo'" rc=0 done - - exit $rc } # function client_sysinfo @@ -128,6 +147,15 @@ function client_sysinfo { echo sysinfo=$sysinfo_client } +# function: fatal [ MESSAGE ] +# +# Fatal error +# Prints its arguments to stderr and exits +function fatal { + echo "$0: ERROR:" "$@" >&2 + exit 1 +} + #----------------------------------------------------------------------------- # Beginning of main line execution. #----------------------------------------------------------------------------- |