summaryrefslogtreecommitdiffstats
path: root/stap-find-servers
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@elastic.org>2008-08-06 12:06:06 -0400
committerFrank Ch. Eigler <fche@elastic.org>2008-08-06 12:06:06 -0400
commit3c4371661f144c331dd55ee6be8dab57ec2323c8 (patch)
tree217ccf5864840f14670138b592d90eceacc75fa3 /stap-find-servers
parent44ab6f3be72e7b5eeaa2514cea0553b87007ee9c (diff)
parent0317fad416059781b7a152296c1d8b5a012bf925 (diff)
downloadsystemtap-steved-3c4371661f144c331dd55ee6be8dab57ec2323c8.tar.gz
systemtap-steved-3c4371661f144c331dd55ee6be8dab57ec2323c8.tar.xz
systemtap-steved-3c4371661f144c331dd55ee6be8dab57ec2323c8.zip
Merge commit 'origin/master' into pr4225
* commit 'origin/master': Use relative instead of absolute line. (bug 6611) move post-0.7 news tidbit to the top Add test for $$vars, $$params, $$locals. typographical tweaks for embedded script code Add $$vars, $$parms, $$locals Rename $path to $pathname of syscall tapset for 2.6.27 Correct several tests for 2.6.27 c code generation: assert C indentation/nesting cancels out at appropriate points Tweak test_installcheck for helloworld.meta and traceio2.meta. Run both tests for installcheck tests. No need for random suffix file cmdline and sysinfo files in the Ensure that a systemtap server is available if 'server' is specified session.h (struct systemtap_session): Added itrace_derived_probe * syscalls2.stp: Add sys_unlinkat. Fix on_each_cpu() call for kernels >2.6.26. Remove unused STAPCONF_MODULE_NSECTIONS
Diffstat (limited to 'stap-find-servers')
-rwxr-xr-xstap-find-servers128
1 files changed, 128 insertions, 0 deletions
diff --git a/stap-find-servers b/stap-find-servers
new file mode 100755
index 00000000..9e7b633d
--- /dev/null
+++ b/stap-find-servers
@@ -0,0 +1,128 @@
+#!/bin/bash
+
+# Find compile servers for systemtap
+#
+# Copyright (C) 2008 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
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+# This script uses avahi to find systemtap compile servers on the local
+# network. Information about each server found is printed to stdout.
+
+#-----------------------------------------------------------------------------
+# Helper functions.
+#-----------------------------------------------------------------------------
+# function: configuration
+function configuration {
+ avahi_service_tag=_stap._tcp
+}
+
+# function: initialization
+function initialization {
+ rc=1 # not found yet
+ if test "X$1" = "X--all"; then
+ find_all=1
+ else
+ find_all=0
+ fi
+}
+
+# function: find_and_connect_to_server
+#
+# Find and establish connection with a compatibale stap server.
+function find_servers {
+ # Find a server
+ avahi-browse $avahi_service_tag --terminate -r 2>/dev/null | match_server
+ rc=$?
+}
+
+# function: match_server
+#
+# Find a suitable server using the avahi-browse output provided on stdin.
+function match_server {
+ local server_ip
+ local server_name
+ local server_sysinfo
+ local server_port
+ local rc=1 # not found yet
+
+ # Loop over the avahi service descriptors.
+ while read
+ do
+ # Examine the next service descriptor
+ # Is it a stap server?
+ (echo $REPLY | grep -q "^=.*_stap") || continue
+
+ # Get the details of the service
+ local service_tag equal data
+ while read service_tag equal service_data
+ do
+ case $service_tag in
+ '=' )
+ break ;;
+ hostname )
+ server_name=`expr "$service_data" : '\[\([^]]*\)\]'`
+ ;;
+ 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
+ # an ip address.
+ server_ip=`expr "$service_data" : '\[\([^]]*\)\]'`
+ local attempt
+ for ((attempt=0; $attempt < 5; ++attempt))
+ do
+ server_ip=`expr "$server_ip" : '^\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)$'`
+ if test "X$server_ip" != "X"; then
+ break
+ fi
+ # Resolve the server.domain to an ip address.
+ server_ip=`avahi-resolve-host-name $hostname`
+ server_ip=`expr "$server_ip" : '.* \(.*\)$'`
+ done
+ ;;
+ port )
+ server_port=`expr "$service_data" : '\[\([^]]*\)\]'`
+ ;;
+ txt )
+ server_sysinfo=`expr "$service_data" : '\[\"\([^]]*\)\"\]'`
+ ;;
+ * )
+ break ;;
+ esac
+ done
+
+ # It is a stap server, but is it compatible?
+ if test $find_all = 0 -a "$server_sysinfo" != "`client_sysinfo`"; then
+ continue
+ fi
+
+ # It's compatible, or we're finding all servers. Print a summary line
+ echo $server_name $server_ip $server_port "'$server_sysinfo'"
+ rc=0
+ done
+
+ exit $rc
+}
+
+# function client_sysinfo
+#
+# Generate the client's sysinfo and echo it to stdout
+function client_sysinfo {
+ if test "X$sysinfo_client" = "X"; then
+ # Add some info from uname
+ sysinfo_client="`uname -rvm`"
+ fi
+ echo $sysinfo_client
+}
+
+#-----------------------------------------------------------------------------
+# Beginning of main line execution.
+#-----------------------------------------------------------------------------
+configuration
+initialization "$@"
+find_servers
+
+exit $rc