]> arthur.barton.de Git - netdata.git/blobdiff - src/plugin_freebsd.h
added compile option NETDATA_VERIFY_LOCKS to enable the locks
[netdata.git] / src / plugin_freebsd.h
index 4ae1a4c21831e7b8ba7f291c6794dbb2190d8d5a..3a1ac39100ff884171bfcb5bdb0a7b3b7afa6e96 100644 (file)
@@ -1,12 +1,27 @@
 #ifndef NETDATA_PLUGIN_FREEBSD_H
 #define NETDATA_PLUGIN_FREEBSD_H 1
 
+#include <sys/sysctl.h>
+
 #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
 
 void *freebsd_main(void *ptr);
 
-int getsysctl(const char *name, void *ptr, size_t len);
-
 extern int do_freebsd_sysctl(int update_every, usec_t dt);
 
+static inline int getsysctl(const char *name, void *ptr, size_t len)
+{
+    size_t nlen = len;
+
+    if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
+        error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
+        return 1;
+    }
+    if (unlikely(nlen != len)) {
+        error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
+        return 1;
+    }
+    return 0;
+}
+
 #endif /* NETDATA_PLUGIN_FREEBSD_H */