Skip to content

Commit 4a7b3a8

Browse files
committed
Processing (GNU): hurd uses cmdline instead of comm
1 parent 20fafa5 commit 4a7b3a8

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/common/processing_linux.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -465,30 +465,23 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
465465
}
466466
else
467467
{
468-
#ifndef __GNU__
469-
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int)pid);
468+
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/"
469+
#if __GNU__
470+
"cmdline"
471+
#else
472+
"comm"
473+
#endif
474+
, (int)pid);
470475
ssize_t nRead = ffReadFileBuffer(procFilePath, name);
471476
if(nRead <= 0)
472-
return "ffReadFileBuffer(/proc/pid/comm, name) failed";
477+
return "ffReadFileBuffer(/proc/pid/"
478+
#if __GNU__
479+
"cmdline"
480+
#else
481+
"comm"
482+
#endif
483+
", name) failed";
473484
ffStrbufTrimRightSpace(name);
474-
#else
475-
// No /proc/1/comm on Hurd so read /proc/1/stat again
476-
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid);
477-
char buf[PROC_FILE_BUFFSIZ];
478-
ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf);
479-
if(nRead <= 8)
480-
return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed";
481-
buf[nRead] = '\0';
482-
483-
ffStrbufEnsureFixedLengthFree(name, 255);
484-
if(
485-
sscanf(buf, "%*s (%255[^)]) %*c %*d %*d %*d %*d", name->chars) == 0 || //stat (comm) state ppid pgrp session tty
486-
name->chars[0] == '\0'
487-
)
488-
return "sscanf(stat) failed";
489-
490-
ffStrbufRecalculateLength(name);
491-
#endif
492485
}
493486

494487
#elif defined(__APPLE__)

0 commit comments

Comments
 (0)