diff options
Diffstat (limited to 'stap-serverd')
-rwxr-xr-x | stap-serverd | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/stap-serverd b/stap-serverd index 45aacf63..b46a4254 100755 --- a/stap-serverd +++ b/stap-serverd @@ -23,13 +23,21 @@ trap 'terminate' SIGTERM SIGINT function initialization { # Default settings. avahi_type=_stap._tcp + + # We need either netcat or nc. + netcat=`which netcat 2>/dev/null` + test "X$netcat" = "X" && netcat=`which nc 2>/dev/null` + test "X$netcat" = "X" && fatal "ERROR: cannot find required program 'netcat' or 'nc' on PATH" + + # See if the given port, or the default port is busy. If so, select another. port=$1 test "X$port" = "X" && port=65000 - export port2=$(($port + 1)) - if netstat -atn | awk '{print $4}' | cut -f2 -d: | egrep -q "^($port|$port2)\$"; then + port2=$(($port + 1)) + while netstat -atn | awk '{print $4}' | cut -f2 -d: | egrep -q "^($port|$port2)\$"; do # Whoops, the port is busy; try another one. - initialization $((1024+($port + $RANDOM)%64000)) - fi + port=$((1024+($port + $RANDOM)%64000)) + port2=$(($port + 1)) + done } # function: advertise_presence @@ -57,8 +65,8 @@ function listen { do for ((attempt=0; $attempt < 5; ++attempt)) do - nc -ld $port 2>/dev/null | process_request & - wait '%nc -l' + $netcat -ld $port 2>/dev/null | process_request & + wait '%$netcat -l' rc=$? if test $rc = 0 -o $rc = 127; then break; # port was read ok @@ -111,11 +119,11 @@ function terminate { # Kill any running 'stap-server' job. kill -s SIGTERM "%stap-server" 2> /dev/null - wait "%stap-server" >/dev/null 2>&1 + wait '%stap-server' >/dev/null 2>&1 - # Kill any running 'nc -l' job. - kill -s SIGTERM "%?nc -l" 2> /dev/null - wait "%?nc - l" >/dev/null 2>&1 + # Kill any running '$netcat -l' job. + kill -s SIGTERM '%$netcat -l' 2>/dev/null + wait '%$netcat -l' >/dev/null 2>&1 exit } |