X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fbackward-compatibility-group-by.c;h=241c21f469b8356b813926037550ab60cbb8c8c7;hp=dd5ccffd532147f8fb317d7f6c23669aa2c11d6a;hb=d2cb4a903e7b0868be99c6d558ce0c782af81c27;hpb=eb60c7af29eaaefeb68516339df2c7f86136ce23 diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.c b/src/bin/lttng-relayd/backward-compatibility-group-by.c index dd5ccffd5..241c21f46 100644 --- a/src/bin/lttng-relayd/backward-compatibility-group-by.c +++ b/src/bin/lttng-relayd/backward-compatibility-group-by.c @@ -1,20 +1,11 @@ /* - * Copyright (C) 2019 - Jonathan Rajotte + * Copyright (C) 2019 Jonathan Rajotte * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "common/time.h" #include #include #include @@ -38,8 +29,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; @@ -70,7 +62,7 @@ char *backward_compat_group_by_session( /* * The use of strtok with '/' as delimiter is valid since we refuse '/' * in session name and '/' is not a valid hostname character based on - * RFC-952 [1], RFC-921 [2] and refined in RFC-1123 [2]. + * RFC-952 [1], RFC-921 [2] and refined in RFC-1123 [3]. * [1] https://tools.ietf.org/html/rfc952 * [2] https://tools.ietf.org/html/rfc921 * [3] https://tools.ietf.org/html/rfc1123#page-13 @@ -172,7 +164,7 @@ 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); datetime = strdup(local_session_name + @@ -181,8 +173,21 @@ char *backward_compat_group_by_session( 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)) { /*