Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix can not get any logs issue #361

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions logViewerService/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_component
find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Core Gui REQUIRED)

find_package(PolkitQt${QT_DESIRED_VERSION}-1)
if (QT_DESIRED_VERSION MATCHES 5)
pkg_check_modules(Gio REQUIRED gio-qt)
endif()
pkg_check_modules(Gio REQUIRED gio-qt${DTK_VERSION_MAJOR})


set(LINK_LIBS
Qt${QT_DESIRED_VERSION}::Core
Expand Down
70 changes: 9 additions & 61 deletions logViewerService/logviewerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#include "qtcompat.h"

#include <pwd.h>
#include <unistd.h>

Check warning on line 9 in logViewerService/logviewerservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <fstream>

Check warning on line 10 in logViewerService/logviewerservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <fstream> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <polkit-qt5-1/PolkitQt1/Authority>
#include <dgiofile.h>

Check warning on line 12 in logViewerService/logviewerservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dgiofile.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dgiovolume.h>

Check warning on line 13 in logViewerService/logviewerservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dgiovolume.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dgiovolumemanager.h>

Check warning on line 14 in logViewerService/logviewerservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dgiovolumemanager.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <polkit-qt5-1/PolkitQt1/Authority>
#else
#include <polkit-qt6-1/PolkitQt1/Authority>

Check warning on line 18 in logViewerService/logviewerservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <polkit-qt6-1/PolkitQt1/Authority> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif
using namespace PolkitQt1;

Expand Down Expand Up @@ -652,17 +652,9 @@
QStringList LogViewerService::getExternalDevPaths()
{
QStringList devPaths;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QList<QExplicitlySharedDataPointer<DGioMount> > mounts = getMounts_safe();
#else
const QList<DMount> mounts = getMounts_safe();
#endif
for (auto mount : mounts) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QString uri = mount->getRootFile()->uri();
#else
QString uri = mount.source();
#endif
QString scheme = QUrl(uri).scheme();

// sbm路径判断,分为gvfs挂载和cifs挂载两种
Expand All @@ -679,12 +671,8 @@
if ((scheme == "file") || //usb device
(scheme == "gphoto2") || //phone photo
(scheme == "mtp")) { //android file
// QExplicitlySharedDataPointer<DGioFile> locationFile = mount->getDefaultLocationFile();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QString path = mount->getDefaultLocationFile()->path();
#else
QString path = mount.target();
#endif
QExplicitlySharedDataPointer<DGioFile> locationFile = mount->getDefaultLocationFile();
QString path = locationFile->path();
if (path.startsWith("/media/")) {
QFlags <QFileDevice::Permission> power = QFile::permissions(path);
if (power.testFlag(QFile::WriteUser)) {
Expand All @@ -698,38 +686,11 @@
}

//可重入版本的getMounts
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QList<QExplicitlySharedDataPointer<DMount>> LogViewerService::getMounts_safe()
#else
QList<DMount> LogViewerService::getMounts_safe()
#endif
QList<QExplicitlySharedDataPointer<DGioMount> > LogViewerService::getMounts_safe()
{
static QMutex mutex;
mutex.lock();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto result = DGioVolumeManager::getMounts();
#else
QList<DMount> result;
QFile mountsFile("/proc/mounts");
if (mountsFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&mountsFile);
while (!in.atEnd()) {
QString line = in.readLine();
QStringList parts = line.split(' ');
if (parts.size() >= 4) {
Mount mount(new MountData);
mount.setSource(parts.at(0));
mount.setTarget(parts.at(1));
mount.setFilesystemType(parts.at(2));
mount.setOptions(parts.at(3));
result.append(mount);
}
}
mountsFile.close();
} else {
qWarning() << "Failed to open /proc/mounts";
}
#endif
mutex.unlock();
return result;
}
Expand Down Expand Up @@ -1095,23 +1056,10 @@
uint pid = conn.interface()->servicePid(msg.service()).value();

// 判断是否存在执行路径且是否存在于可调用者名单中
QFileInfo initNsMntFileInfo("/proc/1/ns/mnt");
QFileInfo senderNsMntFileInfo(QString("/proc/%1/ns/mnt").arg(pid));
QString initNsMnt;
QString senderNsMnt;

if (!initNsMntFileInfo.isSymLink() || !senderNsMntFileInfo.isSymLink()) {
sendErrorReply(QDBusError::ErrorType::Failed, "Invalid symlink!!!!!");
return false;
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
initNsMnt = initNsMntFileInfo.symLinkTarget().trimmed();
senderNsMnt = senderNsMntFileInfo.symLinkTarget().trimmed();
#else
initNsMnt = initNsMntFileInfo.readLink().trimmed();
senderNsMnt = senderNsMntFileInfo.readLink().trimmed();
#endif
QFile initNsMntFile("/proc/1/ns/mnt");
QFile senderNsMntFile(QString("/proc/%1/ns/mnt").arg(pid));
auto initNsMnt = initNsMntFile.symLinkTarget().trimmed().remove(0, QString("/proc/1/ns/mnt").length());
auto senderNsMnt = senderNsMntFile.symLinkTarget().trimmed().remove(0, QString("/proc/%1/ns/mnt").arg(pid).length());
if (initNsMnt != senderNsMnt) {
sendErrorReply(QDBusError::ErrorType::Failed, "Illegal calls!!!!!");
return false;
Expand Down
47 changes: 3 additions & 44 deletions logViewerService/logviewerservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,14 @@
#ifndef LOGVIEWERSERVICE_H
#define LOGVIEWERSERVICE_H

#include <dgiomount.h>

Check warning on line 8 in logViewerService/logviewerservice.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dgiomount.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QObject>

Check warning on line 10 in logViewerService/logviewerservice.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusContext>

Check warning on line 11 in logViewerService/logviewerservice.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusContext> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QScopedPointer>

Check warning on line 12 in logViewerService/logviewerservice.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScopedPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>
#include <QTemporaryDir>
#include <QDBusUnixFileDescriptor>
#include <QTextStream>

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <dgiomount.h>

using DMount = DGioMount;

#else
class MountData : public QSharedData {
public:
QString source;
QString target;
QString filesystemType;
QString options;
};

class Mount {
public:
Mount() : d(new MountData) {}
Mount(const Mount& other) : d(other.d) {}
Mount(MountData* data) : d(data) {}

QString source() const { return d->source; }
QString target() const { return d->target; }
QString filesystemType() const { return d->filesystemType; }
QString options() const { return d->options; }

void setSource(const QString& source) { d->source = source; }
void setTarget(const QString& target) { d->target = target; }
void setFilesystemType(const QString& filesystemType) { d->filesystemType = filesystemType; }
void setOptions(const QString& options) { d->options = options; }

private:
QExplicitlySharedDataPointer<MountData> d;
};

using DMount = Mount;

#endif

class QTextStream;
class DGioVolumeManager;
Expand Down Expand Up @@ -87,11 +50,7 @@
QStringList getHomePaths();
// 获取外设挂载路径(包括smb路径)
QStringList getExternalDevPaths();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QList<QExplicitlySharedDataPointer<DMount>> getMounts_safe();
#else
QList<DMount> getMounts_safe();
#endif
QList<QExplicitlySharedDataPointer<DGioMount>> getMounts_safe();

private:
QString readLog(const QString &filePath);
Expand Down