@cryptotaxi247 / netdata-1 / commits / 2c0f57151

error exit when rrdhost localhost init fails #7504 (#7663)

* error exit when rrdhost localhost init fails #7504

Timo committed Jan 9, 2020 at 18:51 UTC 2c0f57151e09b6eda008181912fb891e0a471544
3 files changed +9 -4
daemon/main.c
+6 -2
@@ -941,7 +941,10 @@ int main(int argc, char **argv) {
941 default_rrd_update_every = 1;
942 default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
943 default_health_enabled = 0;
944 - rrd_init("unittest", NULL);
944 + if(rrd_init("unittest", NULL)) {
945 + fprintf(stderr, "rrd_init failed for unittest\n");
946 + return 1;
947 + }
948 default_rrdpush_enabled = 0;
949 if(run_all_mockup_tests()) return 1;
950 if(unit_test_storage()) return 1;
@@ -1277,7 +1280,8 @@ int main(int argc, char **argv) {
1280 struct rrdhost_system_info *system_info = calloc(1, sizeof(struct rrdhost_system_info));
1281 get_system_info(system_info);
1282
1280 - rrd_init(netdata_configured_hostname, system_info);
1283 + if(rrd_init(netdata_configured_hostname, system_info))
1284 + fatal("Cannot initialize localhost instance with name '%s'.", netdata_configured_hostname);
1285
1286 // ------------------------------------------------------------------------
1287 // Claim netdata agent to a cloud endpoint
database/rrd.h
+1 -1
@@ -800,7 +800,7 @@ extern netdata_rwlock_t rrd_rwlock;
800 extern size_t rrd_hosts_available;
801 extern time_t rrdhost_free_orphan_time;
802
803 -extern void rrd_init(char *hostname, struct rrdhost_system_info *system_info);
803 +extern int rrd_init(char *hostname, struct rrdhost_system_info *system_info);
804
805 extern RRDHOST *rrdhost_find_by_hostname(const char *hostname, uint32_t hash);
806 extern RRDHOST *rrdhost_find_by_guid(const char *guid, uint32_t hash);
database/rrdhost.c
+2 -1
@@ -483,7 +483,7 @@ restart_after_removal:
483 // ----------------------------------------------------------------------------
484 // RRDHOST global / startup initialization
485
486 -void rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
486 +int rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
487 rrdset_free_obsolete_time = config_get_number(CONFIG_SECTION_GLOBAL, "cleanup obsolete charts after seconds", rrdset_free_obsolete_time);
488 gap_when_lost_iterations_above = (int)config_get_number(CONFIG_SECTION_GLOBAL, "gap when lost iterations above", gap_when_lost_iterations_above);
489 if (gap_when_lost_iterations_above < 1)
@@ -517,6 +517,7 @@ void rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
517 );
518 rrd_unlock();
519 web_client_api_v1_management_init();
520 + return localhost==NULL;
521 }
522
523 // ----------------------------------------------------------------------------