diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-04-19 23:15:38 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-04-19 23:17:49 +0400 |
commit | 0c13951b4684fe8a6eee0a88820a754903d520c4 (patch) | |
tree | 8fc03ab18717aa2579447f0994f5ad822614de2e | |
parent | b63c0307bf57bf949240b43b170e2becbab29528 (diff) | |
download | htop-master.tar.gz |
Fixed wrong value of this->cpuCount:
htop now shows processes again and does not crash on exit.
-rw-r--r-- | ProcessList.c | 7 | ||||
-rw-r--r-- | htop-sysdeps.h | 1 | ||||
-rw-r--r-- | sysdeps/linux.c | 6 | ||||
-rw-r--r-- | sysdeps/solaris.c | 6 |
4 files changed, 16 insertions, 4 deletions
diff --git a/ProcessList.c b/ProcessList.c index 8d518c8..aff695b 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -192,8 +192,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { /* tree-view auxiliary buffers */ this->processes2 = Vector_new(Class(Process), true, DEFAULT_SIZE); - int cpus = sysconf(_SC_NPROCESSORS_ONLN); - this->cpuCount = cpus; + this->cpuCount = sysdep_number_of_cpus(); #ifdef HAVE_LIBHWLOC this->topologyOk = false; @@ -203,9 +202,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { this->topologyOk = true; } #endif - this->cpus = calloc(sizeof(CPUData), cpus); + this->cpus = calloc(sizeof(CPUData), this->cpuCount + 1); - for (int i = 0; i < cpus; i++) { + for (int i = 0; i <= this->cpuCount; i++) { this->cpus[i].totalTime = 1; this->cpus[i].totalPeriod = 1; } diff --git a/htop-sysdeps.h b/htop-sysdeps.h index e189e34..6a5c023 100644 --- a/htop-sysdeps.h +++ b/htop-sysdeps.h @@ -13,6 +13,7 @@ void sysdep_set_ioprio(pid_t, IOPriority); void sysdep_get_meminfo(ProcessList*); void sysdep_update_cpu_data(ProcessList *); int sysdep_max_pid(); +int sysdep_number_of_cpus(); bool sysdep_get_process_info(Process *, pid_t); long sysdep_uptime(); // seconds since boot #endif diff --git a/sysdeps/linux.c b/sysdeps/linux.c index 52b6e78..ab8710e 100644 --- a/sysdeps/linux.c +++ b/sysdeps/linux.c @@ -283,3 +283,9 @@ sysdep_uptime () } return (long) uptime; } + +int +sysdep_number_of_cpus () +{ + return sysconf (_SC_NPROCESSORS_ONLN); +} diff --git a/sysdeps/solaris.c b/sysdeps/solaris.c index 705ec9c..243975c 100644 --- a/sysdeps/solaris.c +++ b/sysdeps/solaris.c @@ -375,3 +375,9 @@ sysdep_uptime () } return uptime; } + +int +sysdep_number_of_cpus () +{ + return sysconf (_SC_NPROCESSORS_ONLN); +} |