OS_getSystemUptime: use nitems for calculating the number of elements

in a sysctl mib instead of hardcoding the number 2

MFC after:	3 days
This commit is contained in:
Enji Cooper 2017-01-05 09:28:38 +00:00
parent f193c8ce0d
commit 18d124d977
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311393

View File

@ -33,7 +33,7 @@
* Host Resources MIB scalars implementation for SNMPd.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <pwd.h>
@ -85,7 +85,7 @@ OS_getSystemUptime(uint32_t *ut)
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
size_t len = sizeof(kernel_boot_timestamp);
if (sysctl(mib, 2, &kernel_boot_timestamp,
if (sysctl(mib, nitems(mib), &kernel_boot_timestamp,
&len, NULL, 0) == -1) {
syslog(LOG_ERR, "sysctl KERN_BOOTTIME failed: %m");
return (SNMP_ERR_GENERR);