summaryrefslogtreecommitdiffstats
path: root/runtime/staprun
diff options
context:
space:
mode:
authorhunt <hunt>2007-10-12 19:42:32 +0000
committerhunt <hunt>2007-10-12 19:42:32 +0000
commit2972246a08bfc7c516455ecc4ef976e10c0ddb2c (patch)
tree030cb7ae2694103f6c9abb64e5419a0df11368eb /runtime/staprun
parent7651c16b0e3d7dba7265be5e83720e324bdf64b0 (diff)
downloadsystemtap-steved-2972246a08bfc7c516455ecc4ef976e10c0ddb2c.tar.gz
systemtap-steved-2972246a08bfc7c516455ecc4ef976e10c0ddb2c.tar.xz
systemtap-steved-2972246a08bfc7c516455ecc4ef976e10c0ddb2c.zip
2007-10-12 Martin Hunt <hunt@redhat.com>
Changes to separate the symbols from the command channel. * cap.c (init_cap): Add CAP_DAC_OVERRIDE. * staprun.h: Change init_ctl_channel prototype. * ctl.c (init_ctl_channel): Modify to open either a command or symbol channel. Use ".cmd" and ".symbols" as the new names. * mainloop.c (init_stapio): Call init_ctl_channel(0); * staprun.c (cleanup): Call stop_symbol_thread(). (main): Call start_symbol_thread(). * staprun_funcs.c (handle_symbols): Make a thread. (start_symbol_thread): New. (stop_symbol_thread): New.
Diffstat (limited to 'runtime/staprun')
-rw-r--r--runtime/staprun/ChangeLog15
-rw-r--r--runtime/staprun/cap.c4
-rw-r--r--runtime/staprun/ctl.c13
-rw-r--r--runtime/staprun/mainloop.c2
-rw-r--r--runtime/staprun/staprun.c5
-rw-r--r--runtime/staprun/staprun.h10
-rw-r--r--runtime/staprun/staprun_funcs.c46
-rw-r--r--runtime/staprun/symbols.c13
8 files changed, 81 insertions, 27 deletions
diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog
index 2a9029d0..f03f3606 100644
--- a/runtime/staprun/ChangeLog
+++ b/runtime/staprun/ChangeLog
@@ -1,3 +1,18 @@
+2007-10-12 Martin Hunt <hunt@redhat.com>
+ Changes to separate the symbols from the command channel.
+
+ * cap.c (init_cap): Add CAP_DAC_OVERRIDE.
+ * staprun.h: Change init_ctl_channel prototype.
+ * ctl.c (init_ctl_channel): Modify to open either
+ a command or symbol channel. Use ".cmd" and ".symbols"
+ as the new names.
+ * mainloop.c (init_stapio): Call init_ctl_channel(0);
+ * staprun.c (cleanup): Call stop_symbol_thread().
+ (main): Call start_symbol_thread().
+ * staprun_funcs.c (handle_symbols): Make a thread.
+ (start_symbol_thread): New.
+ (stop_symbol_thread): New.
+
2007-10-11 Frank Ch. Eigler <fche@elastic.org>
* staprun.c (main): Move checks for init_cap and getuid
diff --git a/runtime/staprun/cap.c b/runtime/staprun/cap.c
index df4a7130..6f22dfc9 100644
--- a/runtime/staprun/cap.c
+++ b/runtime/staprun/cap.c
@@ -28,7 +28,7 @@
_perr(msg); \
exit(1); \
} \
-
+
/*
* init_cap() sets up the initial capabilities for staprun. Then
* it calls prctl( PR_SET_KEEPCAPS) to arrrange to keep these capabilities
@@ -57,7 +57,7 @@
int init_cap(void)
{
cap_t caps = cap_init();
- cap_value_t capv[] = {CAP_SYS_MODULE, CAP_SYS_ADMIN, CAP_SYS_NICE, CAP_SETUID, CAP_SETGID};
+ cap_value_t capv[] = {CAP_SYS_MODULE, CAP_SYS_ADMIN, CAP_SYS_NICE, CAP_SETUID, CAP_SETGID, CAP_DAC_OVERRIDE};
const int numcaps = sizeof(capv) / sizeof(capv[0]);
uid_t uid = getuid();
gid_t gid = getgid();
diff --git a/runtime/staprun/ctl.c b/runtime/staprun/ctl.c
index 7fe57206..af7e6c1a 100644
--- a/runtime/staprun/ctl.c
+++ b/runtime/staprun/ctl.c
@@ -12,18 +12,23 @@
#include "staprun.h"
-int init_ctl_channel(void)
+int init_ctl_channel(int symbols)
{
- char buf[PATH_MAX];
+ char *cname, buf[PATH_MAX];
struct statfs st;
int old_transport = 0;
+
+ if (symbols)
+ cname = ".symbols";
+ else
+ cname = ".cmd";
if (statfs("/sys/kernel/debug", &st) == 0 && (int) st.f_type == (int) DEBUGFS_MAGIC) {
- if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/cmd", modname))
+ if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/%s", modname, cname))
return -1;
} else {
old_transport = 1;
- if (sprintf_chk(buf, "/proc/systemtap/%s/cmd", modname))
+ if (sprintf_chk(buf, "/proc/systemtap/%s/%s", modname, cname))
return -1;
}
diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c
index d919164f..c0722b56 100644
--- a/runtime/staprun/mainloop.c
+++ b/runtime/staprun/mainloop.c
@@ -164,7 +164,7 @@ int init_stapio(void)
dbug(2, "init_stapio\n");
/* create control channel */
- use_old_transport = init_ctl_channel();
+ use_old_transport = init_ctl_channel(0);
if (use_old_transport < 0) {
err("Failed to initialize control channel.\n");
return -1;
diff --git a/runtime/staprun/staprun.c b/runtime/staprun/staprun.c
index 44ac0313..f4e67fdb 100644
--- a/runtime/staprun/staprun.c
+++ b/runtime/staprun/staprun.c
@@ -181,6 +181,8 @@ static void cleanup(int rc)
if (setpriority (PRIO_PROCESS, 0, 0) < 0)
_perr("setpriority");
+ stop_symbol_thread();
+
/* rc == 2 means disconnected */
if (rc == 2)
return;
@@ -276,8 +278,7 @@ int main(int argc, char **argv)
exit(1);
setup_staprun_signals();
- if (!attach_mod)
- handle_symbols();
+ start_symbol_thread();
rc = run_stapio(argv);
cleanup(rc);
diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h
index 685de294..c22cc4f3 100644
--- a/runtime/staprun/staprun.h
+++ b/runtime/staprun/staprun.h
@@ -35,12 +35,7 @@
#include <linux/version.h>
#include <sys/capability.h>
-#define DEBUG
-#ifdef DEBUG
#define dbug(level, args...) {if (verbose>=level) {fprintf(stderr,"%s:%s:%d ",__name__,__FUNCTION__, __LINE__); fprintf(stderr,args);}}
-#else
-#define dbug(level, args...) ;
-#endif /* DEBUG */
extern char *__name__;
@@ -125,7 +120,7 @@ int send_request(int type, void *data, int len);
void cleanup_and_exit (int);
int do_module(void *);
void do_kernel_symbols(void);
-int init_ctl_channel(void);
+int init_ctl_channel(int);
void close_ctl_channel(void);
int init_relayfs(void);
void close_relayfs(void);
@@ -145,7 +140,8 @@ int insert_module(const char *path, const char *special_options,
char **options);
int mountfs(void);
int check_permissions(void);
-void handle_symbols(void);
+void start_symbol_thread(void);
+void stop_symbol_thread(void);
/* common.c functions */
void parse_args(int argc, char **argv);
diff --git a/runtime/staprun/staprun_funcs.c b/runtime/staprun/staprun_funcs.c
index eec4ae63..86a72985 100644
--- a/runtime/staprun/staprun_funcs.c
+++ b/runtime/staprun/staprun_funcs.c
@@ -385,8 +385,10 @@ int check_permissions(void)
return check_path();
}
-/* wait for symbol requests and reply */
-void handle_symbols(void)
+pthread_t symbol_thread_id = (pthread_t)0;
+
+/* Symbol handling thread */
+void *handle_symbols(void __attribute__((unused)) *arg)
{
ssize_t nb;
void *data;
@@ -395,12 +397,6 @@ void handle_symbols(void)
dbug(2, "waiting for symbol requests\n");
- /* create control channel */
- if (init_ctl_channel() < 0) {
- err("Failed to initialize control channel.\n");
- exit(1);
- }
-
while (1) { /* handle messages from control channel */
nb = read(control_channel, recvbuf, sizeof(recvbuf));
if (nb <= 0) {
@@ -417,7 +413,7 @@ void handle_symbols(void)
{
dbug(2, "STP_MODULES request received\n");
do_module(data);
- goto done;
+ break;
}
case STP_SYMBOLS:
{
@@ -439,6 +435,36 @@ void handle_symbols(void)
err("WARNING: ignored message of type %d\n", (type));
}
}
-done:
+
+ return NULL;
+}
+
+void start_symbol_thread(void)
+{
+ int status;
+
+ /* create symbol control channel */
+ status = do_cap(CAP_DAC_OVERRIDE, init_ctl_channel, 1);
+ drop_cap(CAP_DAC_OVERRIDE);
+ if (status < 0) {
+ err("Failed to initialize control channel.\n");
+ exit(1);
+ }
+ status = pthread_create(&symbol_thread_id, NULL, handle_symbols, NULL);
+ if (status) {
+ perr("Failed to create symbol thread.\n");
+ exit(1);
+ }
+}
+
+void stop_symbol_thread(void)
+{
+
+ if (symbol_thread_id) {
+ dbug(2, "Stopping symbol thread.\n");
+ pthread_cancel(symbol_thread_id);
+ pthread_join(symbol_thread_id, NULL);
+ }
close_ctl_channel();
}
+
diff --git a/runtime/staprun/symbols.c b/runtime/staprun/symbols.c
index 61b56b2e..315362fa 100644
--- a/runtime/staprun/symbols.c
+++ b/runtime/staprun/symbols.c
@@ -140,7 +140,10 @@ err0:
}
#undef SECDIR
-void send_module (char *mname)
+/*
+ * For modules, we send the name, section names, and offsets
+ */
+static void send_module (char *mname)
{
char data[32768];
int len = get_sections(mname, data, sizeof(data));
@@ -152,6 +155,9 @@ void send_module (char *mname)
}
}
+/*
+ * Send either all modules, or a specific one.
+ */
int do_module (void *data)
{
struct _stp_module *mod = (struct _stp_module *)data;
@@ -183,6 +189,11 @@ static int compar(const void *p1, const void *p2)
#define MAX_SYMBOLS 32*1024
+/*
+ * Read /proc/kallsyms and send all kernel symbols to the
+ * systemtap module. Ignore module symbols; the systemtap module
+ * can access them directly.
+ */
void do_kernel_symbols(void)
{
FILE *kallsyms=NULL;