Revision control

Copy as Markdown

// Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default
#ifndef QLOCKFILE_P_H
#define QLOCKFILE_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/private/qglobal_p.h>
#include <QtCore/qlockfile.h>
#include <QtCore/qfile.h>
#include <optional>
QT_BEGIN_NAMESPACE
class QLockFilePrivate
{
public:
struct LockFileInfo
{
qint64 pid;
QString appname;
QString hostname;
QByteArray hostid;
QByteArray bootid;
QT_DEFINE_TAG_STRUCT(Current);
LockFileInfo() = default;
LockFileInfo(Current);
QByteArray asFileContents() const;
};
explicit QLockFilePrivate(const QString &fn);
~QLockFilePrivate();
QLockFile::LockError tryLock_sys(const LockFileInfo &current);
bool removeStaleLock();
// Returns \c true if the lock belongs to dead PID, or is old.
// The attempt to delete it will tell us if it was really stale or not, though.
bool isApparentlyStale(const LockFileInfo &current) const;
// used in dbusmenu
Q_CORE_EXPORT static QString processNameByPid(qint64 pid);
static bool isProcessRunning(qint64 pid, const QString &appname);
QString fileName;
static std::optional<LockFileInfo> getLockInfo_helper(const QString &fileName);
static int openNewFileDescriptor(const QString &fileName);
#ifdef Q_OS_WIN
Qt::HANDLE fileHandle = Qt::HANDLE(-1); // INVALID_HANDLE_VALUE
#else
int fileHandle = -1;
int dirHandle = -1; // the directory where the file is located
#endif
std::chrono::milliseconds staleLockTime = std::chrono::seconds{30};
QLockFile::LockError lockError = QLockFile::NoError;
bool isLocked = false;
// used in tst_QLockFile:
static auto getLockFileHandle(QLockFile *f)
{
return f->d_func()->fileHandle;
}
};
QT_END_NAMESPACE
#endif /* QLOCKFILE_P_H */