// SPDX-License-Identifier: GPL-3.0-or-later
#include "common.h"
#include "buildinfo.h"
#include "static_threads.h"
int netdata_zero_metrics_enabled;
int netdata_anonymous_statistics_enabled;
struct netdata_static_thread *static_threads;
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...");
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
aclk_sync_exit_all();
#endif
cancel_main_threads();
// free the database
info("EXIT: freeing database memory...");