2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef __nsProfileLock_h___
|
|
|
|
#define __nsProfileLock_h___
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIProfileUnlocker;
|
|
|
|
|
|
|
|
#if defined (XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (XP_UNIX)
|
2009-12-14 03:44:27 -08:00
|
|
|
#include <signal.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prclist.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsProfileLock
|
|
|
|
#if defined (XP_UNIX)
|
|
|
|
: public PRCList
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsProfileLock();
|
|
|
|
nsProfileLock(nsProfileLock& src);
|
|
|
|
|
|
|
|
~nsProfileLock();
|
|
|
|
|
|
|
|
nsProfileLock& operator=(nsProfileLock& rhs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-05 19:08:30 -07:00
|
|
|
nsresult Lock(nsIFile* aProfileDir, nsIProfileUnlocker* *aUnlocker);
|
2010-07-16 14:12:09 -07: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 07:59:28 -07:00
|
|
|
* signal, set aFatalSignal to true.
|
2010-07-16 14:12:09 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult Unlock(bool aFatalSignal = false);
|
2011-11-07 21:20:42 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the modification time of a replaced profile lock, otherwise 0.
|
|
|
|
*/
|
2012-08-30 00:10:35 -07:00
|
|
|
nsresult GetReplacedLockTime(PRTime* aResult);
|
2011-11-07 21:20:42 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHaveLock;
|
2012-08-30 00:10:35 -07:00
|
|
|
PRTime mReplacedLockTime;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if defined (XP_WIN)
|
|
|
|
HANDLE mLockFileHandle;
|
|
|
|
#elif defined (XP_UNIX)
|
2010-07-16 14:12:09 -07:00
|
|
|
|
2011-06-14 22:32:03 -07:00
|
|
|
struct RemovePidLockFilesExiting {
|
|
|
|
RemovePidLockFilesExiting() {}
|
|
|
|
~RemovePidLockFilesExiting() {
|
2011-10-17 07:59:28 -07:00
|
|
|
RemovePidLockFiles(false);
|
2011-06-14 22:32:03 -07:00
|
|
|
}
|
|
|
|
};
|
2010-07-16 14:12:09 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static void RemovePidLockFiles(bool aFatalSignal);
|
2010-11-07 01:20:50 -07:00
|
|
|
static void FatalSignalHandler(int signo
|
|
|
|
#ifdef SA_SIGINFO
|
|
|
|
, siginfo_t *info, void *context
|
|
|
|
#endif
|
|
|
|
);
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRCList mPidLockList;
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult LockWithFcntl(nsIFile *aLockFile);
|
2007-03-22 10:30:00 -07: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-05 19:08:30 -07:00
|
|
|
nsresult LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
char* mPidLockFileName;
|
|
|
|
int mLockFileDesc;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __nsProfileLock_h___ */
|