diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2008-08-28 14:44:06 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2008-08-28 14:44:06 -0400 |
commit | 30f926f0b0a198dd416ea735353e852a7ee79d69 (patch) | |
tree | 7c924e8de6a9a38ee904d9793f0bafffc00b8d85 /stap-serverd | |
parent | fb84c077272764f8cb000e9b02572fb7c9cac24f (diff) | |
parent | 84f00e279d98edba986225386c7183db3c5968b0 (diff) | |
download | systemtap-steved-30f926f0b0a198dd416ea735353e852a7ee79d69.tar.gz systemtap-steved-30f926f0b0a198dd416ea735353e852a7ee79d69.tar.xz systemtap-steved-30f926f0b0a198dd416ea735353e852a7ee79d69.zip |
Merge commit 'origin/master' into pr4225
* commit 'origin/master':
PR5686: correct regression in semok/optimize.stp
trailing whitespace removal, as approved by emacs
fix global-var array index rendering
fix NEWS to refer to simpler context.stp tapset functions in auto-printing blurb
Document written but unread global variable automatic display.
2nd try
initial
Make _get_sock_addr return correct address in kernel before 2.6.16.
Automatically print written but unread globals
Make nodwf test passed when CONFIG_QUOTACTL unset
Uses STAPCONF_DPATH_PATH instead of a kernel version check.
Simplified "rpm" target a bit.
Moved tar archive creation step from "rpm" target to "dist-gzip" target.
remove support for "make dist" since git-archive does as well;
Examples html files moved into subdir.
2008-08-25 David Smith <dsmith@redhat.com>
ChangeLog Entries
Robustness improvements for the stap client/server
Diffstat (limited to 'stap-serverd')
-rwxr-xr-x | stap-serverd | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/stap-serverd b/stap-serverd index 6970217d..45aacf63 100755 --- a/stap-serverd +++ b/stap-serverd @@ -22,11 +22,10 @@ trap 'terminate' SIGTERM SIGINT # function: initialization PORT function initialization { # Default settings. - tmpdir_prefix_serverd=stap.serverd avahi_type=_stap._tcp port=$1 test "X$port" = "X" && port=65000 - port2=$(($port + 1)) + export port2=$(($port + 1)) if netstat -atn | awk '{print $4}' | cut -f2 -d: | egrep -q "^($port|$port2)\$"; then # Whoops, the port is busy; try another one. initialization $((1024+($port + $RANDOM)%64000)) @@ -53,43 +52,41 @@ function advertise_presence { # # Listen for and handle requests to the server. function listen { - # Work in a temporary directory - tmpdir=`mktemp -dt $tmpdir_prefix_serverd.XXXXXX` || \ - fatal "ERROR: cannot create temporary directory " $tmpdir - cd $tmpdir - - # Create a fifo for communicating with the server - local fifo_name=$tmpdir_prefix_serverd.fifo - mknod $fifo_name p || \ - fatal "ERROR: cannot create temporary fifo " $tmpdir/$fifo_name - # Loop forever accepting requests - first=1 - set -o pipefail # We want the status of 'nc' not 'stap-server'. while true do - # Run this in the background and wait for it. This way any signals - # received (i.e. SIGTERM) will be processed. Make sure we don't - # advertise our presence until we're actually listening. for ((attempt=0; $attempt < 5; ++attempt)) do - nc -l $port < $fifo_name | stap-server $((port + 1)) > $fifo_name 2>&1 & - if test $first = 1; then - advertise_presence - first=0 - fi - wait '%nc' >/dev/null 2>&1 + nc -ld $port 2>/dev/null | process_request & + wait '%nc -l' rc=$? - if test $rc = 127 -o $rc = 0; then - break; # success + if test $rc = 0 -o $rc = 127; then + break; # port was read ok fi - sleep 1 done if test $attempt = 5; then fatal "ERROR: cannot listen on port $port. rc==$rc" fi done - set +o pipefail # restore +} + +# 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 } # function: fatal [ MESSAGE ] @@ -112,13 +109,13 @@ function terminate { kill -s SIGTERM %avahi-publish-service 2> /dev/null wait '%avahi-publish-service' >/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 'stap-server' job. + kill -s SIGTERM "%stap-server" 2> /dev/null + wait "%stap-server" >/dev/null 2>&1 - # Clean up - cd `dirname $tmpdir` - rm -fr $tmpdir + # Kill any running 'nc -l' job. + kill -s SIGTERM "%?nc -l" 2> /dev/null + wait "%?nc - l" >/dev/null 2>&1 exit } @@ -127,4 +124,5 @@ function terminate { # Beginning of main line execution. #----------------------------------------------------------------------------- initialization "$@" +advertise_presence listen |