summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog24
-rwxr-xr-xstap-client83
-rwxr-xr-xstap-server35
-rwxr-xr-xstap-serverd2
4 files changed, 63 insertions, 81 deletions
diff --git a/ChangeLog b/ChangeLog
index 0b5e55b8..f6886301 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2008-08-14 Dave Brolley <brolley@redhat.com>
+
+ PR 6834
+ * stap-client (initialization): initialize staprun_running.
+ (send_request): No server response message required.
+ (receive_response): No server response message required. Simply
+ receive the tar file. The tar file should contain a file called 'rc'.
+ (connect_to_server): Use 'nc'.
+ (disconnect_from_server): No action required.
+ (process_response): Renamed from 'stream_output'. Obtain the exit
+ code from the 'rc' file.
+ (maybe_call_staprun): set 'staprun_running' while staprun is running.
+ (check_server_error): Removed.
+ (server_fatal): Removed.
+ (cleanup): Redirect stderr of 'kill' to /dev/null.
+ (interrupt): Pass SIGINT on to staprun, if it is running. Otherwise,
+ exit.
+ * stap-server (initialization): Create the server temp directory here...
+ (unpack_request): ... not here.
+ (receive_request): Don't send a ready message.
+ (create_response): Write the exit code of 'stap' to the 'rc' file.
+ (send_response): Don't send a status message.
+ (fatal,error): Redirect to $tmpdir_server/stderr.
+
2008-08-13 Dave Brolley <brolley@redhat.com>
* stap-client: Trap SIGTERM and SIGINT.
diff --git a/stap-client b/stap-client
index b6664bc3..bced5e5f 100755
--- a/stap-client
+++ b/stap-client
@@ -35,6 +35,7 @@ function initialization {
rc=0
wd=`pwd`
umask 0
+ staprun_running=0
# Default options settings
p_phase=5
@@ -365,19 +366,8 @@ function package_request {
# Notify the server and then send $tar_client to the server
# The protocol is:
# client -> "request:"
-# server -> "ready:"
# client -> $tar_client
function send_request {
- echo "request:" >&3
- # Get the server's response.
- read <&3
- local line=$REPLY
- check_server_error $line
-
- # Check for the proper response.
- test "$line" = "ready:" || \
- fatal "ERROR: server response, '$line', is incorrect"
-
# 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.
@@ -390,23 +380,7 @@ function send_request {
# function: receive_response
#
# Wait for a response from the server indicating the results of our request.
-# protocol is:
-# server -> "{done,failed}:"
-# server -> $tar_server
function receive_response {
- # Get the server's response.
- read <&3
- local line=$REPLY
- check_server_error $line
-
- # Check for the proper response.
- 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
@@ -448,14 +422,17 @@ function unpack_response {
# Check the contents of the expanded directory. It should contain:
# 1) a file called stdout
# 2) a file called stderr
- # 3) optionally a directory named to match stap??????
+ # 3) a file called rc
+ # 4) optionally a directory named to match stap??????
local num_files=`ls $tmpdir_server | wc -l`
- test $num_files = 3 -o $num_files = 2 || \
+ test $num_files = 4 -o $num_files = 3 || \
fatal "ERROR: Wrong number of files in server's temp directory"
test -f $tmpdir_server/stdout || \
fatal "ERROR: `pwd`/$tmpdir_server/stdout does not exist or is not a regular file"
test -f $tmpdir_server/stderr || \
fatal "ERROR: `pwd`/$tmpdir_server/stderr does not exist or is not a regular file"
+ test -f $tmpdir_server/rc || \
+ fatal "ERROR: `pwd`/$tmpdir_server/rc does not exist or is not a regular file"
# See if there is a systemtap temp directory
tmpdir_stap=`ls $tmpdir_server | grep stap`
@@ -537,26 +514,30 @@ function choose_server {
#
# Establish connection with the given server
function connect_to_server {
- # Open a connection to the server
- exec 3<> /dev/tcp/$1/$2
+ until echo "request:" | nc $1 $2 > /dev/null
+ do
+ sleep 1
+ done
}
# function: disconnect_from_server
#
# Disconnect from the server.
function disconnect_from_server {
- # Close the connection to the server.
- exec 3<&-
+ :
}
-# function: stream_output
+# function: process_response
#
# Write the stdout and stderr from the server to stdout and stderr respectively.
-function stream_output {
+function process_response {
# Output stdout and stderr as directed
cd $tmpdir_server
cat stderr >&2
eval cat stdout $stdout_redirection
+
+ # Pick up the results of running stap on the server.
+ rc=`cat rc`
}
# function: maybe_call_staprun
@@ -602,8 +583,10 @@ function maybe_call_staprun {
# way any signals send to us can be caught.
PATH=`staprun_PATH` eval staprun "$staprun_opts" \
$tmpdir_stap/`ls $tmpdir_stap | grep '.ko$'` &
+ staprun_running=1
wait %?staprun
rc=$?
+ staprun_running=0
# 127 from wait means that the job was already finished.
test $rc=127 && rc=0
fi
@@ -627,14 +610,6 @@ function staprun_PATH {
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:" && \
- server_fatal "Server:" "$@"
-}
-
# function: fatal [ MESSAGE ]
#
# Fatal error
@@ -646,18 +621,6 @@ function fatal {
exit 1
}
-# function: server_fatal [ MESSAGE ]
-#
-# Fatal error
-# Prints its arguments to stderr and exits
-function server_fatal {
- echo "$0:" "$@" >&2
- cat <&3 >&2
- disconnect_from_server
- cleanup
- exit 1
-}
-
# function cleanup
#
# Cleanup work files unless asked to keep them.
@@ -681,7 +644,7 @@ function terminate {
cleanup
# Kill any running staprun job
- kill -s SIGTERM %?staprun
+ kill -s SIGTERM %?staprun 2>/dev/null
exit 1
}
@@ -691,7 +654,11 @@ function terminate {
# Pass an interrupt (ctrl-C) to staprun
function interrupt {
# Pass the signal on to any running staprun job
- kill -s SIGINT %?staprun
+ kill -s SIGINT %?staprun 2>/dev/null
+
+ # If staprun was running, then just interrupt it. Otherwise
+ # we exit.
+ test $staprun_running = 0 && exit 1
}
#-----------------------------------------------------------------------------
@@ -707,7 +674,7 @@ send_request
receive_response
disconnect_from_server
unpack_response
-stream_output
+process_response
maybe_call_staprun
cleanup
diff --git a/stap-server b/stap-server
index 15a2fb48..12f93757 100755
--- a/stap-server
+++ b/stap-server
@@ -37,6 +37,11 @@ function initialization {
# Default options settings
p_phase=5
keep_temps=0
+
+ # Make a temp directory to work in.
+ tmpdir_server=`mktemp -dt $tmpdir_prefix_server.XXXXXX` || \
+ fatal "ERROR: cannot create temporary directory " $tmpdir_server
+ tmpdir_env=`dirname $tmpdir_server`
}
# function: receive_request
@@ -44,7 +49,6 @@ function initialization {
# Receive a tar file representing the request from the client:
# The protocol is:
# client -> "request:"
-# server -> "ready:"
# client -> $tar_client
function receive_request {
# Request from the client is on stdin
@@ -64,8 +68,7 @@ function receive_request {
# provided.
nc -l $port < /dev/zero > $tar_client &
- # Request that the file be sent.
- echo "ready:"
+ # Wait for the transfer to complete.
wait %nc
}
@@ -74,11 +77,6 @@ function receive_request {
# Unpack the tar file received from the client and make the contents
# available for use when running 'stap'
function unpack_request {
- # Make a temp directory to work in.
- tmpdir_server=`mktemp -dt $tmpdir_prefix_server.XXXXXX` || \
- fatal "ERROR: cannot create temporary directory " $tmpdir_server
- tmpdir_env=`dirname $tmpdir_server`
-
cd $tmpdir_server
# Unpack the tar file.
@@ -151,7 +149,7 @@ function check_compatibility {
# function: read_data_file PREFIX
#
# Find a file whose name is '$1' and whose first line
-# contents are '$1: .*'. Read and echo the first line.
+# contents are '$1: .*'. Read and echo the data.
function read_data_file {
test -f $1 || \
fatal "ERROR: Data file $1 not found"
@@ -369,6 +367,9 @@ function create_response {
if test $p_phase = 5; then
sed -i '/\.ko$/d' stdout
fi
+
+ # The return status of the stap command.
+ echo -n $stap_rc > rc
}
# function: package_response
@@ -390,22 +391,12 @@ function package_response {
# function: send_response
#
-# Notify the client that $tar_server is ready and wait for the client to take
-# it.
-# The protocol is:
-# server -> "{done,failed}:"
-# server -> $tar_server
+# Wait for the client to take the response file.
function send_response {
# 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 $stap_rc = 0; then
- echo "done:"
- else
- echo "failed:"
- fi
wait %nc
}
@@ -414,7 +405,7 @@ function send_response {
# Fatal error
# Prints its arguments to stderr and exits
function fatal {
- echo "$@" >&2
+ echo "`basename $0`:" "$@" >> $tmpdir_server/stderr
cleanup
exit 1
}
@@ -422,7 +413,7 @@ function fatal {
# Non fatal error
# Prints its arguments to stderr but does not exit
function error {
- echo "$@" >&2
+ echo "`basename $0`:" "$@" >> $tmpdir_server/stderr
}
# function cleanup
diff --git a/stap-serverd b/stap-serverd
index 32888ecc..a6611255 100755
--- a/stap-serverd
+++ b/stap-serverd
@@ -85,7 +85,7 @@ function listen {
fi
sleep 1
done
- if test $attempt = 10; then
+ if test $attempt = 5; then
fatal "ERROR: cannot listen on port $port. rc==$rc"
fi
done