From a982c5c058188316363ac2830b2583d5644207db Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Fri, 17 Feb 2017 22:42:59 +0200 Subject: [PATCH] move machine_guid from registry to rrdhost --- src/registry.c | 2 +- src/registry_internals.c | 24 ++++++++++++------------ src/registry_internals.h | 2 -- src/rrd.h | 1 + 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/registry.c b/src/registry.c index 633535a6..77638abe 100644 --- a/src/registry.c +++ b/src/registry.c @@ -45,7 +45,7 @@ static inline void registry_json_header(struct web_client *w, const char *action buffer_flush(w->response.data); w->response.data->contenttype = CT_APPLICATION_JSON; buffer_sprintf(w->response.data, "{\n\t\"action\": \"%s\",\n\t\"status\": \"%s\",\n\t\"hostname\": \"%s\",\n\t\"machine_guid\": \"%s\"", - action, status, registry.hostname, registry.machine_guid); + action, status, registry.hostname, localhost.machine_guid); } static inline void registry_json_footer(struct web_client *w) { diff --git a/src/registry_internals.c b/src/registry_internals.c index d32d549e..04fcf347 100644 --- a/src/registry_internals.c +++ b/src/registry_internals.c @@ -275,8 +275,8 @@ static inline int is_machine_guid_blacklisted(const char *guid) { } char *registry_get_this_machine_guid(void) { - if(likely(registry.machine_guid[0])) - return registry.machine_guid; + if(likely(localhost.machine_guid[0])) + return localhost.machine_guid; // read it from disk int fd = open(registry.machine_guid_filename, O_RDONLY); @@ -286,38 +286,38 @@ char *registry_get_this_machine_guid(void) { error("Failed to read machine GUID from '%s'", registry.machine_guid_filename); else { buf[GUID_LEN] = '\0'; - if(registry_regenerate_guid(buf, registry.machine_guid) == -1) { + if(registry_regenerate_guid(buf, localhost.machine_guid) == -1) { error("Failed to validate machine GUID '%s' from '%s'. Ignoring it - this might mean this netdata will appear as duplicate in the registry.", buf, registry.machine_guid_filename); - registry.machine_guid[0] = '\0'; + localhost.machine_guid[0] = '\0'; } - else if(is_machine_guid_blacklisted(registry.machine_guid)) - registry.machine_guid[0] = '\0'; + else if(is_machine_guid_blacklisted(localhost.machine_guid)) + localhost.machine_guid[0] = '\0'; } close(fd); } // generate a new one? - if(!registry.machine_guid[0]) { + if(!localhost.machine_guid[0]) { uuid_t uuid; uuid_generate_time(uuid); - uuid_unparse_lower(uuid, registry.machine_guid); - registry.machine_guid[GUID_LEN] = '\0'; + uuid_unparse_lower(uuid, localhost.machine_guid); + localhost.machine_guid[GUID_LEN] = '\0'; // save it fd = open(registry.machine_guid_filename, O_WRONLY|O_CREAT|O_TRUNC, 444); if(fd == -1) fatal("Cannot create unique machine id file '%s'. Please fix this.", registry.machine_guid_filename); - if(write(fd, registry.machine_guid, GUID_LEN) != GUID_LEN) + if(write(fd, localhost.machine_guid, GUID_LEN) != GUID_LEN) fatal("Cannot write the unique machine id file '%s'. Please fix this.", registry.machine_guid_filename); close(fd); } - setenv("NETDATA_REGISTRY_UNIQUE_ID", registry.machine_guid, 1); + setenv("NETDATA_REGISTRY_UNIQUE_ID", localhost.machine_guid, 1); - return registry.machine_guid; + return localhost.machine_guid; } diff --git a/src/registry_internals.h b/src/registry_internals.h index 9c0b7445..42c36620 100644 --- a/src/registry_internals.h +++ b/src/registry_internals.h @@ -14,8 +14,6 @@ struct registry { int enabled; - char machine_guid[GUID_LEN + 1]; - // entries counters / statistics unsigned long long persons_count; unsigned long long machines_count; diff --git a/src/rrd.h b/src/rrd.h index 4b96a47d..e1f312a7 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -297,6 +297,7 @@ struct rrdhost { avl avl; char *hostname; + char machine_guid[GUID_LEN + 1]; RRDSET *rrdset_root; pthread_rwlock_t rrdset_root_rwlock; -- 2.39.2