From 9c96e34c54f6e2beda872953c4d5955967c9fef4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 29 Jul 2022 17:40:45 -0400 Subject: [PATCH] ust-ctl: allow runtime version checks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Officially, building (and dynamically linking) mismatching LTTng-UST and LTTng-tools versions is unsupported. At build time, LTTng-tools ensures that both versions match. However, it remains possible for a user to mistakenly deploy LTTng-tools built againt liblttng-ust-ctl v2.x and liblttng-ust-ctl.so from a different LTTng-UST release. Since the soname major version of liblttng-ust-ctl is not bumped at every release, this would allow LTTng-tools binary to load. In practice, this is unlikely to work since new symbols are introduced at almost every release cycle. However, it isn't guaranteed. In the case of a recent change -- removing the underscore prefix of enumeration mappings used by a variant -- we don't change the ABI, but we rely on the LTTNG_UST_ABI_MAJOR_VERSION to indicate whether or not the fix is present to change the interpretation of existing fields. Adding lttng_ust_ctl_get_version() provides an additional safety net to check, at runtime, that the version of liblttng-ust-ctl.so that is loaded matches that of LTTng-tools. Technically, only major and minor versions are necessary. I propose including the patchlevel version for future-proofing should we want to work around known bugs in the future. Signed-off-by: Jérémie Galarneau Signed-off-by: Mathieu Desnoyers Change-Id: I14bee30bb5d2109be0c8c015ed845d70df16630b --- include/lttng/ust-ctl.h | 2 ++ src/lib/lttng-ust-ctl/ustctl.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/lttng/ust-ctl.h b/include/lttng/ust-ctl.h index 25e588b3..42b30ea9 100644 --- a/include/lttng/ust-ctl.h +++ b/include/lttng/ust-ctl.h @@ -660,6 +660,8 @@ int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter *counter, void lttng_ust_ctl_sigbus_handle(void *addr); +int lttng_ust_ctl_get_version(uint32_t *major, uint32_t *minor, uint32_t *patchlevel); + #ifdef __cplusplus } #endif diff --git a/src/lib/lttng-ust-ctl/ustctl.c b/src/lib/lttng-ust-ctl/ustctl.c index 6faaef5e..7b679880 100644 --- a/src/lib/lttng-ust-ctl/ustctl.c +++ b/src/lib/lttng-ust-ctl/ustctl.c @@ -3294,6 +3294,14 @@ int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter *counter, return counter->ops->counter_clear(counter->counter, dimension_indexes); } +int lttng_ust_ctl_get_version(uint32_t *major, uint32_t *minor, + uint32_t *patchlevel) { + *major = LTTNG_UST_MAJOR_VERSION; + *minor = LTTNG_UST_MINOR_VERSION; + *patchlevel = LTTNG_UST_PATCHLEVEL_VERSION; + return 0; +} + static void lttng_ust_ctl_ctor(void) __attribute__((constructor)); -- 2.34.1