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 committed
Sep 20, 2021 at 11:47 UTC
2ca7905a1a5aedad9fcd4c952f6f5d5196a239d1
3 files changed
+6
-7
daemon/analytics.c
+2
-4
@@ -709,7 +709,7 @@ void set_late_global_environment()
709
analytics_get_install_type();
710
}
711
712
-static void get_system_timezone(void)
712
+void get_system_timezone(void)
713
{
714
// avoid flood calls to stat(/etc/localtime)
715
// 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)
730
// use the contents of /etc/timezone
731
if (!timezone && !read_file("/etc/timezone", buffer, FILENAME_MAX)) {
732
timezone = buffer;
733
- info("TIMEZONE: using the contents of /etc/timezone: '%s'", timezone);
733
+ info("TIMEZONE: using the contents of /etc/timezone");
734
}
735
736
// read the link /etc/localtime
@@ -916,8 +916,6 @@ void set_global_environment()
916
if (clean)
917
freez(default_port);
918
919
- get_system_timezone();
920
-
919
// set the path we need
920
char path[1024 + 1], *p = getenv("PATH");
921
if (!p)
daemon/analytics.h
+1
@@ -91,6 +91,7 @@ extern void analytics_log_prometheus(void);
91
extern void analytics_log_dashboard(void);
92
extern void analytics_gather_mutable_meta_data(void);
93
extern void analytics_report_oom_score(long long int score);
94
+extern void get_system_timezone(void);
95
96
extern struct analytics_data analytics_data;
97
daemon/main.c
+3
-3
@@ -1130,7 +1130,10 @@ int main(int argc, char **argv) {
1130
// get log filenames and settings
1131
log_init();
1132
error_log_limit_unlimited();
1133
+ // initialize the log files
1134
+ open_all_log_files();
1135
1136
+ get_system_timezone();
1137
// --------------------------------------------------------------------
1138
// get the certificate and start security
1139
#ifdef ENABLE_HTTPS
@@ -1180,9 +1183,6 @@ int main(int argc, char **argv) {
1183
api_listen_sockets_setup();
1184
}
1185
1183
- // initialize the log files
1184
- open_all_log_files();
1185
-
1186
#ifdef NETDATA_INTERNAL_CHECKS
1187
if(debug_flags != 0) {
1188
struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };