Skip to content

fix: honour logind block inhibitors for power actions - #121

Merged
zccrs merged 1 commit into
linuxdeepin:masterfrom
Groveer:master
Nov 12, 2026
Merged

zccrs merged 1 commit into
linuxdeepin:masterfrom
Groveer:master

Conversation

@Groveer

@Groveer Groveer commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor
  1. ddm runs as root and called the old Suspend(bool)-style logind
  2. methods, which only set SD_LOGIND_INTERACTIVE, so logind let root
  3. ignore block inhibitors and a file copy task in a Treeland session
  4. could still be suspended from the lock screen shutdown menu
  5. Call the *WithFlags variants with SD_LOGIND_ROOT_CHECK_INHIBITORS so
  6. logind enforces the inhibitors for root as well, and log a warning
  7. when the request is refused

Log: Power actions from the lock screen now honour app block inhibitors

Influence:

  1. Start a large copy in dde-file-manager, then choose Suspend from the shutdown menu; the system must stay awake and ddm must log a warning
  2. Without any inhibitor, verify Suspend, Hibernate, Power Off and Reboot still work from the lock screen
  3. Verify power actions from the greeter before login still work, and a ConsoleKit2 build keeps the old logind call

fix: 电源操作不再绕过 logind 的待机/关机抑制

  1. ddm 以 root 运行且调用旧式 Suspend(bool) 系列 logind 接口,该接口只 设置 SD_LOGIND_INTERACTIVE,logind 因此允许 root 忽略 block inhibitor,Treeland 会话中有拷贝任务时仍能从关机菜单待机
  2. 改用 *WithFlags 系列接口并传入 SD_LOGIND_ROOT_CHECK_INHIBITORS,由 logind 对 root 一并校验抑制,被拒时记录告警日志

Log: 关机菜单发起的待机、关机等电源操作现在会遵守应用的待机抑制

Influence:

  1. 用文件管理器拷贝大文件,再从关机菜单点待机,系统应保持唤醒且 ddm 日志中出现告警
  2. 无任何抑制时,锁屏下待机、休眠、关机、重启均正常工作
  3. 登录界面(greeter)下的电源操作正常,ConsoleKit2 环境仍走旧接口

PMS: BUG-380947

Summary by Sourcery

Honor logind power-action inhibitors for root-initiated operations from the lock screen.

Bug Fixes:

  • Ensure lock-screen power actions respect logind block inhibitors even when requested by the root-running daemon.
  • Log a warning when logind refuses a power action due to an inhibitor.

Enhancements:

  • Preserve the existing ConsoleKit2 power-action behavior while using inhibitor-aware logind operations where supported.

@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Route logind power actions through the inhibitor-aware WithFlags methods while preserving the existing ConsoleKit2 calls, and log refused requests.

  • src/daemon/PowerManager.cpp L174-213

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/daemon/PowerManager.cpp" line_range="207" />
<code_context>
+            }
+
+            constexpr qint64 rootCheckInhibitors = 1; // SD_LOGIND_ROOT_CHECK_INHIBITORS
+            auto reply = m_interface->call(flagsMethod, rootCheckInhibitors);
+            if (reply.type() == QDBusMessage::ErrorMessage)
+                qWarning() << flagsMethod << "refused:" << reply.errorMessage();
</code_context>
<issue_to_address>
**Power actions are rejected**

When the logind backend handles a power action, `callWithInhibitCheck` sends only a signed `qint64` instead of the required interactive boolean and unsigned 64-bit flags argument, so logind rejects the request and the power action does not happen.

Pass the interactive boolean and flags value with the D-Bus types required by logind’s `*WithFlags` methods.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

}

constexpr qint64 rootCheckInhibitors = 1; // SD_LOGIND_ROOT_CHECK_INHIBITORS
auto reply = m_interface->call(flagsMethod, rootCheckInhibitors);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Power actions are rejected

When the logind backend handles a power action, callWithInhibitCheck sends only a signed qint64 instead of the required interactive boolean and unsigned 64-bit flags argument, so logind rejects the request and the power action does not happen.

Pass the interactive boolean and flags value with the D-Bus types required by logind’s *WithFlags methods.

Prompt for AI agents
In `src/daemon/PowerManager.cpp` at line 207:

**Power actions are rejected**

When the logind backend handles a power action, `callWithInhibitCheck` sends only a signed `qint64` instead of the required interactive boolean and unsigned 64-bit flags argument, so logind rejects the request and the power action does not happen.

Pass the interactive boolean and flags value with the D-Bus types required by logind’s `*WithFlags` methods.

1. ddm runs as root and called the old Suspend(bool)-style logind
2. methods, which only set SD_LOGIND_INTERACTIVE, so logind let root
3. ignore block inhibitors and a file copy task in a Treeland session
4. could still be suspended from the lock screen shutdown menu
5. Call the *WithFlags variants with SD_LOGIND_ROOT_CHECK_INHIBITORS so
6. logind enforces the inhibitors for root as well, and log a warning
7. when the request is refused

Log: Power actions from the lock screen now honour app block inhibitors

Influence:
1. Start a large copy in dde-file-manager, then choose Suspend from the
   shutdown menu; the system must stay awake and ddm must log a warning
2. Without any inhibitor, verify Suspend, Hibernate, Power Off and Reboot
   still work from the lock screen
3. Verify power actions from the greeter before login still work, and a
   ConsoleKit2 build keeps the old logind call

fix: 电源操作不再绕过 logind 的待机/关机抑制

1. ddm 以 root 运行且调用旧式 Suspend(bool) 系列 logind 接口,该接口只
   设置 SD_LOGIND_INTERACTIVE,logind 因此允许 root 忽略 block
   inhibitor,Treeland 会话中有拷贝任务时仍能从关机菜单待机
2. 改用 *WithFlags 系列接口并传入 SD_LOGIND_ROOT_CHECK_INHIBITORS,由
   logind 对 root 一并校验抑制,被拒时记录告警日志

Log: 关机菜单发起的待机、关机等电源操作现在会遵守应用的待机抑制

Influence:
1. 用文件管理器拷贝大文件,再从关机菜单点待机,系统应保持唤醒且 ddm
   日志中出现告警
2. 无任何抑制时,锁屏下待机、休眠、关机、重启均正常工作
3. 登录界面(greeter)下的电源操作正常,ConsoleKit2 环境仍走旧接口

PMS: BUG-380947
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次变更修复了电源管理操作(关机/重启/挂起/休眠/混合睡眠)未遵守 logind block inhibitors 的问题,通过新增 callWithInhibitCheck 辅助方法,在 systemd-logind 接口下使用 *WithFlags 变体并设置 SD_LOGIND_ROOT_CHECK_INHIBITORS 标志,使 root 权限的调用者也受 block inhibitor 约束。四维度分析均通过,未发现安全漏洞,代码逻辑正确、注释详尽、结构清晰、性能无影响。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['可考虑在 *WithFlags 调用失败时回退到 plainMethod 调用作为兜底,以增强对旧版 systemd 的兼容性;但需确保回退路径不会重新引入忽略 inhibitor 的原始问题。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 可选增强:在 *WithFlags 调用失败时提供回退路径
void callWithInhibitCheck(const QString &plainMethod, const QString &flagsMethod) const {
    if (m_interface->interface() != LOGIN1_OBJECT) {
        m_interface->call(plainMethod, true);
        return;
    }

    constexpr qint64 rootCheckInhibitors = 1; // SD_LOGIND_ROOT_CHECK_INHIBITORS
    auto reply = m_interface->call(flagsMethod, rootCheckInhibitors);
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qWarning() << flagsMethod << "refused:" << reply.errorMessage();
        // 可选:回退到旧方法(注意可能重新引入忽略 inhibitor 的问题)
        // m_interface->call(plainMethod, true);
    }
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Groveer, zccrs

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

@zccrs
zccrs merged commit f5181ff into linuxdeepin:master Nov 12, 2026
6 of 7 checks passed
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