| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "netdata-conf.h" |
| 4 | #include "daemon/common.h" |
| 5 | |
| 6 | bool netdata_conf_load(char *filename, char overwrite_used, const char **user) { |
| 7 | FUNCTION_RUN_ONCE_RET(false); |
| 8 | |
| 9 | errno_clear(); |
| 10 | |
| 11 | int ret = 0; |
| 12 | |
| 13 | if(filename && *filename) { |
| 14 | ret = inicfg_load(&netdata_config, filename, overwrite_used, NULL); |
| 15 | if(!ret) |
| 16 | netdata_log_error("CONFIG: cannot load config file '%s'.", filename); |
| 17 | } |
| 18 | else { |
| 19 | filename = filename_from_path_entry_strdupz(netdata_configured_user_config_dir, "netdata.conf"); |
| 20 | |
| 21 | ret = inicfg_load(&netdata_config, filename, overwrite_used, NULL); |
| 22 | if(!ret) { |
| 23 | netdata_log_info("CONFIG: cannot load user config '%s'. Will try the stock version.", filename); |
| 24 | freez(filename); |
| 25 | |
| 26 | filename = filename_from_path_entry_strdupz(netdata_configured_stock_config_dir, "netdata.conf"); |
| 27 | ret = inicfg_load(&netdata_config, filename, overwrite_used, NULL); |
| 28 | if(!ret) |
| 29 | netdata_log_info("CONFIG: cannot load stock config '%s'. Running with internal defaults.", filename); |
| 30 | } |
| 31 | |
| 32 | freez(filename); |
| 33 | } |
| 34 | |
| 35 | netdata_conf_backwards_compatibility(); |
| 36 | netdata_conf_section_directories(); |
| 37 | netdata_conf_section_global_run_as_user(user); |
| 38 | libuv_initialize(); |
| 39 | return ret; |
| 40 | } |