Add the GMT offset in the rotated chunk path
[lttng-tools.git] / src / bin / lttng-sessiond / rotate.c
index 49ccea94e381fd6ee520162b8c362f310efe7e9e..4264cd4bd91fadeca704f9895b4c0733610a1b9c 100644 (file)
@@ -32,6 +32,8 @@
 #include <signal.h>
 #include <inttypes.h>
 
+#include <lttng/rotate-internal.h>
+
 #include "session.h"
 #include "rotate.h"
 #include "rotation-thread.h"
@@ -207,8 +209,8 @@ error:
 int rename_complete_chunk(struct ltt_session *session, time_t ts)
 {
        struct tm *timeinfo;
-       char datetime[16], start_datetime[16];
        char new_path[LTTNG_PATH_MAX];
+       char datetime[21], start_datetime[21];
        int ret;
        size_t strf_ret;
 
@@ -219,7 +221,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts)
                ret = -1;
                goto end;
        }
-       strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S",
+
+       strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%dT%H%M%S%z",
                        timeinfo);
        if (strf_ret == 0) {
                ERR("Failed to format timestamp while renaming completed session chunk");
@@ -228,7 +231,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts)
        }
 
        if (session->rotate_count == 1) {
-               char start_time[16];
+               char start_time[21];
 
                timeinfo = localtime(&session->last_chunk_start_ts);
                if (!timeinfo) {
@@ -238,7 +241,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts)
                }
 
                strf_ret = strftime(start_time, sizeof(start_time),
-                               "%Y%m%d-%H%M%S", timeinfo);
+                               "%Y%m%dT%H%M%S%z", timeinfo);
                if (strf_ret == 0) {
                        ERR("Failed to format timestamp while renaming completed session chunk");
                        ret = -1;
@@ -300,7 +303,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts)
                        ret = -1;
                        goto end;
                }
-               strf_ret = strftime(start_datetime, sizeof(start_datetime), "%Y%m%d-%H%M%S", timeinfo);
+               strf_ret = strftime(start_datetime, sizeof(start_datetime),
+                               "%Y%m%dT%H%M%S%z", timeinfo);
                if (!strf_ret) {
                        ERR("Failed to format timestamp while renaming completed session chunk");
                        ret = -1;
@@ -346,7 +350,54 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts)
        goto end;
 
 error:
-       session->rotation_status = LTTNG_ROTATION_STATUS_ERROR;
+       session->rotation_state = LTTNG_ROTATION_STATE_ERROR;
+end:
+       return ret;
+}
+
+int relay_rotate_pending(struct ltt_session *session, uint64_t chunk_id)
+{
+       int ret;
+       struct consumer_socket *socket;
+       struct consumer_output *output;
+       struct lttng_ht_iter iter;
+
+       /*
+        * Either one of the sessions is enough to find the consumer_output
+        * and uid/gid.
+        */
+       if (session->kernel_session) {
+               output = session->kernel_session->consumer;
+       } else if (session->ust_session) {
+               output = session->ust_session->consumer;
+       } else {
+               assert(0);
+       }
+
+       if (!output || !output->socks) {
+               ERR("No consumer output found");
+               ret = -1;
+               goto end;
+       }
+
+       ret = -1;
+
+       rcu_read_lock();
+       /*
+        * We have to iterate to find a socket, but we only need to send the
+        * rotate pending command to one consumer, so we break after the first
+        * one.
+        */
+       cds_lfht_for_each_entry(output->socks->ht, &iter.iter, socket,
+                       node.node) {
+               pthread_mutex_lock(socket->lock);
+               ret = consumer_rotate_pending_relay(socket, output, session->id,
+                               chunk_id);
+               pthread_mutex_unlock(socket->lock);
+               break;
+       }
+       rcu_read_unlock();
+
 end:
        return ret;
 }
This page took 0.040635 seconds and 4 git commands to generate.