Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ myhtopsources = \
Process.c \
ProcessLocksScreen.c \
ProcessTable.c \
ProgramLauncher.c \
Row.c \
RichString.c \
Scheduling.c \
Expand Down Expand Up @@ -144,6 +145,7 @@ myhtopheaders = \
Process.h \
ProcessLocksScreen.h \
ProcessTable.h \
ProgramLauncher.h \
ProvideCurses.h \
ProvideTerm.h \
RichString.h \
Expand Down
24 changes: 21 additions & 3 deletions OpenFilesScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ in the source distribution for its full text.

#include "Macros.h"
#include "Panel.h"
#include "ProgramLauncher.h"
#include "ProvideCurses.h"
#include "Vector.h"
#include "XUtils.h"
Expand All @@ -46,6 +47,8 @@ typedef struct OpenFiles_FileData_ {
struct OpenFiles_FileData_* next;
} OpenFiles_FileData;

static ProgramLauncher OpenFiles_ProgramLauncher;
Comment thread
Explorer09 marked this conversation as resolved.

static size_t getIndexForType(char type) {
switch (type) {
case 'f':
Expand Down Expand Up @@ -100,6 +103,12 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
pdata->cols[getIndexForType('o')] = 8;
pdata->cols[getIndexForType('i')] = 8;

ProgramLauncher_setPath(&OpenFiles_ProgramLauncher, "lsof");
if (OpenFiles_ProgramLauncher.lastErrno != 0) {
pdata->error = 1;
return pdata;
Comment on lines +106 to +109

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Preserve the actionable lsof resolution error.

OpenFilesScreen_scan() only shows the specific PATH hint when pdata->error == 127. Returning 1 here turns ProgramLauncher_setPath() failures such as ENOENT into the generic "Failed listing open files." path.

}

int fdpair[2] = {-1, -1};
if (pipe(fdpair) < 0) {
pdata->error = 1;
Expand Down Expand Up @@ -127,9 +136,18 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
close(fdnull);
char buffer[32] = {0};
xSnprintf(buffer, sizeof(buffer), "%d", pid);
// Use of NULL in variadic functions must have a pointer cast.
// The NULL constant is not required by standard to have a pointer type.
execlp("lsof", "lsof", "-P", "-o", "-p", buffer, "-F", (char*)NULL);

const char* argv[] = {
"lsof",
"-P",
"-o",
"-p",
buffer,
"-F",
NULL
};
ProgramLauncher_execv_const(&OpenFiles_ProgramLauncher, argv);

exit(127);
}
close(fdpair[1]);
Expand Down
Loading
Loading