diff options
-rw-r--r-- | ChangeLog | 34 | ||||
-rw-r--r-- | Makefile.am | 42 | ||||
-rw-r--r-- | Makefile.in | 42 | ||||
-rwxr-xr-x | stap-client | 151 | ||||
-rwxr-xr-x | stap-find-or-start-server | 16 | ||||
-rwxr-xr-x | stap-server | 65 | ||||
-rwxr-xr-x | stap-serverd | 9 | ||||
-rwxr-xr-x | stap-start-server | 12 | ||||
-rw-r--r-- | systemtap.spec | 10 | ||||
-rw-r--r-- | testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | testsuite/Makefile.am | 4 | ||||
-rw-r--r-- | testsuite/Makefile.in | 4 | ||||
-rw-r--r-- | testsuite/lib/systemtap.exp | 50 |
13 files changed, 273 insertions, 174 deletions
@@ -1,3 +1,37 @@ +2008-08-08 Dave Brolley <brolley@redhat.com> + + * stap-client: Use quotes when echoing. Exit with $rc. + (initialization): Initialize 'rc'. + (parse_options): Manage the command line in three pieces: + pre-script name, script name, post-script name. + (process_*): Likewise. + (send_request): Redirect stdout of 'nc' to /dev/null. + (receive_response): Handle "failed:" response. Redirect stdin of 'nc' + from /dev/zero. + (maybe_call_staprun): Check $rc. Check the requested phase limit + before looking for the module. + * stap-server: Use quotes when echoing. Exit with $rc. + (initialization): Initialize 'rc'. + (receive_request): Start 'nc' in the background before sending the + "ready:" message. Redirect stdin of 'nc' from /dev/zero. + (read_data_file): Allow for multiple lines of data. + (call_stap): Quoet $cmdline. Set 'rc'. + (send_response): Send "failed:" if stap is unsuccessful. Start 'nc' + in the background before sending the response. + (cleanup): Kill any running 'nc' job. + (terminate): Exit with $rc. + * stap-serverd: Start the server before advertising our presence. + * stap-find-or-start-server: Echo 0 if a server is already running. + Echo -1 if no server is running and one can't be started. + * stap-start-server: Wait until the server starts before exiting. Exit + with 1 if the server does not start. + * systemtap.spec: Move client side script to the runtime sub package. + The main package and the runtime sub package both depend on avahi-tools + and nc. + * Makefile.am: Revert previous changes. Now done in + testsuite/lib/systemtap.exp. + * Makefile.in: Regenerated. + 2008-08-04 Stan Cox <scox@redhat.com> * tapsets.cxx (dwarf_var_expanding_copy_visitor::visit_target_symbol): diff --git a/Makefile.am b/Makefile.am index eaddfd59..f2a5a7b9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -250,28 +250,9 @@ SUBDIRS = testsuite doc check: SRCDIR=`cd $(srcdir); pwd`; \ - BUILDDIR=`cd $(builddir); pwd`; \ - need_server=0; \ - (echo "X$(EXTRA_TOOL_OPTS)" | grep -q server) && need_server=1; \ - if test $$need_server = 1; then \ - echo "Testing using a systemtap server"; \ - need_server=0; \ - server_pid=`stap-find-or-start-server` || need_server=1; \ - if test $$need_server = 1; then \ - echo "Cannot find or start a systemtap server"; \ - exit -1; \ - fi; \ - client_path="$$BUILDDIR/testsuite/net"; \ - mkdir -p $$BUILDDIR/testsuite/net; \ - cp -p $$SRCDIR/stap-client $$BUILDDIR/testsuite/net/stap; \ - fi; \ - $(MAKE) -C testsuite check SYSTEMTAP_RUNTIME=$$SRCDIR/runtime SYSTEMTAP_TAPSET=$$SRCDIR/tapset LD_LIBRARY_PATH=$(PWD)/lib-elfutils:$(PWD)/lib-elfutils/systemtap SYSTEMTAP_PATH="$$client_path:$(PWD)" RUNTESTFLAGS="$(RUNTESTFLAGS)"; \ - if test "X$$server_pid" != "X"; then \ - stap-stop-server $$server_pid; \ - fi + $(MAKE) -C testsuite check SYSTEMTAP_RUNTIME=$$SRCDIR/runtime SYSTEMTAP_TAPSET=$$SRCDIR/tapset LD_LIBRARY_PATH=$(PWD)/lib-elfutils:$(PWD)/lib-elfutils/systemtap SYSTEMTAP_PATH="$(PWD)" RUNTESTFLAGS="$(RUNTESTFLAGS)"; installcheck: - BUILDDIR=`cd $(builddir); pwd`; \ if test \! -e $(DESTDIR)$(bindir)/stap; then \ echo $(DESTDIR)$(bindir)/stap doesn\'t exist, run make install; \ exit -1; \ @@ -279,25 +260,8 @@ installcheck: if test $(builddir)/stap -nt $(DESTDIR)$(bindir)/stap; then \ echo "$(DESTDIR)$(bindir)/stap is not recent, run make install"; \ exit -1; \ - fi; \ - need_server=0; \ - (echo "X$(EXTRA_TOOL_OPTS)" | grep -q server) && need_server=1; \ - if test $$need_server = 1; then \ - echo "Testing using a systemtap server"; \ - need_server=0; \ - server_pid=`stap-find-or-start-server` || need_server=1; \ - if test $$need_server = 1; then \ - echo "Cannot find or start a systemtap server"; \ - exit -1; \ - fi; \ - client_path=":$$BUILDDIR/testsuite/net"; \ - mkdir -p $$BUILDDIR/testsuite/net; \ - cp -p $(DESTDIR)$(bindir)/stap-client $$BUILDDIR/testsuite/net/stap; \ - fi; \ - $(MAKE) -C testsuite installcheck RUNTESTFLAGS="$(RUNTESTFLAGS)" EXTRA_SYSTEMTAP_PATH="$(EXTRA_SYSTEMTAP_PATH)$$client_path"; \ - if test "X$$server_pid" != "X"; then \ - stap-stop-server $$server_pid; \ - fi + fi; + $(MAKE) -C testsuite installcheck RUNTESTFLAGS="$(RUNTESTFLAGS)" EXTRA_SYSTEMTAP_PATH="$(EXTRA_SYSTEMTAP_PATH)" rpm: systemtap.spec dist rpmbuild --define "_sourcedir $(PWD)/" -ba systemtap.spec diff --git a/Makefile.in b/Makefile.in index e3b6f146..745205a9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1636,28 +1636,9 @@ uninstall-local: check: SRCDIR=`cd $(srcdir); pwd`; \ - BUILDDIR=`cd $(builddir); pwd`; \ - need_server=0; \ - (echo "X$(EXTRA_TOOL_OPTS)" | grep -q server) && need_server=1; \ - if test $$need_server = 1; then \ - echo "Testing using a systemtap server"; \ - need_server=0; \ - server_pid=`stap-find-or-start-server` || need_server=1; \ - if test $$need_server = 1; then \ - echo "Cannot find or start a systemtap server"; \ - exit -1; \ - fi; \ - client_path="$$BUILDDIR/testsuite/net"; \ - mkdir -p $$BUILDDIR/testsuite/net; \ - cp -p $$SRCDIR/stap-client $$BUILDDIR/testsuite/net/stap; \ - fi; \ - $(MAKE) -C testsuite check SYSTEMTAP_RUNTIME=$$SRCDIR/runtime SYSTEMTAP_TAPSET=$$SRCDIR/tapset LD_LIBRARY_PATH=$(PWD)/lib-elfutils:$(PWD)/lib-elfutils/systemtap SYSTEMTAP_PATH="$$client_path:$(PWD)" RUNTESTFLAGS="$(RUNTESTFLAGS)"; \ - if test "X$$server_pid" != "X"; then \ - stap-stop-server $$server_pid; \ - fi + $(MAKE) -C testsuite check SYSTEMTAP_RUNTIME=$$SRCDIR/runtime SYSTEMTAP_TAPSET=$$SRCDIR/tapset LD_LIBRARY_PATH=$(PWD)/lib-elfutils:$(PWD)/lib-elfutils/systemtap SYSTEMTAP_PATH="$(PWD)" RUNTESTFLAGS="$(RUNTESTFLAGS)"; installcheck: - BUILDDIR=`cd $(builddir); pwd`; \ if test \! -e $(DESTDIR)$(bindir)/stap; then \ echo $(DESTDIR)$(bindir)/stap doesn\'t exist, run make install; \ exit -1; \ @@ -1665,25 +1646,8 @@ installcheck: if test $(builddir)/stap -nt $(DESTDIR)$(bindir)/stap; then \ echo "$(DESTDIR)$(bindir)/stap is not recent, run make install"; \ exit -1; \ - fi; \ - need_server=0; \ - (echo "X$(EXTRA_TOOL_OPTS)" | grep -q server) && need_server=1; \ - if test $$need_server = 1; then \ - echo "Testing using a systemtap server"; \ - need_server=0; \ - server_pid=`stap-find-or-start-server` || need_server=1; \ - if test $$need_server = 1; then \ - echo "Cannot find or start a systemtap server"; \ - exit -1; \ - fi; \ - client_path=":$$BUILDDIR/testsuite/net"; \ - mkdir -p $$BUILDDIR/testsuite/net; \ - cp -p $(DESTDIR)$(bindir)/stap-client $$BUILDDIR/testsuite/net/stap; \ - fi; \ - $(MAKE) -C testsuite installcheck RUNTESTFLAGS="$(RUNTESTFLAGS)" EXTRA_SYSTEMTAP_PATH="$(EXTRA_SYSTEMTAP_PATH)$$client_path"; \ - if test "X$$server_pid" != "X"; then \ - stap-stop-server $$server_pid; \ - fi + fi; + $(MAKE) -C testsuite installcheck RUNTESTFLAGS="$(RUNTESTFLAGS)" EXTRA_SYSTEMTAP_PATH="$(EXTRA_SYSTEMTAP_PATH)" rpm: systemtap.spec dist rpmbuild --define "_sourcedir $(PWD)/" -ba systemtap.spec diff --git a/stap-client b/stap-client index d6bb8442..cb9bd888 100755 --- a/stap-client +++ b/stap-client @@ -28,6 +28,7 @@ function configuration { # function: initialization function initialization { + rc=0 wd=`pwd` umask 0 @@ -53,6 +54,8 @@ function initialization { # function parse_options { cmdline= + cmdline1= + cmdline2= while test $# != 0 do advance_p=0 @@ -64,26 +67,38 @@ function parse_options { do # Identify the next option first_char=`expr "$first_token" : '\(.\).*'` + second_char= if test $dash_seen = 0; then if test "$first_char" = "-"; then if test "$first_token" != "-"; then - # It's not a lone dash, so it's an option. Remove the dash. - first_token=`expr "$first_token" : '-\(.*\)'` - dash_seen=1 - first_char=`expr "$first_token" : '\(.\).*'` - cmdline="$cmdline -" + # It's not a lone dash, so it's an option. + # Is it a long option (i.e. --option)? + second_char=`expr "$first_token" : '.\(.\).*'` + if test "$second_char" != "-"; then + # It's not a lone dash, or a long option, so it's a short option string. + # Remove the dash. + first_token=`expr "$first_token" : '-\(.*\)'` + dash_seen=1 + first_char=`expr "$first_token" : '\(.\).*'` + cmdline2="$cmdline2 -" + fi fi fi if test $dash_seen = 0; then # The dash has not been seen. This is either the script file - # name or an arument to be passed to the probe module. + # name, a long argument or an argument to be passed to the probe module. # If this is the first time, and -e has not been specified, # then it could be the name of the script file. - if test "X$e_script" = "X" -a "X$script_file" = "X"; then + if test "X$second_char" = "X-"; then + cmdline2="$cmdline2 $first_token" + elif test "X$e_script" = "X" -a "X$script_file" = "X"; then script_file=$first_token + cmdline1="$cmdline2" + cmdline2= + else + cmdline2="$cmdline2 '$first_token'" fi advance_p=$(($advance_p + 1)) - cmdline="$cmdline $first_token" break fi fi @@ -96,7 +111,7 @@ function parse_options { ;; D) get_arg $first_token $2 - cmdline="${cmdline}D '$stap_arg'" + cmdline2="${cmdline2}D '$stap_arg'" ;; e) get_arg $first_token "$2" @@ -111,11 +126,11 @@ function parse_options { ;; l) get_arg $first_token $2 - cmdline="${cmdline}l '$stap_arg'" + cmdline2="${cmdline2}l '$stap_arg'" ;; m) get_arg $first_token $2 - cmdline="${cmdline}m $stap_arg" + cmdline2="${cmdline2}m $stap_arg" ;; o) get_arg $first_token $2 @@ -127,7 +142,7 @@ function parse_options { ;; r) get_arg $first_token $2 - cmdline="${cmdline}r $stap_arg" + cmdline2="${cmdline2}r $stap_arg" ;; R) get_arg $first_token $2 @@ -135,14 +150,14 @@ function parse_options { ;; s) get_arg $first_token $2 - cmdline="${cmdline}s $stap_arg" + cmdline2="${cmdline2}s $stap_arg" ;; v) v_level=$(($v_level + 1)) ;; x) get_arg $first_token $2 - cmdline="${cmdline}x $stap_arg" + cmdline2="${cmdline2}x $stap_arg" ;; *) # An unknown or unimportant flag. Ignore it, but pass it on to the server. @@ -151,7 +166,7 @@ function parse_options { if test $advance_p = 0; then # Just another flag character. Consume it. - cmdline="$cmdline$first_char" + cmdline2="$cmdline2$first_char" first_token=`expr "$first_token" : '.\(.*\)'` if test "X$first_token" = "X"; then advance_p=$(($advance_p + 1)) @@ -176,7 +191,9 @@ function parse_options { else local_name=$script_file fi - cmdline=`echo $cmdline | sed s,$script_file,script/$local_name,` + cmdline="$cmdline1 script/$local_name $cmdline2" + else + cmdline="$cmdline1 $cmdline2" fi } @@ -207,7 +224,7 @@ function get_arg { # Process the -c flag. function process_c { c_cmd="$1" - cmdline="${cmdline}c '$1'" + cmdline2="${cmdline2}c '$1'" } # function: process_e ARGUMENT @@ -218,9 +235,13 @@ function process_e { # which may have already been identified. if test "X$e_script" = "X"; then e_script="$1" - script_file= + if test "X$script_file" != "X"; then + cmdline1="$cmdline1 $script_file $cmdline2" + cmdline2= + script_file= + fi fi - cmdline="${cmdline}e '$1'" + cmdline2="${cmdline2}e '$1'" } # function: process_I ARGUMENT @@ -229,7 +250,7 @@ function process_e { function process_I { local local_name=`include_file_or_directory tapsets $1` test "X$local_name" != "X" || return - cmdline="${cmdline}I $local_name" + cmdline2="${cmdline2}I 'tapsets/$local_name'" } # function: process_o ARGUMENT @@ -237,7 +258,7 @@ function process_I { # Process the -o flag. function process_o { stdout_redirection="> $1" - cmdline="${cmdline}o $1" + cmdline2="${cmdline2}o '$1'" } # function: process_p ARGUMENT @@ -245,7 +266,7 @@ function process_o { # Process the -p flag. function process_p { p_phase=$1 - cmdline="${cmdline}p '$1'" + cmdline2="${cmdline2}p '$1'" } # function: process_R ARGUMENT @@ -254,7 +275,7 @@ function process_p { function process_R { local local_name=`include_file_or_directory runtime $1` test "X$local_name" != "X" || return - cmdline="${cmdline}R $local_name" + cmdline2="${cmdline2}R 'runtime/$local_name'" } # function: include_file_or_directory PREFIX NAME @@ -268,7 +289,7 @@ function include_file_or_directory { fatal "ERROR: could not create $tmpdir_client/$1/`dirname $local_name`" ln -s /$local_name $tmpdir_client/$1/$local_name || \ fatal "ERROR: could not link $tmpdir_client/$1/$local_name to /$local_name" - echo $local_name + echo "$local_name" } # function: generate_client_temp_name NAME @@ -277,12 +298,12 @@ function include_file_or_directory { # client's temporary directory. function generate_client_temp_name { # Transform the name into a fully qualified path name - local full_name=`echo $1 | sed "s,^\\\([^/]\\\),$wd/\\\\1,"` + local full_name=`echo "$1" | sed "s,^\\\([^/]\\\),$wd/\\\\1,"` # The same name without the initial / or trailing / - local local_name=`echo $full_name | sed 's,^/\(.*\),\1,'` - local_name=`echo $local_name | sed 's,\(.*\)/$,\1,'` - echo $local_name + local local_name=`echo "$full_name" | sed 's,^/\(.*\),\1,'` + local_name=`echo "$local_name" | sed 's,\(.*\)/$,\1,'` + echo "$local_name" } # function: create_request @@ -316,7 +337,7 @@ function client_sysinfo { # Add some info from uname sysinfo_client="`uname -rvm`" fi - echo $sysinfo_client + echo "$sysinfo_client" } # function: package_request @@ -353,8 +374,10 @@ function send_request { test "$line" = "ready:" || \ fatal "ERROR: server response, '$line', is incorrect" - # Send the request file. - until nc $server $(($port + 1)) < $tar_client + # Send the request file. We need to redirect to /dev/null + # in order to workaround a nc bug. It closes the connection + # early if stdin from the other side is not provided. + until nc $server $(($port + 1)) < $tar_client > /dev/null do sleep 1 done @@ -364,7 +387,7 @@ function send_request { # # Wait for a response from the server indicating the results of our request. # protocol is: -# server -> "done:" +# server -> "{done,failed}:" # server -> $tar_server function receive_response { # Get the server's response. @@ -373,15 +396,21 @@ function receive_response { check_server_error $line # Check for the proper response. - test "$line" = "done:" || \ - fatal "ERROR: server response, '$line', is incorrect" + if test "$line" != "done:"; then + if test "$line" != "failed:"; then + fatal "ERROR: server response, '$line', is incorrect" + fi + rc=1 + fi # Make a place to receive the response file. tar_server=`mktemp -t $tmpdir_prefix_client.server.tgz.XXXXXX` || \ fatal "ERROR: cannot create temporary file " $tar_server - # Retrieve the file - until nc $server $(($port + 1)) > $tar_server + # Retrieve the file. We need to redirect stdin from /dev/zero to work + # around a bug in nc. It closes the connection early is stdin is not + # provided. + until nc $server $(($port + 1)) < /dev/zero > $tar_server do sleep 1 done @@ -530,21 +559,37 @@ function stream_output { # # Call staprun using the module returned from the server, if requested. function maybe_call_staprun { - if test $p_phase = 5; then - # Can't call staprun without a module. - test "X$tmpdir_stap" = "X" && return + if test $rc != 0; then + # stap run on the server failed, so don't bother + return + fi + if test $p_phase -ge 4; then + # There should be a systemtap temporary directory. + if test "X$tmpdir_stap" = "X"; then + # OK if no script specified + if test "X$script_file" != "X"; then + fatal "ERROR: systemtap temporary directory is missing in server response" + fi + return + fi + + # There should be a module. local mod_name=`ls $tmpdir_stap | grep '.ko$'` - test "X$mod_name" != "X" || \ - fatal "ERROR: no module to run in $tmpdir_stap" + if test "X$mod_name" = "X"; then + fatal "ERROR: no module was found in $tmpdir_stap" + fi - # We have a module. Try to run it - for ((--v_level; $v_level > 0; --v_level)) - do - staprun_opts="$staprun_opts -v" - done - PATH=`staprun_PATH` staprun $staprun_opts \ - $tmpdir_stap/`ls $tmpdir_stap | grep '.ko$'` + if test $p_phase = 5; then + # We have a module. Try to run it + for ((--v_level; $v_level > 0; --v_level)) + do + staprun_opts="$staprun_opts -v" + done + PATH=`staprun_PATH` staprun $staprun_opts \ + $tmpdir_stap/`ls $tmpdir_stap | grep '.ko$'` + rc=$? + fi fi } @@ -562,14 +607,14 @@ function staprun_PATH { # Otherwise, remove the PATH component where we live from the PATH local PATH_component=`dirname $first_stap` - echo $PATH | sed "s,$PATH_component,,g" + echo "$PATH" | sed "s,$PATH_component,,g" } # function: check_server_error SERVER_RESPONSE # # Check the given server response for an error message. function check_server_error { - echo $1 | grep -q "^ERROR:" && \ + echo "$1" | grep -q "^ERROR:" && \ server_fatal "Server:" "$@" } @@ -578,7 +623,7 @@ function check_server_error { # Fatal error # Prints its arguments to stderr and exits function fatal { - echo $0: "$@" >&2 + echo "$0:" "$@" >&2 disconnect_from_server cleanup exit 1 @@ -589,7 +634,7 @@ function fatal { # Fatal error # Prints its arguments to stderr and exits function server_fatal { - echo $0: "$@" >&2 + echo "$0:" "$@" >&2 cat <&3 >&2 disconnect_from_server cleanup @@ -627,4 +672,4 @@ stream_output maybe_call_staprun cleanup -exit 0 +exit $rc diff --git a/stap-find-or-start-server b/stap-find-or-start-server index 0ea0ef43..32a45052 100755 --- a/stap-find-or-start-server +++ b/stap-find-or-start-server @@ -10,27 +10,23 @@ # later version. # This script attempts to find a systemtap server. If one is found, it -# simply exits with 0. +# echoes 0 and exits with 0. # # Otherwise, it attempts to start a server. If succesful, it echoes the # process id and exits with 0. # -# Otherwise, it exits with 1 +# Otherwise, it echoes -1 and exits with 1 # Is there a server available? -stap-find-servers >/dev/null 2>&1 && exit 0 +stap-find-servers >/dev/null 2>&1 && echo 0 && exit 0 # No server available, try to start one. pid=`stap-start-server` if test $? = 0; then - echo $pid - # Make sure the server is started - for ((attempt=0; $attempt < 5; ++attempt)) - do - stap-find-servers >/dev/null 2>&1 && exit 0 - sleep 1 - done + echo $pid + exit 0 fi # Could not find or start a server +echo -1 exit 1 diff --git a/stap-server b/stap-server index e825c49a..fb4203b6 100755 --- a/stap-server +++ b/stap-server @@ -31,6 +31,7 @@ function configuration { # function: initialization function initialization { # Initialization + rc=0 wd=`pwd` # Default options settings @@ -58,11 +59,14 @@ function receive_request { tar_client=`mktemp -t $tmpdir_prefix_server.client.tgz.XXXXXX` || \ fatal "ERROR: cannot create temporary tar file " $tar_client + # Receive the file. We need to redirect stdin from /dev/zero to work + # around a bug in nc. It closes the connection early is stdin is not + # provided. + nc -l $port < /dev/zero > $tar_client & + # Request that the file be sent. echo "ready:" - - # Receive the file. - nc -l $port < /dev/null > $tar_client + wait %nc } # function: unpack_request @@ -125,7 +129,7 @@ function server_sysinfo { # Add some info from uname sysinfo_server="`uname -rvm`" fi - echo $sysinfo_server + echo "$sysinfo_server" } # function check_compaibility SYSINFO1 SYSINFO2 @@ -152,14 +156,30 @@ function read_data_file { test -f $1 || \ fatal "ERROR: Data file $1 not found" - read < $1 + # Open the file + exec 3< $1 + + # Verify the first line of the file. + read <&3 line=$REPLY data=`expr "$line" : "$1: \\\(.*\\\)"` - if test "X$data" != "X"; then - echo $data + if test "X$data" = "X"; then + fatal "ERROR: Data in file $1 is incorrect" return fi - fatal "ERROR: Data in file $1 is incorrect" + + # Add any additional lines of data + while read <&3 + do + data="$data +$REPLY" + done + + # Close the file + exec 3<&- + + # Echo the result + echo "$data" } # function: parse_options [ STAP-OPTIONS ] @@ -316,9 +336,11 @@ function call_stap { server_p_phase=$p_phase fi - eval stap $cmdline -k -p $server_p_phase \ + eval stap "$cmdline" -k -p $server_p_phase \ >> $tmpdir_server/stdout \ 2>> $tmpdir_server/stderr + + rc=$? } # function: create_response @@ -371,12 +393,20 @@ function package_response { # Notify the client that $tar_server is ready and wait for the client to take # it. # The protocol is: -# server -> "done:" +# server -> "{done,failed}:" # server -> $tar_server function send_response { - echo "done:" - # Now send it - nc -l $port < $tar_server > /dev/null + # Now send it. We need to redirect to /dev/null + # in order to workaround a nc bug. It closes the connection + # early if stdin from the other side is not provided. + nc -l $port < $tar_server > /dev/null & + + if test $rc = 0; then + echo "done:" + else + echo "failed:" + fi + wait %nc } # function: fatal [ MESSAGE ] @@ -408,6 +438,9 @@ function cleanup { rm -fr $tmpdir_server rm -fr $tmpdir_stap fi + + # Kill any nc job that may be running + kill -s SIGTERM %nc 2> /dev/null } # function: terminate @@ -416,7 +449,7 @@ function cleanup { function terminate { # Clean up cleanup - exit + exit $rc } #----------------------------------------------------------------------------- @@ -427,11 +460,11 @@ initialization receive_request unpack_request check_request -eval parse_options $cmdline +eval parse_options "$cmdline" call_stap create_response package_response send_response cleanup -exit 0 +exit $rc diff --git a/stap-serverd b/stap-serverd index af4b2717..e378f6e4 100755 --- a/stap-serverd +++ b/stap-serverd @@ -59,11 +59,17 @@ function listen { fatal "ERROR: cannot create temporary fifo " $tmpdir/$fifo_name # Loop forever accepting requests + first=1 while true do # Run this in the background and wait for it. This way any signals - # received (i.e. SIGTERM) will be processed. + # received (i.e. SIGTERM) will be processed. Make sure we don't + # advertise our presence until we're actually listening. nc -l $port < $fifo_name | stap-server $((port + 1)) > $fifo_name 2>&1 & + if test $first = 1; then + advertise_presence + first=0 + fi wait %nc done } @@ -102,5 +108,4 @@ function terminate { # Beginning of main line execution. #----------------------------------------------------------------------------- initialization "$@" -advertise_presence listen diff --git a/stap-start-server b/stap-start-server index d143e269..eea86526 100755 --- a/stap-start-server +++ b/stap-start-server @@ -16,9 +16,11 @@ stap-serverd </dev/null >/dev/null 2>&1 & server_pid=$! -# Exit if the server did not start ok -(ps | grep -q $server_pid) || exit 1 +# Make sure the server is started +for ((attempt=0; $attempt < 5; ++attempt)) +do + stap-find-servers >/dev/null 2>&1 && echo $server_pid && exit 0 + sleep 1 +done -# The server started ok. Echo its process id. -echo $server_pid -exit 0 +exit 1 # server did not start diff --git a/systemtap.spec b/systemtap.spec index 503022d1..61ccd667 100644 --- a/systemtap.spec +++ b/systemtap.spec @@ -46,6 +46,7 @@ Requires: crash %if %{with_docs} BuildRequires: /usr/bin/latex /usr/bin/dvips /usr/bin/ps2pdf latex2html %endif +Requires: avahi-tools nc %description SystemTap is an instrumentation system for systems running Linux 2.6. @@ -59,6 +60,7 @@ License: GPLv2+ URL: http://sourceware.org/systemtap/ Requires: kernel >= 2.6.9-11 Requires(pre): shadow-utils +Requires: avahi-tools nc %description runtime SystemTap runtime is the runtime component of an instrumentation @@ -178,10 +180,6 @@ exit 0 %{_bindir}/stap %{_bindir}/stap-server %{_bindir}/stap-serverd -%{_bindir}/stap-find-servers -%{_bindir}/stap-start-server -%{_bindir}/stap-find-or-start-server -%{_bindir}/stap-stop-server %{_mandir}/man1/* %{_mandir}/man5/* @@ -203,6 +201,10 @@ exit 0 %defattr(-,root,root) %attr(4111,root,root) %{_bindir}/staprun %{_bindir}/stap-client +%{_bindir}/stap-find-servers +%{_bindir}/stap-start-server +%{_bindir}/stap-find-or-start-server +%{_bindir}/stap-stop-server %{_libexecdir}/%{name} %{_mandir}/man8/* diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 67d741e5..f28f05d7 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2008-08-08 Dave Brolley <brolley@redhat.com> + + * lib/systemtap.exp (setup_systemtap_environment): If use_server_p, + start or find a systemtap server. + (systemtap_exit): If we started a server, stop it. + * Makefile.am (EXTRA_SYSTEMTAP_PATH): Removed. + (EXTRA_TOOL_OPTS): Removed. + * Makefile.in: Regenerated. 2008-08-03 Wenji Huang <wenji.huang@oracle.com> diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 03c70cb6..6daef3f6 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -13,7 +13,7 @@ clean-local: DEJAZILLA=@dejazilla@ -TOOL_OPTS=$(EXTRA_TOOL_OPTS) +TOOL_OPTS= # automake's dejagnu library already runs check-DEJAGNU before check-local # That's why we need to add "execrc" to $(RUNTEST) - to ensure that this @@ -40,7 +40,7 @@ SYSTEMTAP_RUNTIME=$(DESTDIR)$(pkgdatadir)/runtime SYSTEMTAP_TAPSET=$(DESTDIR)$(pkgdatadir)/tapset LD_LIBRARY_PATH=$(DESTDIR)$(libdir)/systemtap CRASH_LIBDIR=$(DESTDIR)$(libdir)/systemtap -SYSTEMTAP_PATH=$(EXTRA_SYSTEMTAP_PATH):$(DESTDIR)$(bindir) +SYSTEMTAP_PATH=$(DESTDIR)$(bindir) RUNTESTDEFAULTFLAGS = --tool $$tool --tool_opts \'$(TOOL_OPTS)\' --srcdir $$srcdir EXPECT = expect diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in index cc23aed4..9c708bc9 100644 --- a/testsuite/Makefile.in +++ b/testsuite/Makefile.in @@ -134,7 +134,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = dejagnu DEJAZILLA = @dejazilla@ -TOOL_OPTS = $(EXTRA_TOOL_OPTS) +TOOL_OPTS = SRCDIR = $(shell cd $(srcdir); pwd) EXTRA_DIST = execrc config lib systemtap \ parseok parseko semok semko transok transko buildok buildok \ @@ -149,7 +149,7 @@ SYSTEMTAP_RUNTIME = $(DESTDIR)$(pkgdatadir)/runtime SYSTEMTAP_TAPSET = $(DESTDIR)$(pkgdatadir)/tapset LD_LIBRARY_PATH = $(DESTDIR)$(libdir)/systemtap CRASH_LIBDIR = $(DESTDIR)$(libdir)/systemtap -SYSTEMTAP_PATH = $(EXTRA_SYSTEMTAP_PATH):$(DESTDIR)$(bindir) +SYSTEMTAP_PATH = $(DESTDIR)$(bindir) RUNTESTDEFAULTFLAGS = --tool $$tool --tool_opts \'$(TOOL_OPTS)\' --srcdir $$srcdir EXPECT = expect RUNTEST = "env SYSTEMTAP_RUNTIME=$(SYSTEMTAP_RUNTIME) SYSTEMTAP_TAPSET=$(SYSTEMTAP_TAPSET) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CRASH_LIBDIR=$(CRASH_LIBDIR) PATH=$(SYSTEMTAP_PATH):$$PATH $(srcdir)/execrc runtest" diff --git a/testsuite/lib/systemtap.exp b/testsuite/lib/systemtap.exp index db5c1587..8b533303 100644 --- a/testsuite/lib/systemtap.exp +++ b/testsuite/lib/systemtap.exp @@ -37,7 +37,7 @@ proc print_systemtap_version {} { proc setup_systemtap_environment {} { - global srcdir prefix env + global srcdir prefix env server_pid # need an absolute SRCDIR for the top-level src/ tree # XXX: or, we could change nearby uses of ${SRCDIR}/testsuite to ${SRCDIR} @@ -51,6 +51,41 @@ proc setup_systemtap_environment {} { # make check and sudo make check don't clobber each other. set env(SYSTEMTAP_DIR) [exec pwd]/.systemtap-[exec whoami] + # Find or start a systemtap server, if requested. + if {[use_server_p]} then { + print "Testing using a systemtap server" + + # Server management scripts are installed if this is an install test, otherwise + # in the source directory. Make sure they are on the $PATH. + if {! [installtest_p]} then { + set env(PATH) "$srcdir/..:$env(PATH)" + } + + # Try to find or start the server. + set server_pid [exec stap-find-or-start-server] + if { $server_pid == -1 } then { + print "Cannot find or start a systemtap server" + set server_pid 0 + # TODO: How do we abort here? + } elseif { $server_pid == 0 } then { + print "A compatible systemtap server is already available" + } else { + print "Started a systemtap server as PID==$server_pid" + } + + # Make a copy of 'stap-client' as 'stap' and make sure it's at the + # beginning of the $PATH. Do this after starting the server so that + # The server does not call this instance of 'stap' + set client_path [exec pwd]/net + exec /bin/mkdir -p $client_path + if {[installtest_p]} then { + exec /bin/cp -p [exec which stap-client] $client_path/stap + } else { + exec /bin/cp -p $srcdir/../stap-client $client_path/stap + } + set env(PATH) "$client_path:$env(PATH)" + } + # PATH, SYSTEMTAP_TAPSET, SYSTEMTAP_RUNTIME, LD_LIBRARY_PATH are already set. foreach var {PATH STAP SRCDIR SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_DIR LD_LIBRARY_PATH} { if [info exists env($var)] { @@ -84,7 +119,18 @@ get_system_info proc systemtap_init {args} {} proc systemtap_version {} {} -proc systemtap_exit {} {} + +proc systemtap_exit {} { + global server_pid + + # Stop the stap server, if we started it. + if {[use_server_p]} then { + if { $server_pid != 0 } then { + print "Stopping the systemtap server with PID==$server_pid" + exec stap-stop-server $server_pid + } + } +} proc stap_run_batch {args} { |