]>
sourceware.org Git - systemtap.git/blob - stap-server
3 # Compile server for systemtap
5 # Copyright (C) 2008, 2009 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 unpacks the tar file provided on stdin and uses the information
13 # contained in the unpacked tree to build the requested systemtap kernel module.
14 # This module is then written to stdout.
16 # Catch ctrl-c and other termination signals
17 trap 'terminate' SIGTERM SIGINT
19 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # function: configuration
23 function configuration
{
24 # INSTALL-HOOK These settings work for running the client from the source tree
25 # INSTALL-HOOK using the dejagnu test harness and will be overridden at install
31 tmpdir_prefix_client
=stap.client
32 tmpdir_prefix_server
=stap.server
35 # function: initialization
36 function initialization
{
41 # Default options settings
47 test "X$zip_client" != "X" || \
48 fatal
"Client request file not specified"
49 test -f $zip_client || \
50 fatal
"Unable to find request file $zip_client"
52 # Temp directory we will be working in
54 test "X$tmpdir_server" != "X" || \
55 fatal
"Server temporary directory not specified"
56 test -d $tmpdir_server || \
57 fatal
"Unable to find temporary directory $tmpdir_server"
58 tmpdir_env
=`dirname $tmpdir_server`
60 # Signed reponse file name.
62 test "X$zip_server" != "X" || \
63 fatal
".zip archive file not specified"
64 # Make sure the specified .zip file exists.
65 test -f $zip_server || \
66 fatal
"Unable to find .zip archive file $zip_server"
68 # Where is the ssl certificate/key database?
70 test "X$ssl_db" != "X" || \
71 fatal
"SSL certificate database not specified"
73 fatal
"Unable to find SSL certificate database $ssl_db"
76 fatal
"Unable to find SSL certificate database password file $nss_pw"
79 touch $tmpdir_server/stdout
80 touch $tmpdir_server/stderr
83 # function: unpack_request
85 # Unpack the zip file received from the client and make the contents
86 # available for use when running 'stap'
87 function unpack_request
{
90 # Unpack the zip file.
91 unzip $zip_client > /dev
/null || \
92 fatal
"Cannot unpack zip archive $zip_client"
94 # Identify the client's request tree. The zip file should have expanded
95 # into a single directory named to match $tmpdir_prefix_client.??????
96 # which should now be the only item in the current directory.
97 test "`ls | wc -l`" = 3 || \
98 fatal
"Wrong number of files after expansion of client's zip file"
100 tmpdir_client
=`ls | grep $tmpdir_prefix_client.......\$`
102 test "X$tmpdir_client" != "X" || \
103 fatal
"Client zip file did not expand as expected"
105 # Move the client's temp directory to a local temp location
106 local local_tmpdir_client
=`mktemp -dt $tmpdir_prefix_server.client.XXXXXX` || \
107 fatal
"Cannot create temporary client request directory " $local_tmpdir_client
108 mv $tmpdir_client/* $local_tmpdir_client
109 rm -fr $tmpdir_client
110 tmpdir_client
=$local_tmpdir_client
113 # function: check_request
115 # Examine the contents of the request to make sure that they are valid.
116 function check_request
{
117 # Work in the temporary directory provided by the client
120 # Add the necessary info from files in our temporary directory.
121 cmdline
=`read_data_file cmdline`
122 test "X$cmdline" != "X" ||
exit 1
124 eval parse_options
"$cmdline"
126 client_sysinfo
=`read_data_file sysinfo`
127 test "X$client_sysinfo" != "X" ||
exit 1
129 check_compatibility
"$client_sysinfo" "`server_sysinfo`"
132 # function server_sysinfo
134 # Generate the server's sysinfo and echo it to stdout
135 function server_sysinfo
{
136 if test "X$sysinfo_server" = "X"; then
137 # Add some info from uname
138 sysinfo_server
="`uname -rvm`"
140 echo "$sysinfo_server"
143 # function check_compaibility SYSINFO1 SYSINFO2
145 # Make sure that systemtap as described by SYSINFO1 and SYSINFO2 are compaible
146 function check_compatibility
{
147 # Compatibility is irrelevant if the request is not for phase 5 activity.
148 test $p_phase -lt 5 && return
150 # TODO: This needs work
151 # - Make sure the linux kernel matches exactly
155 if test "$sysinfo1" != "$sysinfo2"; then
156 error
"System configuration mismatch"
157 error
" client: $sysinfo1"
158 fatal
" server: $sysinfo2"
162 # function: read_data_file PREFIX
164 # Find a file whose name is '$1' and whose first line
165 # contents are '$1: .*'. Read and echo the data.
166 function read_data_file
{
168 fatal
"Data file $1 not found"
173 # Verify the first line of the file.
176 data
=`expr "$line" : "$1: \\\(.*\\\)"`
177 if test "X$data" = "X"; then
178 fatal
"Data in file $1 is incorrect"
185 # Now read the entire file.
186 cat $1 |
sed "s/$1: //"
189 # function: parse_options [ STAP-OPTIONS ]
191 # Examine the command line. We need not do much checking, but we do need to
192 # parse all options in order to discover the ones we're interested in.
193 function parse_options
{
199 # Start of a new token.
201 until test $advance_p != 0
203 # Identify the next option
204 first_char
=`expr "$first_token" : '\(.\).*'`
205 if test $dash_seen = 0; then
206 if test "$first_char" = "-"; then
207 if test "$first_token" != "-"; then
208 # It's not a lone dash, so it's an option. Remove the dash.
209 first_token
=`expr "$first_token" : '-\(.*\)'`
211 first_char
=`expr "$first_token" : '\(.\).*'`
214 if test $dash_seen = 0; then
215 # The dash has not been seen. This is either the script file
216 # name or an arument to be passed to the probe module.
217 # If this is the first time, and -e has not been specified,
218 # then it could be the name of the script file.
219 if test "X$e_script" = "X" -a "X$script_file" = "X"; then
220 script_file
=$first_token
222 advance_p
=$
(($advance_p + 1))
227 # We are at the start of an option. Look at the first character.
230 get_arg
$first_token "$2"
233 get_arg
$first_token $2
236 get_arg
$first_token "$2"
237 process_e
"$stap_arg"
240 get_arg
$first_token $2
246 get_arg
$first_token $2
249 get_arg
$first_token $2
252 get_arg
$first_token $2
255 get_arg
$first_token $2
259 get_arg
$first_token $2
262 get_arg
$first_token $2
265 get_arg
$first_token $2
268 get_arg
$first_token $2
271 # An unknown flag. Ignore it.
275 if test $advance_p = 0; then
276 # Just another flag character. Consume it.
277 first_token
=`expr "$first_token" : '.\(.*\)'`
278 if test "X$first_token" = "X"; then
279 advance_p
=$
(($advance_p + 1))
284 # Consume the arguments we just processed.
285 while test $advance_p != 0
288 advance_p
=$
(($advance_p - 1))
293 # function: get_arg FIRSTWORD SECONDWORD
295 # Collect an argument to the given option
297 # Remove first character. Advance to the next token, if the first one
299 local first
=`expr "$1" : '.\(.*\)'`
300 if test "X$first" = "X"; then
302 advance_p
=$
(($advance_p + 1))
307 advance_p
=$
(($advance_p + 1))
310 # function: process_e ARGUMENT
312 # Process the -e flag.
314 if test "X$e_script" = "X"; then
320 # function: process_p ARGUMENT
322 # Process the -p flag.
324 if test $1 -ge 1 -a $1 -le 5; then
329 # function: call_stap
331 # Call 'stap' with the options provided. Don't run past phase 4.
334 # Use -k so we can return results to the client
335 # Limit to -p4. i.e. don't run the module
337 if test $p_phase -gt 4; then
340 server_p_phase
=$p_phase
343 eval ${exec_prefix}stap
"$cmdline" -k -p $server_p_phase \
344 >> $tmpdir_server/stdout \
345 2>> $tmpdir_server/stderr
350 # function: create_response
352 # Add information to the server's temp directory representing the response
354 function create_response
{
357 # Get the name of the stap temp directory, which was kept, from stderr.
358 tmpdir_line
=`cat stderr | grep "Keeping temp"`
359 tmpdir_stap
=`expr "$tmpdir_line" : '.*"\(.*\)".*'`
361 # Remove the message about keeping the stap temp directory from stderr, unless
362 # the user did request to keep it.
363 if test "X$tmpdir_stap" != "X"; then
364 if test $keep_temps != 1; then
365 sed -i "/^Keeping temp/d" stderr
368 # Add the contents of the stap temp directory to the server output directory
369 ln -s $tmpdir_stap `basename $tmpdir_stap`
372 # If the user specified -p5, remove the name of the kernel module from stdout.
373 if test $p_phase = 5; then
374 sed -i '/\.ko$/d' stdout
377 # The return status of the stap command.
378 echo -n $stap_rc > rc
381 # function: package_response
383 # Package the server's temp directory into a form suitable for sending to the
385 function package_response
{
388 # Compress the server's temporary directory into a .zip archive.
389 (rm $zip_server && zip -r $zip_server `basename $tmpdir_server` > /dev
/null
) || \
390 fatal
"zip of request tree, $tmpdir_server, failed"
393 # function: fatal [ MESSAGE ]
396 # Prints its arguments to stderr and exits
398 echo "$0: ERROR:" "$@" >> $tmpdir_server/stderr
399 echo -n 1 > $tmpdir_server/rc
406 # Prints its arguments to stderr but does not exit
408 echo "$0: ERROR:" "$@" >> $tmpdir_server/stderr
413 # Cleanup work files unless asked to keep them.
417 if test $keep_temps != 1; then
418 rm -fr $tmpdir_server
419 rm -fr $tmpdir_client
424 # function: terminate
426 # Terminate gracefully.
433 #-----------------------------------------------------------------------------
434 # Beginning of main line execution.
435 #-----------------------------------------------------------------------------
This page took 0.057707 seconds and 5 git commands to generate.