Avoid using sysctl on linux
authorZebity Spring <zebity@yahoo.com>
Sat, 9 Nov 2019 12:05:22 +0000 (23:05 +1100)
committerZebity Spring <zebity@yahoo.com>
Sat, 9 Nov 2019 12:05:22 +0000 (23:05 +1100)
src/cpu.c
src/swap.c

index 92ebfd8..8c1d4cb 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -58,7 +58,7 @@
 #include <sys/sysinfo.h>
 #endif /* HAVE_LIBKSTAT */
 
-#if defined(HAVE_SYSCTL) && defined(HAVE_SYSCTLBYNAME)
+#if (defined(HAVE_SYSCTL) && defined(HAVE_SYSCTLBYNAME)) || defined(__OpenBSD__)
 /* Implies BSD variant */
 #include <sys/sysctl.h>
 #endif
 #endif /* HAVE_SYS_DKSTAT_H */
 
 #define CAN_USE_SYSCTL 0
-#if defined(HAVE_SYSCTL) && defined(HAVE_SYSCTLBYNAME)
+#if (defined(HAVE_SYSCTL) && defined(HAVE_SYSCTLBYNAME)) || defined(__OpenBSD__)
 /* Implies BSD variant */
 #if defined(CTL_HW) && defined(HW_NCPU) && defined(CTL_KERN) &&                \
     defined(KERN_CPTIME) && defined(CPUSTATES)
 #define CAN_USE_SYSCTL 1
 #endif
-#endif /* HAVE_SYSCTL_H && HAVE_SYSCTLBYNAME */
+#endif /* HAVE_SYSCTL_H && HAVE_SYSCTLBYNAME || __OpenBSD__ */
 
 #define COLLECTD_CPU_STATE_USER 0
 #define COLLECTD_CPU_STATE_SYSTEM 1
@@ -143,7 +143,7 @@ static int numcpu;
 /* #endif HAVE_LIBKSTAT */
 
 #elif CAN_USE_SYSCTL
-/* Only possible for BSD variant */
+/* Only possible for (Open) BSD variant */
 static int numcpu;
 /* #endif CAN_USE_SYSCTL */
 
@@ -269,7 +269,7 @@ static int init(void) {
       /* #endif HAVE_LIBKSTAT */
 
 #elif CAN_USE_SYSCTL
-  /* Only on BSD variant */
+  /* Only on (Open) BSD variant */
   size_t numcpu_size;
   int mib[2] = {CTL_HW, HW_NCPU};
   int status;
@@ -733,7 +733,7 @@ static int cpu_read(void) {
     /* }}} #endif defined(HAVE_LIBKSTAT) */
 
 #elif CAN_USE_SYSCTL /* {{{ */
-  /* Only on BSD variant */
+  /* Only on (Open) BSD variant */
   uint64_t cpuinfo[numcpu][CPUSTATES];
   size_t cpuinfo_size;
   int status;
index 0a86632..ee5afa0 100644 (file)
@@ -49,7 +49,7 @@
 #if HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
-#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
+#if (defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)) || defined(__OpenBSD__)
 /* implies BSD variant */
 #include <sys/sysctl.h>
 #endif