| 1 | // Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QLOCKFILE_P_H |
| 6 | #define QLOCKFILE_P_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtCore/private/qglobal_p.h> |
| 20 | #include <QtCore/qlockfile.h> |
| 21 | #include <QtCore/qfile.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QLockFilePrivate |
| 26 | { |
| 27 | public: |
| 28 | explicit QLockFilePrivate(const QString &fn); |
| 29 | ~QLockFilePrivate(); |
| 30 | |
| 31 | QLockFile::LockError tryLock_sys(); |
| 32 | bool removeStaleLock(); |
| 33 | QByteArray lockFileContents() const; |
| 34 | // Returns \c true if the lock belongs to dead PID, or is old. |
| 35 | // The attempt to delete it will tell us if it was really stale or not, though. |
| 36 | bool isApparentlyStale() const; |
| 37 | |
| 38 | // used in dbusmenu |
| 39 | Q_CORE_EXPORT static QString processNameByPid(qint64 pid); |
| 40 | static bool isProcessRunning(qint64 pid, const QString &appname); |
| 41 | |
| 42 | QString fileName; |
| 43 | |
| 44 | #ifdef Q_OS_WIN |
| 45 | Qt::HANDLE fileHandle; |
| 46 | #else |
| 47 | int fileHandle; |
| 48 | #endif |
| 49 | |
| 50 | std::chrono::milliseconds staleLockTime = std::chrono::seconds{30}; |
| 51 | QLockFile::LockError lockError = QLockFile::NoError; |
| 52 | bool isLocked = false; |
| 53 | |
| 54 | // used in tst_QLockFile: |
| 55 | Q_CORE_EXPORT static int getLockFileHandle(QLockFile *f); |
| 56 | }; |
| 57 | |
| 58 | QT_END_NAMESPACE |
| 59 | |
| 60 | #endif /* QLOCKFILE_P_H */ |
| 61 | |