]>
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 # Initialize the environment
20 .
`dirname $0`/stap-env
22 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 # function: initialization
26 function initialization
{
31 # Default options settings
37 test "X$zip_client" != "X" || \
38 fatal
"Client request file not specified"
39 test -f $zip_client || \
40 fatal
"Unable to find request file $zip_client"
42 # Temp directory we will be working in
44 test "X$tmpdir_server" != "X" || \
45 fatal
"Server temporary directory not specified"
46 test -d $tmpdir_server || \
47 fatal
"Unable to find temporary directory $tmpdir_server"
48 tmpdir_env
=`dirname $tmpdir_server`
50 # Signed reponse file name.
52 test "X$zip_server" != "X" || \
53 fatal
".zip archive file not specified"
54 # Make sure the specified .zip file exists.
55 test -f $zip_server || \
56 fatal
"Unable to find .zip archive file $zip_server"
58 # Where is the ssl certificate/key database?
60 test "X$ssl_db" != "X" || \
61 fatal
"SSL certificate database not specified"
63 fatal
"Unable to find SSL certificate database $ssl_db"
66 fatal
"Unable to find SSL certificate database password file $nss_pw"
69 touch $tmpdir_server/stdout
70 touch $tmpdir_server/stderr
73 # function: unpack_request
75 # Unpack the zip file received from the client and make the contents
76 # available for use when running 'stap'
77 function unpack_request
{
80 # Unpack the zip file.
81 unzip $zip_client > /dev
/null || \
82 fatal
"Cannot unpack zip archive $zip_client"
84 # Identify the client's request tree. The zip file should have expanded
85 # into a single directory named to match $stap_tmpdir_prefix_client.??????
86 # which should now be the only item in the current directory.
87 test "`ls | wc -l`" = 3 || \
88 fatal
"Wrong number of files after expansion of client's zip file"
90 tmpdir_client
=`ls | grep $stap_tmpdir_prefix_client.......\$`
92 test "X$tmpdir_client" != "X" || \
93 fatal
"Client zip file did not expand as expected"
95 # Move the client's temp directory to a local temp location
96 local local_tmpdir_client
=`mktemp -dt $stap_tmpdir_prefix_server.client.XXXXXX` || \
97 fatal
"Cannot create temporary client request directory " $local_tmpdir_client
98 mv $tmpdir_client/* $local_tmpdir_client
100 tmpdir_client
=$local_tmpdir_client
103 # function: check_request
105 # Examine the contents of the request to make sure that they are valid.
106 function check_request
{
107 # Work in the temporary directory provided by the client
110 # Add the necessary info from files in our temporary directory.
111 cmdline
=`read_data_file cmdline`
112 test "X$cmdline" != "X" ||
exit 1
114 eval parse_options
"$cmdline"
116 client_sysinfo
=`read_data_file sysinfo`
117 test "X$client_sysinfo" != "X" ||
exit 1
119 check_compatibility
"$client_sysinfo" "`server_sysinfo`"
122 # function server_sysinfo
124 # Generate the server's sysinfo and echo it to stdout
125 function server_sysinfo
{
126 if test "X$sysinfo_server" = "X"; then
127 # Add some info from uname
128 sysinfo_server
="`uname -rvm`"
130 echo "$sysinfo_server"
133 # function check_compaibility SYSINFO1 SYSINFO2
135 # Make sure that systemtap as described by SYSINFO1 and SYSINFO2 are compaible
136 function check_compatibility
{
137 # Compatibility is irrelevant if the request is not for phase 5 activity.
138 test $p_phase -lt 5 && return
140 # TODO: This needs work
141 # - Make sure the linux kernel matches exactly
145 if test "$sysinfo1" != "$sysinfo2"; then
146 error
"System configuration mismatch"
147 error
" client: $sysinfo1"
148 fatal
" server: $sysinfo2"
152 # function: read_data_file PREFIX
154 # Find a file whose name is '$1' and whose first line
155 # contents are '$1: .*'. Read and echo the data.
156 function read_data_file
{
158 fatal
"Data file $1 not found"
163 # Verify the first line of the file.
166 data
=`expr "$line" : "$1: \\\(.*\\\)"`
167 if test "X$data" = "X"; then
168 fatal
"Data in file $1 is incorrect"
175 # Now read the entire file.
176 cat $1 |
sed "s/$1: //"
179 # function: parse_options [ STAP-OPTIONS ]
181 # Examine the command line. We need not do much checking, but we do need to
182 # parse all options in order to discover the ones we're interested in.
183 function parse_options
{
189 # Start of a new token.
191 until test $advance_p != 0
193 # Identify the next option
194 first_char
=`expr "$first_token" : '\(.\).*'`
195 if test $dash_seen = 0; then
196 if test "$first_char" = "-"; then
197 if test "$first_token" != "-"; then
198 # It's not a lone dash, so it's an option. Remove the dash.
199 first_token
=`expr "$first_token" : '-\(.*\)'`
201 first_char
=`expr "$first_token" : '\(.\).*'`
204 if test $dash_seen = 0; then
205 # The dash has not been seen. This is either the script file
206 # name or an arument to be passed to the probe module.
207 # If this is the first time, and -e has not been specified,
208 # then it could be the name of the script file.
209 if test "X$e_script" = "X" -a "X$script_file" = "X"; then
210 script_file
=$first_token
212 advance_p
=$
(($advance_p + 1))
217 # We are at the start of an option. Look at the first character.
220 get_arg
$first_token "$2"
223 get_arg
$first_token $2
226 get_arg
$first_token "$2"
227 process_e
"$stap_arg"
230 get_arg
$first_token $2
236 get_arg
$first_token $2
239 get_arg
$first_token $2
242 get_arg
$first_token $2
245 get_arg
$first_token $2
249 get_arg
$first_token $2
252 get_arg
$first_token $2
255 get_arg
$first_token $2
258 get_arg
$first_token $2
261 # An unknown flag. Ignore it.
265 if test $advance_p = 0; then
266 # Just another flag character. Consume it.
267 first_token
=`expr "$first_token" : '.\(.*\)'`
268 if test "X$first_token" = "X"; then
269 advance_p
=$
(($advance_p + 1))
274 # Consume the arguments we just processed.
275 while test $advance_p != 0
278 advance_p
=$
(($advance_p - 1))
283 # function: get_arg FIRSTWORD SECONDWORD
285 # Collect an argument to the given option
287 # Remove first character. Advance to the next token, if the first one
289 local first
=`expr "$1" : '.\(.*\)'`
290 if test "X$first" = "X"; then
292 advance_p
=$
(($advance_p + 1))
297 advance_p
=$
(($advance_p + 1))
300 # function: process_e ARGUMENT
302 # Process the -e flag.
304 if test "X$e_script" = "X"; then
310 # function: process_p ARGUMENT
312 # Process the -p flag.
314 if test $1 -ge 1 -a $1 -le 5; then
319 # function: call_stap
321 # Call 'stap' with the options provided. Don't run past phase 4.
324 # Use -k so we can return results to the client
325 # Limit to -p4. i.e. don't run the module
327 if test $p_phase -gt 4; then
330 server_p_phase
=$p_phase
333 eval ${stap_exec_prefix}stap
"$cmdline" -k -p $server_p_phase \
334 >> $tmpdir_server/stdout \
335 2>> $tmpdir_server/stderr
340 # function: create_response
342 # Add information to the server's temp directory representing the response
344 function create_response
{
347 # Get the name of the stap temp directory, which was kept, from stderr.
348 tmpdir_line
=`cat stderr | grep "Keeping temp"`
349 tmpdir_stap
=`expr "$tmpdir_line" : '.*"\(.*\)".*'`
351 # Remove the message about keeping the stap temp directory from stderr, unless
352 # the user did request to keep it.
353 if test "X$tmpdir_stap" != "X"; then
354 if test $keep_temps != 1; then
355 sed -i "/^Keeping temp/d" stderr
358 # Add the contents of the stap temp directory to the server output directory
359 ln -s $tmpdir_stap `basename $tmpdir_stap`
362 # If the user specified -p5, remove the name of the kernel module from stdout.
363 if test $p_phase = 5; then
364 sed -i '/\.ko$/d' stdout
367 # The return status of the stap command.
368 echo -n $stap_rc > rc
371 # function: package_response
373 # Package the server's temp directory into a form suitable for sending to the
375 function package_response
{
378 # Compress the server's temporary directory into a .zip archive.
379 (rm $zip_server && zip -r $zip_server `basename $tmpdir_server` > /dev
/null
) || \
380 fatal
"zip of request tree, $tmpdir_server, failed"
383 # function: fatal [ MESSAGE ]
386 # Prints its arguments to stderr and exits
388 echo "$0: ERROR:" "$@" >> $tmpdir_server/stderr
389 echo -n 1 > $tmpdir_server/rc
396 # Prints its arguments to stderr but does not exit
398 echo "$0: ERROR:" "$@" >> $tmpdir_server/stderr
403 # Cleanup work files unless asked to keep them.
407 if test $keep_temps != 1; then
408 rm -fr $tmpdir_server
409 rm -fr $tmpdir_client
414 # function: terminate
416 # Terminate gracefully.
423 #-----------------------------------------------------------------------------
424 # Beginning of main line execution.
425 #-----------------------------------------------------------------------------
This page took 0.054865 seconds and 5 git commands to generate.