Repository navigation
fix(daemon): identify active desktop session by UID instead of username - #788
Conversation
Reviewer's GuideThe daemon now identifies and monitors the active desktop session by numeric UID rather than comparing loginctl usernames with the home-directory name, avoiding false inactive-session exits in domain-account environments while keeping startup and runtime checks consistent. Sequence diagram for UID-based active desktop session validationsequenceDiagram
participant Daemon
participant Loginctl
participant OS
Daemon->>Loginctl: list-sessions
Loginctl-->>Daemon: session ID, UID, username, state, desktop
Daemon->>OS: getuid()
OS-->>Daemon: current UID
Daemon->>Daemon: isActiveUser()
alt active session UID equals current UID
Daemon->>Daemon: setProperty(KEY_CURRENT_ACTIVE_USER, activeUid)
Daemon->>Daemon: continue startup
else UID mismatch
Daemon->>Daemon: exit(0)
end
Sequence diagram for runtime active-session UID monitoringsequenceDiagram
participant ServiceManager
participant OS
participant Application
loop every 500 ms
ServiceManager->>OS: getuid()
OS-->>ServiceManager: current UID
ServiceManager->>Application: property(KEY_CURRENT_ACTIVE_USER)
Application-->>ServiceManager: active session UID
alt active UID differs from current UID
ServiceManager->>ServiceManager: stop timer
ServiceManager->>Application: exit(0)
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/apps/daemon/main.cpp" line_range="150-155" />
<code_context>
- qApp->setProperty(KEY_CURRENT_ACTIVE_USER, username);
- qCritical() << "active session user:" << username << " current user:" << curUser;
+ // 域账号场景下会话用户名与家目录名可能不一致(如 "@xxx"),改用 UID 比对判定活动会话
+ QString curUid = QString::number(getuid());
+ qApp->setProperty(KEY_CURRENT_ACTIVE_USER, activeUid);
+ qCritical() << "active session user:" << username << " active uid:" << activeUid << " current uid:" << curUid;
</code_context>
<issue_to_address>
**issue (bug_risk):** Windows builds fail to compile because `getuid()` is compiled after the `_WIN32` early return, while `<unistd.h>` is excluded on Windows; a runtime `return` does not remove the later code from compilation.
**Triggers:** When building the daemon on Windows.
**Suggested fix:** Guard the UID-based code with the same platform condition as the `getuid()` declaration, or provide a Windows-specific UID implementation.
```suggestion
// 域账号场景下会话用户名与家目录名可能不一致(如 "@xxx"),改用 UID 比对判定活动会话
#ifndef _WIN32
QString curUid = QString::number(getuid());
qApp->setProperty(KEY_CURRENT_ACTIVE_USER, activeUid);
qCritical() << "active session user:" << username << " active uid:" << activeUid << " current uid:" << curUid;
return (activeUid == curUid);
#endif
```
</issue_to_address>
### Comment 2
<location path="src/apps/daemon/main.cpp" line_range="144-147" />
<code_context>
// 判断用户状态和桌面状态
if (isActive && isDesktopActive) {
username = sessions.take(session);
+ activeUid = sessionUids.value(session);
}
}
</code_context>
<issue_to_address>
**issue (bug_risk):** When multiple desktop sessions are simultaneously active, each matching session overwrites `activeUid`, so a later active session with a different UID can replace the current user's matching UID and cause `isActiveUser()` to return false.
**Triggers:** When multiple seats or otherwise multiple active desktop sessions exist and the current user's session is not the last one in `QMap` key order.
**Suggested fix:** Evaluate each active desktop session UID against `getuid()` directly, or retain a matching UID instead of unconditionally overwriting `activeUid`.
```suggestion
if (isActive && isDesktopActive) {
if (sessionUids.value(session) == QString::number(getuid())) {
username = sessions.take(session);
activeUid = sessionUids.value(session);
}
}
```
</issue_to_address>370b723 to
ae02d4c
Compare
|
I have read the CLA Document and I hereby sign the CLA. |
- In domain-account environments the loginctl session username may differ from the home directory name (e.g. "@xxx"), and the name comparison failed, making the daemon exit right after startup (inactive desktop session) - isActiveUser() now compares the active desktop session UID against getuid(), decoupled from the user naming scheme; when multiple desktop sessions are active, only the one belonging to the current user is taken as the active session - KEY_CURRENT_ACTIVE_USER now stores the active session UID and the ServiceManager runtime check compares UIDs accordingly - Guard the loginctl/getuid() based session check with _WIN32 so the daemon still compiles on Windows, where the check is not applicable - Update SPDX copyright year to 2023-2026 for the modified files 修复(daemon): 改用 UID 而非用户名判定活动桌面会话 - 域账号场景下 loginctl 会话用户名与家目录名可能不一致(如 "@xxx"), 名字比对失败导致 daemon 启动即退出(exit, inactive desktop session) - isActiveUser 改为比对活动桌面会话 UID 与 getuid(), 与命名体系解耦; 存在多个活跃桌面会话时, 以属于当前用户的会话为准 - KEY_CURRENT_ACTIVE_USER 改存活动会话 UID, ServiceManager 运行时检查同步按 UID 判定 - 活动会话检查增加 _WIN32 平台守卫, 修复 Windows 构建下 getuid() 编译失败的问题 - 更新所改文件的 SPDX 版权年份为 2023-2026 Log: 修复域账号环境下跨端协同 daemon 无法启动的问题
ae02d4c to
eb3bed1
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码语法正确,逻辑清晰。getuid() 通过 #ifndef _WIN32 条件编译正确保护,#include <unistd.h> 头文件引入位置正确。isActiveUser() 函数中新增 sessionUids 映射表和 curUid 变量,与现有 sessions 映射表逻辑一致。条件判断逻辑正确,确保多用户场景下仅匹配当前 UID 的活跃桌面会话。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 1.建议将 #ifndef _WIN32 改为 #else 与 #ifdef _WIN32 配对使用 2.考虑将 username 变量内联到日志语句中 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: getuid() 是轻量级系统调用,性能影响可忽略。新增 sessionUids 映射表内存开销极小。无性能瓶颈。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 1.安全扫描工具误报 main.cpp:223 行 app.exec() 为 RCE,经审计确认为 Qt 事件循环,非远程代码执行 2.getuid() 返回内核控制 UID,不可伪造,比用户名比对更安全 3.QProcess::start() 不使用 shell,不存在命令注入风险 💡 改进建议代码示例// 建议: 使用 #else 替代 #ifndef _WIN32
bool isActiveUser()
{
#ifdef _WIN32
return "admin";
#else
QString username = "";
QString activeUid = "";
// ... 原有逻辑 ...
return (activeUid == curUid);
#endif
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pppanghu77, re2zero 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 |
|
/forcemerge |
问题 / Problem
域账号环境下 dde-cooperation-daemon 启动即退出,日志报
exit, inactive desktop session,跨端协同功能不可用。域账号场景下 loginctl 会话用户名与家目录名可能不一致(如会话用户
TM189295、家目录@TM189295),原实现将两者做字符串比对,比对失败即误判为非活动桌面会话。修复 / Fix
参照 0.8.9 版本包的实现思路,改用 UID 判定活动会话:
isActiveUser()解析loginctl list-sessions时同时记录会话 UID,最终以「活动会话 UID == getuid()」判定,与用户命名体系解耦;KEY_CURRENT_ACTIVE_USER属性改存活动会话 UID,日志同步输出active uid/current uid;ServiceManager运行时活动用户检查同步改为 UID 比对,保持语义一致。自测 / Test
ut005189、家目录/home/ut005189@uos不一致场景)运行新 daemon,判定通过并完整启动;Summary by Sourcery
Identify the active desktop session by the current process UID instead of comparing session and home-directory usernames.
Bug Fixes:
Enhancements: