https://issues.shibboleth.net/jira/browse/CPPOST-60
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / XMLMetadataProvider.cpp
index 961cff6..ff9b262 100644 (file)
 #include <xmltooling/util/Threads.h>
 #include <xmltooling/validation/ValidatorSuite.h>
 
+#if defined(OPENSAML_LOG4SHIB)
+# include <log4shib/NDC.hh>
+#elif defined(OPENSAML_LOG4CPP)
+# include <log4cpp/NDC.hh>
+#endif
+
 using namespace opensaml::saml2md;
 using namespace xmltooling::logging;
 using namespace xmltooling;
@@ -62,13 +68,25 @@ namespace opensaml {
 
             void init() {
                 try {
+                    if (!m_id.empty()) {
+                        string threadid("[");
+                        threadid += m_id + ']';
+                        logging::NDC::push(threadid);
+                    }
                     background_load();
                     startup();
                 }
                 catch (...) {
                     startup();
+                    if (!m_id.empty()) {
+                        logging::NDC::pop();
+                    }
                     throw;
                 }
+
+                if (!m_id.empty()) {
+                    logging::NDC::pop();
+                }
             }
 
             const XMLObject* getMetadata() const {
@@ -134,8 +152,10 @@ XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e)
 
 pair<bool,DOMElement*> XMLMetadataProvider::load(bool backup)
 {
-    // Lower the refresh rate in case of an error.
-    m_reloadInterval = m_minRefreshDelay;
+    if (!backup) {
+        // Lower the refresh rate in case of an error.
+        m_reloadInterval = m_minRefreshDelay;
+    }
 
     // Call the base class to load/parse the appropriate XML resource.
     pair<bool,DOMElement*> raw = ReloadableXMLFile::load(backup);
@@ -216,8 +236,8 @@ pair<bool,DOMElement*> XMLMetadataProvider::load(bool backup)
     // Tracking cacheUntil through the tree is TBD, but
     // validUntil is the tightest interval amongst the children.
 
-    // If a remote resource, adjust the reload interval.
-    if (!backup && !m_local) {
+    // If a remote resource that's monitored, adjust the reload interval.
+    if (!backup && !m_local && m_lock) {
         m_backoffFactor = 1;
         m_reloadInterval = computeNextRefresh();
         m_log.info("adjusted reload interval to %d seconds", m_reloadInterval);