fix: allow treeland to start without any users - #1151
Draft
Groveer wants to merge 1 commit into
Draft
Conversation
1. session.cpp: fall back to getpwuid(getuid()) on getpwnam failure 2. usermodel.cpp: guard empty user list before .first() to avoid UB 3. usermodel.cpp: replace qFatal with qCWarning for D-Bus graceful fallback 4. treeland.cpp: replace Q_ASSERT(globalSession) with runtime null check Log: treeland can now start normally even when no users exist Influence: 1. Test treeland startup with no system users (empty /etc/passwd user list) 2. Test treeland startup when Accounts D-Bus service is unavailable 3. Verify treeland startup with normal user presence is unaffected 4. Test user switching and session management in edge-case scenarios fix: 允许 treeland 在没有任何用户时正常启动 1. session.cpp: getpwnam 失败时回退到 getpwuid 确保全局会话可用 2. usermodel.cpp: 调用 .first() 前增加空列表守卫避免未定义行为 3. usermodel.cpp: qFatal 替换为 qCWarning 实现 D-Bus 优雅降级 4. treeland.cpp: Q_ASSERT 替换为运行时空指针检查 Log: treeland 现在可以在没有任何用户的情况下正常启动 Influence: 1. 测试在无系统用户时启动 treeland 不会崩溃 2. 测试 Accounts D-Bus 服务不可用时 treeland 启动正常 3. 验证正常用户场景下 treeland 启动不受影响 4. 测试边界场景下的用户切换与会话管理功能 Fixes: linuxdeepin#82
Groveer
marked this pull request as draft
July 15, 2026 08:25
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Groveer 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 GuideEnsures Treeland and its greeter start gracefully when no system users or the expected "dde" user exist by adding runtime fallbacks and null/empty checks, and by downgrading fatal errors to logged warnings where appropriate. Sequence diagram for Treeland startup and session fallbacksequenceDiagram
participant Treeland
participant Helper
participant SessionManager
participant passwd_db
Treeland->>Helper: helper
Helper->>SessionManager: globalSession()
SessionManager->>passwd_db: getpwnam(username)
alt passwd entry found
passwd_db-->>SessionManager: passwd
SessionManager-->>Helper: Session
else passwd entry missing
passwd_db-->>SessionManager: null
SessionManager->>passwd_db: getpwuid(getuid())
alt current user passwd found
passwd_db-->>SessionManager: passwd
SessionManager-->>Helper: Session
else current user passwd missing
passwd_db-->>SessionManager: null
SessionManager-->>Helper: nullptr
end
end
Helper-->>Treeland: globalSession
alt globalSession is null
Treeland->>Treeland: qCCritical(lcTlCore)
Treeland->>Treeland: return
else globalSession valid
Treeland->>Treeland: proceed initialization
end
Sequence diagram for UserModel initialization with empty or failing user listsequenceDiagram
participant UserModel
participant AccountsManager as Manager
UserModel->>Manager: userList()
alt userList has error
Manager-->>UserModel: error
UserModel->>UserModel: qCWarning(lcTlGreeter)
UserModel->>UserModel: return
else userList ok
Manager-->>UserModel: uids
UserModel->>UserModel: populate d->users
alt currentUserName is empty
alt d->users is empty
UserModel->>UserModel: qCWarning(lcTlGreeter)
else d->users not empty
UserModel->>UserModel: qCWarning(lcTlGreeter)
UserModel->>UserModel: d->currentUserName = d->users.first()->userName()
end
else currentUserName set
UserModel->>UserModel: keep currentUserName
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
SessionManager::ensureSession, falling back from the requestedusernametogetuid()may be surprising; consider logging the original username and/or propagating a distinct error or status so callers can distinguish between “requested user not found” and “fallback to current user.” - The early
returninTreeland::TreelandwhenglobalSessionis null leaves a partially initialized object; consider moving the check to a factory or init method that can fail explicitly rather than returning from the constructor, or set an explicit "invalid" state that callers can query. - When
UserModelreturns early due to a failure inuserList(), ensure all dependent code paths can handle an emptyd->usersandd->currentUserNamegracefully; if needed, add a simple validity flag or getter to make this state explicit to consumers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `SessionManager::ensureSession`, falling back from the requested `username` to `getuid()` may be surprising; consider logging the original username and/or propagating a distinct error or status so callers can distinguish between “requested user not found” and “fallback to current user.”
- The early `return` in `Treeland::Treeland` when `globalSession` is null leaves a partially initialized object; consider moving the check to a factory or init method that can fail explicitly rather than returning from the constructor, or set an explicit "invalid" state that callers can query.
- When `UserModel` returns early due to a failure in `userList()`, ensure all dependent code paths can handle an empty `d->users` and `d->currentUserName` gracefully; if needed, add a simple validity flag or getter to make this state explicit to consumers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
TAG Bot New tag: 0.8.15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix treeland crash when no system users exist. The compositor previously assumed the "dde" user always exists and would crash via assertion, undefined behavior, or qFatal. This PR ensures treeland can start gracefully in the absence of users.
Changes
getpwuid(getuid())whengetpwnam("dde")fails inensureSession, ensuringglobalSession()is never null.first()to avoid undefined behaviorqFatalwithqCWarning+ early return for graceful D-Bus degradation (Accounts service unavailable)Q_ASSERT(globalSession)with a runtime null checkRelated: WM-82
Summary by Sourcery
Ensure Treeland starts and degrades gracefully when no system users or global session are available.
Bug Fixes: