mirror of https://github.com/xzeldon/htop.git
Improve reading of cgroups.
This commit is contained in:
parent
39a725abc2
commit
a4b03e8875
|
@ -312,22 +312,27 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam
|
||||||
process->cgroup = strdup("");
|
process->cgroup = strdup("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char buffer[256];
|
char output[256];
|
||||||
char *ok = fgets(buffer, 255, file);
|
output[0] = '\0';
|
||||||
if (ok) {
|
char* at = output;
|
||||||
char* trimmed = String_trim(buffer);
|
int left = 255;
|
||||||
int nFields;
|
while (!feof(file) && left > 0) {
|
||||||
char** fields = String_split(trimmed, ':', &nFields);
|
char buffer[256];
|
||||||
free(trimmed);
|
char *ok = fgets(buffer, 255, file);
|
||||||
free(process->cgroup);
|
if (!ok) break;
|
||||||
if (nFields >= 3) {
|
char* group = strchr(buffer, ':');
|
||||||
process->cgroup = strndup(fields[2] + 1, 10);
|
if (!group) break;
|
||||||
} else {
|
if (at != output) {
|
||||||
process->cgroup = strdup("");
|
*at = ';';
|
||||||
|
at++;
|
||||||
|
left--;
|
||||||
}
|
}
|
||||||
String_freeArray(fields);
|
int wrote = snprintf(at, left, "%s", group);
|
||||||
|
left -= wrote;
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
free(process->cgroup);
|
||||||
|
process->cgroup = strdup(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue