Add creation time to UST app path to ensure uniqueness
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 Nov 2011 13:16:14 +0000 (08:16 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 Nov 2011 13:16:14 +0000 (08:16 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng-sessiond/ust-app.c
lttng-sessiond/ust-app.h

index a30b01dca37ce7515d183430921e79929d66c391..2bee4d90ab7626b7b51c314b67ef539d65441634 100644 (file)
@@ -503,17 +503,37 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan,
  * Copy data between a UST app session and a regular LTT session.
  */
 static void shadow_copy_session(struct ust_app_session *ua_sess,
  * Copy data between a UST app session and a regular LTT session.
  */
 static void shadow_copy_session(struct ust_app_session *ua_sess,
-               struct ltt_ust_session *usess)
+               struct ltt_ust_session *usess,
+               struct ust_app *app)
 {
        struct cds_lfht_node *ua_chan_node;
        struct cds_lfht_iter iter;
        struct ltt_ust_channel *uchan;
        struct ust_app_channel *ua_chan;
 {
        struct cds_lfht_node *ua_chan_node;
        struct cds_lfht_iter iter;
        struct ltt_ust_channel *uchan;
        struct ust_app_channel *ua_chan;
+       time_t rawtime;
+       struct tm *timeinfo;
+       char datetime[16];
+       int ret;
+
+       /* Get date and time for unique app path */
+       time(&rawtime);
+       timeinfo = localtime(&rawtime);
+       strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
 
        DBG2("Shadow copy of session handle %d", ua_sess->handle);
 
        ua_sess->uid = usess->uid;
 
 
        DBG2("Shadow copy of session handle %d", ua_sess->handle);
 
        ua_sess->uid = usess->uid;
 
+       ret = snprintf(ua_sess->path, PATH_MAX,
+                       "%s/%s-%d-%s",
+                       usess->pathname, app->name, app->key.pid,
+                       datetime);
+       if (ret < 0) {
+               PERROR("asprintf UST shadow copy session");
+               /* TODO: We cannot return an error from here.. */
+               assert(0);
+       }
+
        /* TODO: support all UST domain */
 
        /* Iterate over all channels in global domain. */
        /* TODO: support all UST domain */
 
        /* Iterate over all channels in global domain. */
@@ -585,7 +605,7 @@ static struct ust_app_session *create_ust_app_session(
                        /* Only malloc can failed so something is really wrong */
                        goto error;
                }
                        /* Only malloc can failed so something is really wrong */
                        goto error;
                }
-               shadow_copy_session(ua_sess, usess);
+               shadow_copy_session(ua_sess, usess, app);
        }
 
        if (ua_sess->handle == -1) {
        }
 
        if (ua_sess->handle == -1) {
@@ -727,21 +747,14 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess,
                        goto error;
                }
 
                        goto error;
                }
 
-               ret = snprintf(ua_sess->metadata->pathname, PATH_MAX, "%s/%s-%d",
-                               pathname, app->name, app->key.pid);
-               if (ret < 0) {
-                       PERROR("asprintf UST create stream");
-                       goto error;
-               }
-
-               ret = mkdir(ua_sess->metadata->pathname, S_IRWXU | S_IRWXG);
+               ret = mkdir(ua_sess->path, S_IRWXU | S_IRWXG);
                if (ret < 0) {
                        PERROR("mkdir UST metadata");
                        goto error;
                }
 
                if (ret < 0) {
                        PERROR("mkdir UST metadata");
                        goto error;
                }
 
-               ret = snprintf(ua_sess->metadata->pathname, PATH_MAX, "%s/%s-%d/metadata",
-                               pathname, app->name, app->key.pid);
+               ret = snprintf(ua_sess->metadata->pathname, PATH_MAX,
+                               "%s/metadata", ua_sess->path);
                if (ret < 0) {
                        PERROR("asprintf UST create stream");
                        goto error;
                if (ret < 0) {
                        PERROR("asprintf UST create stream");
                        goto error;
@@ -1137,9 +1150,9 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
 
                        /* Order is important */
                        cds_list_add_tail(&ustream->list, &ua_chan->streams.head);
 
                        /* Order is important */
                        cds_list_add_tail(&ustream->list, &ua_chan->streams.head);
-                       ret = snprintf(ustream->pathname, PATH_MAX, "%s/%s-%d/%s_%u",
-                                       usess->pathname, app->name, app->key.pid,
-                                       ua_chan->name, ua_chan->streams.count++);
+                       ret = snprintf(ustream->pathname, PATH_MAX, "%s/%s_%u",
+                                       ua_sess->path, ua_chan->name,
+                                       ua_chan->streams.count++);
                        if (ret < 0) {
                                PERROR("asprintf UST create stream");
                                continue;
                        if (ret < 0) {
                                PERROR("asprintf UST create stream");
                                continue;
index 14e04c121510157ebbfa896ffed43794c84513d7..c730cb738044d7daf3a4f517ca570613a20dde0f 100644 (file)
@@ -84,6 +84,7 @@ struct ust_app_session {
        struct lttng_ust_object_data *obj;
        struct cds_lfht *channels; /* Registered channels */
        struct cds_lfht_node node;
        struct lttng_ust_object_data *obj;
        struct cds_lfht *channels; /* Registered channels */
        struct cds_lfht_node node;
+       char path[PATH_MAX];
 };
 
 /*
 };
 
 /*
This page took 0.027875 seconds and 4 git commands to generate.