| 1017 | } |
| 1018 | |
| 1019 | static void |
| 1020 | load_config_file(config_holder_t *config_holder) |
| 1021 | { |
| 1022 | std::fstream fh; |
| 1023 | struct stat s; |
| 1024 | |
| 1025 | config_t *newconfig, *oldconfig; |
| 1026 | TSCont free_cont; |
| 1027 | |
| 1028 | configReloadRequests++; |
| 1029 | lastReloadRequest = time(nullptr); |
| 1030 | |
| 1031 | // check date |
| 1032 | if ((config_holder->config_path == nullptr) || (stat(config_holder->config_path, &s) < 0)) { |
| 1033 | Dbg(dbg_ctl, "Could not stat %s", config_holder->config_path); |
| 1034 | config_holder->config_path = nullptr; |
| 1035 | if (config_holder->config) { |
| 1036 | return; |
| 1037 | } |
| 1038 | } else { |
| 1039 | Dbg(dbg_ctl, "s.st_mtime=%lu, last_load=%lu", s.st_mtime, config_holder->last_load); |
| 1040 | if (s.st_mtime < config_holder->last_load) { |
| 1041 | return; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | if (config_holder->config_path != nullptr) { |
| 1046 | Dbg(dbg_ctl, "Opening config file: %s", config_holder->config_path); |
| 1047 | fh.open(config_holder->config_path, std::ios::in); |
| 1048 | } |
| 1049 | |
| 1050 | if (!fh.is_open() && config_holder->config_path != nullptr) { |
| 1051 | TSError("[%s] Unable to open config: %s. Will use the param as the path, or %s if null\n", PLUGIN_NAME, |
| 1052 | config_holder->config_path, DEFAULT_URL_PATH.c_str()); |
| 1053 | if (config_holder->config) { |
| 1054 | return; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | newconfig = 0; |
| 1059 | newconfig = new_config(fh); |
| 1060 | if (newconfig) { |
| 1061 | configReloads++; |
| 1062 | lastReload = lastReloadRequest; |
| 1063 | config_holder->last_load = lastReloadRequest; |
| 1064 | config_t **confp = &(config_holder->config); |
| 1065 | oldconfig = __sync_lock_test_and_set(confp, newconfig); |
| 1066 | if (oldconfig) { |
| 1067 | Dbg(dbg_ctl, "scheduling free: %p (%p)", oldconfig, newconfig); |
| 1068 | free_cont = TSContCreate(free_handler, TSMutexCreate()); |
| 1069 | TSContDataSet(free_cont, (void *)oldconfig); |
| 1070 | TSContScheduleOnPool(free_cont, FREE_TMOUT, TS_THREAD_POOL_TASK); |
| 1071 | } |
| 1072 | } |
| 1073 | if (fh) { |
| 1074 | fh.close(); |
| 1075 | } |
| 1076 | return; |
no test coverage detected