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
22 changes: 19 additions & 3 deletions application/dbusproxy/dldbushandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,34 @@ bool DLDBusHandler::exportLog(const QString &outDir, const QString &in, bool isF
return m_dbus->exportLog(outDir, in, isFile);
}

bool DLDBusHandler::exportOpsLog()
QString DLDBusHandler::exportOpsLog()
{
m_dbus->setTimeout(1200000);
QDBusPendingReply<bool> reply = m_dbus->exportOpsLog();
QDBusPendingReply<QString> reply = m_dbus->exportOpsLog();
reply.waitForFinished();
m_dbus->setTimeout(-1);

if (reply.isError()) {
qCritical(logDBusHandler) << "call dbus interface 'exportOpsLog' failed. error info:" << reply.error().message();
return QString();
} else {
qCDebug(logDBusHandler) << "exportOpsLog succeeded, root temp dir:" << reply.value();
return reply.value();
}
}

bool DLDBusHandler::removeOpsLogTempDir()
{
m_dbus->setTimeout(60000);
QDBusPendingReply<bool> reply = m_dbus->removeOpsLogTempDir();
reply.waitForFinished();
m_dbus->setTimeout(-1);

if (reply.isError()) {
qCritical(logDBusHandler) << "call dbus interface 'removeOpsLogTempDir' failed. error info:" << reply.error().message();
return false;
} else {
qCDebug(logDBusHandler) << "exportOpsLog succeeded:" << reply.value();
qCDebug(logDBusHandler) << "removeOpsLogTempDir succeeded, result:" << reply.value();
return reply.value();
}
}
Expand Down
3 changes: 2 additions & 1 deletion application/dbusproxy/dldbushandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class DLDBusHandler : public QObject
int exitCode();
void quit();
bool exportLog(const QString &outDir, const QString &in, bool isFile);
bool exportOpsLog();
QString exportOpsLog();
bool removeOpsLogTempDir();
bool isFileExist(const QString &filePath);
quint64 getFileSize(const QString &filePath);
qint64 getLineCount(const QString &filePath);
Expand Down
8 changes: 7 additions & 1 deletion application/dbusproxy/dldbusinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ public Q_SLOTS: // METHODS
return asyncCallWithArgumentList(QStringLiteral("exportLog"), argumentList);
}

inline QDBusPendingReply<bool> exportOpsLog()
inline QDBusPendingReply<QString> exportOpsLog()
{
QList<QVariant> argumentList;
return asyncCallWithArgumentList(QStringLiteral("exportOpsLog"), argumentList);
}

inline QDBusPendingReply<bool> removeOpsLogTempDir()
{
QList<QVariant> argumentList;
return asyncCallWithArgumentList(QStringLiteral("removeOpsLogTempDir"), argumentList);
}

inline QDBusPendingReply<QStringList> getFileInfo(const QString &file, bool unzip)
{
QList<QVariant> argumentList;
Expand Down
19 changes: 15 additions & 4 deletions application/logallexportthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,23 @@ void LogAllExportThread::run()
// 不支持导出 sudo 权限的日志,且导出日志功能主要面向普通用户使用场景,
// 因此当获取到的用户家目录为根目录时,认为是异常情况,不执行导出操作
if (!m_cancel && QDir::homePath() != "/" && QDir::homePath() != "/root") {
QString opsLogPath =tmpPath + "log-ops/";
QString opsLogPath = tmpPath + "log-ops/";
Utils::mkMutiDir(opsLogPath);
QString userHomePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
// 收集运维日志
DLDBusHandler::instance(this)->exportOpsLog();
Utils::exportSomeOpsLogs(opsLogPath, userHomePath);
// 收集运维日志:root 服务在 /var/log 下创建随机临时目录导出日志,并返回该目录路径
QString rootTempDir = DLDBusHandler::instance(this)->exportOpsLog();
if (!rootTempDir.isEmpty() && QDir(rootTempDir).exists()) {
// 将 root 导出的日志从 /var/log 临时目录拷贝到前端的 opsLogPath。
// -rP:递归拷贝且不跟随符号链接,与 root 侧 copy_file_or_dir 的 cp -rP 保持一致,
// 避免临时目录内符号链接指向 FIFO/特殊文件导致前端进程阻塞或读到非预期内容。
Utils::executeCmd("cp", QStringList() << "-rP" << rootTempDir + "/." << opsLogPath);
// 拷贝完成后及时清理 /var/log 下的 root 临时目录,避免遗留含系统日志的目录。
// 无参:服务端清理自身缓存的本次导出路径,杜绝路径替换风险。
DLDBusHandler::instance(this)->removeOpsLogTempDir();
} else {
qCWarning(logExportAll) << "exportOpsLog returned empty or non-existent root temp dir, root-side ops logs may be missing";
}
Utils::exportUserPermissionOpsLogs(opsLogPath, userHomePath);
}

if (!m_cancel) {
Expand Down
73 changes: 73 additions & 0 deletions application/opslogpaths.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef OPSLOGPATHS_H
#define OPSLOGPATHS_H

// 运维日志导出的目录结构常量。
//
// 前端(application/utils.cpp 的 exportUserPermissionOpsLogs 系列)与
// root 服务(logViewerService/opslogexport.cpp 的 createOpsLogDirStruct)必须
// 使用同一份目录结构,避免前后端导出路径不一致,故提取为公共头。
//
// 注意:application 目标以 -std=c++11 编译,故使用 static constexpr(非 C++17
// 的 inline constexpr 变量),命名空间作用域下内部链接,多 TU 包含无 ODR 问题。

static constexpr char kKernelPath[] { "/kernel" };
static constexpr char kSystemPath[] { "/system" };
static constexpr char kDDEPath[] { "/dde" };
static constexpr char kAppPath[] { "/app" };
static constexpr char kJournalPath[] { "/journal" };
static constexpr char kAptPath[] { "/apt" };
static constexpr char kUosStePath[] { "/uos-ste" };
static constexpr char kUossteLogsPath[] { "/uosste_logs" };
static constexpr char kHisiPath[] { "/hisi" };
static constexpr char kDefenderPath[] { "/app/deepin-defender" };
static constexpr char kCloudPrintPath[] { "/app/deepin-cloud-print" };
static constexpr char kCloudScanPath[] { "/app/deepin-cloud-scan" };
static constexpr char kPrinterPath[] { "/app/dde-printer" };
static constexpr char kGraphicsDriverManagerPath[] { "/app/deepin-graphics-driver-manager" };
static constexpr char kBootMakerPath[] { "/app/deepin-boot-maker" };
static constexpr char kScanerPath[] { "/app/deepin-scaner" };
static constexpr char kKMSPath[] { "/app/kms" };
static constexpr char kCompressorPath[] { "/app/deepin-compressor" };
static constexpr char kCalendarPath[] { "/app/dde-calendar" };
static constexpr char kManualPath[] { "/app/deepin-manual" };
static constexpr char kReaderPath[] { "/app/deepin-reader" };
static constexpr char kFontManagerPath[] { "/app/deepin-font-manager" };
static constexpr char kDebInstallerPath[] { "/app/deepin-deb-installer" };
static constexpr char kTerminalPath[] { "/app/deepin-terminal" };
static constexpr char kVoiceNotPath[] { "/app/deepin-voice-note" };
static constexpr char kDevicemanagerPath[] { "/app/deepin-devicemanager" };
static constexpr char kServiceSupportPath[] { "/app/uos-service-support" };
static constexpr char kRemoteAssistancePath[] { "/app/uos-remote-assistance" };
static constexpr char kSystemMonitorPath[] { "/app/deepin-system-monitor" };
static constexpr char kEditorPath[] { "/app/deepin-editor" };
static constexpr char kCalculatorPath[] { "/app/deepin-calculator" };
static constexpr char kMailPath[] { "/app/deepin-mail" };
static constexpr char kScreenRecorderPath[] { "/app/deepin-screen-recorder" };
static constexpr char kDrawPath[] { "/app/deepin-draw" };
static constexpr char kMusicPath[] { "/app/deepin-music" };
static constexpr char kImageViewerPath[] { "/app/deepin-image-viewer" };
static constexpr char kAlbumPath[] { "/app/deepin-album" };
static constexpr char kMoviePath[] { "/app/deepin-movie" };
static constexpr char kCameraPath[] { "/app/deepin-camera" };
static constexpr char kChineseImePath[] { "/app/chineseime" };
static constexpr char kDeepinInstallerPath[] { "/app/deepin-installer" };
static constexpr char kDeepinRecoveryPath[] { "/app/deepin-recovery" };
static constexpr char kOemCustomPath[] { "/app/oem-custom" };
static constexpr char kUosActivatorPath[] { "/app/uos-activator" };
static constexpr char kUosActivatorLogPath[] { "/app/uos-activator/log" };
static constexpr char kFcitxPath[] { "/app/fcitx" };
static constexpr char kDiskManagerPath[] { "/app/deepin-diskmanager" };
static constexpr char kDownloaderPath[] { "/app/downloader" };
static constexpr char kKwinPath[] { "/app/kwin" };
static constexpr char kKboxPath[] { "/app/kbox" };
static constexpr char kDeepinLogViewerPath[] { "/app/deepin-log-viewer" };
static constexpr char kDdeDesktopPath[] { "/dde/dde-desktop" };
static constexpr char kDdeFileManagerPath[] { "/dde/dde-file-manager" };
static constexpr char kDdeDockPath[] { "/dde/dde-dock" };
static constexpr char kSystemPulseaudioPath[] { "/system/pulseaudio" };

#endif // OPSLOGPATHS_H
Loading
Loading