ust: continue implementation of ustd
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 24 Feb 2009 02:49:13 +0000 (21:49 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 24 Feb 2009 02:49:13 +0000 (21:49 -0500)
libtracectl/tracectl.c
libtracing/relay.c
libtracing/relay.h
libustcomm/ustcomm.c
libustcomm/ustcomm.h

index 50cb3038882a19b055e4bdd8600ea83d33acf3e9..d041e6bb0ce3caef7ac72bea86fe677c8349df60 100644 (file)
@@ -12,6 +12,8 @@
 #include "localerr.h"
 #include "ustcomm.h"
 
+#define USE_CLONE
+
 #define UNIX_PATH_MAX 108
 
 #define SOCKETDIR "/tmp/socks"
@@ -45,7 +47,6 @@ struct trctl_msg {
        char payload[94];
 };
 
-pid_t mypid;
 char mysocketfile[UNIX_PATH_MAX] = "";
 //int pfd = -1;
 
@@ -162,15 +163,18 @@ int consumer(void *arg)
 
 void start_consumer(void)
 {
+#ifdef USE_CLONE
        int result;
 
        result = clone(consumer, consumer_stack+sizeof(consumer_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD, NULL);
        if(result == -1) {
                perror("clone");
        }
-//     pthread_t thread;
-//
-//     pthread_create(&thread, NULL, consumer, NULL);
+#else
+       pthread_t thread;
+
+       pthread_create(&thread, NULL, consumer, NULL);
+#endif
 }
 
 static void print_markers(void)
@@ -222,6 +226,8 @@ void notif_cb(void)
 
 static int inform_consumer_daemon(void)
 {
+       ustcomm_request_consumer(getpid(), "metadata");
+       ustcomm_request_consumer(getpid(), "ust");
 }
 
 int listener_main(void *p)
@@ -307,6 +313,30 @@ int listener_main(void *p)
                                return;
                        }
                }
+               else if(!strncmp(recvbuf, "get_shmid ", 10)) {
+                       struct ltt_trace_struct *trace;
+                       char trace_name[] = "auto";
+                       int i;
+
+                       DBG("get_shmid");
+
+                       ltt_lock_traces();
+                       trace = _ltt_trace_find(trace_name);
+                       ltt_unlock_traces();
+
+                       if(trace == NULL) {
+                               CPRINTF("cannot find trace!");
+                               return 1;
+                       }
+
+                       for(i=0; i<trace->nr_channels; i++) {
+                               struct rchan *rchan = trace->channels[i].trans_channel_data;
+                               struct rchan_buf *rbuf = rchan->buf;
+
+                               DBG("the shmid is %d", rbuf->shmid);
+
+                       }
+               }
 
                free(recvbuf);
        }
@@ -320,13 +350,16 @@ void create_listener(void)
        static char listener_stack[16384];
        //char *listener_stack = malloc(16384);
 
+#ifdef USE_CLONE
        result = clone(listener_main, listener_stack+sizeof(listener_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD, NULL);
        if(result == -1) {
                perror("clone");
        }
-       //pthread_t thread;
+#else
+       pthread_t thread;
 
-       //pthread_create(&thread, NULL, listener_main, NULL);
+       pthread_create(&thread, NULL, listener_main, NULL);
+#endif
 }
 
 /* The signal handler itself. Signals must be setup so there cannot be
@@ -426,7 +459,18 @@ static void __attribute__((constructor(1000))) init()
 
        DBG("UST_TRACE constructor");
 
-       mypid = getpid();
+       /* Must create socket before signal handler to prevent races.
+         */
+       result = init_socket();
+       if(result == -1) {
+               ERR("init_socket error");
+               return;
+       }
+       result = init_signal_handler();
+       if(result == -1) {
+               ERR("init_signal_handler error");
+               return;
+       }
 
        if(getenv("UST_TRACE")) {
                char trace_name[] = "auto";
@@ -469,21 +513,10 @@ static void __attribute__((constructor(1000))) init()
                        ERR("ltt_trace_start failed");
                        return;
                }
-               start_consumer();
+               //start_consumer();
+               inform_consumer_daemon();
        }
 
-       /* Must create socket before signal handler to prevent races.
-         */
-       result = init_socket();
-       if(result == -1) {
-               ERR("init_socket error");
-               return;
-       }
-       result = init_signal_handler();
-       if(result == -1) {
-               ERR("init_signal_handler error");
-               return;
-       }
 
        return;
 
index 16f5322e1b7b7f42c7268c3374782ce7e3ea6926..a8775ec77d2554e30bee693a1c6a102c49ec91fd 100644 (file)
@@ -97,17 +97,16 @@ static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
 
        void *ptr;
        int result;
-       int shmid;
 
        *size = PAGE_ALIGN(*size);
 
-       result = shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
-       if(shmid == -1) {
+       result = buf->shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
+       if(buf->shmid == -1) {
                PERROR("shmget");
                return -1;
        }
 
-       ptr = shmat(shmid, NULL, 0);
+       ptr = shmat(buf->shmid, NULL, 0);
        if(ptr == (void *) -1) {
                perror("shmat");
                goto destroy_shmem;
@@ -116,7 +115,7 @@ static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
        /* Already mark the shared memory for destruction. This will occur only
          * when all users have detached.
         */
-       result = shmctl(shmid, IPC_RMID, NULL);
+       result = shmctl(buf->shmid, IPC_RMID, NULL);
        if(result == -1) {
                perror("shmctl");
                return -1;
@@ -128,7 +127,7 @@ static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
        return 0;
 
        destroy_shmem:
-       result = shmctl(shmid, IPC_RMID, NULL);
+       result = shmctl(buf->shmid, IPC_RMID, NULL);
        if(result == -1) {
                perror("shmctl");
        }
index 80f0b6bf69ba383cb3a1505745a4a90286d152e8..1689418342fa5fde75d3a40f409dcd0fbb6c0cfe 100644 (file)
@@ -59,6 +59,7 @@ struct rchan_buf {
 //ust//        unsigned int page_count;        /* number of current buffer pages */ 
        unsigned int finalized;         /* buffer has been finalized */ 
 //ust//        unsigned int cpu;               /* this buf's cpu */ 
+       int shmid;
 } ____cacheline_aligned; 
 
 /*
index 0275a736b99a22b7f4b82304f5c289ca2544446d..d9c795633b238ac103a4315a7045fbe5e0c5afea 100644 (file)
 
 #define MSG_MAX 1000
 
-static void bt(void)
-{
-       void *buffer[100];
-       int result;
-
-       result = backtrace(&buffer, 100);
-       backtrace_symbols_fd(buffer, result, STDERR_FILENO);
-}
+//static void bt(void)
+//{
+//     void *buffer[100];
+//     int result;
+//
+//     result = backtrace(&buffer, 100);
+//     backtrace_symbols_fd(buffer, result, STDERR_FILENO);
+//}
 
 static void signal_process(pid_t pid)
 {
@@ -124,7 +124,7 @@ int ustcomm_request_consumer(pid_t pid, const char *channel)
 
        asprintf(&msg, "collect %d %s", pid, channel); 
 
-       send_message_path(path, msg, NULL, pid);
+       send_message_path(path, msg, NULL, -1);
        free(msg);
 
        return 0;
@@ -133,7 +133,6 @@ int ustcomm_request_consumer(pid_t pid, const char *channel)
 static int recv_message_fd(int fd, char **msg)
 {
        int result;
-       struct sockaddr_un addr;
 
        *msg = (char *) malloc(MSG_MAX+1);
        result = recvfrom(fd, *msg, MSG_MAX, 0, NULL, NULL);
@@ -146,8 +145,6 @@ static int recv_message_fd(int fd, char **msg)
        
        DBG("ustcomm_app_recv_message: result is %d, message is %s", result, (*msg));
 
-       bt();
-
        return 0;
 }
 
@@ -224,9 +221,19 @@ free_name:
 
 int ustcomm_init_ustd(struct ustcomm_ustd *handle)
 {
-       handle->fd = init_named_socket("ustd", &handle->socketpath);
+       int result;
+       char *name;
+
+       result = asprintf(&name, "%s/%s", SOCK_DIR, "ustd");
+       if(result >= UNIX_PATH_MAX) {
+               ERR("string overflow allocating socket name");
+               return -1;
+       }
+
+       handle->fd = init_named_socket(name, &handle->socketpath);
        if(handle->fd < 0)
                return handle->fd;
+       free(name);
 
        return 0;
 }
index ab475d9a64f059545faa3e91a9b3730c7b656299..08d74803857feecee46be5b3befac1f799201463 100644 (file)
@@ -17,6 +17,9 @@ struct ustcomm_ustd {
 
 int send_message(pid_t pid, const char *msg, char **reply);
 
+int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg);
+int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg);
+
 int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
 
 int ustcomm_init_ustd(struct ustcomm_ustd *handle);
This page took 0.0293099999999999 seconds and 4 git commands to generate.