mirror of https://github.com/xzeldon/htop.git
extra checks for lsof failures
This commit is contained in:
parent
a20ba78b5e
commit
7dcd2beb90
|
@ -26,7 +26,7 @@ in the source distribution for its full text.
|
||||||
typedef struct OpenFiles_ProcessData_ {
|
typedef struct OpenFiles_ProcessData_ {
|
||||||
char* data[256];
|
char* data[256];
|
||||||
struct OpenFiles_FileData_* files;
|
struct OpenFiles_FileData_* files;
|
||||||
bool failed;
|
int error;
|
||||||
} OpenFiles_ProcessData;
|
} OpenFiles_ProcessData;
|
||||||
|
|
||||||
typedef struct OpenFiles_FileData_ {
|
typedef struct OpenFiles_FileData_ {
|
||||||
|
@ -80,16 +80,16 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(int pid) {
|
||||||
OpenFiles_ProcessData* process = calloc(sizeof(OpenFiles_ProcessData), 1);
|
OpenFiles_ProcessData* process = calloc(sizeof(OpenFiles_ProcessData), 1);
|
||||||
OpenFiles_FileData* file = NULL;
|
OpenFiles_FileData* file = NULL;
|
||||||
OpenFiles_ProcessData* item = process;
|
OpenFiles_ProcessData* item = process;
|
||||||
process->failed = true;
|
|
||||||
bool anyRead = false;
|
bool anyRead = false;
|
||||||
|
if (!fd) {
|
||||||
|
process->error = 127;
|
||||||
|
return process;
|
||||||
|
}
|
||||||
while (!feof(fd)) {
|
while (!feof(fd)) {
|
||||||
int cmd = fgetc(fd);
|
int cmd = fgetc(fd);
|
||||||
if (cmd == EOF && !anyRead) {
|
if (cmd == EOF && !anyRead)
|
||||||
process->failed = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
anyRead = true;
|
anyRead = true;
|
||||||
process->failed = false;
|
|
||||||
char* entry = malloc(1024);
|
char* entry = malloc(1024);
|
||||||
if (!fgets(entry, 1024, fd)) break;
|
if (!fgets(entry, 1024, fd)) break;
|
||||||
char* newline = strrchr(entry, '\n');
|
char* newline = strrchr(entry, '\n');
|
||||||
|
@ -106,7 +106,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(int pid) {
|
||||||
}
|
}
|
||||||
item->data[cmd] = entry;
|
item->data[cmd] = entry;
|
||||||
}
|
}
|
||||||
pclose(fd);
|
process->error = pclose(fd);
|
||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,8 +115,10 @@ static void OpenFilesScreen_scan(OpenFilesScreen* this) {
|
||||||
int index = MAX(Panel_getSelectedIndex(panel), 0);
|
int index = MAX(Panel_getSelectedIndex(panel), 0);
|
||||||
Panel_prune(panel);
|
Panel_prune(panel);
|
||||||
OpenFiles_ProcessData* process = OpenFilesScreen_getProcessData(this->process->pid);
|
OpenFiles_ProcessData* process = OpenFilesScreen_getProcessData(this->process->pid);
|
||||||
if (process->failed) {
|
if (process->error == 127) {
|
||||||
Panel_add(panel, (Object*) ListItem_new("Could not execute 'lsof'. Please make sure it is available in your $PATH.", 0));
|
Panel_add(panel, (Object*) ListItem_new("Could not execute 'lsof'. Please make sure it is available in your $PATH.", 0));
|
||||||
|
} else if (process->error == 1) {
|
||||||
|
Panel_add(panel, (Object*) ListItem_new("Failed listing open files.", 0));
|
||||||
} else {
|
} else {
|
||||||
OpenFiles_FileData* file = process->files;
|
OpenFiles_FileData* file = process->files;
|
||||||
while (file) {
|
while (file) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ in the source distribution for its full text.
|
||||||
typedef struct OpenFiles_ProcessData_ {
|
typedef struct OpenFiles_ProcessData_ {
|
||||||
char* data[256];
|
char* data[256];
|
||||||
struct OpenFiles_FileData_* files;
|
struct OpenFiles_FileData_* files;
|
||||||
bool failed;
|
int error;
|
||||||
} OpenFiles_ProcessData;
|
} OpenFiles_ProcessData;
|
||||||
|
|
||||||
typedef struct OpenFiles_FileData_ {
|
typedef struct OpenFiles_FileData_ {
|
||||||
|
|
Loading…
Reference in New Issue