Skip to content

Commit

Permalink
Simplify findCommInCmdline() logic in Process.c
Browse files Browse the repository at this point in the history
Signed-off-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 committed Jan 16, 2025
1 parent 3979caf commit 707cde1
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void Process_fillStarttimeBuffer(Process* this) {
*/
#define TASK_COMM_LEN 16

static bool findCommInCmdline(const char* comm, const char* cmdline, size_t cmdlineBasenameStart, size_t* pCommStart, size_t* pCommEnd) {
static bool findCommInCmdline(const char* comm, const char* cmdline, size_t cmdlineBasenameStart, size_t* pCommStart, size_t* pCommLen) {
/* Try to find procComm in tokenized cmdline - this might in rare cases
* mis-identify a string or fail, if comm or cmdline had been unsuitably
* modified by the process */
Expand All @@ -83,7 +83,7 @@ static bool findCommInCmdline(const char* comm, const char* cmdline, size_t cmdl
if ((tokenLen == commLen || (tokenLen > commLen && commLen == (TASK_COMM_LEN - 1))) &&
strncmp(tokenBase, comm, commLen) == 0) {
*pCommStart = (size_t)(tokenBase - cmdline);
*pCommEnd = (size_t)(token - cmdline);
*pCommLen = tokenLen;
return true;
}

Expand Down Expand Up @@ -381,13 +381,9 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {

bool haveCommInCmdline = false;
size_t commStart = 0;
size_t commEnd = 0;

if (!haveCommInExe && this->cmdline && procComm && searchCommInCmdline && (!Process_isUserlandThread(this) || showThreadNames)) {
haveCommInCmdline = findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd);
}
if (haveCommInCmdline) {
commLen = commEnd - commStart;
haveCommInCmdline = findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commLen);
}

if (!stripExeFromCmdline) {
Expand Down

0 comments on commit 707cde1

Please sign in to comment.