*
*/
+#include "common/time.h"
#include <assert.h>
#include <regex.h>
#include <stdio.h>
*
* 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;
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);
datetime = strdup(local_session_name +
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)) {
/*
#ifndef BACKWARD_COMPATIBILITY_GROUP_BY_H
#define BACKWARD_COMPATIBILITY_GROUP_BY_H
-char *backward_compat_group_by_session(
- const char *path, const char *local_session_name);
+#include <time.h>
+
+char *backward_compat_group_by_session(const char *path,
+ const char *local_session_name,
+ time_t session_creation_time);
#endif /* BACKWARD_COMPATIBILITY_GROUP_BY_H */
group_by_session_path_name =
backward_compat_group_by_session(
path_name,
- session->session_name);
+ session->session_name,
+ session->creation_time.value);
if (!group_by_session_path_name) {
ERR("Failed to apply group by session to stream of session %" PRIu64,
session->id);
}
if (creation_time) {
LTTNG_OPTIONAL_SET(&session->creation_time, *creation_time);
+ } else {
+ LTTNG_OPTIONAL_SET(&session->creation_time, time(NULL));
+ if (session->creation_time.value == (time_t) -1) {
+ PERROR("Failed to sample session creation time");
+ goto error;
+ }
}
session->session_name_contains_creation_time =
session_name_contains_creation_time;
* the other cases.
*/
lttng_uuid sessiond_uuid;
+ /*
+ * Contains the creation time on the session daemon's end for 2.11+
+ * peers. Otherwise, this contains the session creation time on the
+ * relay daemon's end.
+ */
LTTNG_OPTIONAL(time_t) creation_time;
/* Must _not_ be empty for 2.4+ peers. */
char session_name[LTTNG_NAME_MAX];
#include <string.h>
#include <tap/tap.h>
+#include <common/time.h>
+
#include "backward-compatibility-group-by.h"
/* Number of TAP tests in this file */
"", "ust/uid/1000/64-bit", true},
};
-static char *craft_expected(struct test *test)
+static char *craft_expected(struct test *test, time_t relay_session_creation_time)
{
int ret;
char *result = NULL;
+ char relay_session_creation_datetime[DATETIME_STR_LEN];
+
+ ret = time_to_datetime_str(relay_session_creation_time,
+ relay_session_creation_datetime,
+ sizeof(relay_session_creation_datetime));
+ if (ret < 0) {
+ result = NULL;
+ goto end;
+ }
- ret = asprintf(&result, "%s/%s%s%s/%s%s%s", test->session_name,
+ ret = asprintf(&result, "%s/%s-%s/%s%s%s", test->session_name,
test->hostname,
- test->creation_time[0] != '\0' ? "-" : "",
- test->creation_time, test->extra_path,
+ test->creation_time[0] == '\0' ?
+ relay_session_creation_datetime :
+ test->creation_time,
+ test->extra_path,
test->extra_path[0] != '\0' ? "/" : "", test->leftover);
if (ret < 0) {
result = NULL;
+ goto end;
}
+end:
return result;
}
{
int i;
int num_test = sizeof(tests) / sizeof(struct test);
+ const time_t test_time = time(NULL);
plan_tests(NUM_TESTS_PER_TEST * num_test);
diag("Backward compatibility utils for lttng-relayd --group-by-session");
+
+ if (test_time == (time_t) -1) {
+ perror("Failed to sample time");
+ return exit_status();
+ }
+
for (i = 0; i < num_test; i++) {
char *expected = NULL;
char *result = NULL;
- expected = craft_expected(&tests[i]);
+ expected = craft_expected(&tests[i], test_time);
if (!expected) {
fprintf(stderr, "Failed to craft expected output\n");
goto loop;
}
- result = backward_compat_group_by_session(
- tests[i].stream_path, tests[i].session_name);
+ result = backward_compat_group_by_session(tests[i].stream_path,
+ tests[i].session_name, test_time);
if (!result && tests[i].is_valid) {
fprintf(stderr, "Failed to get result\n");
goto loop;