diff --git a/clients/lcdproc/machine_Darwin.c b/clients/lcdproc/machine_Darwin.c index 001fd93..f69a224 100644 --- a/clients/lcdproc/machine_Darwin.c +++ b/clients/lcdproc/machine_Darwin.c @@ -394,8 +394,7 @@ int machine_get_smpload(load_type *result, int *numcpus) load_type curr_load; size = sizeof(int); - if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) - { + if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } @@ -403,11 +402,15 @@ int machine_get_smpload(load_type *result, int *numcpus) if (machine_get_load(&curr_load) == FALSE) return(FALSE); + if (numcpus == NULL) + return(FALSE); + + /* restrict #CPUs to max. *numcpus */ + num = (*numcpus >= num) ? num : *numcpus; *numcpus = num; - num = num > 8 ? 8 : num; + /* Don't know how to get per-cpu-load values */ - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { result[i] = curr_load; } diff --git a/clients/lcdproc/machine_FreeBSD.c b/clients/lcdproc/machine_FreeBSD.c index d535cde..5791318 100644 --- a/clients/lcdproc/machine_FreeBSD.c +++ b/clients/lcdproc/machine_FreeBSD.c @@ -343,8 +343,7 @@ int machine_get_smpload(load_type *result, int *numcpus) load_type curr_load; size = sizeof(int); - if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) - { + if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } @@ -352,11 +351,15 @@ int machine_get_smpload(load_type *result, int *numcpus) if (machine_get_load(&curr_load) == FALSE) return(FALSE); + if (numcpus == NULL) + return(FALSE); + + /* restrict #CPUs to max. *numcpus */ + num = (*numcpus >= num) ? num : *numcpus; *numcpus = num; - num = num > 8 ? 8 : num; + /* Don't know how to get per-cpu-load values */ - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { result[i] = curr_load; } diff --git a/clients/lcdproc/machine_NetBSD.c b/clients/lcdproc/machine_NetBSD.c index 5090474..a8efbac 100644 --- a/clients/lcdproc/machine_NetBSD.c +++ b/clients/lcdproc/machine_NetBSD.c @@ -325,8 +325,7 @@ int machine_get_smpload(load_type *result, int *numcpus) mib[1] = HW_NCPU; size = sizeof(int); - if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) - { + if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } @@ -334,11 +333,15 @@ int machine_get_smpload(load_type *result, int *numcpus) if (machine_get_load(&curr_load) == FALSE) return(FALSE); + if (numcpus == NULL) + return(FALSE); + + /* restrict #CPUs to max. *numcpus */ + num = (*numcpus >= num) ? num : *numcpus; *numcpus = num; - num = num > 8 ? 8 : num; + /* Don't know how to get per-cpu-load values */ - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { result[i] = curr_load; } diff --git a/clients/lcdproc/machine_OpenBSD.c b/clients/lcdproc/machine_OpenBSD.c index c68375c..d412cfc 100644 --- a/clients/lcdproc/machine_OpenBSD.c +++ b/clients/lcdproc/machine_OpenBSD.c @@ -330,8 +330,7 @@ int machine_get_smpload(load_type *result, int *numcpus) mib[1] = HW_NCPU; size = sizeof(int); - if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) - { + if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) { perror("sysctl hw.ncpu"); return(FALSE); } @@ -339,11 +338,15 @@ int machine_get_smpload(load_type *result, int *numcpus) if (machine_get_load(&curr_load) == FALSE) return(FALSE); + if (numcpus == NULL) + return(FALSE); + + /* restrict #CPUs to max. *numcpus */ + num = (*numcpus >= num) ? num : *numcpus; *numcpus = num; - num = num > 8 ? 8 : num; + /* Don't know how to get per-cpu-load values */ - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { result[i] = curr_load; }