From cf20f54068a6cbbdca8f1b12681cc8a8d08623d7 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Thu, 30 May 2019 17:53:36 +0000 Subject: [PATCH] Bug 1553781: When the remote service finds an instance to remote to it doesn't clean up the startup lock. r=glandium This fixes the issue in a few redundant ways: * nsProfileLock is made to properly clean itself up when destroyed. * nsRemoteService makes sure the unlock when destroyed. * nsAppRunner unlocks when a remote client has been found. Differential Revision: https://phabricator.services.mozilla.com/D32360 --HG-- extra : moz-landing-system : lando --- toolkit/components/remote/nsRemoteService.cpp | 11 +++++++---- toolkit/profile/nsProfileLock.cpp | 14 ++++++++++++-- toolkit/xre/nsAppRunner.cpp | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/toolkit/components/remote/nsRemoteService.cpp b/toolkit/components/remote/nsRemoteService.cpp index ff21e75fcaab..a2ad9ed4586f 100644 --- a/toolkit/components/remote/nsRemoteService.cpp +++ b/toolkit/components/remote/nsRemoteService.cpp @@ -77,10 +77,10 @@ void nsRemoteService::LockStartup() { } void nsRemoteService::UnlockStartup() { - mRemoteLock.Unlock(); - mRemoteLock.Cleanup(); - if (mRemoteLockDir) { + mRemoteLock.Unlock(); + mRemoteLock.Cleanup(); + mRemoteLockDir->Remove(false); mRemoteLockDir = nullptr; } @@ -174,7 +174,10 @@ void nsRemoteService::StartupServer() { void nsRemoteService::ShutdownServer() { mRemoteServer = nullptr; } -nsRemoteService::~nsRemoteService() { ShutdownServer(); } +nsRemoteService::~nsRemoteService() { + UnlockStartup(); + ShutdownServer(); +} NS_IMETHODIMP nsRemoteService::Observe(nsISupports* aSubject, const char* aTopic, diff --git a/toolkit/profile/nsProfileLock.cpp b/toolkit/profile/nsProfileLock.cpp index af2546250248..255e1854dffb 100644 --- a/toolkit/profile/nsProfileLock.cpp +++ b/toolkit/profile/nsProfileLock.cpp @@ -84,7 +84,11 @@ nsProfileLock& nsProfileLock::operator=(nsProfileLock& rhs) { return *this; } -nsProfileLock::~nsProfileLock() { Unlock(); } +nsProfileLock::~nsProfileLock() { + Unlock(); + // Note that we don't clean up by default here so on next startup we know when + // the profile was last used based on the modification time of the lock file. +} #if defined(XP_UNIX) @@ -566,8 +570,14 @@ nsresult nsProfileLock::Unlock(bool aFatalSignal) { } nsresult nsProfileLock::Cleanup() { + if (mHaveLock) { + return NS_ERROR_FILE_IS_LOCKED; + } + if (mLockFile) { - return mLockFile->Remove(false); + nsresult rv = mLockFile->Remove(false); + NS_ENSURE_SUCCESS(rv, rv); + mLockFile = nullptr; } return NS_OK; diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 325594afc5b1..48b49fe64003 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -4000,9 +4000,11 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) { RemoteResult rr = mRemoteService->StartClient(desktopStartupIDPtr); if (rr == REMOTE_FOUND) { *aExitFlag = true; + mRemoteService->UnlockStartup(); return 0; } if (rr == REMOTE_ARG_BAD) { + mRemoteService->UnlockStartup(); return 1; } }