From f269cb28a9de4f4bc8745cc895fd0d4517a1d4ea Mon Sep 17 00:00:00 2001 From: zhangkun Date: Wed, 3 Jun 2026 17:03:27 +0800 Subject: [PATCH 1/2] refactor(dde-session): remove Dconf utility and dead code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Remove Dconf wrapper class (dconf.h/cpp) and its CMake references 2. Remove initSwapSched() placeholder and swap-sched-enabled check 3. Remove Dconf-based quick-black-screen logic in suspend/shutdown/reboot 4. Remove dead iowait watcher code block (was already #if 0) 5. Comment out Wayland DPMS command in setDPMSMode() Log: Remove Dconf utility class and related dead/unused code paths refactor(dde-session): 移除 Dconf 工具类及无用代码 1. 移除 Dconf 封装类(dconf.h/cpp)及其 CMake 引用 2. 移除 initSwapSched() 占位函数及 swap-sched-enabled 配置检查 3. 移除挂起/关机/重启中基于 Dconf 的 quick-black-screen 逻辑 4. 移除已禁用的 iowait watcher 代码块(原为 #if 0) 5. 注释掉 setDPMSMode() 中的 Wayland DPMS 命令 Log: 移除 Dconf 工具类及其相关的无用/未使用代码路径 --- src/dde-session/CMakeLists.txt | 2 - src/dde-session/impl/sessionmanager.cpp | 35 ++------------ src/dde-session/impl/sessionmanager.h | 1 - src/dde-session/main.cpp | 14 +----- src/utils/dconf.cpp | 62 ------------------------- src/utils/dconf.h | 30 ------------ 6 files changed, 6 insertions(+), 138 deletions(-) delete mode 100644 src/utils/dconf.cpp delete mode 100644 src/utils/dconf.h diff --git a/src/dde-session/CMakeLists.txt b/src/dde-session/CMakeLists.txt index 249b2a0..2a01988 100644 --- a/src/dde-session/CMakeLists.txt +++ b/src/dde-session/CMakeLists.txt @@ -71,8 +71,6 @@ add_executable(dde-session impl/iowait/iowaitwatcher.cpp impl/iowait/xcursor_remap.h impl/iowait/xcursor_remap.c - ../utils/dconf.h - ../utils/dconf.cpp ../utils/fifo.h ../utils/fifo.cpp ../utils/utils.h diff --git a/src/dde-session/impl/sessionmanager.cpp b/src/dde-session/impl/sessionmanager.cpp index 9b50d3e..ef70266 100644 --- a/src/dde-session/impl/sessionmanager.cpp +++ b/src/dde-session/impl/sessionmanager.cpp @@ -5,7 +5,6 @@ #include "sessionmanager.h" #include "inhibitor.h" #include "inhibitor1adaptor.h" -#include "utils/dconf.h" #include "utils/utils.h" #include "org_deepin_dde_Audio1_Sink.h" @@ -19,11 +18,14 @@ #include #include #include +#include #include #include #include +using namespace Dtk::Core; + #define MASK_SERVICE(service) \ {\ auto reply = m_systemd1ManagerInter->MaskUnitFiles(QStringList() << service, true, true);\ @@ -138,10 +140,6 @@ void SessionManager::initConnections() } }); - if (Dconf::GetValue("com.deepin.dde.startdde", "", "swap-sched-enabled", QVariant(false)).toBool()) { - initSwapSched(); - } - connect(m_DBusInter, &org::freedesktop::DBus::NameOwnerChanged, [ = ](const QString &name, const QString &oldOwner, const QString &newOwner) { if (newOwner == "" && oldOwner != "" && name == oldOwner && name.startsWith(":")) { @@ -156,12 +154,6 @@ void SessionManager::initConnections() , "Unlock", this, SLOT(handleLoginSessionUnlocked())); } -void SessionManager::initSwapSched() -{ - qDebug() << "init swap sched"; - // TODO -} - void SessionManager::prepareLogout(bool force) { if (!force) @@ -463,14 +455,6 @@ void SessionManager::RequestSuspend() return; } - // 使用窗管接口进行黑屏处理 - if (Dconf::SetValue("com.deepin.dde.startdde", "", "quick-black-screen", QVariant(false))) { - QDBusInterface inter("org.kde.KWin", "/BlackScreen", "org.kde.kwin.BlackScreen", QDBusConnection::sessionBus(), this); - const QDBusMessage &msg = inter.call("setActive", true); - if (!msg.errorName().isEmpty()) - qWarning() << "failed to create blackscreen, error: " << msg.errorName(); - } - QDBusPendingReply<> reply = m_login1ManagerInter->Suspend(false); if (reply.isError()) { qWarning() << "failed to suspend, error:" << reply.error().name(); @@ -835,7 +819,8 @@ void SessionManager::playLogoutSound() void SessionManager::setDPMSMode(bool on) { if (Utils::IS_WAYLAND_DISPLAY) { - EXEC_COMMAND("dde_wldpms", QStringList() << "-s" << (on ? "On" : "Off")); + // TODO + // EXEC_COMMAND("dde_wldpms", QStringList() << "-s" << (on ? "On" : "Off")); } else { // TODO 可通过Xlib发送对应请求实现此功能 EXEC_COMMAND("xset", QStringList() << "dpms" << "force" << (on ? "on" : "off")); @@ -870,11 +855,6 @@ void SessionManager::shutdown(bool force) qWarning() << "failed to power off, error: " << reply.error().name(); } - //NOTE: do we need it anymore? - if (Dconf::SetValue("com.deepin.dde.startdde", "", "quick-black-screen", false)) { - setDPMSMode(false); - } - qApp->quit(); } @@ -888,11 +868,6 @@ void SessionManager::reboot(bool force) qWarning() << "failed to reboot, error: " << reply.error().name(); } - // NOTE: do we need it anymore? - if (Dconf::SetValue("com.deepin.dde.startdde", "", "quick-black-screen", QVariant(false))) { - setDPMSMode(false); - } - qApp->quit(); } diff --git a/src/dde-session/impl/sessionmanager.h b/src/dde-session/impl/sessionmanager.h index 5b2e12e..db3c9db 100644 --- a/src/dde-session/impl/sessionmanager.h +++ b/src/dde-session/impl/sessionmanager.h @@ -72,7 +72,6 @@ public Q_SLOTS: ~SessionManager(); void initConnections(); - void initSwapSched(); void prepareLogout(bool force); void prepareShutdown(bool force); void clearCurrentTty(); diff --git a/src/dde-session/main.cpp b/src/dde-session/main.cpp index e47d355..be82d1b 100644 --- a/src/dde-session/main.cpp +++ b/src/dde-session/main.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2021 - 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -133,18 +133,6 @@ int main(int argc, char *argv[]) OthersManager().init(); }); -#if 0 //TODO has no 'com.deepin.dde.startdde' gsetting - // cpu iowait状态检测 - if (Utils::SettingValue("com.deepin.dde.startdde", QByteArray(), "iowait-enabled", false).toBool()) { - QtConcurrent::run([] { - auto watcher = new IOWaitWatcher; - watcher->start(); - }); - } else { - qInfo() << "iowait watcher disabled"; - } -#endif - qInfo() << "iowait watcher disabled"; QThreadPool::globalInstance()->start([&session]() { qInfo()<< "systemd service pipe thread id: " << QThread::currentThreadId(); diff --git a/src/utils/dconf.cpp b/src/utils/dconf.cpp deleted file mode 100644 index 1858c51..0000000 --- a/src/utils/dconf.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "utils/dconf.h" - -#include -#include - -Dconf::Dconf() -{ - -} - -Dconf::~Dconf() -{ - -} - -DConfig *Dconf::connectDconf(const QString &name, const QString &subpath, QObject *parent) -{ - // TODO: move it to dde-session - DConfig *config = DConfig::create("dde-application-manager", name, subpath, parent); - if (config == nullptr) { - qDebug() << "Cannot find dconfigs, name:" << name; - return nullptr; - } - if (!config->isValid()) { - qDebug() << "Cannot find dconfigs, name:" << name; - delete config; - return nullptr; - } - - return config; -} - -const QVariant Dconf::GetValue(const QString &name, const QString &subPath, const QString &key, const QVariant &fallback) -{ - QSharedPointer config(connectDconf(name, subPath)); - if (config && config->isValid() && config->keyList().contains(key)) { - QVariant v = config->value(key); - return v; - } - - qDebug() << "Cannot find dconfigs, name:" << name - << " subPath:" << subPath << " key:" << key - << "Use fallback value:" << fallback; - return fallback; -} - -bool Dconf::SetValue(const QString &name, const QString &subPath, const QString &key, const QVariant &value) -{ - QSharedPointer config(connectDconf(name, subPath)); - if (config && config->isValid() && config->keyList().contains(key)) { - config->setValue(key, value); - return true; - } - - qDebug() << "Cannot find dconfigs, name:" << name - << " subPath:" << subPath << " key:" << key; - return false; -} diff --git a/src/utils/dconf.h b/src/utils/dconf.h deleted file mode 100644 index 2849311..0000000 --- a/src/utils/dconf.h +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef DCONF_H -#define DCONF_H - -#include - -#include -#include - -DCORE_USE_NAMESPACE - -// Dconfig 配置类 -class Dconf -{ -public: - Dconf(); - ~Dconf(); - -public: - static const QVariant GetValue(const QString &name, const QString &subPath = QString(), const QString &key = QString(), const QVariant &fallback = QVariant()); - static bool SetValue(const QString &name, const QString &subPath, const QString &key, const QVariant &value); - -private: - static DConfig *connectDconf(const QString &name, const QString &subpath = QString(), QObject *parent = nullptr); -}; - -#endif // DCONF_H \ No newline at end of file From 2a38b8e1d966f1f54c64a536bdb660b451d45ae9 Mon Sep 17 00:00:00 2001 From: zhangkun Date: Wed, 3 Jun 2026 17:07:51 +0800 Subject: [PATCH 2/2] fix(dde-session): fix thread safety in FIFO pipe handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Move session->setSessionPid/setSessionPath to main thread via QMetaObject::invokeMethod with Qt::QueuedConnection 2. Replace fifo->deleteLater() with direct delete for immediate cleanup 3. Use QueuedConnection for qApp->quit() to ensure thread-safe exit Log: Fix thread safety issues in FIFO pipe read callback by deferring session operations and app quit to the main thread event loop fix(dde-session): 修复 FIFO 管道处理中的线程安全问题 1. 通过 QMetaObject::invokeMethod(Qt::QueuedConnection) 将 setSessionPid/setSessionPath 调度到主线程执行 2. 将 fifo->deleteLater() 改为直接 delete 以立即释放资源 3. 使用 QueuedConnection 调度 qApp->quit() 确保线程安全退出 Log: 修复 FIFO 管道读取回调中的线程安全问题,将 session 操作和应用退出 调度到主线程事件循环执行 --- src/dde-session/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dde-session/main.cpp b/src/dde-session/main.cpp index be82d1b..16bb474 100644 --- a/src/dde-session/main.cpp +++ b/src/dde-session/main.cpp @@ -146,14 +146,15 @@ int main(int argc, char *argv[]) int pid = CurSessionPid.toInt(&ok); qInfo() << "dde-session pid: " << CurSessionPid; if (ok && pid > 0) { - // TODO session在主线程中创建,在这里直接使用是有问题的 - session->setSessionPid(pid); // TODO: session别直接调用 - session->setSessionPath(); + QMetaObject::invokeMethod(session, [session, pid]() { + session->setSessionPid(pid); + session->setSessionPath(); + }, Qt::QueuedConnection); } } - fifo->deleteLater(); + delete fifo; qInfo() << "pipe read finish, app exit."; - qApp->quit(); + QMetaObject::invokeMethod(qApp, &QCoreApplication::quit, Qt::QueuedConnection); }); sd_notify(0, "READY=1");