Bug 977786 - nsProfileLock shouldn't set mHaveLock when locking fails. r=gcp draft
authorLuca Niccoli <lultimouomo@gmail.com>
Tue, 06 Sep 2016 09:54:00 +0200
changeset 410144 970057fe574a080cce7decad236cc3d309aee947
parent 410143 94bf7c3ec5aa4a51eb69774cead8ef0313c6fa35
child 410145 46fca5a19d5bcf1f5fc64e88f1ad99a253e00672
push id28657
push usergpascutto@mozilla.com
push dateTue, 06 Sep 2016 09:50:36 +0000
reviewersgcp
bugs977786
milestone51.0a1
Bug 977786 - nsProfileLock shouldn't set mHaveLock when locking fails. r=gcp MozReview-Commit-ID: 7rpUHuUTNXq
toolkit/profile/nsProfileLock.cpp
--- a/toolkit/profile/nsProfileLock.cpp
+++ b/toolkit/profile/nsProfileLock.cpp
@@ -259,18 +259,16 @@ nsresult nsProfileLock::LockWithFcntl(ns
 #ifdef DEBUG
             printf("fcntl(F_SETLK) failed. errno = %d\n", errno);
 #endif
             if (errno == EAGAIN || errno == EACCES)
                 rv = NS_ERROR_FILE_ACCESS_DENIED;
             else
                 rv = NS_ERROR_FAILURE;
         }
-        else
-            mHaveLock = true;
     }
     else
     {
         NS_ERROR("Failed to open lock file.");
         rv = NS_ERROR_FAILURE;
     }
     return rv;
 }
@@ -380,17 +378,16 @@ nsresult nsProfileLock::LockWithSymlink(
     PR_smprintf_free(signature);
     signature = nullptr;
 
     if (symlink_rv == 0)
     {
         // We exclusively created the symlink: record its name for eventual
         // unlock-via-unlink.
         rv = NS_OK;
-        mHaveLock = true;
         mPidLockFileName = strdup(fileName);
         if (mPidLockFileName)
         {
             PR_APPEND_LINK(this, &mPidLockList);
             if (!setupPidLockCleanup++)
             {
                 // Clean up on normal termination.
                 // This instanciates a dummy class, and will trigger the class
@@ -610,17 +607,18 @@ nsresult nsProfileLock::Lock(nsIFile* aP
                                                       do_QueryObject(unlocker));
             unlockerInterface.forget(aUnlocker);
           }
         }
         return NS_ERROR_FILE_ACCESS_DENIED;
     }
 #endif
 
-    mHaveLock = true;
+    if (NS_SUCCEEDED(rv))
+        mHaveLock = true;
 
     return rv;
 }
 
 
 nsresult nsProfileLock::Unlock(bool aFatalSignal)
 {
     nsresult rv = NS_OK;