Skip to content

Commit 2a1c3fe

Browse files
dengzhongyuan365-devlzwind
authored andcommitted
fix: handle failure in resolving executable path for process ID
- 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.
1 parent a64e259 commit 2a1c3fe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

deepin-system-monitor-system-server/src/systemdbusserver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ static QString getProcIdExe(qint64 id)
6464
// Read contents of virtual /proc/{pid}/cmdline file
6565
QString exeSymlinkPath = QString("/proc/%1/exe").arg(id);
6666
char *actualpath = realpath(exeSymlinkPath.toStdString().c_str(), nullptr);
67-
execName = QString(actualpath);
68-
free(actualpath); // free the memory allocated by realpath
67+
if (actualpath) {
68+
execName = QString(actualpath);
69+
free(actualpath); // free the memory allocated by realpath
70+
} else {
71+
qCWarning(app) << "Failed to resolve path for PID" << id;
72+
}
6973
}
7074
qCDebug(app) << "Executable for PID" << id << "is:" << execName;
7175
return execName;

0 commit comments

Comments
 (0)