Add file lock to avoid adding the duplicated registry section by multi-process
authorHyunbin Lee <hyunbin.lee@samsung.com>
Sat, 7 Sep 2013 06:13:51 +0000 (15:13 +0900)
committerHyunbin Lee <hyunbin.lee@samsung.com>
Sat, 7 Sep 2013 06:14:27 +0000 (15:14 +0900)
Change-Id: I142f9eb56cac3718c49c56dfe66deafab9faf94c
Signed-off-by: Hyunbin Lee <hyunbin.lee@samsung.com>
src/app/FApp_AppRegistryImpl.cpp
src/io/FIo_RegistryCore.cpp

index 5e36476..1914ff2 100644 (file)
@@ -67,11 +67,16 @@ _AppRegistryImpl::Construct(void)
                r = reg.Construct(__regPath, "a+");
                SysAssertf(!IsFailed(r), "[%s] Constructing the registry file (%ls) has failed.", GetErrorMessage(r), __regPath.GetPointer());
 
+               FileLock* pReglock = reg.LockN(FILE_LOCK_EXCLUSIVE);
+               SysTryLog(NID_APP, pReglock != null, "[%s] Locking the app registry file has failed.", GetErrorMessage(GetLastResult()));
+
                r = reg.AddSection(__sectionName);
                if (r == E_SECTION_ALREADY_EXIST)
                {
                        r = E_SUCCESS;
                }
+
+               delete pReglock;
        }
        return r;
 }
index 6cee81a..aa40372 100644 (file)
@@ -234,7 +234,7 @@ _RegistryCore::Parse(void)
                        }
 
                        r = _RegistryCore::AddSection(_sectionList, sectionName);
-                       SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+                       SysTryCatch(NID_IO, !IsFailed(r) || r == E_SECTION_ALREADY_EXIST, , r, "[%s] Propagating to caller...", GetErrorMessage(r));
                }
                else    // not a section.. but may belongs to a section (entry)
                {
@@ -414,6 +414,7 @@ _RegistryCore::AddSection(const String& sectionName)
 
        if (sectionFound == true)
        {
+               SysLog(NID_IO, "[E_SECTION_ALREADY_EXIST] The registry file has the duplicated section name.");
                return E_SECTION_ALREADY_EXIST;
        }
 
@@ -1569,6 +1570,7 @@ _RegistryCore::AddSection(LinkedList& sectionList, const String& sectionName)
 
        if (sectionFound == true)
        {
+               SysLog(NID_IO, "[E_SECTION_ALREADY_EXIST] The registry file has the duplicated section name.");
                return E_SECTION_ALREADY_EXIST;
        }