|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef __nsProfileLock_h___ |
|
7 #define __nsProfileLock_h___ |
|
8 |
|
9 #include "nsIFile.h" |
|
10 |
|
11 class nsIProfileUnlocker; |
|
12 |
|
13 #if defined (XP_WIN) |
|
14 #include <windows.h> |
|
15 #endif |
|
16 |
|
17 #if defined (XP_UNIX) |
|
18 #include <signal.h> |
|
19 #include "prclist.h" |
|
20 #endif |
|
21 |
|
22 class nsProfileLock |
|
23 #if defined (XP_UNIX) |
|
24 : public PRCList |
|
25 #endif |
|
26 { |
|
27 public: |
|
28 nsProfileLock(); |
|
29 nsProfileLock(nsProfileLock& src); |
|
30 |
|
31 ~nsProfileLock(); |
|
32 |
|
33 nsProfileLock& operator=(nsProfileLock& rhs); |
|
34 |
|
35 /** |
|
36 * Attempt to lock a profile directory. |
|
37 * |
|
38 * @param aProfileDir [in] The profile directory to lock. |
|
39 * @param aUnlocker [out] Optional. This is only returned when locking |
|
40 * fails with NS_ERROR_FILE_ACCESS_DENIED, and may not |
|
41 * be returned at all. |
|
42 * @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked. |
|
43 */ |
|
44 nsresult Lock(nsIFile* aProfileDir, nsIProfileUnlocker* *aUnlocker); |
|
45 |
|
46 /** |
|
47 * Unlock a profile directory. If you're unlocking the directory because |
|
48 * the application is in the process of shutting down because of a fatal |
|
49 * signal, set aFatalSignal to true. |
|
50 */ |
|
51 nsresult Unlock(bool aFatalSignal = false); |
|
52 |
|
53 /** |
|
54 * Get the modification time of a replaced profile lock, otherwise 0. |
|
55 */ |
|
56 nsresult GetReplacedLockTime(PRTime* aResult); |
|
57 |
|
58 private: |
|
59 bool mHaveLock; |
|
60 PRTime mReplacedLockTime; |
|
61 |
|
62 #if defined (XP_WIN) |
|
63 HANDLE mLockFileHandle; |
|
64 #elif defined (XP_UNIX) |
|
65 |
|
66 struct RemovePidLockFilesExiting { |
|
67 RemovePidLockFilesExiting() {} |
|
68 ~RemovePidLockFilesExiting() { |
|
69 RemovePidLockFiles(false); |
|
70 } |
|
71 }; |
|
72 |
|
73 static void RemovePidLockFiles(bool aFatalSignal); |
|
74 static void FatalSignalHandler(int signo |
|
75 #ifdef SA_SIGINFO |
|
76 , siginfo_t *info, void *context |
|
77 #endif |
|
78 ); |
|
79 static PRCList mPidLockList; |
|
80 |
|
81 nsresult LockWithFcntl(nsIFile *aLockFile); |
|
82 |
|
83 /** |
|
84 * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this |
|
85 * lock is merely an "obsolete" lock to keep out old Firefoxes |
|
86 */ |
|
87 nsresult LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock); |
|
88 |
|
89 char* mPidLockFileName; |
|
90 int mLockFileDesc; |
|
91 #endif |
|
92 |
|
93 }; |
|
94 |
|
95 #endif /* __nsProfileLock_h___ */ |