fix: stop app.slice before logout/shutdown to ensure clean user proce…#204
Open
yixinshark wants to merge 1 commit intolinuxdeepin:masterfrom
Open
fix: stop app.slice before logout/shutdown to ensure clean user proce…#204yixinshark wants to merge 1 commit intolinuxdeepin:masterfrom
yixinshark wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
There was a problem hiding this comment.
Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
…ss termination Send SIGKILL to all processes in app.slice via systemd D-Bus KillUnit before logout and shutdown. Pms: BUG-350165,BUG-350171 Change-Id: Ibba4a31d93f107946af86b4b1e06a96a5ab4d0eb
a1d85ce to
0a3675e
Compare
deepin pr auto review这段代码主要是为了在系统注销和关机流程中,增加对 以下是对该代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的改进建议: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
5. 改进代码示例针对上述提到的 // sessionmanager.cpp
// 修改后的 stopAppSlice,增加优雅退出尝试
void SessionManager::stopAppSlice()
{
const QString unit = APP_SLICE;
// 1. 先尝试发送 SIGTERM (信号 15),允许进程清理
if (!killUnitProcesses(unit, SIGTERM)) {
qWarning() << "Failed to send SIGTERM to" << unit;
// 如果发送 SIGTERM 失败,可能已经不存在了,或者权限问题,直接返回或继续尝试 SIGKILL 视业务需求而定
return;
}
// 2. 等待一小段时间(例如 500ms - 1000ms),让进程退出
// 注意:这里使用了 QThread::sleep,如果是主线程请谨慎使用,最好改用 QEventLoop 或定时器
// 但鉴于这是关机流程,简单的延时可能是可接受的
QThread::msleep(500);
// 3. 检查进程是否还在,或者直接发送 SIGKILL 确保清理
// 这里为了简单起见,直接发送 SIGKILL 确保残留进程被杀死
// 也可以通过 systemd ListUnits 检查状态,但会增加 D-Bus 调用开销
if (!killUnitProcesses(unit, SIGKILL)) {
qWarning() << "Failed to send SIGKILL to" << unit;
}
}
// killUnitProcesses 保持不变,但建议确认头文件包含
// #include <csignal>
bool SessionManager::killUnitProcesses(const QString &unit, int signal)
{
auto reply = m_systemd1ManagerInter->KillUnit(unit, "all", signal);
if (reply.isError()) {
qWarning() << "failed to kill unit:" << unit << "with signal:" << signal
<< ", error:" << reply.error().name();
return false;
}
return true;
}总结这段代码在功能上实现了需求,但在进程终止的优雅性(直接使用 SIGKILL)和版权年份(2026)上存在改进空间。建议增加 SIGTERM 尝试步骤以提高数据安全性,并修正版权年份。同时,请确认 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ss termination
Send SIGKILL to all processes in app.slice via systemd D-Bus KillUnit before logout and shutdown.
Pms: BUG-350165,BUG-350171
Change-Id: Ibba4a31d93f107946af86b4b1e06a96a5ab4d0eb