Browse Source

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

* error exit when rrdhost localhost init fails #7504
Timo 5 years ago
parent
commit
2c0f57151e
3 changed files with 9 additions and 4 deletions
  1. 6 2
      daemon/main.c
  2. 1 1
      database/rrd.h
  3. 2 1
      database/rrdhost.c

+ 6 - 2
daemon/main.c

@@ -941,7 +941,10 @@ int main(int argc, char **argv) {
                             default_rrd_update_every = 1;
                             default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
                             default_health_enabled = 0;
-                            rrd_init("unittest", NULL);
+                            if(rrd_init("unittest", NULL)) {
+                                fprintf(stderr, "rrd_init failed for unittest\n");
+                                return 1;
+                            }
                             default_rrdpush_enabled = 0;
                             if(run_all_mockup_tests()) return 1;
                             if(unit_test_storage()) return 1;
@@ -1277,7 +1280,8 @@ int main(int argc, char **argv) {
     struct rrdhost_system_info *system_info = calloc(1, sizeof(struct rrdhost_system_info));
     get_system_info(system_info);
 
-    rrd_init(netdata_configured_hostname, system_info);
+    if(rrd_init(netdata_configured_hostname, system_info))
+        fatal("Cannot initialize localhost instance with name '%s'.", netdata_configured_hostname);
 
     // ------------------------------------------------------------------------
     // Claim netdata agent to a cloud endpoint

+ 1 - 1
database/rrd.h

@@ -800,7 +800,7 @@ extern netdata_rwlock_t rrd_rwlock;
 extern size_t rrd_hosts_available;
 extern time_t rrdhost_free_orphan_time;
 
-extern void rrd_init(char *hostname, struct rrdhost_system_info *system_info);
+extern int rrd_init(char *hostname, struct rrdhost_system_info *system_info);
 
 extern RRDHOST *rrdhost_find_by_hostname(const char *hostname, uint32_t hash);
 extern RRDHOST *rrdhost_find_by_guid(const char *guid, uint32_t hash);

+ 2 - 1
database/rrdhost.c

@@ -483,7 +483,7 @@ restart_after_removal:
 // ----------------------------------------------------------------------------
 // RRDHOST global / startup initialization
 
-void rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
+int rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
     rrdset_free_obsolete_time = config_get_number(CONFIG_SECTION_GLOBAL, "cleanup obsolete charts after seconds", rrdset_free_obsolete_time);
     gap_when_lost_iterations_above = (int)config_get_number(CONFIG_SECTION_GLOBAL, "gap when lost iterations above", gap_when_lost_iterations_above);
     if (gap_when_lost_iterations_above < 1)
@@ -517,6 +517,7 @@ void rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
     );
     rrd_unlock();
 	web_client_api_v1_management_init();
+    return localhost==NULL;
 }
 
 // ----------------------------------------------------------------------------