]> sourceware.org Git - systemtap.git/blob - stap-serverd
Merge commit 'origin/master' into pr6429-comp-unwindsyms
[systemtap.git] / stap-serverd
1 #!/bin/bash
2
3 # Compile server manager for systemtap
4 #
5 # Copyright (C) 2008 Red Hat Inc.
6 #
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
10 # later version.
11
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.
15
16 # Catch ctrl-c
17 trap 'handle_sigint' SIGINT
18
19 #-----------------------------------------------------------------------------
20 # Helper functions.
21 #-----------------------------------------------------------------------------
22 # function: initialization PORT
23 function initialization {
24 # Default settings.
25 tmpdir_prefix_serverd=stap.serverd
26 avahi_type=_stap._tcp
27 port=$1
28 test "X$port" = "X" && port=65000
29 }
30
31 # function: advertise_presence
32 #
33 # Advertise the availability of the server on the network.
34 function advertise_presence {
35 # Build up a string representing our server's properties.
36 # TODO: this needs fleshing out.
37
38 local sysinfo=`uname -r`
39 local txt="$sysinfo"
40
41 # Call avahi-publish-service to advertise our presence.
42 avahi-publish-service "Systemtap Compile Server on `uname -n`" \
43 $avahi_type $port $txt > /dev/null 2>&1 &
44
45 echo "Systemtap Compile Server on `uname -n` listening on port $port"
46 }
47
48 # function: listen
49 #
50 # Listen for and handle requests to the server.
51 function listen {
52 # Work in a temporary directory
53 tmpdir=`mktemp -dt $tmpdir_prefix_serverd.XXXXXX` || \
54 fatal "ERROR: cannot create temporary directory " $tmpdir
55 cd $tmpdir
56
57 # Create a fifo for communicating with the server
58 local fifo_name=$tmpdir_prefix_serverd.fifo
59 mknod $fifo_name p || \
60 fatal "ERROR: cannot create temporary fifo " $tmpdir/$fifo_name
61
62 # Loop forever accepting requests
63 while true
64 do
65 nc -l $port < $fifo_name | stap-server $((port + 1)) > $fifo_name 2>&1
66 done
67 }
68
69 # function: fatal [ MESSAGE ]
70 #
71 # Fatal error
72 # Prints its arguments to stderr and exits
73 function fatal {
74 echo "$@" >&2
75 exit 1
76 }
77
78 # function: handle_sigint
79 #
80 # Terminate gracefully when SIGINT is received.
81 function handle_sigint {
82 echo "$0: received SIGINT. Exiting."
83 cd `dirname $tmpdir`
84 rm -fr $tmpdir
85 exit
86 }
87
88 #-----------------------------------------------------------------------------
89 # Beginning of main line execution.
90 #-----------------------------------------------------------------------------
91 initialization "$@"
92 advertise_presence
93 listen
This page took 0.044973 seconds and 6 git commands to generate.