]> arthur.barton.de Git - netdata.git/blobdiff - src/common.c
apps.plugin detects in-place process changes; fixes #1698
[netdata.git] / src / common.c
index 5b6c52505ea20f8bb7983c2620c98385f7316356..57bcaaab5d73f28c30552e08c237cc0ed8677996 100644 (file)
@@ -1060,17 +1060,6 @@ char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
     return s;
 }
 
-char *strncpyz(char *dst, const char *src, size_t n) {
-    char *p = dst;
-
-    while (*src && n--)
-        *dst++ = *src++;
-
-    *dst = '\0';
-
-    return p;
-}
-
 int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args) {
     int size = vsnprintf(dst, n, fmt, args);
 
@@ -1110,6 +1099,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 +1142,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 +1151,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 +1186,7 @@ pid_t get_system_pid_max(void) {
     pid_max = (pid_t) max;
     return pid_max;
 
-    #endif /* __APPLE__ */
+    #endif /* __APPLE__, __FreeBSD__ */
 }
 
 unsigned int hz;