Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F149946455
D30114.id88639.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D30114.id88639.diff
View Options
Index: usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c
===================================================================
--- usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c
+++ usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c
@@ -47,9 +47,6 @@
#include "hostres_oid.h"
#include "hostres_tree.h"
-/* boot timestamp in centi-seconds */
-static uint64_t kernel_boot;
-
/* physical memory size in Kb */
static uint64_t phys_mem_size;
@@ -76,39 +73,19 @@
static int
OS_getSystemUptime(uint32_t *ut)
{
- struct timeval right_now;
- uint64_t now;
-
- if (kernel_boot == 0) {
- /* first time, do the sysctl */
- struct timeval kernel_boot_timestamp;
- int mib[2] = { CTL_KERN, KERN_BOOTTIME };
- size_t len = sizeof(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);
- }
+ uint64_t uptime;
+ struct timespec ts;
- HRDBG("boot timestamp from kernel: {%lld, %ld}",
- (long long)kernel_boot_timestamp.tv_sec,
- (long)kernel_boot_timestamp.tv_usec);
-
- kernel_boot = ((uint64_t)kernel_boot_timestamp.tv_sec * 100) +
- (kernel_boot_timestamp.tv_usec / 10000);
- }
-
- if (gettimeofday(&right_now, NULL) < 0) {
- syslog(LOG_ERR, "gettimeofday failed: %m");
+ if (clock_gettime(CLOCK_UPTIME, &ts)) {
+ syslog(LOG_ERR, "clock_gettime failed: %m");
return (SNMP_ERR_GENERR);
}
- now = ((uint64_t)right_now.tv_sec * 100) + (right_now.tv_usec / 10000);
- if (now - kernel_boot > UINT32_MAX)
+ uptime = ts.tv_sec * 100 + ts.tv_nsec / 1000000;
+ if (uptime > UINT32_MAX)
*ut = UINT32_MAX;
else
- *ut = now - kernel_boot;
+ *ut = (uint32_t)uptime;
return (SNMP_ERR_NOERROR);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 29, 7:21 AM (14 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30516810
Default Alt Text
D30114.id88639.diff (1 KB)
Attached To
Mode
D30114: bsnmpd: Return the correct uptime.
Attached
Detach File
Event Timeline
Log In to Comment