Skip to content

Commit 9aa4e70

Browse files
committed
OpenFilesScreen use ProgramLauncher to launch lsof(8)
1 parent dce4da6 commit 9aa4e70

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

OpenFilesScreen.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ in the source distribution for its full text.
2222

2323
#include "Macros.h"
2424
#include "Panel.h"
25+
#include "ProgramLauncher.h"
2526
#include "ProvideCurses.h"
2627
#include "Vector.h"
2728
#include "XUtils.h"
@@ -46,6 +47,8 @@ typedef struct OpenFiles_FileData_ {
4647
struct OpenFiles_FileData_* next;
4748
} OpenFiles_FileData;
4849

50+
static ProgramLauncher OpenFiles_ProgramLauncher;
51+
4952
static size_t getIndexForType(char type) {
5053
switch (type) {
5154
case 'f':
@@ -100,6 +103,12 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
100103
pdata->cols[getIndexForType('o')] = 8;
101104
pdata->cols[getIndexForType('i')] = 8;
102105

106+
ProgramLauncher_setPath(&OpenFiles_ProgramLauncher, "lsof");
107+
if (OpenFiles_ProgramLauncher.lastErrno != 0) {
108+
pdata->error = 1;
109+
return pdata;
110+
}
111+
103112
int fdpair[2] = {-1, -1};
104113
if (pipe(fdpair) < 0) {
105114
pdata->error = 1;
@@ -127,9 +136,18 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
127136
close(fdnull);
128137
char buffer[32] = {0};
129138
xSnprintf(buffer, sizeof(buffer), "%d", pid);
130-
// Use of NULL in variadic functions must have a pointer cast.
131-
// The NULL constant is not required by standard to have a pointer type.
132-
execlp("lsof", "lsof", "-P", "-o", "-p", buffer, "-F", (char*)NULL);
139+
140+
const char* argv[] = {
141+
"lsof",
142+
"-P",
143+
"-o",
144+
"-p",
145+
buffer,
146+
"-F",
147+
NULL
148+
};
149+
ProgramLauncher_execv_const(&OpenFiles_ProgramLauncher, argv);
150+
133151
exit(127);
134152
}
135153
close(fdpair[1]);

0 commit comments

Comments
 (0)