Skip to content
Merged
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
11 changes: 7 additions & 4 deletions linux/LinuxProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ ProcessFieldData Process_fields[] = {
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
#ifdef HAVE_OPENVZ
[CTID] = { .name = "CTID", .title = " CTID ", .description = "OpenVZ container ID (a.k.a. virtual environment ID)", .flags = PROCESS_FLAG_LINUX_OPENVZ, },
[VPID] = { .name = "VPID", .title = " VPID ", .description = "OpenVZ process ID", .flags = PROCESS_FLAG_LINUX_OPENVZ, },
[CTID] = { .name = "CTID", .title = " CTID ", .description = "OpenVZ container ID (a.k.a. virtual environment ID)", .flags = PROCESS_FLAG_LINUX_OPENVZ, },
[VPID] = { .name = "VPID", .title = " VPID ", .description = "OpenVZ process ID", .flags = PROCESS_FLAG_LINUX_OPENVZ, },
#endif
#ifdef HAVE_VSERVER
[VXID] = { .name = "VXID", .title = " VXID ", .description = "VServer process ID", .flags = PROCESS_FLAG_LINUX_VSERVER, },
Expand Down Expand Up @@ -148,6 +148,9 @@ void Process_delete(Object* cast) {
Process_done((Process*)cast);
#ifdef HAVE_CGROUP
free(this->cgroup);
#endif
#ifdef HAVE_OPENVZ
free(this->ctid);
#endif
free(this->secattr);
free(this->ttyDevice);
Expand Down Expand Up @@ -253,7 +256,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
}
#endif
#ifdef HAVE_OPENVZ
case CTID: xSnprintf(buffer, n, "%7u ", lp->ctid); break;
case CTID: xSnprintf(buffer, n, "%-8s ", lp->ctid ? lp->ctid : ""); break;
case VPID: xSnprintf(buffer, n, Process_pidFormat, lp->vpid); break;
#endif
#ifdef HAVE_VSERVER
Expand Down Expand Up @@ -351,7 +354,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
#endif
#ifdef HAVE_OPENVZ
case CTID:
return (p2->ctid - p1->ctid);
return strcmp(p1->ctid ? p1->ctid : "", p2->ctid ? p2->ctid : "");
case VPID:
return (p2->vpid - p1->vpid);
#endif
Expand Down
4 changes: 2 additions & 2 deletions linux/LinuxProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ typedef struct LinuxProcess_ {
double io_rate_write_bps;
#endif
#ifdef HAVE_OPENVZ
unsigned int ctid;
unsigned int vpid;
char* ctid;
Comment thread
BenBE marked this conversation as resolved.
pid_t vpid;
#endif
#ifdef HAVE_VSERVER
unsigned int vxid;
Expand Down
93 changes: 81 additions & 12 deletions linux/LinuxProcessList.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,94 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di

static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) {
if ( (access(PROCDIR "/vz", R_OK) != 0)) {
free(process->ctid);
process->ctid = NULL;
process->vpid = process->super.pid;
process->ctid = 0;
return;
}

char filename[MAX_NAME+1];
xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name);
xSnprintf(filename, sizeof(filename), "%s/%s/status", dirname, name);
FILE* file = fopen(filename, "r");
if (!file)
if (!file) {
free(process->ctid);
process->ctid = NULL;
process->vpid = process->super.pid;
return;
(void)! fscanf(file,
"%*32u %*32s %*1c %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %32u %32u",
&process->vpid, &process->ctid);
}

bool foundEnvID = false;
bool foundVPid = false;
char linebuf[256];
while(fgets(linebuf, sizeof(linebuf), file) != NULL) {
if(strchr(linebuf, '\n') == NULL) {
// Partial line, skip to end of this line
while(fgets(linebuf, sizeof(linebuf), file) != NULL) {
if(strchr(linebuf, '\n') != NULL) {
break;
}
}
continue;
}

char* name_value_sep = strchr(linebuf, ':');
if(name_value_sep == NULL) {
continue;
}

int field;
if(0 == strncasecmp(linebuf, "envID", name_value_sep - linebuf)) {
field = 1;
} else if(0 == strncasecmp(linebuf, "VPid", name_value_sep - linebuf)) {
field = 2;
} else {
continue;
}

do {
name_value_sep++;
} while(*name_value_sep != '\0' && *name_value_sep <= 32);

char* value_end = name_value_sep;

while(*value_end != '\0' && *value_end > 32) {
value_end++;
}

if(name_value_sep == value_end) {
continue;
}

*value_end = '\0';

switch(field) {
case 1:
foundEnvID = true;
if(0 != strcmp(name_value_sep, process->ctid ? process->ctid : "")) {
free(process->ctid);
process->ctid = xStrdup(name_value_sep);
}
break;
case 2:
foundVPid = true;
process->vpid = strtoul(name_value_sep, NULL, 0);
break;
default:
//Sanity Check: Should never reach here, or the implementation is missing something!
Comment thread
BenBE marked this conversation as resolved.
assert(false && "OpenVZ handling: Unimplemented case for field handling reached.");
}
}

fclose(file);

if(!foundEnvID) {
free(process->ctid);
process->ctid = NULL;
}

if(!foundVPid) {
process->vpid = process->super.pid;
}
}

#endif
Expand Down