author Ryan VanderMeulen <>
Sat, 19 Mar 2016 15:16:30 -0400
changeset 351260 351882d470a769b8e185deeda24a4ddffb19c105
parent 273861 42077df6e5734b34aeaf2370bb6ffe8364925a6d
child 489668 cbb8fdf1daf98a15f7d57f6b08d273bdf96aa1a0
child 499370 d58dc3d94d98186696c9176ce2aba1f78658db65
child 503870 5f415fdfdbdc383f1975a34deabc6f692973bd5d
permissions -rw-r--r--
Bug 1252707. r=terrence a=lizzard MozReview-Commit-ID: EIjq93wa1nD

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 */

#ifndef __nsProfileLock_h___
#define __nsProfileLock_h___

#include "nsIFile.h"

class nsIProfileUnlocker;

#if defined (XP_WIN)
#include <windows.h>

#if defined (XP_UNIX)
#include <signal.h>
#include "prclist.h"

class nsProfileLock
#if defined (XP_UNIX)
  : public PRCList
                            nsProfileLock(nsProfileLock& src);

    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.
    nsresult                Lock(nsIFile* aProfileDir, nsIProfileUnlocker* *aUnlocker);

     * Unlock a profile directory.  If you're unlocking the directory because
     * the application is in the process of shutting down because of a fatal
     * signal, set aFatalSignal to true.
    nsresult                Unlock(bool aFatalSignal = false);

     * Get the modification time of a replaced profile lock, otherwise 0.
    nsresult                GetReplacedLockTime(PRTime* aResult);

    bool                    mHaveLock;
    PRTime                  mReplacedLockTime;

#if defined (XP_WIN)
    HANDLE                  mLockFileHandle;
#elif defined (XP_UNIX)

    struct RemovePidLockFilesExiting {
        RemovePidLockFilesExiting() {}
        ~RemovePidLockFilesExiting() {

    static void             RemovePidLockFiles(bool aFatalSignal);
    static void             FatalSignalHandler(int signo
                                               , siginfo_t *info, void *context
    static PRCList          mPidLockList;

    nsresult                LockWithFcntl(nsIFile *aLockFile);

     * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this
     * lock is merely an "obsolete" lock to keep out old Firefoxes
    nsresult                LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock);

    char*                   mPidLockFileName;
    int                     mLockFileDesc;


#endif /* __nsProfileLock_h___ */