summaryrefslogtreecommitdiffstats
path: root/stap-serverd
diff options
context:
space:
mode:
authorDave Brolley <brolley@redhat.com>2008-12-09 15:31:00 -0500
committerDave Brolley <brolley@redhat.com>2008-12-09 15:31:00 -0500
commit309cc9ecf51b082d6de8f1c3b0028c398daa395f (patch)
tree1dbfaf6a68ea919bd3df775b8e46992f6fd97498 /stap-serverd
parent4ffc629674ac7d1d84b93cb7fdca71953983f762 (diff)
downloadsystemtap-steved-309cc9ecf51b082d6de8f1c3b0028c398daa395f.tar.gz
systemtap-steved-309cc9ecf51b082d6de8f1c3b0028c398daa395f.tar.xz
systemtap-steved-309cc9ecf51b082d6de8f1c3b0028c398daa395f.zip
Use netcat or nc, whichever is available.
Diffstat (limited to 'stap-serverd')
-rwxr-xr-xstap-serverd28
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
}