Skip to content

feat: log detailed dbus error messages on failure#205

Open
zzxyb wants to merge 1 commit into
linuxdeepin:masterfrom
zzxyb:dbus
Open

feat: log detailed dbus error messages on failure#205
zzxyb wants to merge 1 commit into
linuxdeepin:masterfrom
zzxyb:dbus

Conversation

@zzxyb
Copy link
Copy Markdown

@zzxyb zzxyb commented May 13, 2026

The current implementation only printed generic warning messages when D-Bus calls failed during session initialization. This made it difficult to diagnose underlying issues like systemd transaction conflicts or permission errors.

Log: Added detailed D-Bus error reporting to improve diagnostic capability

Influence:

  1. Verify that logs now show detailed error strings when D-Bus calls fail

Summary by Sourcery

Improve diagnostic logging for failed D-Bus and systemd operations during session management.

Enhancements:

  • Augment warning logs for systemd environment updates, D-Bus activation environment updates, and lock screen D-Bus queries with detailed error information.
  • Include detailed error output when starting systemd units fails to aid in troubleshooting startup issues.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds detailed D-Bus/systemd error logging for failed QDBus calls to improve diagnosability during session initialization and related operations.

Sequence diagram for detailed D-Bus/systemd error logging on failure

sequenceDiagram
    participant EnvironmentsManager
    participant systemd1_Manager as systemd1_Manager
    participant QDBusPendingReply as QDBusPendingReply

    EnvironmentsManager->>systemd1_Manager: SetEnvironment(envs)
    systemd1_Manager-->>EnvironmentsManager: QDBusPendingReply
    EnvironmentsManager->>QDBusPendingReply: waitForFinished()
    EnvironmentsManager->>QDBusPendingReply: isError()
    alt [replySystemd1 is error]
        EnvironmentsManager->>QDBusPendingReply: error()
        EnvironmentsManager->>EnvironmentsManager: qWarning() with envs and error
    end
Loading

File-Level Changes

Change Details Files
Include QDBus error details in environment update failures
  • Extend warning when setting systemd1 environment variables to log the associated QDBus error object
  • Extend warning when updating D-Bus activation environment during init to log the associated QDBus error object
  • Extend warning when unsetting D-Bus environment variables to include the associated QDBus error object before returning failure
src/dde-session/environmentsmanager.cpp
Include QDBus error details when querying lock screen service over D-Bus
  • Extend warning on GetNameOwner failure for org.deepin.dde.LockFront1 to log the QDBus error object
  • Extend warning on GetConnectionUnixProcessID failure for the lock front service owner to log the QDBus error object
src/dde-session/impl/sessionmanager.cpp
Include QDBus error details when starting systemd units
  • Extend warning on systemd StartUnit failure to log the QDBus error object along with the unit name
src/dde-session/main.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

yixinshark
yixinshark previously approved these changes May 13, 2026
The current implementation only printed generic warning messages when
D-Bus calls failed during session initialization. This made it difficult
to diagnose underlying issues like systemd transaction conflicts or
permission errors.

Log: Added detailed D-Bus error reporting to improve diagnostic capability

Influence:
1. Verify that logs now show detailed error strings when D-Bus calls fail
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zzxyb

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

1 similar comment
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zzxyb

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

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已经仔细审查了你提供的Git Diff输入。本次修改主要包含两大部分:一是更新了版权声明的时间范围(从2023更新至2026),二是为多处D-Bus调用的错误日志补充了具体的错误信息(reply.error())。

整体来看,这次修改的方向是非常好的,显著增强了问题排查时的可读性和信息量。但针对代码的逻辑、性能和安全性,我仍有以下几点改进意见:

1. 语法与逻辑

  • 日志字符串拼接格式微调
    在新增的日志中,出现了 ", error:" 这样的拼接方式,例如:
    qWarning() << "failed to set systemd1 envs: " << envs << ", error:" << replySystemd1.error();
    虽然功能正常,但在Qt的日志流中,直接使用逗号拼接会使日志输出显得有些生硬。建议去掉逗号或调整格式,使其更符合常见的日志阅读习惯:
    // 建议写法 1:去掉逗号
    qWarning() << "failed to set systemd1 envs:" << envs << "error:" << replySystemd1.error();
    // 建议写法 2:使用括号包裹错误信息,更具可读性
    qWarning() << "failed to set systemd1 envs:" << envs << "(error:" << replySystemd1.error() << ")";

2. 代码性能 (严重)

  • 同步阻塞D-Bus调用导致主线程卡顿
    在本次修改涉及的几个地方(以及原有代码中),大量使用了 waitForFinished() 来等待D-Bus异步调用完成:
    QDBusPendingReply<void> replySystemd1 = systemd1.SetEnvironment(envs);
    replySystemd1.waitForFinished(); // 阻塞当前线程
    问题waitForFinished() 会阻塞当前线程直到D-Bus返回结果。如果D-Bus守护进程响应缓慢或挂起,会导致当前线程(如果是主线程则会导致UI冻结)长时间无响应。
    改进建议:强烈建议使用 信号与槽 的异步方式处理D-Bus返回结果,避免阻塞。如果因为业务逻辑必须同步等待,也建议加上超时机制,或者将此类操作移至工作线程中执行。
    // 异步调用示例:
    QDBusPendingCall asyncCall = systemd1.SetEnvironment(envs);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this);
    connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
        QDBusPendingReply<void> reply = *watcher;
        if (reply.isError()) {
            qWarning() << "failed to set systemd1 envs (error:" << reply.error() << ")";
        }
        watcher->deleteLater();
    });

3. 代码安全

  • 版权声明年份的合规性
    修改中将 2021 - 2023 改为了 2021 - 2026
    问题:通常情况下,开源代码的版权结束年份应当是代码首次发布或最后一次修改的自然年份(如2024)。将结束年份提前设定为未来的2026年,在部分开源合规审查中可能会被认为是不准确的时间声明。
    建议:请确认项目组的统一规范。如果规范允许声明未来年份则无妨;否则,建议修改为当前实际年份(如 2021 - 2024)。

  • 环境变量注入与PID获取的潜在风险(针对原有逻辑的延伸建议):

    • EnvironmentsManager 中,直接将 envs 设置到 systemd 和 dbus 中,需确保 envs 的来源已经被严格校验,避免恶意或不当的环境变量导致后续启动的服务行为异常。
    • handleLoginSessionUnlocked 中,通过获取锁屏服务的 PID 来进行后续逻辑,需注意 PID 回收复用的问题(TOCTOU竞态)。虽然锁屏服务生命周期相对稳定,但在安全敏感场景下,直接信任 PID 存在一定的理论风险。

4. 代码质量

  • 错误处理策略的一致性
    handleLoginSessionUnlocked 函数中:
    if (ownerReply.isError()) {
        qWarning() << "failed to get lockFront service owner" << ", error:" << ownerReply.error();
        return; // 直接返回,中断了后续逻辑
    }
    而在 unsetEnv 函数中,失败时返回了 false。建议统一审查整个类的错误处理逻辑,确保关键路径上的D-Bus失败能够有合适的重试机制或向上层抛出明确的状态,而不是仅仅打印日志后静默返回。

总结

本次Diff的核心改动(补充错误日志)是非常值得肯定的,能极大减少排查D-Bus通信故障的时间。但最需要重视的是 waitForFinished() 导致的潜在性能/卡顿问题,建议在后续迭代中逐步重构为异步调用。日志格式的小瑕疵可以顺手修复。

如果你需要我将上述建议直接转换为代码补丁,请告诉我!

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.

3 participants