Skip to content

fix(treeland): activate session before unlocking#103

Draft
zorowk wants to merge 1 commit into
linuxdeepin:masterfrom
zorowk:fix_346587
Draft

fix(treeland): activate session before unlocking#103
zorowk wants to merge 1 commit into
linuxdeepin:masterfrom
zorowk:fix_346587

Conversation

@zorowk

@zorowk zorowk commented Jul 9, 2026

Copy link
Copy Markdown

Treeland 解锁已有用户 session 时,原流程先调用UnlockSession(sessionId), 再调用 activateSession(user, sessionId)。这会让 logind Unlock 信号有机 会先于 Treeland activation 到达,使 Treeland 仍按旧 active session判断 unlock 目标,并可能把目标 session 重新锁回去。

本次仅调整 Treeland session 的解锁顺序:先通知 Treeland 激活目标 user 再调用 logind UnlockSession(sessionId)。非 Treeland session 仍保持原来 的 unlock 后切 VT 流程不变,避免影响 X11/Wayland 其它路径
Log: Fix Treeland unlock ordering during user switch PMS: BUG-346587
Influence: Affects DDM Treeland user switching and unlock flow

Summary by Sourcery

Bug Fixes:

  • Prevent Treeland sessions from being relocked during user switching by ensuring activation happens before logind unlock.

Treeland 解锁已有用户 session 时,原流程先调用UnlockSession(sessionId),
再调用 activateSession(user, sessionId)。这会让 logind Unlock 信号有机
会先于 Treeland activation 到达,使 Treeland 仍按旧 active session判断
unlock 目标,并可能把目标 session 重新锁回去。

本次仅调整 Treeland session 的解锁顺序:先通知 Treeland 激活目标 user
再调用 logind UnlockSession(sessionId)。非 Treeland session 仍保持原来
的 unlock 后切 VT 流程不变,避免影响 X11/Wayland 其它路径
Log: Fix Treeland unlock ordering during user switch
PMS: BUG-346587
Influence: Affects DDM Treeland user switching and unlock flow
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zorowk

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the unlock and activation ordering for Treeland sessions so Treeland activates the target user session before logind unlocks it, while preserving the existing VT-switch flow for non-Treeland sessions.

Sequence diagram for updated Treeland vs non-Treeland session unlock ordering

sequenceDiagram
    actor User
    participant Display as DDM_Display
    participant Treeland
    participant Logind
    participant Seatd

    User ->> Display: auth successful
    alt auth->type == Treeland
        Display ->> Treeland: activateSession(user, xdgSessionId)
        Display ->> Logind: UnlockSession(xdgSessionId)
    else auth->type != Treeland
        Display ->> Logind: UnlockSession(xdgSessionId)
        Display ->> Seatd: requestSwitchVt(tty)
    end
Loading

File-Level Changes

Change Details Files
Reordered Treeland session activation and logind unlock calls while maintaining behavior for non-Treeland sessions.
  • For Treeland sessions, call activateSession(user, xdgSessionId) before manager.UnlockSession(xdgSessionId).
  • For non-Treeland sessions, keep the existing flow: unlock the session via logind, then request a VT switch and log a warning on failure.
  • Refactored the conditional logic to separate Treeland and non-Treeland handling using explicit braces and duplicated unlock calls in each branch.
src/daemon/Display.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider extracting QString::number(auth->xdgSessionId) into a local variable and/or consolidating the UnlockSession call to avoid duplication between the Treeland and non-Treeland branches.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting `QString::number(auth->xdgSessionId)` into a local variable and/or consolidating the `UnlockSession` call to avoid duplication between the Treeland and non-Treeland branches.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了会话解锁与激活的时序问题,逻辑清晰且无安全风险
语法逻辑完全正确,代码质量良好,无安全漏洞,不扣分

■ 【详细分析】

  • 1.语法逻辑完全正确✓

修改后的代码在 src/daemon/Display.cpp 第 491-498 行,通过 if-else 分支明确了 Treeland 与非 Treeland 会话的处理逻辑。将 UnlockSessionactivateSession 的调用顺序依据会话类型进行拆分,解决了原逻辑中可能因时序不当导致的会话切换失败问题,分支覆盖完整,无逻辑遗漏。
建议:保持当前逻辑。

  • 2.代码质量良好✓

修改后的代码为 if 和 else 分支添加了大括号 {},相比原代码单行控制流不加括号的写法,显著提升了代码的可读性和可维护性,符合 C++ 编码规范。
建议:保持当前代码风格。

  • 3.代码性能无性能问题✓

代码仅调整了 D-Bus 方法调用和本地函数调用的顺序,未引入额外的系统调用、循环或内存分配,对运行时性能无任何负面影响。
建议:无需优化。

  • 4.代码安全存在0个安全漏洞✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码涉及的 manager.UnlockSession 方法参数由 QString::number(auth->xdgSessionId) 生成,有效防止了字符串注入风险。D-Bus 底层权限由 Logind 策略控制,会话解锁与激活的顺序调整属于业务逻辑修复,未引入权限绕过或信息泄露等安全风险。
建议:无需额外安全加固。

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需修改,此处展示当前最终形态
namespace DDM {
    OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(),
                                                 Logind::managerPath(),
                                                 QDBusConnection::systemBus());
    if (auth->type == Treeland) {
        activateSession(user, auth->xdgSessionId);
        manager.UnlockSession(QString::number(auth->xdgSessionId));
    } else {
        manager.UnlockSession(QString::number(auth->xdgSessionId));
        if (!daemonApp->seatdControl()->requestSwitchVt(auth->tty))
            qWarning() << "Failed to switch to session VT" << auth->tty << "for user" << user;
    }
    qInfo() << "Successfully identified user" << user;
    return;
}

@zorowk zorowk marked this pull request as draft July 9, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants