]> granicus.if.org Git - icinga2/commitdiff
Add missing locks in ApiListener::UpdateConfigDir
authorGunnar Beutner <gunnar@beutner.name>
Tue, 24 Feb 2015 15:03:32 +0000 (16:03 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 24 Feb 2015 15:03:32 +0000 (16:03 +0100)
lib/remote/apilistener-sync.cpp

index 6ae194a45b9653b647e3fe50415a0eb8e5471968..0b4e02689042a975dacc9fb190f2269fa9bd43ea 100644 (file)
@@ -72,22 +72,26 @@ bool ApiListener::UpdateConfigDir(const Dictionary::Ptr& oldConfig, const Dictio
                        return false;
        }
 
-       BOOST_FOREACH(const Dictionary::Pair& kv, newConfig) {
-               if (oldConfig->Get(kv.first) != kv.second) {
-                       configChange = true;
-
-                       String path = configDir + "/" + kv.first;
-                       Log(LogInformation, "ApiListener")
-                           << "Updating configuration file: " << path;
-
-                       //pass the directory and generate a dir tree, if not existing already
-                       Utility::MkDirP(Utility::DirName(path), 0755);
-                       std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
-                       fp << kv.second;
-                       fp.close();
+       {
+               ObjectLock olock(newConfig);
+               BOOST_FOREACH(const Dictionary::Pair& kv, newConfig) {
+                       if (oldConfig->Get(kv.first) != kv.second) {
+                               configChange = true;
+
+                               String path = configDir + "/" + kv.first;
+                               Log(LogInformation, "ApiListener")
+                                   << "Updating configuration file: " << path;
+
+                               //pass the directory and generate a dir tree, if not existing already
+                               Utility::MkDirP(Utility::DirName(path), 0755);
+                               std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
+                               fp << kv.second;
+                               fp.close();
+                       }
                }
        }
 
+       ObjectLock xlock(oldConfig);
        BOOST_FOREACH(const Dictionary::Pair& kv, oldConfig) {
                if (!newConfig->Contains(kv.first)) {
                        configChange = true;