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.8.3~1 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6beb3779248926b2c75175b18e90ac883d528e3c;p=lttng-tools.git 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 fed029443..ae0a56ac6 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -3436,6 +3436,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_metadata_regenerate(struct ltt_ust_session *usess) { @@ -3457,6 +3478,15 @@ int ust_metadata_regenerate(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) {