]> arthur.barton.de Git - netdata.git/commitdiff
Fix processors and pid_max for FreeBSD
authorVladimir Kobal <vlad@prokk.net>
Tue, 31 Jan 2017 21:48:58 +0000 (23:48 +0200)
committerVladimir Kobal <vlad@prokk.net>
Tue, 31 Jan 2017 21:48:58 +0000 (23:48 +0200)
src/Makefile.am
src/common.c
src/plugin_freebsd.c
src/plugin_freebsd.h

index 921b26e5e6e90fd49fac4e9a7f2a0031f48ff947..bec3ef92d80db15b9264ce6481211bbe781de399 100644 (file)
@@ -135,6 +135,12 @@ apps_plugin_SOURCES = \
        web_buffer.c web_buffer.h \
        $(NULL)
 
+if FREEBSD
+apps_plugin_SOURCES += \
+       plugin_freebsd.h \
+       $(NULL)
+endif
+
 apps_plugin_LDADD = \
        $(OPTIONAL_MATH_LIBS) \
        $(OPTIONAL_CAP_LIBS) \
index 5b6c52505ea20f8bb7983c2620c98385f7316356..f4dfbb02915c759e7d0a36ae6fa32121ee3397b3 100644 (file)
@@ -1110,6 +1110,16 @@ long get_system_cpus(void) {
             processors = tmp_processors;
         }
 
+        return processors;
+    #elif __FreeBSD__
+        int32_t tmp_processors;
+
+        if (unlikely(GETSYSCTL("hw.ncpu", tmp_processors))) {
+            error("Assuming system has %d processors.", processors);
+        } else {
+            processors = tmp_processors;
+        }
+
         return processors;
     #else
 
@@ -1143,7 +1153,7 @@ long get_system_cpus(void) {
     debug(D_SYSTEM, "System has %d processors.", processors);
     return processors;
 
-    #endif /* __APPLE__ */
+    #endif /* __APPLE__, __FreeBSD__ */
 }
 
 pid_t pid_max = 32768;
@@ -1152,6 +1162,17 @@ pid_t get_system_pid_max(void) {
         // As we currently do not know a solution to query pid_max from the os
         // we use the number defined in bsd/sys/proc_internal.h in XNU sources
         pid_max = 99999;
+        return pid_max;
+    #elif __FreeBSD__
+        int32_t tmp_pid_max;
+
+        if (unlikely(GETSYSCTL("kern.pid_max", tmp_pid_max))) {
+            pid_max = 99999;
+            error("Assuming system's maximum pid is %d.", pid_max);
+        } else {
+            pid_max = tmp_pid_max;
+        }
+
         return pid_max;
     #else
 
@@ -1176,7 +1197,7 @@ pid_t get_system_pid_max(void) {
     pid_max = (pid_t) max;
     return pid_max;
 
-    #endif /* __APPLE__ */
+    #endif /* __APPLE__, __FreeBSD__ */
 }
 
 unsigned int hz;
index 134d035b58f0af087870c4a005768a377135bdbf..4fef148ab6a86da1e82e81f62600b51e850623a5 100644 (file)
@@ -50,18 +50,3 @@ void *freebsd_main(void *ptr) {
     pthread_exit(NULL);
     return NULL;
 }
-
-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;
-}
index e4767a091310399a39eeade063c6d446e501ad75..3a1ac39100ff884171bfcb5bdb0a7b3b7afa6e96 100644 (file)
@@ -7,8 +7,21 @@
 
 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 */