]> sourceware.org Git - systemtap.git/blob - stap-client
Ensure that the client/server scripts call the installed copies of any
[systemtap.git] / stap-client
1 #!/bin/bash
2
3 # Compile server client for systemtap
4 #
5 # Copyright (C) 2008, 2009 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 examines the systemtap command line and packages the files and
13 # information needed to execute the command. This is then sent to a trusted
14 # systemtap server which will process the request and return the resulting
15 # kernel module (if requested) and any other information generated by the
16 # request. If a kernel module is generated, this script will load the module
17 # and execute it using 'staprun', if requested.
18
19 # Catch ctrl-c and other termination signals
20 trap 'terminate' SIGTERM
21 trap 'interrupt' SIGINT
22 trap 'ignore_signal' SIGHUP SIGPIPE
23
24 #-----------------------------------------------------------------------------
25 # Helper functions.
26 #-----------------------------------------------------------------------------
27 # function: configuration
28 function configuration {
29 tmpdir_prefix_client=stap.client
30 tmpdir_prefix_server=stap.server
31 avahi_service_tag=_stap._tcp
32 }
33
34 # function: initialization
35 function initialization {
36 rc=0
37 wd=`pwd`
38 umask 0
39 staprun_running=0
40
41 # Where are we installed?
42 if test "`basename $0`" = "stap" -a "$0" = `which stap`; then
43 # The dejagnu test harness may invoke us as 'stap' relying on $PATH to
44 # find us. If so, then use the $PATH to find the rest of the systemtap
45 # tools.
46 exec_prefix=""
47 # Also, set the prefix to point to where we were found.
48 prefix=`which stap`
49 prefix=`dirname $prefix`
50 else
51 # Assume we were installed normally
52 exec_prefix=`dirname $0`
53 exec_prefix=`cd $exec_prefix && pwd`/
54 prefix=`dirname $exec_prefix`
55 fi
56
57 # Default location for server certificates if we're not root
58 if test $EUID != 0; then
59 local_ssl_dbs="$HOME/.systemtap/ssl/client"
60 fi
61 # Additional location for all users.
62 public_ssl_dbs=$prefix/etc/systemtap/ssl/client
63
64 # Default options settings
65 p_phase=5
66 v_level=0
67 keep_temps=0
68 b_specified=0
69
70 # Create a temporary directory to package things in
71 # Do this before parsing the command line so that there is a place
72 # to put -I and -R directories.
73 tmpdir_client=`mktemp -dt $tmpdir_prefix_client.XXXXXX` || \
74 fatal "ERROR: cannot create temporary directory " $tmpdir_client
75 tmpdir_env=`dirname $tmpdir_client`
76 }
77
78 # function: parse_options [ STAP-OPTIONS ]
79 #
80 # Examine the command line. We need not do much checking, but we do need to
81 # parse all options in order to discover the ones we're interested in.
82 # The server will take care of most situations and return the appropriate
83 # output.
84 #
85 function parse_options {
86 cmdline=
87 cmdline1=
88 cmdline2=
89 while test $# != 0
90 do
91 advance_p=0
92 dash_seen=0
93
94 # Start of a new token.
95 first_token=$1
96 until test $advance_p != 0
97 do
98 # Identify the next option
99 first_char=`expr "$first_token" : '\(.\).*'`
100 second_char=
101 if test $dash_seen = 0; then
102 if test "$first_char" = "-"; then
103 if test "$first_token" != "-"; then
104 # It's not a lone dash, so it's an option.
105 # Is it a long option (i.e. --option)?
106 second_char=`expr "$first_token" : '.\(.\).*'`
107 if test "X$second_char" = "X-"; then
108 long_option=`expr "$first_token" : '--\(.*\)=.*'`
109 test "X$long_option" != "X" || long_option=`expr "$first_token" : '--\(.*\)'`
110 case $long_option in
111 ssl)
112 process_ssl $first_token
113 ;;
114 *)
115 # An unknown or unimportant option.
116 # Ignore it, but pass it on to the server.
117 cmdline2="$cmdline2 $first_token"
118 ;;
119 esac
120 advance_p=$(($advance_p + 1))
121 break
122 fi
123 # It's not a lone dash, or a long option, so it's a short option string.
124 # Remove the dash.
125 first_token=`expr "$first_token" : '-\(.*\)'`
126 dash_seen=1
127 first_char=`expr "$first_token" : '\(.\).*'`
128 cmdline2="$cmdline2 -"
129 fi
130 fi
131 if test $dash_seen = 0; then
132 # The dash has not been seen. This is either the script file
133 # name, a long argument or an argument to be passed to the probe module.
134 # If this is the first time, and -e has not been specified,
135 # then it could be the name of the script file.
136 if test "X$second_char" = "X-"; then
137 cmdline2="$cmdline2 $first_token"
138 elif test "X$e_script" = "X" -a "X$script_file" = "X"; then
139 script_file=$first_token
140 cmdline1="$cmdline2"
141 cmdline2=
142 elif test "$first_char" != "'"; then
143 cmdline2="$cmdline2 '$first_token'"
144 else
145 cmdline2="$cmdline2 $first_token"
146 fi
147 advance_p=$(($advance_p + 1))
148 break
149 fi
150 fi
151
152 # We are at the start of an option. Look at the first character.
153 case $first_char in
154 b)
155 b_specified=1
156 ;;
157 c)
158 get_arg $first_token "$2"
159 process_c "$stap_arg"
160 ;;
161 D)
162 get_arg $first_token $2
163 cmdline2="${cmdline2}D '$stap_arg'"
164 ;;
165 e)
166 get_arg $first_token "$2"
167 process_e "$stap_arg"
168 ;;
169 I)
170 get_arg $first_token $2
171 process_I $stap_arg
172 ;;
173 k)
174 keep_temps=1
175 ;;
176 l)
177 get_arg $first_token $2
178 cmdline2="${cmdline2}l '$stap_arg'"
179 ;;
180 m)
181 get_arg $first_token $2
182 process_m $stap_arg
183 ;;
184 o)
185 get_arg $first_token $2
186 process_o $stap_arg
187 ;;
188 p)
189 get_arg $first_token $2
190 process_p $stap_arg
191 ;;
192 r)
193 get_arg $first_token $2
194 cmdline2="${cmdline2}r '$stap_arg'"
195 ;;
196 R)
197 get_arg $first_token $2
198 process_R $stap_arg
199 ;;
200 s)
201 get_arg $first_token $2
202 cmdline2="${cmdline2}s '$stap_arg'"
203 ;;
204 v)
205 v_level=$(($v_level + 1))
206 ;;
207 x)
208 get_arg $first_token $2
209 cmdline2="${cmdline2}x '$stap_arg'"
210 ;;
211 *)
212 # An unknown or unimportant flag. Ignore it, but pass it on to the server.
213 ;;
214 esac
215
216 if test $advance_p = 0; then
217 # Just another flag character. Consume it.
218 cmdline2="$cmdline2$first_char"
219 first_token=`expr "$first_token" : '.\(.*\)'`
220 if test "X$first_token" = "X"; then
221 advance_p=$(($advance_p + 1))
222 fi
223 fi
224 done
225
226 # Consume the arguments we just processed.
227 while test $advance_p != 0
228 do
229 shift
230 advance_p=$(($advance_p - 1))
231 done
232 done
233
234 # If the script file was given and it's not '-', then replace it with its
235 # client-temp-name in the command string.
236 if test "X$script_file" != "X"; then
237 local local_name
238 if test "$script_file" != "-"; then
239 local_name=`generate_client_temp_name $script_file`
240 else
241 local_name=$script_file
242 fi
243 cmdline="$cmdline1 script/$local_name $cmdline2"
244 else
245 cmdline="$cmdline1 $cmdline2"
246 fi
247
248 local_ssl_dbs="$additional_local_ssl_dbs $local_ssl_dbs"
249 }
250
251 # function: get_arg FIRSTWORD SECONDWORD
252 #
253 # Collect an argument to the given option
254 function get_arg {
255 # Remove first character.
256 local opt=`expr "$1" : '\(.\).*'`
257 local first=`expr "$1" : '.\(.*\)'`
258
259 # Advance to the next token, if the first one is exhausted.
260 if test "X$first" = "X"; then
261 shift
262 advance_p=$(($advance_p + 1))
263 first=$1
264 fi
265
266 test "X$first" != "X" || \
267 fatal "Missing argument to -$opt"
268
269 stap_arg="$first"
270 advance_p=$(($advance_p + 1))
271 }
272
273 # function: process_ssl ARGUMENT
274 #
275 # Process the --ssl option.
276 function process_ssl {
277 local db=`expr "$1" : '--ssl=\(.*\)'`
278
279 test "X$db" != "X" || \
280 fatal "Missing argument to --ssl"
281
282 additional_local_ssl_dbs="$additional_local_ssl_dbs $db"
283 }
284
285 # function: process_c ARGUMENT
286 #
287 # Process the -c flag.
288 function process_c {
289 c_cmd="$1"
290 cmdline2="${cmdline2}c '$1'"
291 }
292
293 # function: process_e ARGUMENT
294 #
295 # Process the -e flag.
296 function process_e {
297 # Only the first -e option is recognized and it overrides any script file name
298 # which may have already been identified.
299 if test "X$e_script" = "X"; then
300 e_script="$1"
301 if test "X$script_file" != "X"; then
302 cmdline1="$cmdline1 $script_file $cmdline2"
303 cmdline2=
304 script_file=
305 fi
306 fi
307 cmdline2="${cmdline2}e '$1'"
308 }
309
310 # function: process_I ARGUMENT
311 #
312 # Process the -I flag.
313 function process_I {
314 local local_name=`include_file_or_directory tapsets $1`
315 test "X$local_name" != "X" || return
316 cmdline2="${cmdline2}I 'tapsets/$local_name'"
317 }
318
319 # function: process_m ARGUMENT
320 #
321 # Process the -m flag.
322 function process_m {
323 m_name="$1"
324 cmdline2="${cmdline2}m '$1'"
325 }
326
327 # function: process_o ARGUMENT
328 #
329 # Process the -o flag.
330 function process_o {
331 stdout_redirection="$1"
332 cmdline2="${cmdline2}o '$1'"
333 }
334
335 # function: process_p ARGUMENT
336 #
337 # Process the -p flag.
338 function process_p {
339 p_phase=$1
340 cmdline2="${cmdline2}p '$1'"
341 }
342
343 # function: process_R ARGUMENT
344 #
345 # Process the -R flag.
346 function process_R {
347 local local_name=`include_file_or_directory runtime $1`
348 test "X$local_name" != "X" || return
349 cmdline2="${cmdline2}R 'runtime/$local_name'"
350 }
351
352 # function: include_file_or_directory PREFIX NAME
353 #
354 # Include the given file or directory in the client's temporary
355 # tree to be sent to the server.
356 function include_file_or_directory {
357 # Add a symbolic link of the named file or directory to our temporary directory
358 local local_name=`generate_client_temp_name $2`
359 mkdir -p $tmpdir_client/$1/`dirname $local_name` || \
360 fatal "ERROR: could not create $tmpdir_client/$1/`dirname $local_name`"
361 ln -s /$local_name $tmpdir_client/$1/$local_name || \
362 fatal "ERROR: could not link $tmpdir_client/$1/$local_name to /$local_name"
363 echo "$local_name"
364 }
365
366 # function: generate_client_temp_name NAME
367 #
368 # Generate the name to be used for the given file/directory relative to the
369 # client's temporary directory.
370 function generate_client_temp_name {
371 # Transform the name into a fully qualified path name
372 local full_name=`echo "$1" | sed "s,^\\\([^/]\\\),$wd/\\\\1,"`
373
374 # The same name without the initial / or trailing /
375 local local_name=`echo "$full_name" | sed 's,^/\(.*\),\1,'`
376 local_name=`echo "$local_name" | sed 's,\(.*\)/$,\1,'`
377 echo "$local_name"
378 }
379
380 # function: create_request
381 #
382 # Add information to the client's temp directory representing the request
383 # to the server.
384 function create_request {
385 # Work in our temporary directory
386 cd $tmpdir_client
387
388 if test "X$script_file" != "X"; then
389 if test "$script_file" = "-"; then
390 mkdir -p $tmpdir_client/script || \
391 fatal "ERROR: cannot create temporary directory " $tmpdir_client/script
392 cat > $tmpdir_client/script/$script_file
393 else
394 include_file_or_directory script $script_file > /dev/null
395 fi
396 fi
397
398 # Add the necessary info to special files in our temporary directory.
399 echo "cmdline: $cmdline" > cmdline
400 echo "sysinfo: `client_sysinfo`" > sysinfo
401 }
402
403 # function client_sysinfo
404 #
405 # Generate the client's sysinfo and echo it to stdout
406 function client_sysinfo {
407 if test "X$sysinfo_client" = "X"; then
408 # Add some info from uname
409 sysinfo_client="`uname -rvm`"
410 fi
411 echo "$sysinfo_client"
412 }
413
414 # function: package_request
415 #
416 # Package the client's temp directory into a form suitable for sending to the
417 # server.
418 function package_request {
419 # Package up the temporary directory into a zip file
420 cd $tmpdir_env
421
422 local tmpdir_client_base=`basename $tmpdir_client`
423 zip_client=$tmpdir_env/`mktemp $tmpdir_client_base.zip.XXXXXX` || \
424 fatal "ERROR: cannot create temporary file " $zip_client
425
426 (rm $zip_client && zip -r $zip_client $tmpdir_client_base > /dev/null) || \
427 fatal "ERROR: zip of request tree, $tmpdir_client, failed"
428 }
429
430 # function: unpack_response
431 #
432 # Unpack the jar file received from the server and make the contents available
433 # for printing the results and/or running 'staprun'.
434 function unpack_response {
435 tmpdir_server=`mktemp -dt $tmpdir_prefix_client.server.XXXXXX` || \
436 fatal "ERROR: cannot create temporary file " $tmpdir_server
437
438 # Unpack and verify the digitally signed server output directory
439 if ! signtool -d $ssl_db -v $jar_server > /dev/null 2>&1; then
440 # Run the verification again to get the reason
441 fatal "ERROR: Verification of server response, $jar_server, failed.
442 "`signtool -d $ssl_db -v $jar_server | grep "reported reason"`
443 fi
444
445 # Unpack the server output directory
446 unzip -d $tmpdir_server $jar_server > /dev/null || \
447 fatal "ERROR: Cannot unpack server response, $jar_server"
448
449 # Check the contents of the expanded directory. It should contain:
450 # 1) a file called stdout
451 # 2) a file called stderr
452 # 3) a file called rc
453 # 4) a directory called META-INF
454 # 5) optionally a directory named to match stap??????
455 local num_files=`ls $tmpdir_server | wc -l`
456 test $num_files = 5 -o $num_files = 4 || \
457 fatal "ERROR: Wrong number of files in server's temp directory"
458 test -f $tmpdir_server/stdout || \
459 fatal "ERROR: `pwd`/$tmpdir_server/stdout does not exist or is not a regular file"
460 test -f $tmpdir_server/stderr || \
461 fatal "ERROR: `pwd`/$tmpdir_server/stderr does not exist or is not a regular file"
462 test -f $tmpdir_server/rc || \
463 fatal "ERROR: `pwd`/$tmpdir_server/rc does not exist or is not a regular file"
464 test -d $tmpdir_server/META-INF || \
465 fatal "ERROR: `pwd`/$tmpdir_server/META-INF does not exist or is not a directory"
466
467 # See if there is a systemtap temp directory
468 tmpdir_stap=`ls $tmpdir_server | grep stap`
469 tmpdir_stap=`expr "$tmpdir_stap" : "\\\(stap......\\\)"`
470 if test "X$tmpdir_stap" != "X"; then
471 test -d $tmpdir_server/$tmpdir_stap || \
472 fatal "ERROR: `pwd`/$tmpdir_server/$tmpdir_stap is not a directory"
473
474 # Move the systemtap temp directory to a local temp location, if -k
475 # was specified.
476 if test $keep_temps = 1; then
477 local local_tmpdir_stap=`mktemp -dt stapXXXXXX` || \
478 fatal "ERROR: cannot create temporary directory " $local_tmpdir_stap
479 mv $tmpdir_server/$tmpdir_stap/* $local_tmpdir_stap 2>/dev/null
480 rm -fr $tmpdir_server/$tmpdir_stap
481
482 # Correct the name of the temp directory in the server's stderr output
483 sed -i "s,^Keeping temporary directory.*,Keeping temporary directory \"$local_tmpdir_stap\"," $tmpdir_server/stderr
484 tmpdir_stap=$local_tmpdir_stap
485 else
486 # Make sure we own the systemtap temp directory if we are root.
487 test $EUID = 0 && chown $EUID:$EUID $tmpdir_server/$tmpdir_stap
488 fi
489 fi
490 }
491
492 # function: find_and_connect_to_server
493 #
494 # Find and establish connection with a compatible stap server.
495 function find_and_connect_to_server {
496 # Use a temp file here instead of a pipeline so that the side effects
497 # of choose_server are seen by the rest of this script.
498 cd $tmpdir_client
499 ${exec_prefix}stap-find-servers > servers
500 choose_server < servers
501 rm -fr servers
502 }
503
504 # function: choose_server
505 #
506 # Examine each line from stdin and attempt to connect to each server
507 # specified until successful.
508 function choose_server {
509 local num_servers=0
510 local name
511 while read name server port remain
512 do
513 num_servers=$(($num_servers + 1))
514
515 # The server must match the dns name on the certificate
516 # and must be 'localhost' if the server is on the local host.
517 local server_host_name=`expr "$name" : "\\\([a-zA-Z0-9-]*\\\).*"`
518 local server_domain_name=`expr "$name" : "$server_host_name\\\(.*\\\)"`
519 local our_host_name=`expr "$HOSTNAME" : "\\\([a-zA-Z0-9-]*\\\).*"`
520 local our_domain_name=`expr "$HOSTNAME" : "$our_host_name\\\(.*\\\)"`
521
522 if test "X$server_domain_name" = "X.local"; then
523 server_domain_name=$our_domain_name
524 fi
525 if test "X$server_host_name$server_domain_name" = "X$our_host_name$our_domain_name"; then
526 server=localhost
527 else
528 server=$server_host_name$server_domain_name
529 fi
530
531 if test "X$server" = "X"; then
532 fatal "ERROR: server ip address not provided"
533 fi
534
535 if test "X$port" = "X"; then
536 fatal "ERROR: server port not provided"
537 fi
538
539 if send_receive; then
540 return 0
541 fi
542 done
543
544 if test $num_servers = 0; then
545 fatal "ERROR: unable to find a server"
546 fi
547
548 cat $tmpdir_client/connect >&2
549 fatal "ERROR: unable to connect to a server"
550 }
551
552 # function: send_receive
553 #
554 # Connect to the server, send the request and receive the response
555 function send_receive {
556 # Make a place to receive the response file.
557 jar_server=`mktemp -t $tmpdir_prefix_client.server.jar.XXXXXX` || \
558 fatal "ERROR: cannot create temporary file " $jar_server
559
560 # If the server is local, try to connect using each of the given local
561 # certificate databases in turn for verification.
562 if test "X$server" = "Xlocalhost"; then
563 for db in $local_ssl_dbs
564 do
565 # Send the request and receive the response using stap-client-connect
566 echo "Attempting connection with $server using certificate database in '$db'" >> $tmpdir_client/connect
567 ${exec_prefix}stap-client-connect -i $zip_client -o $jar_server -d $db -p $port -h $server >> $tmpdir_client/connect 2>&1 &
568 wait '%${exec_prefix}stap-client-connect'
569 test $? = 0 && ssl_db=$db && return 0
570 sleep 1
571 done
572 fi
573
574 # We can try the public certificate databases for all servers.
575 for db in $public_ssl_dbs
576 do
577 # Send the request and receive the response using stap-client-connect
578 echo "Attempting connection with $server using certificate database in '$db'" >> $tmpdir_client/connect
579 ${exec_prefix}stap-client-connect -i $zip_client -o $jar_server -d $db -p $port -h $server >> $tmpdir_client/connect 2>&1 &
580 wait '%${exec_prefix}stap-client-connect'
581 test $? = 0 && ssl_db=$db && return 0
582 sleep 1
583 done
584
585 # Could not connect using any of the certificate databases
586 return 1
587 }
588
589 # function: process_response
590 #
591 # Write the stdout and stderr from the server to stdout and stderr respectively.
592 function process_response {
593 # Pick up the results of running stap on the server.
594 cd $tmpdir_server
595 rc=`cat rc`
596
597 # Copy the module to the current directory, if -m was specified
598 if test "X$m_name" != "X"; then
599 if test -f $tmpdir_stap/$m_name.ko; then
600 cp $tmpdir_stap/$m_name.ko $wd
601 else
602 stream_output
603 fatal "module $tmpdir_stap/$m_name.ko does not exist"
604 fi
605 fi
606
607 # Output stdout and stderr as directed
608 stream_output
609 }
610
611 # function: stream_output
612 #
613 # Output stdout and stderr as directed
614 function stream_output {
615 cd $tmpdir_server
616 cat stderr >&2
617 cat stdout
618 }
619
620 # function: maybe_call_staprun
621 #
622 # Call staprun using the module returned from the server, if requested.
623 function maybe_call_staprun {
624 if test $rc != 0; then
625 # stap run on the server failed, so don't bother
626 return
627 fi
628
629 if test $p_phase -ge 4; then
630 # There should be a systemtap temporary directory.
631 if test "X$tmpdir_stap" = "X"; then
632 # OK if no script specified
633 if test "X$e_script" != "X" -o "X$script_file" != "X"; then
634 fatal "ERROR: systemtap temporary directory is missing in server response"
635 fi
636 return
637 fi
638
639 # There should be a module.
640 local mod_name=`ls $tmpdir_stap | grep '.ko$'`
641 if test "X$mod_name" = "X"; then
642 fatal "ERROR: no module was found in $tmpdir_stap"
643 fi
644
645 if test $p_phase = 5; then
646 test $v_level -gt 0 && echo "Pass 5: starting run." >&2
647
648 # We have a module. Try to run it
649 # If a -c command was specified, pass it along.
650 if test "X$c_cmd" != "X"; then
651 staprun_opts="-c '$c_cmd'"
652 fi
653
654 # The -v level will be one less than what was specified
655 # for us.
656 for ((vl=$((v_level - 1)); $vl > 0; --vl))
657 do
658 staprun_opts="$staprun_opts -v"
659 done
660
661 # if -o was specified, pass it along
662 if test "X$stdout_redirection" != "X"; then
663 staprun_opts="$staprun_opts -o $stdout_redirection"
664 fi
665
666 # Run it in the background and wait for it. This
667 # way any signals send to us can be caught.
668 if test $v_level -ge 2; then
669 echo "running `which staprun` $staprun_opts $tmpdir_stap/`ls $tmpdir_stap | grep '.ko$'`" >&2
670 fi
671 eval `staprun_PATH` "$staprun_opts" \
672 $tmpdir_stap/`ls $tmpdir_stap | grep '.ko$'`
673 staprun_running=1
674 wait '%?staprun' > /dev/null 2>&1
675 rc=$?
676 staprun_running=0
677 # 127 from wait means that the job was already finished.
678 test $rc=127 && rc=0
679
680 # Wait until the job actually disappears so that its output is complete.
681 while jobs '%?staprun' >/dev/null 2>&1
682 do
683 sleep 1
684 done
685
686 test $v_level -gt 0 && echo "Pass 5: run completed in 0usr/0sys/0real ms." >&2
687 fi
688 fi
689 }
690
691 # function: staprun_PATH
692 #
693 # Compute a PATH suitable for running staprun.
694 function staprun_PATH {
695 # If $SYSTEMTAP_STAPRUN is set, then use that
696 if test "X$SYSTEMTAP_STAPRUN" != "X"; then
697 echo $SYSTEMTAP_STAPRUN
698 return
699 fi
700
701 # Otherwise, if there is an exec_prefix, then use it.
702 if test "X$exec_prefix" != "X"; then
703 echo ${exec_prefix}staprun
704 return
705 fi
706
707 # Otherwise, we have been called by the dejagnu test harness as 'stap'
708 # and we are the first 'stap' on the path. Since staprun may call
709 # 'stap', remove the PATH component where we live from the PATH in order to
710 # avoid recursion.
711 local first_stap=`which stap`
712 local PATH_component=`dirname $first_stap`
713 echo "PATH=$PATH staprun" | sed "s,$PATH_component,,g"
714 }
715
716 # function: fatal [ MESSAGE ]
717 #
718 # Fatal error
719 # Prints its arguments to stderr and exits
720 function fatal {
721 echo "$0:" "$@" >&2
722 cleanup
723 exit 1
724 }
725
726 # function cleanup
727 #
728 # Cleanup work files unless asked to keep them.
729 function cleanup {
730 # Clean up.
731 cd $tmpdir_env
732 if test $keep_temps != 1; then
733 rm -fr $tmpdir_client
734 rm -f $zip_client
735 rm -f $jar_server
736 rm -fr $tmpdir_server
737 fi
738 }
739
740 # function: terminate
741 #
742 # Terminate gracefully.
743 function terminate {
744 # Clean up
745 echo "$0: terminated by signal" >&2
746 cleanup
747
748 # Kill any running staprun job
749 kill -s SIGTERM '%?staprun' 2>/dev/null
750
751 # Kill any stap-client-connect job
752 kill -s SIGTERM '%${exec_prefix}stap-client-connect'
753
754 exit 1
755 }
756
757 # function: interrupt
758 #
759 # Pass an interrupt (ctrl-C) to staprun
760 function interrupt {
761 # Pass the signal on to any running staprun job
762 if test $staprun_running = 1; then
763 kill -s SIGINT '%?staprun' 2>/dev/null
764 return
765 fi
766
767 # Kill any stap-client-connect job
768 # SIGINT won't do it.
769 kill -s SIGTERM '%${exec_prefix}stap-client-connect'
770
771 # If staprun was not running, then exit.
772 cleanup
773 exit 1
774 }
775
776 # function: ignore_signal
777 #
778 # Called in order to ignore a signal
779 function ignore_signal {
780 :
781 }
782
783 #-----------------------------------------------------------------------------
784 # Beginning of main line execution.
785 #-----------------------------------------------------------------------------
786 configuration
787 initialization
788 parse_options "$@"
789 create_request
790 package_request
791 find_and_connect_to_server
792 unpack_response
793 process_response
794 maybe_call_staprun
795 cleanup
796
797 exit $rc
This page took 0.07551 seconds and 6 git commands to generate.