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-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
_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
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();
#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;
}
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;
if (setpriority (PRIO_PROCESS, 0, 0) < 0)
_perr("setpriority");
+ stop_symbol_thread();
+
/* rc == 2 means disconnected */
if (rc == 2)
return;
exit(1);
setup_staprun_signals();
- if (!attach_mod)
- handle_symbols();
+ start_symbol_thread();
rc = run_stapio(argv);
cleanup(rc);
#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__;
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);
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);
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;
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) {
{
dbug(2, "STP_MODULES request received\n");
do_module(data);
- goto done;
+ break;
}
case STP_SYMBOLS:
{
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();
}
+
}
#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));
}
}
+/*
+ * Send either all modules, or a specific one.
+ */
int do_module (void *data)
{
struct _stp_module *mod = (struct _stp_module *)data;
#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;