Update values for fields whose columns may appear later. Fixes #80.

This commit is contained in:
Hisham Muhammad 2014-05-03 17:49:05 -03:00
parent c3e66b2d81
commit f54a37b4a9
2 changed files with 20 additions and 15 deletions

View File

@ -663,9 +663,9 @@ static void Process_display(Object* cast, RichString* out) {
void Process_delete(Object* cast) { void Process_delete(Object* cast) {
Process* this = (Process*) cast; Process* this = (Process*) cast;
assert (this != NULL); assert (this != NULL);
if (this->comm) free(this->comm); free(this->comm);
#ifdef HAVE_CGROUP #ifdef HAVE_CGROUP
if (this->cgroup) free(this->cgroup); free(this->cgroup);
#endif #endif
free(this); free(this);
} }

View File

@ -242,8 +242,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
this->flags = 0; this->flags = 0;
for (int i = 0; defaultHeaders[i]; i++) { for (int i = 0; defaultHeaders[i]; i++) {
this->fields[i] = defaultHeaders[i]; this->fields[i] = defaultHeaders[i];
this->fields[i] |= Process_fieldFlags[defaultHeaders[i]]; this->flags |= Process_fieldFlags[defaultHeaders[i]];
} }
#ifdef HAVE_OPENVZ
this->flags |= PROCESS_FLAG_OPENVZ;
#endif
this->sortKey = PERCENT_CPU; this->sortKey = PERCENT_CPU;
this->direction = 1; this->direction = 1;
this->hideThreads = false; this->hideThreads = false;
@ -580,9 +585,10 @@ static bool ProcessList_readStatmFile(Process* process, const char* dirname, con
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
static void ProcessList_readOpenVZData(Process* process, const char* dirname, const char* name) { static void ProcessList_readOpenVZData(Process* process, const char* dirname, const char* name) {
if (access("/proc/vz", R_OK) != 0) { if ( (!(this->flags & PROCESS_FLAG_OPENVZ)) || (access("/proc/vz", R_OK) != 0)) {
process->vpid = process->pid; process->vpid = process->pid;
process->ctid = 0; process->ctid = 0;
this->flags |= ~PROCESS_FLAG_OPENVZ;
return; return;
} }
char filename[MAX_NAME+1]; char filename[MAX_NAME+1];
@ -806,24 +812,14 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
process->user = UsersTable_getRef(this->usersTable, process->st_uid); process->user = UsersTable_getRef(this->usersTable, process->st_uid);
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
if (this->flags & PROCESS_FLAG_OPENVZ)
ProcessList_readOpenVZData(process, dirname, name); ProcessList_readOpenVZData(process, dirname, name);
#endif #endif
#ifdef HAVE_CGROUP
if (this->flags & PROCESS_FLAG_CGROUP)
ProcessList_readCGroupFile(process, dirname, name);
#endif
#ifdef HAVE_VSERVER #ifdef HAVE_VSERVER
if (this->flags & PROCESS_FLAG_VSERVER) if (this->flags & PROCESS_FLAG_VSERVER)
ProcessList_readVServerData(process, dirname, name); ProcessList_readVServerData(process, dirname, name);
#endif #endif
#ifdef HAVE_OOM
ProcessList_readOomData(process, dirname, name);
#endif
if (! ProcessList_readCmdlineFile(process, dirname, name)) if (! ProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
@ -835,6 +831,15 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
} }
} }
#ifdef HAVE_CGROUP
if (this->flags & PROCESS_FLAG_CGROUP)
ProcessList_readCGroupFile(process, dirname, name);
#endif
#ifdef HAVE_OOM
ProcessList_readOomData(process, dirname, name);
#endif
if (process->state == 'Z') { if (process->state == 'Z') {
free(process->comm); free(process->comm);
process->basenameOffset = -1; process->basenameOffset = -1;