diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2024-02-05 13:43:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-05 13:43:48 +0200 |
commit | 4299ff70891ca142411c663aaa8420707f2ad9fb (patch) | |
tree | 177a276063635529545f4109c7c941dc885a99dc | |
parent | 908d8b6206b0a95bf6e2760cbf84ca1c062925de (diff) |
Protect analytics set data (#16929)
-rw-r--r-- | daemon/analytics.c | 6 | ||||
-rw-r--r-- | daemon/analytics.h | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/daemon/analytics.c b/daemon/analytics.c index be1e1caa65..de09a69600 100644 --- a/daemon/analytics.c +++ b/daemon/analytics.c @@ -116,12 +116,14 @@ void analytics_free_data(void) */ void analytics_set_data(char **name, char *value) { + spinlock_lock(&analytics_data.spinlock); if (*name) { analytics_data.data_length -= strlen(*name); freez(*name); } *name = strdupz(value); analytics_data.data_length += strlen(*name); + spinlock_unlock(&analytics_data.spinlock); } /* @@ -130,6 +132,7 @@ void analytics_set_data(char **name, char *value) void analytics_set_data_str(char **name, const char *value) { size_t value_string_len; + spinlock_lock(&analytics_data.spinlock); if (*name) { analytics_data.data_length -= strlen(*name); freez(*name); @@ -138,6 +141,7 @@ void analytics_set_data_str(char **name, const char *value) *name = mallocz(sizeof(char) * value_string_len); snprintfz(*name, value_string_len - 1, "\"%s\"", value); analytics_data.data_length += strlen(*name); + spinlock_unlock(&analytics_data.spinlock); } /* @@ -466,6 +470,8 @@ void analytics_alarms(void) */ void analytics_misc(void) { + analytics_data.spinlock.locked = false; + #ifdef ENABLE_ACLK analytics_set_data(&analytics_data.netdata_host_cloud_available, "true"); analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "Next Generation"); diff --git a/daemon/analytics.h b/daemon/analytics.h index 4ba625683e..04991036ce 100644 --- a/daemon/analytics.h +++ b/daemon/analytics.h @@ -71,6 +71,7 @@ struct analytics_data { size_t charts_count; size_t metrics_count; + SPINLOCK spinlock; bool exporting_enabled; }; |