summaryrefslogtreecommitdiffstats
path: root/daemon/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-30 18:47:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-30 18:47:00 +0000
commit03bf87dcb06f7021bfb2df2fa8691593c6148aff (patch)
treee16b06711a2ed77cafb4b7754be0220c3d14a9d7 /daemon/main.c
parentAdding upstream version 1.36.1. (diff)
downloadnetdata-03bf87dcb06f7021bfb2df2fa8691593c6148aff.tar.xz
netdata-03bf87dcb06f7021bfb2df2fa8691593c6148aff.zip
Adding upstream version 1.37.0.upstream/1.37.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'daemon/main.c')
-rw-r--r--daemon/main.c91
1 files changed, 69 insertions, 22 deletions
diff --git a/daemon/main.c b/daemon/main.c
index ada3c14f2..6b591385d 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -4,6 +4,7 @@
#include "buildinfo.h"
#include "static_threads.h"
+bool unittest_running = false;
int netdata_zero_metrics_enabled;
int netdata_anonymous_statistics_enabled;
@@ -55,13 +56,19 @@ void netdata_cleanup_and_exit(int ret) {
// free the database
info("EXIT: freeing database memory...");
#ifdef ENABLE_DBENGINE
- for(int tier = 0; tier < storage_tiers ; tier++)
- rrdeng_prepare_exit(multidb_ctx[tier]);
+ if(dbengine_enabled) {
+ for (size_t tier = 0; tier < storage_tiers; tier++)
+ rrdeng_prepare_exit(multidb_ctx[tier]);
+ }
#endif
+ metadata_sync_shutdown_prepare();
rrdhost_free_all();
+ metadata_sync_shutdown();
#ifdef ENABLE_DBENGINE
- for(int tier = 0; tier < storage_tiers ; tier++)
- rrdeng_exit(multidb_ctx[tier]);
+ if(dbengine_enabled) {
+ for (size_t tier = 0; tier < storage_tiers; tier++)
+ rrdeng_exit(multidb_ctx[tier]);
+ }
#endif
}
sql_close_context_database();
@@ -255,7 +262,8 @@ void cancel_main_threads() {
for (i = 0; static_threads[i].name != NULL ; i++)
freez(static_threads[i].thread);
- free(static_threads);
+
+ freez(static_threads);
}
struct option_def option_definitions[] = {
@@ -303,7 +311,7 @@ int help(int exitcode) {
" | '-' '-' '-' '-' real-time performance monitoring, done right! \n"
" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->\n"
"\n"
- " Copyright (C) 2016-2020, Netdata, Inc. <info@netdata.cloud>\n"
+ " Copyright (C) 2016-2022, Netdata, Inc. <info@netdata.cloud>\n"
" Released under GNU General Public License v3 or later.\n"
" All rights reserved.\n"
"\n"
@@ -314,7 +322,8 @@ int help(int exitcode) {
" License : https://github.com/netdata/netdata/blob/master/LICENSE.md\n"
"\n"
" Twitter : https://twitter.com/linuxnetdata\n"
- " Facebook : https://www.facebook.com/linuxnetdata/\n"
+ " LinkedIn : https://linkedin.com/company/netdata-cloud/\n"
+ " Facebook : https://facebook.com/linuxnetdata/\n"
"\n"
"\n"
);
@@ -379,10 +388,10 @@ int help(int exitcode) {
static void security_init(){
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s/ssl/key.pem",netdata_configured_user_config_dir);
- security_key = config_get(CONFIG_SECTION_WEB, "ssl key", filename);
+ netdata_ssl_security_key = config_get(CONFIG_SECTION_WEB, "ssl key", filename);
snprintfz(filename, FILENAME_MAX, "%s/ssl/cert.pem",netdata_configured_user_config_dir);
- security_cert = config_get(CONFIG_SECTION_WEB, "ssl certificate", filename);
+ netdata_ssl_security_cert = config_get(CONFIG_SECTION_WEB, "ssl certificate", filename);
tls_version = config_get(CONFIG_SECTION_WEB, "tls version", "1.3");
tls_ciphers = config_get(CONFIG_SECTION_WEB, "tls ciphers", "none");
@@ -402,6 +411,9 @@ static void log_init(void) {
snprintfz(filename, FILENAME_MAX, "%s/access.log", netdata_configured_log_dir);
stdaccess_filename = config_get(CONFIG_SECTION_LOGS, "access", filename);
+ snprintfz(filename, FILENAME_MAX, "%s/health.log", netdata_configured_log_dir);
+ stdhealth_filename = config_get(CONFIG_SECTION_LOGS, "health", filename);
+
#ifdef ENABLE_ACLK
aclklog_enabled = config_get_boolean(CONFIG_SECTION_CLOUD, "conversation log", CONFIG_BOOLEAN_NO);
if (aclklog_enabled) {
@@ -667,7 +679,7 @@ static void get_netdata_configured_variables() {
// ------------------------------------------------------------------------
// get default Database Engine page cache size in MiB
- db_engine_use_malloc = config_get_boolean(CONFIG_SECTION_DB, "dbengine page cache with malloc", CONFIG_BOOLEAN_NO);
+ db_engine_use_malloc = config_get_boolean(CONFIG_SECTION_DB, "dbengine page cache with malloc", CONFIG_BOOLEAN_YES);
default_rrdeng_page_cache_mb = (int) config_get_number(CONFIG_SECTION_DB, "dbengine page cache size MB", default_rrdeng_page_cache_mb);
if(default_rrdeng_page_cache_mb < RRDENG_MIN_PAGE_CACHE_SIZE_MB) {
error("Invalid page cache size %d given. Defaulting to %d.", default_rrdeng_page_cache_mb, RRDENG_MIN_PAGE_CACHE_SIZE_MB);
@@ -736,12 +748,6 @@ static void get_netdata_configured_variables() {
}
// --------------------------------------------------------------------
- // rrdcontext
-
- rrdcontext_enabled = config_get_boolean(CONFIG_SECTION_CLOUD, "rrdcontexts", rrdcontext_enabled);
-
-
- // --------------------------------------------------------------------
// get various system parameters
get_system_HZ();
@@ -801,12 +807,13 @@ int get_system_info(struct rrdhost_system_info *system_info) {
info("Executing %s", script);
- FILE *fp = mypopen(script, &command_pid);
- if(fp) {
+ FILE *fp_child_input;
+ FILE *fp_child_output = netdata_popen(script, &command_pid, &fp_child_input);
+ if(fp_child_output) {
char line[200 + 1];
// Removed the double strlens, if the Coverity tainted string warning reappears I'll revert.
// One time init code, but I'm curious about the warning...
- while (fgets(line, 200, fp) != NULL) {
+ while (fgets(line, 200, fp_child_output) != NULL) {
char *value=line;
while (*value && *value != '=') value++;
if (*value=='=') {
@@ -827,7 +834,7 @@ int get_system_info(struct rrdhost_system_info *system_info) {
}
}
}
- mypclose(fp, command_pid);
+ netdata_pclose(fp_child_input, fp_child_output, command_pid);
}
freez(script);
return 0;
@@ -976,6 +983,8 @@ int main(int argc, char **argv) {
}
if(strcmp(optarg, "unittest") == 0) {
+ unittest_running = true;
+
if (unit_test_static_threads())
return 1;
if (unit_test_buffer())
@@ -987,7 +996,6 @@ int main(int argc, char **argv) {
// No call to load the config file on this code-path
post_conf_load(&user);
get_netdata_configured_variables();
- rrdcontext_enabled = CONFIG_BOOLEAN_NO;
default_rrd_update_every = 1;
default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
default_health_enabled = 0;
@@ -1004,8 +1012,11 @@ int main(int argc, char **argv) {
if(test_dbengine()) return 1;
#endif
if(test_sqlite()) return 1;
+ if(string_unittest(10000)) return 1;
if (dictionary_unittest(10000))
return 1;
+ if(aral_unittest(10000))
+ return 1;
if (rrdlabels_unittest())
return 1;
if (ctx_unittest())
@@ -1013,6 +1024,9 @@ int main(int argc, char **argv) {
fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
return 0;
}
+ else if(strcmp(optarg, "escapetest") == 0) {
+ return command_argument_sanitization_tests();
+ }
#ifdef ENABLE_ML_TESTS
else if(strcmp(optarg, "mltest") == 0) {
return test_ml(argc, argv);
@@ -1020,17 +1034,33 @@ int main(int argc, char **argv) {
#endif
#ifdef ENABLE_DBENGINE
else if(strcmp(optarg, "mctest") == 0) {
+ unittest_running = true;
return mc_unittest();
}
else if(strcmp(optarg, "ctxtest") == 0) {
+ unittest_running = true;
return ctx_unittest();
}
else if(strcmp(optarg, "dicttest") == 0) {
+ unittest_running = true;
return dictionary_unittest(10000);
}
+ else if(strcmp(optarg, "araltest") == 0) {
+ unittest_running = true;
+ return aral_unittest(10000);
+ }
+ else if(strcmp(optarg, "stringtest") == 0) {
+ unittest_running = true;
+ return string_unittest(10000);
+ }
else if(strcmp(optarg, "rrdlabelstest") == 0) {
+ unittest_running = true;
return rrdlabels_unittest();
}
+ else if(strcmp(optarg, "metatest") == 0) {
+ unittest_running = true;
+ return metadata_unittest();
+ }
else if(strncmp(optarg, createdataset_string, strlen(createdataset_string)) == 0) {
optarg += strlen(createdataset_string);
unsigned history_seconds = strtoul(optarg, NULL, 0);
@@ -1284,6 +1314,7 @@ int main(int argc, char **argv) {
}
#endif
+
if(!config_loaded)
{
load_netdata_conf(NULL, 0);
@@ -1291,6 +1322,11 @@ int main(int argc, char **argv) {
load_cloud_conf(0);
}
+ char *nd_disable_cloud = getenv("NETDATA_DISABLE_CLOUD");
+ if (nd_disable_cloud && !strncmp(nd_disable_cloud, "1", 1)) {
+ appconfig_set(&cloud_config, CONFIG_SECTION_GLOBAL, "enabled", "false");
+ }
+
// ------------------------------------------------------------------------
// initialize netdata
@@ -1303,6 +1339,12 @@ int main(int argc, char **argv) {
i = (int)config_get_number(CONFIG_SECTION_GLOBAL, "glibc malloc arena max for netdata", 1);
if(i > 0)
mallopt(M_ARENA_MAX, 1);
+
+
+#ifdef NETDATA_INTERNAL_CHECKS
+ mallopt(M_PERTURB, 0x5A);
+ // mallopt(M_MXFAST, 0);
+#endif
#endif
// initialize the system clocks
@@ -1401,8 +1443,13 @@ int main(int argc, char **argv) {
if(st->enabled && st->init_routine)
st->init_routine();
- }
+ if(st->env_name)
+ setenv(st->env_name, st->enabled?"YES":"NO", 1);
+
+ if(st->global_variable)
+ *st->global_variable = (st->enabled) ? true : false;
+ }
// --------------------------------------------------------------------
// create the listening sockets