Skip to content

fix(power): respect shutdown inhibitors - #164

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:task/x11power
Sep 7, 2026
Merged

fix(power): respect shutdown inhibitors#164
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:task/x11power

Conversation

@mhduiy

@mhduiy mhduiy commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

修复定时关机绕过关机强阻塞的问题。

  • 定时关机前检查 logind shutdown block inhibitor
  • 存在强阻塞时打开 ShutdownFront,提示具体阻塞程序
  • 无强阻塞时继续直接关机

PMS: BUG-375851

Summary by Sourcery

Bug Fixes:

  • Ensure scheduled shutdowns respect logind shutdown-blocking inhibitors and present the shutdown front when a blocking application prevents shutdown.

1. Check logind block inhibitors before scheduled shutdown.
2. Open ShutdownFront when an application blocks shutdown.

Log: Prevent scheduled shutdown from bypassing block inhibitors.
Influence: Blocking applications are shown instead of logout.

fix(power): 遵循关机强阻塞

1. 定时关机前检查 logind 强阻塞项。
2. 存在程序阻止关机时打开 ShutdownFront 提示界面。

Log: 防止定时关机绕过应用程序的关机强阻塞。
PMS: BUG-375851
Influence: 显示阻塞程序,不再异常进入登录界面。
Change-Id: I5de0f44647bb121cd91ebb5535e675fe2b53b4f2
@sourcery-ai

sourcery-ai Bot commented Sep 7, 2026

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

Reviewer's Guide

Scheduled shutdowns now check for shutdown block inhibitors, presenting the shutdown UI with the blocking program when necessary while retaining direct shutdown behavior when no inhibitor exists.

Sequence diagram for inhibitor-aware scheduled shutdown

sequenceDiagram
    participant Timer as ScheduledShutdown
    participant PowerManager
    participant Logind as ShutdownInhibitors
    participant ShutdownFront
    participant System as PowerSystem

    Timer->>PowerManager: doAutoShutdown()
    PowerManager->>Logind: isInConfigOrPowerButtonInhibitors(shutdown, who)
    alt shutdown inhibitor exists
        Logind-->>PowerManager: true, who
        PowerManager->>ShutdownFront: requestShutdownByFront()
    else no shutdown inhibitor
        Logind-->>PowerManager: false
        PowerManager->>System: requestShutdown()
    end
Loading

File-Level Changes

Change Details Files
Make scheduled shutdown honor logind shutdown block inhibitors before choosing the shutdown path.
  • Check configured and power-button shutdown inhibitors and capture the blocking program.
  • Log the blocker and invoke the shutdown front-end when blocked so the user receives a specific explanation.
  • Preserve the direct shutdown request when no strong inhibitor is present.
src/plugin-qt/power/session/powermanager.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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 99 分,大于 70 分通过阈值。本次提交修复了定时关机绕过关机强阻塞的 Bug,代码实现与现有 doSuspend/doShutdown/doHibernate 函数中的 inhibitor 检查模式一致,逻辑正确,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。doAutoShutdown() 函数在调用 closeNotify() 后,先通过 isInConfigOrPowerButtonInhibitors 检查是否存在关机强阻塞项,若存在则调用 requestShutdownByFront() 弹出前端提示界面,否则调用 requestShutdown() 直接关机。逻辑与 doSuspend()、doShutdown()、doHibernate() 中的 inhibitor 检查模式一致。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

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

建议: 代码结构与现有模式一致,可读性好。建议在 doAutoShutdown() 中添加简要注释说明为何使用 blockOnly 默认值 true(仅检查强阻塞),与 doShutdown() 的 blockOnly=false 区分。closeNotify() 在 inhibitor 检查前调用是合理的,因为 requestShutdownByFront() 会展示自己的 UI 界面。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理。isInConfigOrPowerButtonInhibitors() 通过 D-Bus 获取 inhibitor 列表,这是必要的一次性调用,与 doSuspend()、doHibernate() 中的使用方式一致,无性能瓶颈。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在0个安全漏洞,安全合规。who 变量来源于 D-Bus 返回的 inhibitor 信息,仅用于日志输出,不存在注入风险。代码使用 Qt QString 安全处理字符串,无缓冲区溢出风险。


💡 改进建议代码示例

// 建议在 doAutoShutdown() 中添加注释说明 blockOnly 差异
void PowerManager::doAutoShutdown()
{
    qInfo(logPowerSession) << "Performing auto shutdown";
    closeNotify();

    QString who;
    // 仅检查 block 模式的强阻塞(与 doShutdown 的 blockOnly=false 不同,
    // 定时关机不需要响应 delay 模式的延迟阻塞)
    if (isInConfigOrPowerButtonInhibitors(QStringLiteral("shutdown"), who)) {
        qInfo(logPowerSession) << "Scheduled shutdown blocked by" << who;
        m_proxy->requestShutdownByFront();
    } else {
        m_proxy->requestShutdown();
    }
}

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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

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

@mhduiy

mhduiy commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 3e12e8a into linuxdeepin:master Sep 7, 2026
6 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