From 98f552c28ebbed982e96be5798a8454c7220925a Mon Sep 17 00:00:00 2001 From: Dave Brolley Date: Thu, 12 Mar 2009 13:38:51 -0400 Subject: 2009-03-12 Dave Brolley * util.cxx (remove_file_or_dir): New function. * util.h (remove_file_or_dir): New function. * systemtap.spec (stap): Add stap-env, stap-gen-cert, stap-authorize-cert, and stap-authorize-signing-cert. (stap-client): Remove stap-find-or-start-server, stap-add-server-cert. Add stap-authorize-server-cert. (stap-server): Add stap-find-servers, stap-find-or-start-server, stap-authorize-server-cert. Remove stap-gen-server-cert. * stap-find-servers: Source stap-env. Use $stap_avahi_service_tag. (initialization): Set timeout to 10. (find_servers): Run avahi-browse in the background and wait for it. Use a temp file for the output of avahi-browse. Kill avahi-browse if the timeout expires. (match_server): Set read timeout. (fatal): New function. * stap-find-or-start-server: Source stap-env. Use $stap_exec_prefix. Always exit with 0. * stap-start-server: Source stap-env. Check for the server PID as a running process and for avahi-publish-service running as a child in order to verify that the server is ready. * stap-add-server-cert: Renamed to stap-authorize-server-cert. Source stap-env. Call stap-authorize-cert. * stap-client: Source stap-env. Use $stap_user_ssl_db and $stap_root_ssl_db. Use $stap_tmpdir_prefix_client, $stap_tmpdir_prefix_server. Use $stap_exec_prefix. (configuration): Removed. (staprun_running): Removed. (interrupt): Don't kill staprun. * stap-server: Source stap-env. Use $stap_user_ssl_db and $stap_root_ssl_db. Use $stap_tmpdir_prefix_client, $stap_tmpdir_prefix_server. Use $stap_exec_prefix. (configuration): Removed. * session.h (systemtap_session): Add cert_db_path. * runtime/staprun/staprun_funcs.c (config.h): #include it. (modverify.h): #include it. (check_signature): New function. (check_groups): New function extracted from check_permissions. (check_permissions): Call check_groups and check_signature. * runtime/staprun/mainloop.c (cleanup_and_exit): Pass modpath to staprun, not modname. * main.cxx (main): Initialize cert_db_path. Handle LONG_OPT_SIGN_MODULE. Save the module signature if the module was signed and is being saved. (LONG_OPT_SIGN_MODULE): #define it. (long_options): Add --sign-module. * cache.cxx (config.h): #include it. (add_to_cache): Add the module signature file to the cache if the module has been signed. * buildrun.cxx (modsign.h): #include it. (compile_pass): Call sign_module, if requested. * configure.ac: Define HAVE_NSS if NSS libraries are available. * Makefile.am (AM_CPPFLAGS): Add -DSYSCONFDIR. (bin_SCRIPTS): Add stap-env, stap-gen-cert, stap-authorize-cert, stap-authorize-signing-cert, stap-authorize-server-cert. Remove stap-gen-server-cert, stap-add-server-cert. (stap_SOURCES): Add nsscommon.c, modsign.cxx (stap_CPPFLAGS): Add $(nss_CFLAGS), $(nspr_CFLAGS). (stap_LDADD): Add -lnss3. (staprun_SOURCES): Add nsscommon.c. * modsign.cxx: New file. * modsign.h: New file. * nsscommon.c: New file. * nsscommon.h: New file. * runtime/staprun/modverify.c: New file. * runtime/staprun/modverify.h: New file. * stap-authorize-cert: New file. * stap-authorize-signing-cert: New file. * stap-env: New file. * Makefile.in: Regenerated. * aclocal.m4: Regenerated. * config.in: Regenerated. * configure: Regenerated. * doc/Makefile.in: Regenerated. * doc/SystemTap_Tapset_Reference/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * testsuite/aclocal.m4: Regenerated. --- stap-find-servers | 65 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'stap-find-servers') diff --git a/stap-find-servers b/stap-find-servers index 3038c54e..e0838708 100755 --- a/stap-find-servers +++ b/stap-find-servers @@ -2,7 +2,7 @@ # Find compile servers for systemtap # -# Copyright (C) 2008 Red Hat Inc. +# Copyright (C) 2008, 2009 Red Hat Inc. # # This file is part of systemtap, and is free software. You can # redistribute it and/or modify it under the terms of the GNU General @@ -12,14 +12,12 @@ # This script uses avahi to find systemtap compile servers on the local # network. Information about each server found is printed to stdout. +# Initialize the environment +. stap-env + #----------------------------------------------------------------------------- # Helper functions. #----------------------------------------------------------------------------- -# function: configuration -function configuration { - avahi_service_tag=_stap._tcp -} - # function: initialization function initialization { rc=1 # not found yet @@ -28,15 +26,35 @@ function initialization { else find_all=0 fi + timeout=10 # seconds } -# function: find_and_connect_to_server +# function: find_servers # -# Find and establish connection with a compatibale stap server. +# Find and establish connection with a compatible stap server. function find_servers { - # Find a server - avahi-browse $avahi_service_tag --terminate -r 2>/dev/null | match_server - rc=$? + # Create a temp file for the list of servers. We do this instead + # of using a pipe so that we can kill avahi-browse if it + # takes too long. + tmpfile=`mktemp -t stap-serversXXXXXX` || \ + fatal "Cannot create temporary file " $tmpfile + + # Find servers + avahi-browse $stap_avahi_service_tag --terminate -r 2>/dev/null > $tmpfile & + + for ((attempt=0; $attempt < $timeout; ++attempt)) + do + if ! jobs '%avahi-browse' >/dev/null 2>&1; then + break + fi + sleep 1 + done + + # Kill avahi-browse, if it's still running + test $attempt = $timeout && kill -s SIGTERM '%avahi-browse' 2>/dev/null + + match_server < $tmpfile + rm -fr $tmpfile } # function: match_server @@ -47,10 +65,11 @@ function match_server { local server_name local server_sysinfo local server_port - local rc=1 # not found yet + + rc=1 # not found yet # Loop over the avahi service descriptors. - read || exit $rc + read -t $timeout || return while test "X$REPLY" != "X" do server_name= @@ -61,14 +80,14 @@ function match_server { # Examine the next service descriptor # Is it a stap server? if ! echo $REPLY | grep -q "=.* .* IPv4 .*_stap"; then - read || exit $rc + read -t $timeout || return continue fi REPLY= # Get the details of the service local service_tag equal service_data - while read service_tag equal service_data + while read -t $timeout service_tag equal service_data do case $service_tag in hostname ) @@ -76,7 +95,7 @@ function match_server { ;; address ) # Sometimes (seems random), avahi-resolve-host-name resolves a local server to its - # hardware address rather its ip address. Keep trying until we get + # hardware address rather than its ip address. Keep trying until we get # an ip address. server_ip=`expr "$service_data" : '\[\([^]]*\)\]'` local attempt @@ -104,7 +123,7 @@ function match_server { esac done - # It is a stap server, but is it compatible? + # It's an stap server, but is it compatible? if test $find_all = 0 -a "$server_sysinfo" != "`client_sysinfo`"; then continue fi @@ -113,8 +132,6 @@ function match_server { echo "$server_name $server_ip $server_port '$server_sysinfo'" rc=0 done - - exit $rc } # function client_sysinfo @@ -128,10 +145,18 @@ function client_sysinfo { echo sysinfo=$sysinfo_client } +# function: fatal [ MESSAGE ] +# +# Fatal error +# Prints its arguments to stderr and exits +function fatal { + echo "$0: ERROR:" "$@" >&2 + exit 1 +} + #----------------------------------------------------------------------------- # Beginning of main line execution. #----------------------------------------------------------------------------- -configuration initialization "$@" find_servers -- cgit