fix: add X connection monitoring for session logout#199
fix: add X connection monitoring for session logout#199mhduiy wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
Added XCB dependency and implemented X server connection monitoring to detect when the X server disconnects. This ensures the session properly logs out when the X server connection is lost, preventing orphaned sessions. 1. Added libxcb1-dev to Build-Depends in debian/control 2. Added XCB pkg-config check and linking in CMakeLists.txt 3. Implemented watchXConnection() method that establishes an XCB connection and monitors the file descriptor using QSocketNotifier 4. When X connection errors are detected, the session automatically triggers logout to clean up resources 5. Only activates on X11 displays, not Wayland This fix addresses cases where X server crashes or disconnects unexpectedly, leaving the session manager running without a display server. fix: 添加X连接监控以实现会话登出 添加XCB依赖并实现X服务器连接监控,以检测X服务器断开连接的情况。这确保当X 服务器连接丢失时会话能正确登出,防止出现孤儿会话。 1. 在debian/control的Build-Depends中添加libxcb1-dev 2. 在CMakeLists.txt中添加XCB pkg-config检查和链接 3. 实现watchXConnection()方法,使用XCB建立连接并通过QSocketNotifier监控 文件描述符 4. 当检测到X连接错误时,会话自动触发登出以清理资源 5. 仅在X11显示环境下激活,Wayland环境下不启用 此修复解决了X服务器崩溃或意外断开连接时,会话管理器在没有显示服务器的情 况下继续运行的问题。 PMS: BUG-353461
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideImplements X11 connection monitoring in the session manager using libxcb and QSocketNotifier so that when the X server disconnects, the session manager detects the error and triggers a logout, with corresponding build system and packaging updates for the new XCB dependency. Sequence diagram for X server disconnect triggering session logoutsequenceDiagram
participant SessionManager
participant XCBConnection
participant QSocketNotifier
participant XServer
SessionManager->>SessionManager: init()
alt not Utils_IS_WAYLAND_DISPLAY
SessionManager->>SessionManager: watchXConnection()
SessionManager->>XCBConnection: xcb_connect()
XCBConnection-->>SessionManager: connection handle and fd
SessionManager->>QSocketNotifier: create with fd and Read
SessionManager->>QSocketNotifier: connect activated signal
end
XServer--x XCBConnection: disconnect or crash
XCBConnection-->>QSocketNotifier: fd becomes readable
QSocketNotifier-->>SessionManager: activated(fd, Read)
SessionManager->>XCBConnection: xcb_poll_for_event() loop
SessionManager->>XCBConnection: xcb_connection_has_error()
alt connection has error
SessionManager->>QSocketNotifier: setEnabled(false)
SessionManager->>XCBConnection: xcb_disconnect()
SessionManager->>SessionManager: doLogout()
else no error
SessionManager-->>QSocketNotifier: continue monitoring
end
Updated class diagram for SessionManager with X connection monitoringclassDiagram
class SessionManager {
+init() void
+watchXConnection() void
+handleOSSignal() void
+shutdown(bool force) void
+reboot(bool force) void
+setDPMSMode(bool on) void
+doLogout() void
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码主要实现了在非 Wayland 环境下监听 X Server 连接状态的功能,当 X Server 连接断开时触发登出操作。以下是对该代码的详细审查和改进建议: 1. 语法与逻辑审查
2. 代码质量与规范
3. 代码性能
4. 代码安全
5. 改进后的代码建议针对上述提到的安全风险(主要是 void SessionManager::watchXConnection()
{
xcb_connection_t *conn = xcb_connect(nullptr, nullptr);
if (xcb_connection_has_error(conn) || !conn) {
qWarning() << "watchXConnection: failed to connect to X server";
if (conn) xcb_disconnect(conn);
return;
}
int fd = xcb_get_file_descriptor(conn);
auto *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
// 使用 trackConnection 确保在 lambda 中安全捕获
// 使用 QPointer 防止悬垂指针(虽然 notifier 父对象是 this,但为了更严谨的代码习惯)
QPointer<QSocketNotifier> safeNotifier = notifier;
connect(notifier, &QSocketNotifier::activated, this, [=]() {
// 如果 notifier 已经被标记为删除或无效,直接返回
if (!safeNotifier) return;
// 排空所有待处理事件
xcb_generic_event_t *ev;
while ((ev = xcb_poll_for_event(conn)) != nullptr) {
free(ev);
}
// 若连接已断开则触发登出
if (xcb_connection_has_error(conn)) {
qWarning() << "X connection closed, logging out";
// 立即禁用 notifier 防止重复触发
if (safeNotifier) {
safeNotifier->setEnabled(false);
safeNotifier->deleteLater(); // 安全地标记删除
}
xcb_disconnect(conn);
doLogout();
}
});
}总结这段代码整体质量不错,逻辑清晰,能够解决检测 X Server 断开的问题。主要需要改进的地方是在错误处理路径上加强对 |
Added XCB dependency and implemented X server connection monitoring to detect when the X server disconnects. This ensures the session properly logs out when the X server connection is lost, preventing orphaned sessions.
This fix addresses cases where X server crashes or disconnects unexpectedly, leaving the session manager running without a display server.
fix: 添加X连接监控以实现会话登出
添加XCB依赖并实现X服务器连接监控,以检测X服务器断开连接的情况。这确保当X
服务器连接丢失时会话能正确登出,防止出现孤儿会话。
此修复解决了X服务器崩溃或意外断开连接时,会话管理器在没有显示服务器的情
况下继续运行的问题。
PMS: BUG-353461
Summary by Sourcery
Monitor the X server connection in the session manager and trigger logout when the X connection is lost on X11 displays.
Bug Fixes:
Enhancements:
Build: