From: Liguang Li Date: Mon, 28 Nov 2016 08:37:47 +0000 (+0800) Subject: Fix: truncate the metadata file in shm-path X-Git-Tag: v2.10.0-rc1~95 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=7802bae326824ecb116cb0d782bb7472eaa6f6e4 Fix: truncate the metadata file in shm-path In the shm-path mode, the metadata will be backuped to a metadata file, when run the lttng command "lttng metadata regenerate" to resample the wall time following a major NTP correction, the metadata file will not be truncated and regenerated. Add the function clear_metadata_file() to truncate and regenerate the metadata file. Signed-off-by: Liguang Li Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 325ffd2cf..cc81906b6 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -3377,6 +3377,27 @@ end: return ret; } +static +int clear_metadata_file(int fd) +{ + int ret; + + ret = lseek(fd, 0, SEEK_SET); + if (ret < 0) { + PERROR("lseek"); + goto end; + } + + ret = ftruncate(fd, 0); + if (ret < 0) { + PERROR("ftruncate"); + goto end; + } + +end: + return ret; +} + static int ust_regenerate_metadata(struct ltt_ust_session *usess) { @@ -3398,6 +3419,15 @@ int ust_regenerate_metadata(struct ltt_ust_session *usess) memset(registry->metadata, 0, registry->metadata_alloc_len); registry->metadata_len = 0; registry->metadata_version++; + if (registry->metadata_fd > 0) { + /* Clear the metadata file's content. */ + ret = clear_metadata_file(registry->metadata_fd); + if (ret) { + pthread_mutex_unlock(®istry->lock); + goto end; + } + } + ret = ust_metadata_session_statedump(registry, NULL, registry->major, registry->minor); if (ret) {