Skip to content

Commit 2225888

Browse files
author
Vincent Landgraf
committed
#12 support net/openbsd boottime using sysctl
1 parent c3fa559 commit 2225888

2 files changed

Lines changed: 29 additions & 34 deletions

File tree

ext/vmstat/extconf.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
have_const 'NETLINK_GENERIC', sys_headers
4747
have_const 'IFMIB_IFDATA', sys_headers
4848
have_const 'IFDATA_GENERAL', sys_headers
49-
have_const 'CTL_KERN', sys_headers
50-
have_const 'KERN_BOOTTIME', sys_headers
49+
50+
have_const 'CTL_KERN', ['sys/sysctl.h', 'sys/types.h']
51+
have_const 'KERN_BOOTTIME', ['sys/sysctl.h', 'sys/types.h']
5152

5253
# bsd.h
5354
# only if we have *bsd like stats check for sysctlbyname

ext/vmstat/hw/sysctl.h

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
#if defined(HAVE_SYS_SYSCTL_H) && \
2-
defined(HAVE_SYS_TYPES_H) && \
3-
defined(HAVE_SYS_SOCKET_H) && \
4-
defined(HAVE_NET_IF_H) && \
5-
defined(HAVE_NET_IF_MIB_H) && \
6-
defined(HAVE_NET_IF_TYPES_H) && \
7-
defined(HAVE_GETLOADAVG) && \
8-
defined(HAVE_SYSCTL) && \
9-
defined(HAVE_TYPE_STRUCT_IFMIBDATA) && \
10-
defined(HAVE_CONST_CTL_NET) && \
11-
defined(HAVE_CONST_PF_LINK) && \
12-
defined(HAVE_CONST_NETLINK_GENERIC) && \
13-
defined(HAVE_CONST_IFMIB_IFDATA) && \
14-
defined(HAVE_CONST_IFDATA_GENERAL) && \
15-
defined(HAVE_CONST_CTL_KERN) && \
16-
defined(HAVE_CONST_KERN_BOOTTIME)
1+
#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYS_TYPES_H) && \
2+
defined(HAVE_CONST_CTL_KERN) && defined(HAVE_CONST_KERN_BOOTTIME)
173
#include <vmstat.h>
184
#include <sys/sysctl.h>
195
#include <sys/types.h>
6+
7+
#ifndef VMSTAT_BOOT_TIME
8+
#define VMSTAT_BOOT_TIME
9+
static int BOOT_TIME_MIB[] = { CTL_KERN, KERN_BOOTTIME };
10+
11+
VALUE vmstat_boot_time(VALUE self) {
12+
struct timeval tv;
13+
size_t size = sizeof(tv);
14+
15+
if (sysctl(BOOT_TIME_MIB, 2, &tv, &size, NULL, 0) == 0) {
16+
return rb_time_new(tv.tv_sec, tv.tv_usec);
17+
} else {
18+
return Qnil;
19+
}
20+
}
21+
#endif // VMSTAT_BOOT_TIME
22+
23+
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NET_IF_H) && \
24+
defined(HAVE_NET_IF_MIB_H) && defined(HAVE_NET_IF_TYPES_H) && \
25+
defined(HAVE_GETLOADAVG) && defined(HAVE_SYSCTL) && \
26+
defined(HAVE_TYPE_STRUCT_IFMIBDATA) && defined(HAVE_CONST_CTL_NET) && \
27+
defined(HAVE_CONST_PF_LINK) && defined(HAVE_CONST_NETLINK_GENERIC) && \
28+
defined(HAVE_CONST_IFMIB_IFDATA) && defined(HAVE_CONST_IFDATA_GENERAL)
2029
#include <sys/socket.h>
2130
#include <net/if.h>
2231
#include <net/if_mib.h>
@@ -52,21 +61,6 @@ VALUE vmstat_network_interfaces(VALUE self) {
5261

5362
return devices;
5463
}
55-
#endif
56-
57-
#ifndef VMSTAT_BOOT_TIME
58-
#define VMSTAT_BOOT_TIME
59-
static int BOOT_TIME_MIB[] = { CTL_KERN, KERN_BOOTTIME };
60-
61-
VALUE vmstat_boot_time(VALUE self) {
62-
struct timeval tv;
63-
size_t size = sizeof(tv);
64-
65-
if (sysctl(BOOT_TIME_MIB, 2, &tv, &size, NULL, 0) == 0) {
66-
return rb_time_new(tv.tv_sec, tv.tv_usec);
67-
} else {
68-
return Qnil;
69-
}
70-
}
64+
#endif // VMSTAT_NETWORK_INTERFACES
7165
#endif
7266
#endif

0 commit comments

Comments
 (0)