Skip to content

Commit

Permalink
Processing(Linux, SunOS): little optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
apocelipes committed Oct 14, 2024
1 parent fbed730 commit bc470aa
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/common/processing_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons

#ifdef __linux__

char filePath[64];
char filePath[24];
snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid);

if(ffReadFileBuffer(filePath, exe))
Expand All @@ -139,12 +139,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
if (exePath)
{
snprintf(filePath, sizeof(filePath), "/proc/%d/exe", (int)pid);
ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX);
ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1);
char buf[PATH_MAX];
ssize_t length = readlink(filePath, buf, PATH_MAX - 1);
if (length > 0) // doesn't contain trailing NUL
{
exePath->chars[length] = '\0';
exePath->length = (uint32_t) length;
buf[length] = '\0';
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
}
}

Expand Down Expand Up @@ -242,7 +243,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons

#elif defined(__sun)

char filePath[PATH_MAX];
char filePath[64];
snprintf(filePath, sizeof(filePath), "/proc/%d/psinfo", (int) pid);
psinfo_t proc;
if (ffReadFileData(filePath, sizeof(proc), &proc) == sizeof(proc))
Expand All @@ -254,12 +255,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
if (exePath)
{
snprintf(filePath, sizeof(filePath), "/proc/%d/path/a.out", (int) pid);
ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX);
ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1);
char buf[PATH_MAX];
ssize_t length = readlink(filePath, buf, PATH_MAX - 1);
if (length > 0) // doesn't contain trailing NUL
{
exePath->chars[length] = '\0';
exePath->length = (uint32_t) length;
buf[length] = '\0';
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
}
}

Expand Down Expand Up @@ -293,7 +295,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i

#ifdef __linux__

char procFilePath[64];
char procFilePath[24];
if (ppid)
{
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid);
Expand Down Expand Up @@ -377,7 +379,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
}

#elif defined(__sun)
char path[128];
char path[64];
snprintf(path, sizeof(path), "/proc/%d/psinfo", (int) pid);
psinfo_t proc;
if (ffReadFileData(path, sizeof(proc), &proc) != sizeof(proc))
Expand Down

0 comments on commit bc470aa

Please sign in to comment.