fix: handle failure in resolving executable path for process ID#494
Merged
max-lvs merged 1 commit intolinuxdeepin:release/eaglefrom Feb 11, 2026
Merged
fix: handle failure in resolving executable path for process ID#494max-lvs merged 1 commit intolinuxdeepin:release/eaglefrom
max-lvs merged 1 commit intolinuxdeepin:release/eaglefrom
Conversation
2e759d4 to
75a3d36
Compare
- Added error handling for the case when the executable path cannot be resolved from the /proc/{pid}/exe symlink.
- Log a warning message when the resolution fails, improving debugging capabilities.
Log: Enhance robustness in process ID executable path resolution.
75a3d36 to
a2b0fb9
Compare
max-lvs
approved these changes
Feb 11, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, max-lvs 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 |
deepin pr auto review这段代码修改主要针对 1. 语法逻辑审查结果:通过
2. 代码质量审查结果:良好,有优化空间
3. 代码性能审查结果:影响极小
4. 代码安全审查结果:显著提升
综合改进建议代码结合上述分析,建议代码可以进一步优化如下,利用 Qt 特性简化代码并增强安全性: #include <QByteArray>
#include <QDebug>
static QString getProcIdExe(qint64 id)
{
QString execName;
if (id > 0) {
// Read contents of virtual /proc/{pid}/exe file
QString exeSymlinkPath = QString("/proc/%1/exe").arg(id);
// 使用 QByteArray 自动管理内存,避免手动 free
// 注意:realpath 需要 char*,QByteArray 数据是可写的
QByteArray buffer(PATH_MAX, 0); // 预分配 PATH_MAX 大小
// 使用 buffer.data() 作为接收缓冲区,避免 malloc/free
if (realpath(exeSymlinkPath.toLocal8Bit().constData(), buffer.data())) {
execName = QString(buffer);
} else {
// 记录错误,包含 errno 可以更好地诊断原因(如权限不足、文件不存在等)
qWarning() << "Failed to resolve path for PID" << id << ", error:" << strerror(errno);
}
}
return execName;
}优化点说明:
|
Author
|
/merge |
Contributor
|
This pr cannot be merged! (status: unstable) |
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.
Log: Enhance robustness in process ID executable path resolution.