pkgsrc/sysutils/collectd/patches/patch-src_cpu.c
fhajny 125c46fdc8 Update sysutils/collectd to 5.6.2.
Most of the NetBSD specific patches were re-applied due to code
syntax changes.

Upstream changes in 5.6.2:
- collectd: A compile error on AIX has been fixed: "MSG_DONTWAIT" is not
  available on AIX.
- collectd: The capability checking has been rewritten to be more
  portable.
- collectd.conf(5): Various typos have been fixed.
- collectd-tg: Incorrect usage of "nanosleep()" has been fixed which
  caused the tool to sleep (almost) indefinitely.
- Build system: Detection of the Java environment has been made
  deterministic to allow for reproducible builds.
- Build system: Detection of the Lua headers has been improved.
- APC UPS plugin: Unavailable metrics are now skipped instead of
  reported as 0 (zero).
- Modbus plugin: Build issues on FreeBSD have been fixed.
- OpenVPN plugin: Gracefully handle empty configurations.
- PowerDNS plugin: The "recursor command" has been fixed so PowerDNS can
  correctly parse all requested fields.
- Write Graphite and AMQP plugins: A bug that could lead to a missing
  null-termination has been fixed.
- Write HTTP plugin: A logic error when checking the correctness of the
  data set has been fixed.
- Write Kafka plugin: The "Key Random" config option has been fixed.
- Write Kafka plugin: Support for librdkafka 0.9.0 has been added.
- Write Riemann plugin: Build issues on Solaris have been fixed.
- ZFS ARC plugin: A duplicate metric has been removed.
2016-12-07 17:28:39 +00:00

48 lines
1.5 KiB
C

$NetBSD: patch-src_cpu.c,v 1.3 2016/12/07 17:28:39 fhajny Exp $
Port this too to NetBSD.
--- src/cpu.c.orig 2016-11-30 08:52:01.308911943 +0000
+++ src/cpu.c
@@ -81,7 +81,7 @@
#if HAVE_SYSCTL
#if defined(CTL_HW) && defined(HW_NCPU) && defined(CTL_KERN) && \
- defined(KERN_CPTIME) && defined(CPUSTATES)
+ (defined(KERN_CPTIME) || defined(KERN_CP_TIME)) && defined(CPUSTATES)
#define CAN_USE_SYSCTL 1
#else
#define CAN_USE_SYSCTL 0
@@ -673,6 +673,24 @@ static int cpu_read(void) {
memset(cpuinfo, 0, sizeof(cpuinfo));
+#if defined(KERN_CP_TIME) && defined(KERNEL_NETBSD)
+ {
+ int mib[] = {CTL_KERN, KERN_CP_TIME};
+
+ cpuinfo_size = sizeof(cpuinfo[0]) * numcpu * CPUSTATES;
+ status = sysctl(mib, 2, cpuinfo, &cpuinfo_size, NULL, 0);
+ if (status == -1) {
+ char errbuf[1024];
+
+ ERROR ("cpu plugin: sysctl failed: %s.",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return -1;
+ }
+ if (cpuinfo_size == (sizeof(cpuinfo[0]) * CPUSTATES)) {
+ numcpu = 1;
+ }
+ }
+#else /* defined(KERN_CP_TIME) && defined(KERNEL_NETBSD) */
#if defined(KERN_CPTIME2)
if (numcpu > 1) {
for (int i = 0; i < numcpu; i++) {
@@ -710,6 +728,7 @@ static int cpu_read(void) {
cpuinfo[0][i] = cpuinfo_tmp[i];
}
}
+#endif /* defined(KERN_CP_TIME) && defined(KERNEL_NETBSD) */
for (int i = 0; i < numcpu; i++) {
cpu_stage(i, COLLECTD_CPU_STATE_USER, (derive_t)cpuinfo[i][CP_USER], now);