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;

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;
}

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