1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2002
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Conrad Carlen <ccarlen@netscape.com>
24 : * Brendan Eich <brendan@mozilla.org>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef __nsProfileLock_h___
41 : #define __nsProfileLock_h___
42 :
43 : #include "nsILocalFile.h"
44 :
45 : class nsIProfileUnlocker;
46 :
47 : #if defined (XP_WIN)
48 : #include <windows.h>
49 : #endif
50 :
51 : #if defined (XP_OS2)
52 : #define INCL_DOSERRORS
53 : #define INCL_DOSFILEMGR
54 : #include <os2.h>
55 : #endif
56 :
57 : #if defined (XP_UNIX)
58 : #include <signal.h>
59 : #include "prclist.h"
60 : #endif
61 :
62 : class nsProfileLock
63 : #if defined (XP_UNIX)
64 : : public PRCList
65 : #endif
66 : {
67 : public:
68 : nsProfileLock();
69 : nsProfileLock(nsProfileLock& src);
70 :
71 : ~nsProfileLock();
72 :
73 : nsProfileLock& operator=(nsProfileLock& rhs);
74 :
75 : /**
76 : * Attempt to lock a profile directory.
77 : *
78 : * @param aProfileDir [in] The profile directory to lock.
79 : * @param aUnlocker [out] Optional. This is only returned when locking
80 : * fails with NS_ERROR_FILE_ACCESS_DENIED, and may not
81 : * be returned at all.
82 : * @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked.
83 : */
84 : nsresult Lock(nsILocalFile* aProfileDir, nsIProfileUnlocker* *aUnlocker);
85 :
86 : /**
87 : * Unlock a profile directory. If you're unlocking the directory because
88 : * the application is in the process of shutting down because of a fatal
89 : * signal, set aFatalSignal to true.
90 : */
91 : nsresult Unlock(bool aFatalSignal = false);
92 :
93 : /**
94 : * Get the modification time of a replaced profile lock, otherwise 0.
95 : */
96 : nsresult GetReplacedLockTime(PRInt64* aResult);
97 :
98 : private:
99 : bool mHaveLock;
100 : PRInt64 mReplacedLockTime;
101 :
102 : #if defined (XP_WIN)
103 : HANDLE mLockFileHandle;
104 : #elif defined (XP_OS2)
105 : LHANDLE mLockFileHandle;
106 : #elif defined (XP_UNIX)
107 :
108 : struct RemovePidLockFilesExiting {
109 0 : RemovePidLockFilesExiting() {}
110 0 : ~RemovePidLockFilesExiting() {
111 0 : RemovePidLockFiles(false);
112 0 : }
113 : };
114 :
115 : static void RemovePidLockFiles(bool aFatalSignal);
116 : static void FatalSignalHandler(int signo
117 : #ifdef SA_SIGINFO
118 : , siginfo_t *info, void *context
119 : #endif
120 : );
121 : static PRCList mPidLockList;
122 :
123 : nsresult LockWithFcntl(nsILocalFile *aLockFile);
124 :
125 : /**
126 : * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this
127 : * lock is merely an "obsolete" lock to keep out old Firefoxes
128 : */
129 : nsresult LockWithSymlink(nsILocalFile *aLockFile, bool aHaveFcntlLock);
130 :
131 : char* mPidLockFileName;
132 : int mLockFileDesc;
133 : #endif
134 :
135 : };
136 :
137 : #endif /* __nsProfileLock_h___ */
|