From: Vladimir Kobal Date: Tue, 31 Jan 2017 21:48:58 +0000 (+0200) Subject: Fix processors and pid_max for FreeBSD X-Git-Tag: ab-debian_0.20170201.01-0ab1~6^2~1 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netdata.git;a=commitdiff_plain;h=54dcdaf6856c180420b5a186c9efb3e6b24ce837 Fix processors and pid_max for FreeBSD --- diff --git a/src/Makefile.am b/src/Makefile.am index 921b26e5..bec3ef92 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) \ diff --git a/src/common.c b/src/common.c index 5b6c5250..f4dfbb02 100644 --- a/src/common.c +++ b/src/common.c @@ -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; diff --git a/src/plugin_freebsd.c b/src/plugin_freebsd.c index 134d035b..4fef148a 100644 --- a/src/plugin_freebsd.c +++ b/src/plugin_freebsd.c @@ -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; -} diff --git a/src/plugin_freebsd.h b/src/plugin_freebsd.h index e4767a09..3a1ac391 100644 --- a/src/plugin_freebsd.h +++ b/src/plugin_freebsd.h @@ -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 */