MCPcopy Create free account
hub / github.com/apache/trafficserver / UpdateHostsFile

Function UpdateHostsFile

src/iocore/hostdb/HostDB.cc:1591–1611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1589std::atomic<bool> HostDBFileUpdateActive{false};
1590
1591void
1592UpdateHostsFile(swoc::file::path const &path, ts_seconds interval)
1593{
1594 // Test and set for update in progress.
1595 bool flag = false;
1596 if (!HostDBFileUpdateActive.compare_exchange_strong(flag, true)) {
1597 Dbg(dbg_ctl_hostdb, "Skipped load of host file because update already in progress");
1598 return;
1599 }
1600
1601 std::shared_ptr<HostFile> hf = ParseHostFile(path, interval);
1602
1603 // Swap the pointer
1604 if (hf) {
1605 std::unique_lock lock(hostDB.host_file_mutex);
1606 hostDB.host_file = std::move(hf);
1607 }
1608 hostdb_hostfile_update_timestamp = hostdb_current_timestamp;
1609 // Mark this one as completed, so we can allow another update to happen
1610 HostDBFileUpdateActive = false;
1611}
1612
1613//
1614// Regression tests

Callers 1

backgroundEventMethod · 0.85

Calls 1

ParseHostFileFunction · 0.85

Tested by

no test coverage detected