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