Browse Source

Fix issue with log messages appearing in the terminal instead of the error.log on startup (#11524)

* Open logfiles earlier in the initialization process

* Configure system timezone after logfiles are open

* Skip the read file contents (report only the fixed timezone)
Stelios Fragkakis 3 years ago
parent
commit
2ca7905a1a
3 changed files with 6 additions and 7 deletions
  1. 2 4
      daemon/analytics.c
  2. 1 0
      daemon/analytics.h
  3. 3 3
      daemon/main.c

+ 2 - 4
daemon/analytics.c

@@ -709,7 +709,7 @@ void set_late_global_environment()
     analytics_get_install_type();
 }
 
-static void get_system_timezone(void)
+void get_system_timezone(void)
 {
     // avoid flood calls to stat(/etc/localtime)
     // http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
@@ -730,7 +730,7 @@ static void get_system_timezone(void)
     // use the contents of /etc/timezone
     if (!timezone && !read_file("/etc/timezone", buffer, FILENAME_MAX)) {
         timezone = buffer;
-        info("TIMEZONE: using the contents of /etc/timezone: '%s'", timezone);
+        info("TIMEZONE: using the contents of /etc/timezone");
     }
 
     // read the link /etc/localtime
@@ -916,8 +916,6 @@ void set_global_environment()
     if (clean)
         freez(default_port);
 
-    get_system_timezone();
-
     // set the path we need
     char path[1024 + 1], *p = getenv("PATH");
     if (!p)

+ 1 - 0
daemon/analytics.h

@@ -91,6 +91,7 @@ extern void analytics_log_prometheus(void);
 extern void analytics_log_dashboard(void);
 extern void analytics_gather_mutable_meta_data(void);
 extern void analytics_report_oom_score(long long int score);
+extern void get_system_timezone(void);
 
 extern struct analytics_data analytics_data;
 

+ 3 - 3
daemon/main.c

@@ -1130,7 +1130,10 @@ int main(int argc, char **argv) {
         // get log filenames and settings
         log_init();
         error_log_limit_unlimited();
+        // initialize the log files
+        open_all_log_files();
 
+        get_system_timezone();
         // --------------------------------------------------------------------
         // get the certificate and start security
 #ifdef ENABLE_HTTPS
@@ -1180,9 +1183,6 @@ int main(int argc, char **argv) {
             api_listen_sockets_setup();
     }
 
-    // initialize the log files
-    open_all_log_files();
-
 #ifdef NETDATA_INTERNAL_CHECKS
     if(debug_flags != 0) {
         struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };