------------------------------------------------------------------------- RecCoreInit -------------------------------------------------------------------------
| 195 | // RecCoreInit |
| 196 | //------------------------------------------------------------------------- |
| 197 | int |
| 198 | RecCoreInit(Diags *_diags) |
| 199 | { |
| 200 | if (g_initialized) { |
| 201 | return REC_ERR_OKAY; |
| 202 | } |
| 203 | |
| 204 | // set our diags |
| 205 | RecSetDiags(_diags); |
| 206 | |
| 207 | // Initialize config file parsing data structures. |
| 208 | RecConfigFileInit(); |
| 209 | |
| 210 | g_num_records = 0; |
| 211 | |
| 212 | // initialize record array for our internal stats (this can be reallocated later) |
| 213 | g_records = static_cast<RecRecord *>(ats_malloc(max_records_entries * sizeof(RecRecord))); |
| 214 | |
| 215 | // initialize record rwlock |
| 216 | ink_rwlock_init(&g_records_rwlock); |
| 217 | |
| 218 | // read stats |
| 219 | RecReadStatsFile(); |
| 220 | |
| 221 | // read configs |
| 222 | bool file_exists = true; |
| 223 | |
| 224 | ink_mutex_init(&g_rec_config_lock); |
| 225 | |
| 226 | g_rec_config_fpath = ats_stringdup(RecConfigReadConfigPath(nullptr, ts::filename::RECORDS)); |
| 227 | |
| 228 | // Make sure there is no legacy file, if so we drop a BIG WARNING and fail. |
| 229 | // This is to avoid issues with someone ignoring that we now use records.yaml |
| 230 | swoc::file::path old_config{RecConfigReadConfigPath(nullptr, "records.config")}; |
| 231 | if (swoc::file::is_readable(old_config)) { |
| 232 | RecLog(DL_Fatal, |
| 233 | "**** Found a legacy config file (%s). Please remove it and migrate to the new YAML format before continuing. ****", |
| 234 | old_config.c_str()); |
| 235 | } |
| 236 | |
| 237 | if (RecFileExists(g_rec_config_fpath) == REC_ERR_FAIL) { |
| 238 | RecLog(DL_Warning, "Could not find '%s', system will run with defaults\n", ts::filename::RECORDS); |
| 239 | file_exists = false; |
| 240 | } |
| 241 | |
| 242 | if (file_exists) { |
| 243 | auto err = RecReadYamlConfigFile(); |
| 244 | RecLog(DL_Note, "records parsing completed."); |
| 245 | if (!err.empty()) { |
| 246 | std::string text; |
| 247 | RecLog(DL_Warning, "%s", |
| 248 | swoc::bwprint(text, "We have found the following issues when reading the records node:\n {}", err).c_str()); |
| 249 | } |
| 250 | } else { |
| 251 | RecLog(DL_Note, "%s does not exist.", g_rec_config_fpath); |
| 252 | } |
| 253 | |
| 254 | RecLog(DL_Note, "%s finished loading", std::string{g_rec_config_fpath}.c_str()); |
no test coverage detected