get rid of magic numbers - get bound from parameter passed
This commit is contained in:
@@ -394,8 +394,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
load_type curr_load;
|
load_type curr_load;
|
||||||
|
|
||||||
size = sizeof(int);
|
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");
|
perror("sysctl hw.ncpu");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
@@ -403,11 +402,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
if (machine_get_load(&curr_load) == FALSE)
|
if (machine_get_load(&curr_load) == FALSE)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
|
if (numcpus == NULL)
|
||||||
|
return(FALSE);
|
||||||
|
|
||||||
|
/* restrict #CPUs to max. *numcpus */
|
||||||
|
num = (*numcpus >= num) ? num : *numcpus;
|
||||||
*numcpus = num;
|
*numcpus = num;
|
||||||
num = num > 8 ? 8 : num;
|
|
||||||
/* Don't know how to get per-cpu-load values */
|
/* 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;
|
result[i] = curr_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,8 +343,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
load_type curr_load;
|
load_type curr_load;
|
||||||
|
|
||||||
size = sizeof(int);
|
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");
|
perror("sysctl hw.ncpu");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
@@ -352,11 +351,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
if (machine_get_load(&curr_load) == FALSE)
|
if (machine_get_load(&curr_load) == FALSE)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
|
if (numcpus == NULL)
|
||||||
|
return(FALSE);
|
||||||
|
|
||||||
|
/* restrict #CPUs to max. *numcpus */
|
||||||
|
num = (*numcpus >= num) ? num : *numcpus;
|
||||||
*numcpus = num;
|
*numcpus = num;
|
||||||
num = num > 8 ? 8 : num;
|
|
||||||
/* Don't know how to get per-cpu-load values */
|
/* 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;
|
result[i] = curr_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -325,8 +325,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
mib[1] = HW_NCPU;
|
mib[1] = HW_NCPU;
|
||||||
size = sizeof(int);
|
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");
|
perror("sysctl hw.ncpu");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
@@ -334,11 +333,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
if (machine_get_load(&curr_load) == FALSE)
|
if (machine_get_load(&curr_load) == FALSE)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
|
if (numcpus == NULL)
|
||||||
|
return(FALSE);
|
||||||
|
|
||||||
|
/* restrict #CPUs to max. *numcpus */
|
||||||
|
num = (*numcpus >= num) ? num : *numcpus;
|
||||||
*numcpus = num;
|
*numcpus = num;
|
||||||
num = num > 8 ? 8 : num;
|
|
||||||
/* Don't know how to get per-cpu-load values */
|
/* 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;
|
result[i] = curr_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,8 +330,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
mib[1] = HW_NCPU;
|
mib[1] = HW_NCPU;
|
||||||
size = sizeof(int);
|
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");
|
perror("sysctl hw.ncpu");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
@@ -339,11 +338,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
if (machine_get_load(&curr_load) == FALSE)
|
if (machine_get_load(&curr_load) == FALSE)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
|
if (numcpus == NULL)
|
||||||
|
return(FALSE);
|
||||||
|
|
||||||
|
/* restrict #CPUs to max. *numcpus */
|
||||||
|
num = (*numcpus >= num) ? num : *numcpus;
|
||||||
*numcpus = num;
|
*numcpus = num;
|
||||||
num = num > 8 ? 8 : num;
|
|
||||||
/* Don't know how to get per-cpu-load values */
|
/* 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;
|
result[i] = curr_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user