From 7a5e50b18fbe1093870efaf0dc3bee6e900af13c Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 3 Apr 2019 16:29:44 -0400 Subject: [PATCH] index common code: introduce lttng_index_file_unlink Signed-off-by: Mathieu Desnoyers --- src/common/index/index.c | 32 ++++++++++++++++++++++++++++++++ src/common/index/index.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/common/index/index.c b/src/common/index/index.c index 9bfb56fa0..07d2cf3c0 100644 --- a/src/common/index/index.c +++ b/src/common/index/index.c @@ -78,11 +78,15 @@ struct lttng_index_file *lttng_index_file_create(char *path_name, */ ret = utils_unlink_stream_file(fullpath, stream_name, size, count, uid, gid, DEFAULT_INDEX_FILE_SUFFIX); + DBG("utils_unlink_stream_file %s %s ret %d errno %d", + fullpath, stream_name, ret, errno); if (ret < 0 && errno != ENOENT) { goto error; } ret = utils_create_stream_file(fullpath, stream_name, size, count, uid, gid, DEFAULT_INDEX_FILE_SUFFIX); + DBG("utils_create_stream_file %s %s ret %d errno %d", + fullpath, stream_name, ret, errno); if (ret < 0) { goto error; } @@ -119,6 +123,34 @@ error: return NULL; } +int lttng_index_file_unlink(char *path_name, + char *stream_name, int uid, int gid, + uint64_t tracefile_size, + uint64_t tracefile_count_current) +{ + int ret; + char fullpath[PATH_MAX]; + + ret = snprintf(fullpath, sizeof(fullpath), "%s/" DEFAULT_INDEX_DIR, + path_name); + if (ret < 0) { + PERROR("snprintf index path"); + goto error; + } + + ret = utils_unlink_stream_file(fullpath, stream_name, + tracefile_size, tracefile_count_current, uid, + gid, DEFAULT_INDEX_FILE_SUFFIX); + if (ret < 0 && errno != ENOENT) { + goto error; + } + + return 0; + +error: + return -1; +} + /* * Write index values to the given index file. * diff --git a/src/common/index/index.h b/src/common/index/index.h index 7020936b6..b240969e2 100644 --- a/src/common/index/index.h +++ b/src/common/index/index.h @@ -40,6 +40,9 @@ struct lttng_index_file { struct lttng_index_file *lttng_index_file_create(char *path_name, char *stream_name, int uid, int gid, uint64_t size, uint64_t count, uint32_t major, uint32_t minor); +int lttng_index_file_unlink(char *path_name, + char *stream_name, int uid, int gid, + uint64_t tracefile_size, uint64_t tracefile_count_current); struct lttng_index_file *lttng_index_file_open(const char *path_name, const char *channel_name, uint64_t tracefile_count, uint64_t tracefile_count_current); -- 2.34.1