Add missing locks in ApiListener::UpdateConfigDir

This commit is contained in:
Gunnar Beutner 2015-02-24 16:03:32 +01:00
parent 38deef0411
commit 5fe2536629
1 changed files with 15 additions and 11 deletions

View File

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