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