]> sourceware.org Git - systemtap.git/commitdiff
2007-10-12 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Fri, 12 Oct 2007 19:42:32 +0000 (19:42 +0000)
committerhunt <hunt>
Fri, 12 Oct 2007 19:42:32 +0000 (19:42 +0000)
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.

runtime/staprun/ChangeLog
runtime/staprun/cap.c
runtime/staprun/ctl.c
runtime/staprun/mainloop.c
runtime/staprun/staprun.c
runtime/staprun/staprun.h
runtime/staprun/staprun_funcs.c
runtime/staprun/symbols.c

index 2a9029d0c5d4dd7d94ecc5c4fb608c20cc7d90d4..f03f360686fd783d18a226547a73b1f5019c599b 100644 (file)
@@ -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
index df4a71308670f8ffdcb86d69716715729e8b45c5..6f22dfc94919c2b3956e2ea420f8bdee29af0190 100644 (file)
@@ -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();
index 7fe572069cf8cb0a6b968b7a3015820ae4afeb33..af7e6c1a5e1ca4cba341f70fd589a22bcd52a872 100644 (file)
 
 #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;
        }
        
index d919164fbb1a771f9f21fa07647dd006c4824a26..c0722b561d883612a37426c76f5db4c6285d637a 100644 (file)
@@ -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;
index 44ac03134430e435f46a3faa064ced2bc748b571..f4e67fdbac1d3a891d1cfe99a9c488dd53e7f757 100644 (file)
@@ -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);
index 685de2946257ca333c9d73408971152ae25af4dd..c22cc4f3cb7ed91666f236cd63eb7493ec84d3aa 100644 (file)
 #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);
index eec4ae632b8842745af3b5833f95fe0559f122d5..86a72985b73570ea6ce4884c9db3155146240a4d 100644 (file)
@@ -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();
 }
+
index 61b56b2ee22ba67c8b1e79ae6d0b2185ec54ec89..315362fa38b59ba25b69fb4739475bf822d611b7 100644 (file)
@@ -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;
This page took 0.037944 seconds and 5 git commands to generate.