X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fbackward-compatibility-group-by.c;h=9e144f9f52b1a68d4273f544196048d8f93eb70c;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=45bbe17284b551a5f7ddb5b667a445bfc486b725;hpb=4f173935e4dfec4ca32ab3825871736b7b0f64d8;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.c b/src/bin/lttng-relayd/backward-compatibility-group-by.c index 45bbe1728..9e144f9f5 100644 --- a/src/bin/lttng-relayd/backward-compatibility-group-by.c +++ b/src/bin/lttng-relayd/backward-compatibility-group-by.c @@ -5,7 +5,7 @@ * */ -#include +#include "common/time.h" #include #include #include @@ -17,7 +17,6 @@ #include "backward-compatibility-group-by.h" -#define DATETIME_STRING_SIZE 16 #define DATETIME_REGEX \ ".*-[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9][0-5][0-9]$" @@ -28,8 +27,9 @@ * * Return the allocated string containing the new stream path or else NULL. */ -char *backward_compat_group_by_session( - const char *path, const char *local_session_name) +char *backward_compat_group_by_session(const char *path, + const char *local_session_name, + time_t relay_session_creation_time) { int ret; size_t len; @@ -43,9 +43,9 @@ char *backward_compat_group_by_session( const char *hostname_ptr; regex_t regex; - assert(path); - assert(local_session_name); - assert(local_session_name[0] != '\0'); + LTTNG_ASSERT(path); + LTTNG_ASSERT(local_session_name); + LTTNG_ASSERT(local_session_name[0] != '\0'); DBG("Parsing path \"%s\" of session \"%s\" to create a new path that is grouped by session", path, local_session_name); @@ -162,17 +162,30 @@ char *backward_compat_group_by_session( ret = regexec(®ex, local_session_name, 0, NULL, 0); if (ret == 0) { const ssize_t local_session_name_offset = - strlen(local_session_name) - DATETIME_STRING_SIZE + 1; + strlen(local_session_name) - DATETIME_STR_LEN + 1; - assert(local_session_name_offset >= 0); + LTTNG_ASSERT(local_session_name_offset >= 0); datetime = strdup(local_session_name + local_session_name_offset); if (!datetime) { PERROR("Failed to parse session path: couldn't copy datetime on regex match"); goto error_regex; } + } else { + datetime = zmalloc(DATETIME_STR_LEN); + if (!datetime) { + PERROR("Failed to allocate DATETIME string"); + goto error; + } + + ret = time_to_datetime_str(relay_session_creation_time, + datetime, DATETIME_STR_LEN); + if (ret) { + /* time_to_datetime_str already logs errors. */ + goto error; + } } - } else if (len == DATETIME_STRING_SIZE && + } else if (len == DATETIME_STR_LEN && !regexec(®ex, leftover_second_token_ptr, 0, NULL, 0)) { /* @@ -193,8 +206,8 @@ char *backward_compat_group_by_session( * "name-" format. Using the datetime from such a * session would be invalid. * */ - assert(partial_base_path == NULL); - assert(datetime == NULL); + LTTNG_ASSERT(partial_base_path == NULL); + LTTNG_ASSERT(datetime == NULL); partial_base_path = strdup(second_token_ptr); if (!partial_base_path) {