Skip to content
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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_subdirectory(logViewerAuth)
add_subdirectory(logViewerTruncate)

add_subdirectory(logViewerService)
add_subdirectory(opsLogViewerService)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(tests)
Expand Down
24 changes: 10 additions & 14 deletions application/dbusproxy/dldbushandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

#include "dldbushandler.h"
#include <QDebug>
#include <QStandardPaths>

Check warning on line 7 in application/dbusproxy/dldbushandler.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 8 in application/dbusproxy/dldbushandler.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

constexpr const char* kLogExportService = "org.deepin.logviewer.service.opsLogExport";
constexpr const char* kLogExportPath = "/org/deepin/logviewer/service/opsLogExport";
constexpr const char* kLogExportInterface = "org.deepin.logviewer.service.opsLogExport";

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(logDBusHandler, "org.deepin.log.viewer.dbus.handler")
#else
Expand Down Expand Up @@ -169,19 +165,19 @@

bool DLDBusHandler::exportOpsLog(const QString &outDir, const QString &userHomeDir)
{
QDBusMessage message = QDBusMessage::createMethodCall(kLogExportService,
kLogExportPath,
kLogExportInterface,
"ExportOpsLog");
message << outDir << userHomeDir;
m_dbus->setTimeout(1200000);
QDBusPendingReply<bool> reply = m_dbus->exportOpsLog(outDir, userHomeDir);
reply.waitForFinished();
m_dbus->setTimeout(-1);

if (reply.isError()) {
qCritical(logDBusHandler) << "call dbus interface 'exportHwOpsLog' failed. error info:" << reply.error().message();

QDBusMessage reply = QDBusConnection::systemBus().call(message, QDBus::Block, 1200000);
if (reply.type() == QDBusMessage::ErrorMessage) {
qCritical(logDBusHandler) << "call dbus interface 'exportHwOpsLog' failed. error info:" << reply.errorMessage();
return false;
} else {
qCDebug(logDBusHandler) << "exportOpsLog succeeded:" << reply.value();
return reply.value();
}

return reply.arguments().first().toBool();
}

bool DLDBusHandler::isFileExist(const QString &filePath)
Expand Down
81 changes: 71 additions & 10 deletions application/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,25 +615,86 @@ QByteArray Utils::executeCmd(const QString &cmdStr, const QStringList &args, con
return processCmdWithArgs(cmdStr, workPath, args);
}

static void appendToFile(const QString &filePath, const QByteArray &content)
{
QFile file(filePath);

if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
file.write(content);
} else {
qWarning() << "Error opening file for writing:" << file.errorString();
}
}

// 查找所有物理网络接口
QStringList getPhysicalInterfaces()
{
QStringList physicalInterfaces;
QDir netDir("/sys/class/net/");

if (!netDir.exists()) {
qWarning("Directory /sys/class/net/ does not exist. This program is for Linux only.");
return physicalInterfaces;
}

// 设置过滤器,只列出目录
netDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
QStringList interfaceList = netDir.entryList();

for (const QString &iface : interfaceList) {
// 物理网卡在 /sys/class/net/ 下会有一个指向 device 的符号链接或目录
QFileInfo deviceInfo(netDir.filePath(iface + "/device"));
if (deviceInfo.exists() && deviceInfo.isSymLink()) {
physicalInterfaces.append(iface);
}
}

return physicalInterfaces;
}

static QStringList expandPathWithWildcardIterator(const QString &pathWithWildcard)
{
// 1. 分离目录和文件名模式
QFileInfo fileInfo(pathWithWildcard);
QString dirPath = fileInfo.path();
QString fileNamePattern = fileInfo.fileName();

QStringList matchedFiles;
QStringList nameFilters;
nameFilters << fileNamePattern;

// 2. 创建 QDirIterator
// 构造函数参数:目录, 名称过滤器, 实体类型过滤器, 迭代器标志
QDirIterator it(dirPath, nameFilters, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::NoIteratorFlags);

// 3. 循环遍历所有匹配项
while (it.hasNext()) {
// it.next() 直接返回下一个匹配项的完整路径
matchedFiles.append(it.next());
}

return matchedFiles;
}

void Utils::exportSomeOpsLogs(const QString &outDir, const QString &userHomeDir)
{
Q_UNUSED(userHomeDir)

std::string tmpCmd;

// app
tmpCmd = ("glxinfo -B >> " + outDir + "/app/kwin/glxinfo.log").toStdString();
system(tmpCmd.c_str());
tmpCmd = ("cp -rf /tmp/fcitx*.log " + outDir + "/app/fcitx/").toStdString();
system(tmpCmd.c_str());
appendToFile(outDir + "/app/kwin/glxinfo.log", executeCmd("glxinfo", { "-display", qEnvironmentVariable("DISPLAY"), "-B" }));
QStringList args = { "-rf" };
args.append(expandPathWithWildcardIterator("/tmp/fcitx*.log"));
args.append(outDir + "/app/fcitx/");
executeCmd("cp", args);

// kernel
tmpCmd = ("aplay -l >> " + outDir + "/kernel/aplay.log").toStdString();
system(tmpCmd.c_str());
tmpCmd = ("ethtool -i $(ifconfig | grep --max-count=1 ^en | awk -F ':' '{print $1}') >> " + outDir + "/kernel/eth_info.log").toStdString();
system(tmpCmd.c_str());
tmpCmd = ("ifconfig >> " + outDir + "/kernel/ifconfig.log").toStdString();
system(tmpCmd.c_str());
appendToFile(outDir + "/kernel/aplay.log", executeCmd("aplay", { "-l" }));
for (const QString &iface : getPhysicalInterfaces()) {
appendToFile(outDir + "/kernel/eth_info.log", executeCmd("ethtool", { "-i", iface }));
}
appendToFile(outDir + "/kernel/ifconfig.log", executeCmd("ifconfig", { }));
}

#ifdef DTKCORE_CLASS_DConfigFile
Expand Down
4 changes: 0 additions & 4 deletions debian/deepin-log-viewer.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ usr/bin/deepin-log-viewer
usr/bin/logViewerAuth
usr/bin/logViewerTruncate
usr/bin/deepin-logger
usr/bin/ops-log-viewer-service
usr/lib/deepin-daemon/log-view-service
usr/lib/systemd/user/coredump-reporter.service
usr/lib/systemd/user/coredump-reporter.timer
usr/lib/systemd/system/deepin-log-viewer-daemon.service
usr/lib/systemd/system/deepin-log-viewer-ops.service
usr/share/applications/deepin-log-viewer.desktop
usr/share/dbus-1/system-services/com.deepin.logviewer.service
usr/share/dbus-1/system-services/org.deepin.logviewer.ops.service
usr/share/dbus-1/system.d/com.deepin.logviewer.conf
usr/share/dbus-1/system.d/org.deepin.logviewer.ops.conf
usr/share/deepin-log-viewer/DocxTemplate/*.dfw
usr/share/dsg/configs/org.deepin.log.viewer/*.json
usr/share/glib-2.0/schemas/*.gschema.xml
Expand Down
Loading
Loading