Update and fix UST register and session creation
authorDavid Goulet <david.goulet@polymtl.ca>
Sun, 28 Aug 2011 21:29:40 +0000 (17:29 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Sun, 28 Aug 2011 21:51:55 +0000 (17:51 -0400)
The handling of the apps command pollfd, in the registration thread and
the update function, was incorrect. The update process, when
unregistring, was overwritting connected socket thus not being able to
monitor them with poll().

This is the first step forward to fully support LTTng UST tracer.

Add create UST session to ustctl and the session daemon. At this
commit, this feature is not used yet.

Move the register done command to ustctl. Adds the ustcomm_send_command
which returns the reply structure from the UST application.

The ustctl and ustcomm are cleaned up.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
14 files changed:
include/lttng-sessiond-comm.h
liblttng-sessiond-comm/lttng-sessiond-comm.c
ltt-sessiond/Makefile.am
ltt-sessiond/main.c
ltt-sessiond/session.c
ltt-sessiond/session.h
ltt-sessiond/trace-ust.c
ltt-sessiond/trace-ust.h
ltt-sessiond/traceable-app.c
ltt-sessiond/ust-comm.c
ltt-sessiond/ust-comm.h
ltt-sessiond/ust-ctl.c
ltt-sessiond/ust-ctl.h
tests/test_sessions.c

index 4deec5fc8d4fd00163fb1ee110a41e26ef523997..c8f09d39c6b2fa54f7c52eb43b2b2554ab0fe50e 100644 (file)
@@ -113,6 +113,7 @@ enum lttcomm_return_code {
        LTTCOMM_KERN_DIR_EXIST,                 /* Kernel trace directory exist */
        LTTCOMM_KERN_NO_SESSION,                /* No kernel session found */
        LTTCOMM_KERN_LIST_FAIL,                 /* Kernel listing events failed */
+       LTTCOMM_UST_SESS_FAIL,                  /* UST create session failed */
        KCONSUMERD_COMMAND_SOCK_READY,  /* when kconsumerd command socket ready */
        KCONSUMERD_SUCCESS_RECV_FD,             /* success on receiving fds */
        KCONSUMERD_ERROR_RECV_FD,               /* error on receiving fds */
index b293ac0b0e2672c2a37b2371e2b5417088323f87..06a4b77f08c809c56c6cee4b4f45e670ffa1586a 100644 (file)
@@ -71,6 +71,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DIR_EXIST) ] = "Kernel trace directory already exist",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NO_SESSION) ] = "No kernel session found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_LIST_FAIL) ] = "Listing kernel events failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_SESS_FAIL) ] = "UST create session failed",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_COMMAND_SOCK_READY) ] = "Kconsumerd command socket ready",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_SUCCESS_RECV_FD) ] = "Kconsumerd success on receiving fds",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_ERROR_RECV_FD) ] = "Kconsumerd error on receiving fds",
index 6cffbd738e06aead5fa803415f9de58258119a50..0a1f1571224c48da4dcde5b2c4bd47d534d788a9 100644 (file)
@@ -8,13 +8,13 @@ bin_PROGRAMS = ltt-sessiond
 ltt_sessiond_SOURCES = utils.c utils.h \
                        trace-kernel.c trace-kernel.h \
                        trace-ust.c trace-ust.h \
-                       session.c session.h \
                        traceable-app.c traceable-app.h \
+                       ust-comm.c ust-comm.h \
                        ust-ctl.c ust-ctl.h \
                        kernel-ctl.c kernel-ctl.h \
                        context.c context.h \
                        futex.c futex.h \
-                       ust-comm.c ust-comm.h \
+                       session.c session.h \
                        ltt-sessiond.h main.c
 
 # link on liblttngctl for check if sessiond is already alive.
index 3f9d0eb5e4d55e97a5e6f2440e3b210597ae7c64..a3335292bc0760746a701f0426d79a6a011dd34a 100644 (file)
@@ -48,7 +48,7 @@
 #include "traceable-app.h"
 #include "ust-ctl.h"
 #include "utils.h"
-#include "ust-comm.h"
+#include "ust-ctl.h"
 
 /* Const values */
 const char default_home_dir[] = DEFAULT_HOME_DIR;
@@ -406,34 +406,6 @@ error:
 }
 
 #ifdef DISABLED
-/*
- * Return a socket connected to the libust communication socket of the
- * application identified by the pid.
- *
- * If the pid is not found in the traceable list, return -1 to indicate error.
- */
-static int ust_connect_app(pid_t pid)
-{
-       int sock;
-       struct ltt_traceable_app *lta;
-
-       DBG("Connect to application pid %d", pid);
-
-       lta = find_app_by_pid(pid);
-       if (lta == NULL) {
-               /* App not found */
-               DBG("Application pid %d not found", pid);
-               return -1;
-       }
-
-       sock = ustctl_connect_pid(lta->pid);
-       if (sock < 0) {
-               ERR("Fail connecting to the PID %d", pid);
-       }
-
-       return sock;
-}
-
 /*
  * Notify apps by writing 42 to a named pipe using name. Every applications
  * waiting for a ltt-sessiond will be notified and re-register automatically to
@@ -830,16 +802,25 @@ error:
  *
  * The first two fds must be there at all time.
  */
-static int update_apps_cmd_pollfd(unsigned int nb_fd, struct pollfd **pollfd)
+static int update_apps_cmd_pollfd(unsigned int nb_fd, unsigned int old_nb_fd,
+               struct pollfd **pollfd)
 {
+       int i, count;
+       struct pollfd *old_pollfd = NULL;
+
        /* Can't accept pollfd less than 2 */
        if (nb_fd < 2) {
                goto end;
        }
 
-       *pollfd = realloc(*pollfd, nb_fd * sizeof(struct pollfd));
+       if (*pollfd) {
+               /* Save pointer */
+               old_pollfd = *pollfd;
+       }
+
+       *pollfd = malloc(nb_fd * sizeof(struct pollfd));
        if (*pollfd == NULL) {
-               perror("realloc manage apps pollfd");
+               perror("malloc manage apps pollfd");
                goto error;
        }
 
@@ -849,30 +830,36 @@ static int update_apps_cmd_pollfd(unsigned int nb_fd, struct pollfd **pollfd)
        (*pollfd)[1].fd = apps_cmd_pipe[0];
        (*pollfd)[1].events = POLLIN;
 
+       /* Start count after the two pipes below */
+       count = 2;
+       for (i = 2; i < old_nb_fd; i++) {
+               /* Add to new pollfd */
+               if (old_pollfd[i].fd != -1) {
+                       (*pollfd)[count].fd = old_pollfd[i].fd;
+                       (*pollfd)[count].events = POLLHUP | POLLNVAL | POLLERR;
+                       count++;
+               }
+
+               if (count > nb_fd) {
+                       ERR("Updating poll fd wrong size");
+                       goto error;
+               }
+       }
+
+       /* Destroy old pollfd */
+       free(old_pollfd);
+
        DBG("Apps cmd pollfd realloc of size %d", nb_fd);
 
 end:
        return 0;
 
 error:
+       /* Destroy old pollfd */
+       free(old_pollfd);
        return -1;
 }
 
-/*
- * Send registration done packet to the application.
- */
-static int send_ust_register_done(int sock)
-{
-       struct lttcomm_ust_msg lum;
-
-       DBG("Sending register done command to %d", sock);
-
-       lum.cmd = LTTNG_UST_REGISTER_DONE;
-       lum.handle = LTTNG_UST_ROOT_HANDLE;
-
-       return ustcomm_send_command(sock, &lum);
-}
-
 /*
  * This thread manage application communication.
  */
@@ -897,16 +884,17 @@ static void *thread_manage_apps(void *data)
 
                /* The pollfd struct must be updated */
                if (update_poll_flag) {
-                       ret = update_apps_cmd_pollfd(nb_fd, &pollfd);
+                       ret = update_apps_cmd_pollfd(nb_fd, ARRAY_SIZE(pollfd), &pollfd);
                        if (ret < 0) {
                                /* malloc failed so we quit */
                                goto error;
                        }
+
                        if (ust_cmd.sock != -1) {
                                /* Update pollfd with the new UST socket */
                                DBG("Adding sock %d to apps cmd pollfd", ust_cmd.sock);
                                pollfd[nb_fd - 1].fd = ust_cmd.sock;
-                               pollfd[nb_fd - 1].events = POLLHUP | POLLNVAL;
+                               pollfd[nb_fd - 1].events = POLLHUP | POLLNVAL | POLLERR;
                                ust_cmd.sock = -1;
                        }
                }
@@ -923,31 +911,36 @@ static void *thread_manage_apps(void *data)
                /* Thread quit pipe has been closed. Killing thread. */
                if (pollfd[0].revents == POLLNVAL) {
                        goto error;
-               } else if (pollfd[1].revents == POLLERR) {
-                       ERR("Apps command pipe poll error");
-                       goto error;
-               } else if (pollfd[1].revents == POLLIN) {
-                       /* Empty pipe */
-                       ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
-                       if (ret < 0 || ret < sizeof(ust_cmd)) {
-                               perror("read apps cmd pipe");
+               } else {
+                       /* apps_cmd_pipe pipe events */
+                       switch (pollfd[1].revents) {
+                       case POLLERR:
+                               ERR("Apps command pipe poll error");
                                goto error;
-                       }
+                       case POLLIN:
+                               /* Empty pipe */
+                               ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
+                               if (ret < 0 || ret < sizeof(ust_cmd)) {
+                                       perror("read apps cmd pipe");
+                                       goto error;
+                               }
 
-                       /* Register applicaton to the session daemon */
-                       ret = register_traceable_app(&ust_cmd.reg_msg, ust_cmd.sock);
-                       if (ret < 0) {
-                               /* Only critical ENOMEM error can be returned here */
-                               goto error;
-                       }
+                               /* Register applicaton to the session daemon */
+                               ret = register_traceable_app(&ust_cmd.reg_msg, ust_cmd.sock);
+                               if (ret < 0) {
+                                       /* Only critical ENOMEM error can be returned here */
+                                       goto error;
+                               }
 
-                       ret = send_ust_register_done(ust_cmd.sock);
-                       if (ret < 0) {
-                               /*
-                                * If the registration is not possible, we simply unregister
-                                * the apps and continue
-                                */
-                               unregister_traceable_app(ust_cmd.sock);
+                               ret = ustctl_register_done(ust_cmd.sock);
+                               if (ret < 0) {
+                                       /*
+                                        * If the registration is not possible, we simply unregister
+                                        * the apps and continue
+                                        */
+                                       unregister_traceable_app(ust_cmd.sock);
+                               }
+                               break;
                        }
                }
 
@@ -955,11 +948,15 @@ static void *thread_manage_apps(void *data)
                for (i = 2; i < count; i++) {
                        /* Apps socket is closed/hungup */
                        switch (pollfd[i].revents) {
-                       case POLLNVAL:
+                       case POLLERR:
                        case POLLHUP:
+                       case POLLNVAL:
                                /* Pipe closed */
                                unregister_traceable_app(pollfd[i].fd);
+                               /* Indicate to remove this fd from the pollfd */
+                               pollfd[i].fd = -1;
                                nb_fd--;
+                               break;
                        }
                }
 
@@ -1554,6 +1551,43 @@ error:
        return NULL;
 }
 
+/*
+ * Create an UST session and add it to the session ust list.
+ */
+static int create_ust_session(pid_t pid, struct ltt_session *session)
+{
+       int ret = -1;
+       struct ltt_ust_session *lus;
+
+       DBG("Creating UST session");
+
+       lus = trace_ust_create_session(session->path, pid);
+       if (lus == NULL) {
+               goto error;
+       }
+
+       ret = mkdir_recursive(lus->path, S_IRWXU | S_IRWXG,
+                       geteuid(), allowed_group());
+       if (ret < 0) {
+               if (ret != -EEXIST) {
+                       ERR("Trace directory creation error");
+                       goto error;
+               }
+       }
+
+       /* Create session on the UST tracer */
+       ret = ustctl_create_session(lus);
+       if (ret < 0) {
+               goto error;
+       }
+
+       return 0;
+
+error:
+       free(lus);
+       return ret;
+}
+
 /*
  * Create a kernel tracer session then create the default channel.
  */
@@ -1729,7 +1763,6 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                                goto error;
                        }
                }
-
                /* Need a session for kernel command */
                switch (cmd_ctx->lsm->cmd_type) {
                case LTTNG_CALIBRATE:
@@ -1744,9 +1777,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                                        ret = LTTCOMM_KERN_SESS_FAIL;
                                        goto error;
                                }
-
                                /* Start the kernel consumer daemon */
-
                                if (kconsumerd_pid == 0 &&
                                                cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) {
                                        ret = start_kconsumerd();
@@ -1967,8 +1998,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
 
                        kernel_wait_quiescent(kernel_tracer_fd);
                        break;
+               case LTTNG_DOMAIN_UST_PID:
+                       break;
                default:
-                       /* TODO: Userspace tracing */
                        ret = LTTCOMM_NOT_IMPLEMENTED;
                        goto error;
                }
@@ -2352,7 +2384,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                        nb_dom++;
                }
 
-               nb_dom += cmd_ctx->session->ust_trace_count;
+               nb_dom += cmd_ctx->session->ust_session_list.count;
 
                ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_domain) * nb_dom);
                if (ret < 0) {
index 118c8f57cb6d2ff14ca5c9656c35cddab7535c4d..1ace823c7143b8d0169feb1f551a9151e75e7fe4 100644 (file)
@@ -213,21 +213,18 @@ int create_session(char *name, char *path)
        /* Init kernel session */
        new_session->kernel_session = NULL;
 
-       /* Init list */
-       CDS_INIT_LIST_HEAD(&new_session->ust_traces);
+       /* Init UST session list */
+       CDS_INIT_LIST_HEAD(&new_session->ust_session_list.head);
 
-       /* Set trace list counter */
-       new_session->ust_trace_count = 0;
+       /* Init lock */
+       pthread_mutex_init(&new_session->lock, NULL);
 
        /* Add new session to the session list */
        lock_session_list();
        add_session_list(new_session);
        unlock_session_list();
 
-       /* Init lock */
-       pthread_mutex_init(&new_session->lock, NULL);
-
-       DBG("Tracing session %s created in %s", new_session->name, new_session->path);
+       DBG("Tracing session %s created in %s", name, path);
 
        return 0;
 
index fa1d064b6b4e4bbab83f75d048946b8f423d8d22..fb271ea623997a28ac05a4a077e210802e3aa310 100644 (file)
@@ -59,8 +59,7 @@ struct ltt_session {
        char *name;
        char *path;
        struct ltt_kernel_session *kernel_session;
-       struct cds_list_head ust_traces;
-       unsigned int ust_trace_count;
+       struct ltt_ust_session_list ust_session_list;
        /*
         * Protect any read/write on this session data structure. This lock must be
         * acquired *before* using any public functions declared below. Use
index 957ac770b51eb9f9428ddbc3ea8648e49fad10ea..a9aa1abceb8cf3779ec7e02ab4f96eb9dc7613f3 100644 (file)
 
 #include "trace-ust.h"
 
+/*
+ * Return an UST session by traceable app PID.
+ */
+struct ltt_ust_session *trace_ust_get_session_by_pid(pid_t pid,
+               struct ltt_ust_session_list *session_list)
+{
+       struct ltt_ust_session *lus;
+
+       cds_list_for_each_entry(lus, &session_list->head, list) {
+               if (lus->app->pid == pid) {
+                       DBG("Found UST session by pid %d", pid);
+                       return lus;
+               }
+       }
+
+       return NULL;
+}
+
 /*
  * Find the channel name for the given ust session.
  */
@@ -80,8 +98,9 @@ error:
  *
  * Return pointer to structure or NULL.
  */
-struct ltt_ust_session *trace_ust_create_session(void)
+struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid)
 {
+       int ret;
        struct ltt_ust_session *lus;
 
        /* Allocate a new ltt ust session */
@@ -97,9 +116,17 @@ struct ltt_ust_session *trace_ust_create_session(void)
        lus->uconsumer_fds_sent = 0;
        lus->path = NULL;
        lus->metadata = NULL;
+       lus->app = NULL;        /* TODO: Search app by PID */
        lus->channels.count = 0;
        CDS_INIT_LIST_HEAD(&lus->channels.head);
 
+       /* Set session path */
+       ret = asprintf(&lus->path, "%s/ust_%d", path, pid);
+       if (ret < 0) {
+               perror("asprintf kernel traces path");
+               goto error;
+       }
+
        return lus;
 
 error:
index fa86cb94f5fa921a263c2bcff484d8ac71b4ae0c..55a452c6092ea6cbd81669671def2c88b0e42951 100644 (file)
 #include <lttng/lttng.h>
 #include <lttng-ust.h>
 
+#include "traceable-app.h"
+
+/*
+ * UST session list.
+ */
+struct ltt_ust_session_list {
+       unsigned int count;
+       struct cds_list_head head;
+};
+
 /* UST event list */
 struct ltt_ust_event_list {
        unsigned int count;
@@ -71,8 +81,10 @@ struct ltt_ust_session {
        int enabled;
        int uconsumer_fds_sent;
        char *path;
+       struct ltt_traceable_app *app;
        struct ltt_ust_metadata *metadata;
        struct ltt_ust_channel_list channels;
+       struct cds_list_head list;
 };
 
 /*
@@ -82,11 +94,13 @@ struct ltt_ust_event *trace_ust_get_event_by_name(
                char *name, struct ltt_ust_channel *channel);
 struct ltt_ust_channel *trace_ust_get_channel_by_name(
                char *name, struct ltt_ust_session *session);
+struct ltt_ust_session *trace_ust_get_session_by_pid(pid_t pid,
+               struct ltt_ust_session_list *session_list);
 
 /*
  * Create functions malloc() the data structure.
  */
-struct ltt_ust_session *trace_ust_create_session(void);
+struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid);
 struct ltt_ust_channel *trace_ust_create_channel(char *name, char *path,
                struct lttng_ust_channel *attr);
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev);
index 85d50393a6b9eaaa60eeb17bb963370656d9708a..cde3f97f2e5a798b47b28156b4e0def6d2ac9a58 100644 (file)
@@ -98,6 +98,24 @@ static struct ltt_traceable_app *find_app_by_sock(int sock)
        return NULL;
 }
 
+/*
+ * Iterate over the traceable apps list and return a pointer or NULL if not
+ * found.
+ */
+struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid)
+{
+       struct ltt_traceable_app *iter;
+
+       cds_list_for_each_entry(iter, &ltt_traceable_app_list.head, list) {
+               if (iter->pid == pid) {
+                       /* Found */
+                       return iter;
+               }
+       }
+
+       return NULL;
+}
+
 /*
  * Using pid and uid (of the app), allocate a new ltt_traceable_app struct and
  * add it to the global traceable app list.
index accd4276d27c48156bfebb3e0a92602f75b6c60f..31c40070e92758b94779ef6b58e27f7b5ce39a23 100644 (file)
@@ -16,6 +16,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
+#include <stdlib.h>
+
 #include <lttngerr.h>
 
 #include "ust-comm.h"
  * Send msg containing a command to an UST application via sock and wait for
  * the reply.
  *
- * Return -1 on error or if reply fails else return 0.
+ * Return the replied structure or NULL.
  */
-int ustcomm_send_command(int sock, struct lttcomm_ust_msg *msg)
+struct lttcomm_ust_reply *ustcomm_send_command(int sock,
+               struct lttcomm_ust_msg *msg)
 {
        ssize_t len;
-       struct lttcomm_ust_reply reply;
+       struct lttcomm_ust_reply *reply;
+
+       /* Extra safety */
+       if (msg == NULL || sock < 0) {
+               goto error;
+       }
 
        DBG("Sending UST command %d to sock %d", msg->cmd, sock);
 
@@ -39,20 +47,22 @@ int ustcomm_send_command(int sock, struct lttcomm_ust_msg *msg)
                goto error;
        }
 
-       DBG("Receiving UST reply on sock %d", sock);
-
-       /* Get UST reply */
-       len = lttcomm_recv_unix_sock(sock, &reply, sizeof(reply));
-       if (len < 0) {
+       reply = malloc(sizeof(struct lttcomm_ust_reply));
+       if (reply == NULL) {
+               perror("malloc ust reply");
                goto error;
        }
 
-       if (reply.ret_code != LTTCOMM_OK) {
+       DBG("Receiving UST reply on sock %d", sock);
+
+       /* Get UST reply */
+       len = lttcomm_recv_unix_sock(sock, reply, sizeof(*reply));
+       if (len < 0 || len < sizeof(*reply)) {
                goto error;
        }
 
-       return 0;
+       return reply;
 
 error:
-       return -1;
+       return NULL;
 }
index 8a04f85a5c027b94503867db81a92dc52129e8ef..f7a3951668ed19a61985e9bc5dbdaffc0d031f24 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <lttng-sessiond-comm.h>
 
-int ustcomm_send_command(int sock, struct lttcomm_ust_msg *msg);
+struct lttcomm_ust_reply *ustcomm_send_command(int sock,
+               struct lttcomm_ust_msg *msg);
 
 #endif /* _LTT_UST_COMM_H */
index fe65fafe2c6f3d00a930c5108595657d91522000..5f4e8a9fcefe09dda5fecef4335de708b35b85a2 100644 (file)
  */
 
 #define _GNU_SOURCE
-#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 
 #include <lttng-sessiond-comm.h>
-#include "lttngerr.h"
-#include "ust-ctl.h"
-
-#ifdef DISABLED
-/*
- *  find_session_ust_trace_by_pid
- *
- *  Iterate over the session ust_traces and
- *  return a pointer or NULL if not found.
- */
-static struct ltt_ust_trace *find_session_ust_trace_by_pid(
-               struct ltt_session *session, pid_t pid)
-{
-       struct ltt_ust_trace *iter;
+#include <lttngerr.h>
 
-       cds_list_for_each_entry(iter, &session->ust_traces, list) {
-               if (iter->pid == pid) {
-                       /* Found */
-                       return iter;
-               }
-       }
-
-       return NULL;
-}
-
-/*
- *  get_trace_count_per_session
- *
- *  Return the total count of traces (ust and kernel)
- *  for the specified session.
- */
-int get_trace_count_per_session(struct ltt_session *session)
-{
-       return session->ust_trace_count;
-}
+#include "ust-comm.h"
+#include "ust-ctl.h"
 
 /*
- *  get_traces_per_session
- *
- *  Fill the lttng_trace array of all the
- *  available trace of the session.
+ * Send registration done packet to the application.
  */
-/*
-void get_traces_per_session(struct ltt_session *session, struct lttng_trace *traces)
+int ustctl_register_done(int sock)
 {
-       int i = 0;
-       struct ltt_ust_trace *ust_iter;
-       struct lttng_trace trace;
-
-       DBG("Getting userspace traces for session %s", session->name);
-
-       cds_list_for_each_entry(ust_iter, &session->ust_traces, list) {
-               trace.type = USERSPACE;
-               trace.pid = ust_iter->pid;
-               strncpy(trace.name, ust_iter->name, sizeof(trace.name));
-               trace.name[sizeof(trace.name) - 1] = '\0';
-               memcpy(&traces[i], &trace, sizeof(trace));
-               memset(&trace, 0, sizeof(trace));
-               i++;
-       }
-
-       DBG("Getting kernel traces for session %s", session->name);
-
-       if (session->kern_session_count > 0) {
-               trace.type = KERNEL;
-               strncpy(trace.name, "kernel", sizeof(trace.name));
-               trace.name[sizeof(trace.name) - 1] = '\0';
-               memcpy(&traces[i], &trace, sizeof(trace));
-       }
-}
-*/
+       struct lttcomm_ust_msg command;
+       struct lttcomm_ust_reply *reply;
 
-/*
- *  ust_create_trace
- *
- *  Create an userspace trace using pid.
- *  This trace is then appended to the current session
- *  ust trace list.
- */
-int ust_create_trace(struct command_ctx *cmd_ctx)
-{
-       int ret;
-       struct ltt_ust_trace *trace;
+       DBG("Sending register done command to %d", sock);
 
-       DBG("Creating trace for pid %d", cmd_ctx->lsm->pid);
+       command.cmd = LTTNG_UST_REGISTER_DONE;
+       command.handle = LTTNG_UST_ROOT_HANDLE;
 
-       trace = malloc(sizeof(struct ltt_ust_trace));
-       if (trace == NULL) {
-               perror("malloc");
-               ret = -1;
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
                goto error;
        }
 
-       /* Init */
-       trace->pid = cmd_ctx->lsm->pid;
-       trace->shmid = 0;
-       /* NOTE: to be removed. Trace name will no longer be
-        * required for LTTng userspace tracer. For now, we set it
-        * to 'auto' for API compliance.
-        */
-       snprintf(trace->name, 5, "auto");
-
-       ret = ustctl_create_trace(cmd_ctx->ust_sock, trace->name);
-       if (ret < 0) {
-               ret = LTTCOMM_CREATE_FAIL;
-               goto error_create;
-       }
-
-       /* Check if current session is valid */
-       if (cmd_ctx->session) {
-               cds_list_add(&trace->list, &cmd_ctx->session->ust_traces);
-               cmd_ctx->session->ust_trace_count++;
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code));
+               goto error;
        }
 
-       return LTTCOMM_OK;
+       return 0;
 
-error_create:
-       free(trace);
 error:
-       return ret;
+       return -1;
 }
 
 /*
- *  ust_start_trace
- *
- *  Start a trace. This trace, identified by the pid, must be
- *  in the current session ust_traces list.
+ * Create an UST session on the tracer.
  */
-int ust_start_trace(struct command_ctx *cmd_ctx)
+int ustctl_create_session(struct ltt_ust_session *session)
 {
-       int ret;
-       struct ltt_ust_trace *trace;
+       struct lttcomm_ust_msg command;
+       struct lttcomm_ust_reply *reply;
 
-       DBG("Starting trace for pid %d", cmd_ctx->lsm->pid);
+       DBG("Creating UST session for app pid:%d", session->app->pid);
 
-       trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid);
-       if (trace == NULL) {
-               ret = LTTCOMM_NO_TRACE;
-               goto error;
-       }
+       command.cmd = LTTNG_UST_SESSION;
+       command.handle = LTTNG_UST_ROOT_HANDLE;
 
-       ret = ustctl_start_trace(cmd_ctx->ust_sock, "auto");
-       if (ret < 0) {
-               ret = LTTCOMM_START_FAIL;
+       reply = ustcomm_send_command(session->app->sock, &command);
+       if (reply == NULL) {
                goto error;
        }
 
-       ret = LTTCOMM_OK;
-
-error:
-       return ret;
-}
-
-/*
- *  ust_stop_trace
- *
- *  Stop a trace. This trace, identified by the pid, must be
- *  in the current session ust_traces list.
- */
-int ust_stop_trace(struct command_ctx *cmd_ctx)
-{
-       int ret;
-       struct ltt_ust_trace *trace;
-
-       DBG("Stopping trace for pid %d", cmd_ctx->lsm->pid);
-
-       trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid);
-       if (trace == NULL) {
-               ret = LTTCOMM_NO_TRACE;
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code));
                goto error;
        }
 
-       ret = ustctl_stop_trace(cmd_ctx->ust_sock, trace->name);
-       if (ret < 0) {
-               ret = LTTCOMM_STOP_FAIL;
-               goto error;
-       }
+       /* Save session handle */
+       session->handle = reply->handle;
 
-       ret = LTTCOMM_OK;
+       return 0;
 
 error:
-       return ret;
+       return -1;
 }
-#endif
-
index 6ec5fbdc4080f0708c2e66862b293cb895925be1..8f8bebc99590e74c7994ba8a57f8904493f83ecf 100644 (file)
 #ifndef _LTT_UST_CTL_H
 #define _LTT_UST_CTL_H
 
+#include "trace-ust.h"
+
+int ustctl_register_done(int sock);
+int ustctl_create_session(struct ltt_ust_session *session);
+int ustctl_destroy_session(struct ltt_ust_session *session);
+
 #endif /* _LTT_UST_CTL_H */
index 422c4160387575fff6e6929cf15685ceb9f8f393..f99d2a462d6f69999c1bce5a2f0ebd14f7b94eb3 100644 (file)
@@ -269,7 +269,7 @@ int main(int argc, char **argv)
        }
        /* Basic init session values */
        assert(tmp->kernel_session == NULL);
-       assert(tmp->ust_trace_count == 0);
+       assert(tmp->ust_session_list.count == 0);
        assert(strlen(tmp->path));
        assert(strlen(tmp->name));
        lock_session(tmp);
This page took 0.040672 seconds and 5 git commands to generate.