fix(service): improve service lifecycle management with D-Bus based detection#207
Conversation
There was a problem hiding this comment.
Sorry @wangrong1069, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Note
详情{
"application/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
"line_number": 80,
"rule": "S35",
"reason": "Url link | c08ef69076"
}
]
} |
…etection Replace pidof-based process detection with D-Bus GetNameOwner for more reliable service startup detection. Add authorization check to Quit() method and implement a graceful shutdown by calling the Quit() method. 使用 D-Bus GetNameOwner 替代 pidof 进行服务启动检测,提高可靠性。 为 Quit 方法添加鉴权检查,并通过调用 Quit 方法来实现优雅关闭。 Log: 改进服务生命周期管理,使用D-Bus检测替代pidof PMS: BUG-364093 Influence: 服务启动检测更可靠,避免竞态问题;Quit 接口增加鉴权防止未授权调用。
|
Note
详情{
"application/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
"line_number": 80,
"rule": "S35",
"reason": "Url link | c08ef69076"
}
]
} |
deepin pr auto review★ 总体评分:60分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // application/main.cpp:增加超时机制防止死循环
// 启动服务后,循环查询后台服务是否已经启动
const int maxWaitMs = 5000;
const int pollIntervalMs = 300;
for (int elapsed = 0; elapsed < maxWaitMs; elapsed += pollIntervalMs) {
QDBusReply<QString> newReply = dbusInterface.call("GetNameOwner", serviceName);
if (newReply.isValid()) {
const QString newDbusOwner = newReply.value();
if (!newDbusOwner.isEmpty() && newDbusOwner != oldDbusOwner) {
break;
}
}
QThread::msleep(pollIntervalMs);
}
// service/diskmanagerservice.cpp:拆分退出接口,内部退出无需鉴权
void DiskManagerService::Quit()
{
if (!checkAuthorization())
return;
qDebug() << "DiskManagerService::Quit called by external client";
gracefulExit();
}
void DiskManagerService::InternalQuit()
{
qDebug() << "DiskManagerService::InternalQuit called by new instance";
gracefulExit();
}
void DiskManagerService::gracefulExit()
{
m_partedcore->delTempMountFile();
QCoreApplication::exit(0);
}
// service/main.cpp:调用无需鉴权的内部退出接口,并替换 usleep
static bool stopExistingService(QDBusConnection &systemBus)
{
QDBusInterface existingService(DiskManagerServiceName, DiskManagerPath, DiskManagerServiceName, systemBus);
if (!existingService.isValid()) {
qWarning() << "Cannot access existing service via D-Bus interface,"
<< "service may have already exited, retry registration";
return true;
}
qDebug() << "Calling InternalQuit() on existing service...";
QDBusPendingCall pendingCall = existingService.asyncCall("InternalQuit");
pendingCall.waitForFinished();
if (pendingCall.isError()) {
qWarning() << "InternalQuit() call failed:" << pendingCall.error().message();
return false;
}
qDebug() << "InternalQuit() called successfully, waiting for service to exit...";
const int maxWaitMs = 3000;
const int pollIntervalMs = 200;
for (int elapsed = 0; elapsed < maxWaitMs; elapsed += pollIntervalMs) {
QThread::msleep(pollIntervalMs); // 替换 usleep
if (systemBus.registerService(DiskManagerServiceName)) {
systemBus.unregisterService(DiskManagerServiceName);
qDebug() << "Service name released after" << (elapsed + pollIntervalMs) << "ms";
return true;
}
}
qWarning() << "Timed out waiting for existing service to exit";
return false;
} |
1.语法逻辑(存在错误) 4.代码安全(存在 1 个安全漏洞) |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, wangrong1069 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 |
|
/merge |
Summary
Related