mirror of https://github.com/xzeldon/htop.git
Merge branch 'main' (Linux: fix crash in LXD, fixes #965) of er-azh/htop into main
This commit is contained in:
commit
8b927ba596
|
@ -174,21 +174,24 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
|
||||||
LinuxProcessList* this = (LinuxProcessList*) super;
|
LinuxProcessList* this = (LinuxProcessList*) super;
|
||||||
unsigned int existing = 0, active = 0;
|
unsigned int existing = 0, active = 0;
|
||||||
|
|
||||||
DIR* dir = opendir("/sys/devices/system/cpu");
|
// Initialize the cpuData array before anything else.
|
||||||
if (!dir) {
|
if (!this->cpuData) {
|
||||||
this->cpuData = xReallocArrayZero(this->cpuData, super->existingCPUs ? (super->existingCPUs + 1) : 0, 2, sizeof(CPUData));
|
this->cpuData = xCalloc(2, sizeof(CPUData));
|
||||||
this->cpuData[0].online = true; /* average is always "online" */
|
this->cpuData[0].online = true; /* average is always "online" */
|
||||||
this->cpuData[1].online = true;
|
this->cpuData[1].online = true;
|
||||||
super->activeCPUs = 1;
|
super->activeCPUs = 1;
|
||||||
super->existingCPUs = 1;
|
super->existingCPUs = 1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DIR* dir = opendir("/sys/devices/system/cpu");
|
||||||
|
if (!dir)
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned int currExisting = super->existingCPUs;
|
unsigned int currExisting = super->existingCPUs;
|
||||||
|
|
||||||
const struct dirent* entry;
|
const struct dirent* entry;
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
if (entry->d_type != DT_DIR)
|
if (entry->d_type != DT_DIR && entry->d_type != DT_UNKNOWN)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!String_startsWith(entry->d_name, "cpu"))
|
if (!String_startsWith(entry->d_name, "cpu"))
|
||||||
|
@ -233,6 +236,10 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
// return if no CPU is found
|
||||||
|
if (existing < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef HAVE_SENSORS_SENSORS_H
|
#ifdef HAVE_SENSORS_SENSORS_H
|
||||||
/* When started with offline CPUs, libsensors does not monitor those,
|
/* When started with offline CPUs, libsensors does not monitor those,
|
||||||
* even when they become online. */
|
* even when they become online. */
|
||||||
|
|
Loading…
Reference in New Issue