From: Pierre-Marc Fournier Date: Tue, 24 Feb 2009 02:49:13 +0000 (-0500) Subject: ust: continue implementation of ustd X-Git-Tag: v1.9.1~1047 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3847c3bab100bfb6b01b5654c2429a5d0d162ff5;p=lttng-ust.git ust: continue implementation of ustd --- diff --git a/libtracectl/tracectl.c b/libtracectl/tracectl.c index 50cb3038..d041e6bb 100644 --- a/libtracectl/tracectl.c +++ b/libtracectl/tracectl.c @@ -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; inr_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; diff --git a/libtracing/relay.c b/libtracing/relay.c index 16f5322e..a8775ec7 100644 --- a/libtracing/relay.c +++ b/libtracing/relay.c @@ -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"); } diff --git a/libtracing/relay.h b/libtracing/relay.h index 80f0b6bf..16894183 100644 --- a/libtracing/relay.h +++ b/libtracing/relay.h @@ -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; /* diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index 0275a736..d9c79563 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -20,14 +20,14 @@ #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; } diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index ab475d9a..08d74803 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -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);