From cc280027af4d65437a30613bb63421ae8d7b199a Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 11 Dec 2019 13:18:00 -0500 Subject: [PATCH] common: index: remove redundant separator for empty channel string MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Tweak _lttng_index_file_create_from_trace_chunk() to correctly deal with empty channel_path string, removing redundant "/" separators. Signed-off-by: Mathieu Desnoyers Change-Id: I743917c27e334ad12e145959b3ad3f59f62f1a64 Signed-off-by: Jérémie Galarneau --- src/common/index/index.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/index/index.c b/src/common/index/index.c index b2e36211a..540294a5e 100644 --- a/src/common/index/index.c +++ b/src/common/index/index.c @@ -51,6 +51,7 @@ static struct lttng_index_file *_lttng_index_file_create_from_trace_chunk( char index_file_path[LTTNG_PATH_MAX]; const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; const bool acquired_reference = lttng_trace_chunk_get(chunk); + const char *separator; assert(acquired_reference); @@ -61,8 +62,13 @@ static struct lttng_index_file *_lttng_index_file_create_from_trace_chunk( } index_file->trace_chunk = chunk; + if (channel_path[0] == '\0') { + separator = ""; + } else { + separator = "/"; + } ret = snprintf(index_directory_path, sizeof(index_directory_path), - "%s/" DEFAULT_INDEX_DIR, channel_path); + "%s%s" DEFAULT_INDEX_DIR, channel_path, separator); if (ret < 0 || ret >= sizeof(index_directory_path)) { ERR("Failed to format index directory path"); goto error; -- 2.34.1