Skip to content

refactor: use QDBusServiceWatcher to detect frontend exit#201

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wangrong1069:pr0420
Apr 22, 2026
Merged

refactor: use QDBusServiceWatcher to detect frontend exit#201
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wangrong1069:pr0420

Conversation

@wangrong1069
Copy link
Copy Markdown
Contributor

No description provided.

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.

Sorry @wangrong1069, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@github-actions
Copy link
Copy Markdown

  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "service/main.cpp": {
            "b": [
                "    qunsetenv(\"DISPLAY\");"
            ]
        }
    }
}

@github-actions
Copy link
Copy Markdown

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "application/main.cpp": [
        {
            "line": "    const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
            "line_number": 124,
            "rule": "S35",
            "reason": "Url link | c08ef69076"
        }
    ]
}

Replace polling-based frontend exit detection with event-driven
DBus NameOwnerChanged signal monitoring.

Changes:
- Use QDBusServiceWatcher to monitor frontend DBus name unregistration
- Remove QTimer-based /proc/<pid>/exe polling
- Simplify command-line arguments (remove PID, keep DBus name only)

Benefits:
- Event-driven instead of polling, more efficient
- No dependency on Linux-specific /proc filesystem
- More reliable detection via DBus daemon guarantees

Task: https://pms.uniontech.com/task-view-388685.html
@github-actions
Copy link
Copy Markdown

  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "service/main.cpp": {
            "b": [
                "    qunsetenv(\"DISPLAY\");"
            ]
        }
    }
}

@github-actions
Copy link
Copy Markdown

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "application/main.cpp": [
        {
            "line": "    const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
            "line_number": 124,
            "rule": "S35",
            "reason": "Url link | c08ef69076"
        }
    ]
}

@github-actions
Copy link
Copy Markdown

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "application/main.cpp": [
        {
            "line": "    const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
            "line_number": 124,
            "rule": "S35",
            "reason": "Url link | c08ef69076"
        }
    ]
}

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

Git Diff 代码审查

总体评价

这段代码修改将服务进程监控前端进程的方式从基于PID的轮询检查改为基于DBus服务名称的监控。这是一个很好的改进,利用了Qt提供的DBus服务监听机制,避免了轮询带来的资源浪费,并提高了响应速度。

详细分析

1. 语法逻辑

优点:

  • 代码逻辑正确,使用了QDBusServiceWatcher来监听前端服务的注销事件
  • 参数处理逻辑清晰,正确处理了参数数量不足的情况

改进建议:

  • application/main.cpp中,移除了QCoreApplication::applicationPid()参数,但需要确保QDBusConnection::systemBus().baseService()返回的值是有效的
  • service/main.cpp中,建议添加对frontEndDBusName格式的验证,确保它是一个合法的DBus服务名称

2. 代码质量

优点:

  • 删除了不再需要的checkFrontEndQuit函数,简化了代码
  • 使用了Qt提供的信号槽机制替代定时器轮询,代码更符合Qt的设计理念
  • 添加了有意义的日志输出,便于调试

改进建议:

  • service/main.cpp中,建议添加对DBus服务名称的格式验证:
    // 验证DBus服务名称格式
    if (!frontEndDBusName.startsWith("com.") && !frontEndDBusName.startsWith(":")) {
        qCritical() << "Invalid DBus service name format:" << frontEndDBusName;
        return 1;
    }

3. 代码性能

优点:

  • 使用QDBusServiceWatcher替代了每秒一次的轮询检查,减少了不必要的CPU使用
  • 事件驱动的方式使得前端进程退出时能够立即响应,而不是最多等待1秒

改进建议:

  • 无明显性能问题,当前实现已经很好

4. 代码安全

优点:

  • 移除了基于PID的检查,避免了PID重用可能带来的安全问题
  • 使用DBus服务名称作为标识更可靠,因为DBus服务名称是唯一的

改进建议:

  • 建议添加对DBus服务名称的验证,防止潜在的安全问题
  • service/main.cpp中,建议添加对DBus连接错误的处理:
    if (!QDBusConnection::systemBus().isConnected()) {
        qCritical() << "Cannot connect to system DBus";
        return 1;
    }

总结

这是一次很好的代码改进,将基于轮询的监控方式改为基于事件驱动的方式,提高了代码的效率和可靠性。主要建议是添加DBus服务名称的格式验证和DBus连接状态的检查,以提高代码的健壮性。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wangrong1069

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

@wangrong1069
Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot Bot merged commit 2d77e26 into linuxdeepin:master Apr 22, 2026
22 checks passed
@wangrong1069 wangrong1069 deleted the pr0420 branch April 22, 2026 01:51
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