// SPDX-License-Identifier: GPL-3.0-or-later
#include "common.h"
#include "buildinfo.h"
int netdata_zero_metrics_enabled;
int netdata_anonymous_statistics_enabled;
struct config netdata_config = {
.first_section = NULL,
.last_section = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
.index = {
.avl_tree = {
.root = NULL,
.compar = appconfig_section_compare
},
.rwlock = AVL_LOCK_INITIALIZER
}
};
void netdata_cleanup_and_exit(int ret) {
// enabling this, is wrong
// because the threads will be cancelled while cleaning up
// netdata_exit = 1;
error_log_limit_unlimited();
info("EXIT: netdata prepares to exit with code %d...", ret);
send_statistics("EXIT", ret?"ERROR":"OK","-");
char agent_crash_file[FILENAME_MAX + 1];
char agent_incomplete_shutdown_file[FILENAME_MAX + 1];
snprintfz(agent_crash_file, FILENAME_MAX, "%s/.agent_crash", netdata_configured_varlib_dir);
snprintfz(agent_incomplete_shutdown_file, FILENAME_MAX, "%s/.agent_incomplete_shutdown", netdata_configured_varlib_dir);
(void) rename(agent_crash_file, agent_incomplete_shutdown_file);
// cleanup/save the database and exit
info("EXIT: cleaning up the database...");
rrdhost_cleanup_all();
if(!ret) {
// exit cleanly
// stop everything
info("EXIT: stopping static threads...");
cancel_main_threads();
// free the database
info("EXIT: freeing database memory...");
#ifdef ENABLE_DBENGINE
rrdeng_prepare_exit(&multidb_ctx);
#endif
rrdhost_free_all();