]>
sourceware.org Git - systemtap.git/blob - stap-serverd
3 # Compile server manager for systemtap
5 # Copyright (C) 2008 Red Hat Inc.
7 # This file is part of systemtap, and is free software. You can
8 # redistribute it and/or modify it under the terms of the GNU General
9 # Public License (GPL); either version 2, or (at your option) any
12 # This script publishes its presence on the network and then listens for
13 # incoming connections. When a connection is detected, the stap-server script
14 # is run to handle the request.
16 # Catch ctrl-c and other termination signals
17 trap 'terminate' SIGTERM SIGINT
19 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # function: initialization PORT
23 function initialization
{
27 test "X$port" = "X" && port
=65000
28 export port2
=$
(($port + 1))
29 if netstat
-atn |
awk '{print $4}' | cut
-f2 -d: |
egrep -q "^($port|$port2)\$"; then
30 # Whoops, the port is busy; try another one.
31 initialization $
((1024+($port + $RANDOM)%64000))
35 # function: advertise_presence
37 # Advertise the availability of the server on the network.
38 function advertise_presence
{
39 # Build up a string representing our server's properties.
40 # TODO: this needs fleshing out.
41 local sysinfo
=`uname -rvm`
42 local txt
="sysinfo=$sysinfo"
44 # Call avahi-publish-service to advertise our presence.
45 avahi-publish-service
"Systemtap Compile Server on `uname -n`" \
46 $avahi_type $port "$txt" > /dev
/null
2>&1 &
48 echo "Systemtap Compile Server on `uname -n` listening on port $port"
53 # Listen for and handle requests to the server.
55 # Loop forever accepting requests
58 for ((attempt
=0; $attempt < 5; ++attempt
))
60 nc
-ld $port 2>/dev
/null | process_request
&
63 if test $rc = 0 -o $rc = 127; then
64 break; # port was read ok
67 if test $attempt = 5; then
68 fatal
"ERROR: cannot listen on port $port. rc==$rc"
73 # function: process_request
75 # Process an incoming request on stdin
76 function process_request
{
80 stap-server
$port2 >/dev
/null
2>&1 &
83 test $rc = 127 && rc
=0
92 # function: fatal [ MESSAGE ]
95 # Prints its arguments to stderr and exits
102 # function: terminate
104 # Terminate gracefully.
108 # Kill the running 'avahi-publish-service' job
109 kill -s SIGTERM
%avahi-publish-service
2> /dev
/null
110 wait '%avahi-publish-service' >/dev
/null
2>&1
112 # Kill any running 'stap-server' job.
113 kill -s SIGTERM
"%stap-server" 2> /dev
/null
114 wait "%stap-server" >/dev
/null
2>&1
116 # Kill any running 'nc -l' job.
117 kill -s SIGTERM
"%?nc -l" 2> /dev
/null
118 wait "%?nc - l" >/dev
/null
2>&1
123 #-----------------------------------------------------------------------------
124 # Beginning of main line execution.
125 #-----------------------------------------------------------------------------
This page took 0.045594 seconds and 6 git commands to generate.