michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __nsProfileLock_h___ michael@0: #define __nsProfileLock_h___ michael@0: michael@0: #include "nsIFile.h" michael@0: michael@0: class nsIProfileUnlocker; michael@0: michael@0: #if defined (XP_WIN) michael@0: #include michael@0: #endif michael@0: michael@0: #if defined (XP_UNIX) michael@0: #include michael@0: #include "prclist.h" michael@0: #endif michael@0: michael@0: class nsProfileLock michael@0: #if defined (XP_UNIX) michael@0: : public PRCList michael@0: #endif michael@0: { michael@0: public: michael@0: nsProfileLock(); michael@0: nsProfileLock(nsProfileLock& src); michael@0: michael@0: ~nsProfileLock(); michael@0: michael@0: nsProfileLock& operator=(nsProfileLock& rhs); michael@0: michael@0: /** michael@0: * Attempt to lock a profile directory. michael@0: * michael@0: * @param aProfileDir [in] The profile directory to lock. michael@0: * @param aUnlocker [out] Optional. This is only returned when locking michael@0: * fails with NS_ERROR_FILE_ACCESS_DENIED, and may not michael@0: * be returned at all. michael@0: * @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked. michael@0: */ michael@0: nsresult Lock(nsIFile* aProfileDir, nsIProfileUnlocker* *aUnlocker); michael@0: michael@0: /** michael@0: * Unlock a profile directory. If you're unlocking the directory because michael@0: * the application is in the process of shutting down because of a fatal michael@0: * signal, set aFatalSignal to true. michael@0: */ michael@0: nsresult Unlock(bool aFatalSignal = false); michael@0: michael@0: /** michael@0: * Get the modification time of a replaced profile lock, otherwise 0. michael@0: */ michael@0: nsresult GetReplacedLockTime(PRTime* aResult); michael@0: michael@0: private: michael@0: bool mHaveLock; michael@0: PRTime mReplacedLockTime; michael@0: michael@0: #if defined (XP_WIN) michael@0: HANDLE mLockFileHandle; michael@0: #elif defined (XP_UNIX) michael@0: michael@0: struct RemovePidLockFilesExiting { michael@0: RemovePidLockFilesExiting() {} michael@0: ~RemovePidLockFilesExiting() { michael@0: RemovePidLockFiles(false); michael@0: } michael@0: }; michael@0: michael@0: static void RemovePidLockFiles(bool aFatalSignal); michael@0: static void FatalSignalHandler(int signo michael@0: #ifdef SA_SIGINFO michael@0: , siginfo_t *info, void *context michael@0: #endif michael@0: ); michael@0: static PRCList mPidLockList; michael@0: michael@0: nsresult LockWithFcntl(nsIFile *aLockFile); michael@0: michael@0: /** michael@0: * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this michael@0: * lock is merely an "obsolete" lock to keep out old Firefoxes michael@0: */ michael@0: nsresult LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock); michael@0: michael@0: char* mPidLockFileName; michael@0: int mLockFileDesc; michael@0: #endif michael@0: michael@0: }; michael@0: michael@0: #endif /* __nsProfileLock_h___ */