summaryrefslogtreecommitdiffstats
path: root/stap-serverd
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2009-01-23 14:28:47 +0100
committerMark Wielaard <mjw@redhat.com>2009-01-23 14:28:47 +0100
commitc3bad3042df505a3470f1e20b09822a9df1d4761 (patch)
tree6842e8eaa705e406379d34cf07a85431b6d71344 /stap-serverd
parent750b1f2f5c84acaf0776de5239dc81e2e95c1dec (diff)
parentf120873cb40cfc16cc94f06fd722abc927b96227 (diff)
downloadsystemtap-steved-c3bad3042df505a3470f1e20b09822a9df1d4761.tar.gz
systemtap-steved-c3bad3042df505a3470f1e20b09822a9df1d4761.tar.xz
systemtap-steved-c3bad3042df505a3470f1e20b09822a9df1d4761.zip
Merge branch 'master' into pr6866.
Diffstat (limited to 'stap-serverd')
-rwxr-xr-xstap-serverd91
1 files changed, 39 insertions, 52 deletions
diff --git a/stap-serverd b/stap-serverd
index b46a4254..1c227e6c 100755
--- a/stap-serverd
+++ b/stap-serverd
@@ -2,7 +2,7 @@
# Compile server manager 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
@@ -24,20 +24,42 @@ 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"
+ # Where are we installed?
+ exec_prefix=`dirname $0`
+ exec_prefix=`cd $exec_prefix && pwd`
+ prefix=`dirname $exec_prefix`
- # See if the given port, or the default port is busy. If so, select another.
+ # What port will we listen on?
port=$1
test "X$port" = "X" && port=65000
- port2=$(($port + 1))
- while netstat -atn | awk '{print $4}' | cut -f2 -d: | egrep -q "^($port|$port2)\$"; do
+ while netstat -atn | awk '{print $4}' | cut -f2 -d: | egrep -q "^$port\$";
+ do
# Whoops, the port is busy; try another one.
+ echo "$0: Port $port is busy"
port=$((1024+($port + $RANDOM)%64000))
- port2=$(($port + 1))
done
+
+ # Where is the ssl certificate/key database?
+ ssl_db=$2
+ if test "X$ssl_db" = "X"; then
+ # If no certificate/key database has been specified, then find/create
+ # a local one.
+ if test $EUID = 0; then
+ ssl_db=$prefix/etc/systemtap/ssl/server
+ else
+ ssl_db=$HOME/.systemtap/ssl/server
+ fi
+ if ! test -f $ssl_db/stap-server.cert; then
+ $exec_prefix/stap-gen-server-cert `dirname $ssl_db` || exit 1
+ # Now add the server's certificate to the client's database,
+ # making it a trusted peer. Do this only if the client has been installed.
+ if test -f $exec_prefix/stap-add-server-cert -a -f $exec_prefix/stap-add-server-cert; then
+ $exec_prefix/stap-add-server-cert $ssl_db/stap-server.cert `dirname $ssl_db`
+ fi
+ fi
+ fi
+ nss_pw=$ssl_db/pw
+ nss_cert=stap-server
}
# function: advertise_presence
@@ -60,41 +82,10 @@ function advertise_presence {
#
# Listen for and handle requests to the server.
function listen {
- # Loop forever accepting requests
- while true
- do
- for ((attempt=0; $attempt < 5; ++attempt))
- do
- $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
- fi
- done
- if test $attempt = 5; then
- fatal "ERROR: cannot listen on port $port. rc==$rc"
- fi
- done
-}
-
-# function: process_request
-#
-# Process an incoming request on stdin
-function process_request {
- read
- case $REPLY in
- request:)
- stap-server $port2 >/dev/null 2>&1 &
- wait '%stap-server'
- rc=$?
- test $rc = 127 && rc=0
- ;;
- *)
- rc=1
- esac
-
- exit $rc
+ # The stap-server-connect program will listen forever
+ # accepting requests.
+ $exec_prefix/stap-server-connect -p $port -n $nss_cert -d $ssl_db -w $nss_pw 2>&1 &
+ wait '%$exec_prefix/stap-server-connect' >/dev/null 2>&1
}
# function: fatal [ MESSAGE ]
@@ -114,16 +105,12 @@ function terminate {
echo "$0: Exiting"
# Kill the running 'avahi-publish-service' job
- kill -s SIGTERM %avahi-publish-service 2> /dev/null
+ kill -s SIGTERM '%avahi-publish-service' 2> /dev/null
wait '%avahi-publish-service' >/dev/null 2>&1
- # Kill any running 'stap-server' job.
- kill -s SIGTERM "%stap-server" 2> /dev/null
- wait '%stap-server' >/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
+ # Kill any running 'stap-server-connect' job.
+ kill -s SIGTERM '%$exec_prefix/stap-server-connect' 2> /dev/null
+ wait '%$exec_prefix/stap-server-connect' >/dev/null 2>&1
exit
}