summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--windows/windns/src/windns/dnsagent.cpp37
-rw-r--r--windows/windns/src/windns/dnsagent.h2
2 files changed, 32 insertions, 7 deletions
diff --git a/windows/windns/src/windns/dnsagent.cpp b/windows/windns/src/windns/dnsagent.cpp
index e9b3a4246d..32479a6a07 100644
--- a/windows/windns/src/windns/dnsagent.cpp
+++ b/windows/windns/src/windns/dnsagent.cpp
@@ -18,12 +18,33 @@ DnsAgent::DnsAgent(Protocol protocol, INameServerSource *nameServerSource, IReco
, m_shutdownEvent(nullptr)
{
constructNameServerUpdateEvent();
- constructRootMonitor();
- startTrackingInterfaces(discoverInterfaces());
- updateRecoveryData();
+ try
+ {
+ constructRootMonitor();
+
+ if (false == startTrackingInterfaces(discoverInterfaces()))
+ {
+ throw std::runtime_error("Could not complete initial settings update on interfaces");
+ }
+
+ updateRecoveryData();
+
+ constructThread();
+ }
+ catch (...)
+ {
+ if (nullptr != m_shutdownEvent)
+ {
+ CloseHandle(m_shutdownEvent);
+ }
+
+ m_nameServerSource->unsubscribe(m_serverSourceEvent);
+ CloseHandle(m_serverSourceEvent);
+
+ throw;
+ }
- constructThread();
}
DnsAgent::~DnsAgent()
@@ -381,17 +402,19 @@ void DnsAgent::setNameServers(const std::wstring &interfaceGuid, const std::vect
}
}
-void DnsAgent::startTrackingInterfaces(const std::vector<std::wstring> &interfaces)
+bool DnsAgent::startTrackingInterfaces(const std::vector<std::wstring> &interfaces)
{
const auto enforcedServers = m_nameServerSource->getNameServers(m_protocol);
+ bool successful = true;
+
for (const auto &iface : interfaces)
{
const auto literalOperation = std::wstring(L"Start tracking interface ").append(iface);
XTRACE(literalOperation);
- ConfineOperation(common::string::ToAnsi(literalOperation).c_str(), m_logSink, [&]()
+ successful &= ConfineOperation(common::string::ToAnsi(literalOperation).c_str(), m_logSink, [&]()
{
InterfaceSnap snap(m_protocol, iface);
@@ -414,6 +437,8 @@ void DnsAgent::startTrackingInterfaces(const std::vector<std::wstring> &interfac
}
});
}
+
+ return successful;
}
void DnsAgent::stopTrackingInterfaces(const std::vector<std::wstring> &interfaces)
diff --git a/windows/windns/src/windns/dnsagent.h b/windows/windns/src/windns/dnsagent.h
index db73257330..a45cf75f00 100644
--- a/windows/windns/src/windns/dnsagent.h
+++ b/windows/windns/src/windns/dnsagent.h
@@ -76,7 +76,7 @@ private:
void setNameServers(const std::wstring &interfaceGuid, const std::vector<std::wstring> &enforcedServers);
- void startTrackingInterfaces(const std::vector<std::wstring> &interfaces);
+ bool startTrackingInterfaces(const std::vector<std::wstring> &interfaces);
void stopTrackingInterfaces(const std::vector<std::wstring> &interfaces);
void updateRecoveryData();