@cryptotaxi247 / netdata-1 / commits / 54dcdaf68

Fix processors and pid_max for FreeBSD

Vladimir Kobal committed Jan 31, 2017 at 23:48 UTC 54dcdaf6856c180420b5a186c9efb3e6b24ce837
4 files changed +44 -19
src/Makefile.am
+6
@@ -135,6 +135,12 @@ apps_plugin_SOURCES = \
135 web_buffer.c web_buffer.h \
136 $(NULL)
137
138 +if FREEBSD
139 +apps_plugin_SOURCES += \
140 + plugin_freebsd.h \
141 + $(NULL)
142 +endif
143 +
144 apps_plugin_LDADD = \
145 $(OPTIONAL_MATH_LIBS) \
146 $(OPTIONAL_CAP_LIBS) \
src/common.c
+23 -2
@@ -1110,6 +1110,16 @@ long get_system_cpus(void) {
1110 processors = tmp_processors;
1111 }
1112
1113 + return processors;
1114 + #elif __FreeBSD__
1115 + int32_t tmp_processors;
1116 +
1117 + if (unlikely(GETSYSCTL("hw.ncpu", tmp_processors))) {
1118 + error("Assuming system has %d processors.", processors);
1119 + } else {
1120 + processors = tmp_processors;
1121 + }
1122 +
1123 return processors;
1124 #else
1125
@@ -1143,7 +1153,7 @@ long get_system_cpus(void) {
1153 debug(D_SYSTEM, "System has %d processors.", processors);
1154 return processors;
1155
1146 - #endif /* __APPLE__ */
1156 + #endif /* __APPLE__, __FreeBSD__ */
1157 }
1158
1159 pid_t pid_max = 32768;
@@ -1152,6 +1162,17 @@ pid_t get_system_pid_max(void) {
1162 // As we currently do not know a solution to query pid_max from the os
1163 // we use the number defined in bsd/sys/proc_internal.h in XNU sources
1164 pid_max = 99999;
1165 + return pid_max;
1166 + #elif __FreeBSD__
1167 + int32_t tmp_pid_max;
1168 +
1169 + if (unlikely(GETSYSCTL("kern.pid_max", tmp_pid_max))) {
1170 + pid_max = 99999;
1171 + error("Assuming system's maximum pid is %d.", pid_max);
1172 + } else {
1173 + pid_max = tmp_pid_max;
1174 + }
1175 +
1176 return pid_max;
1177 #else
1178
@@ -1176,7 +1197,7 @@ pid_t get_system_pid_max(void) {
1197 pid_max = (pid_t) max;
1198 return pid_max;
1199
1179 - #endif /* __APPLE__ */
1200 + #endif /* __APPLE__, __FreeBSD__ */
1201 }
1202
1203 unsigned int hz;
src/plugin_freebsd.c
-15
@@ -50,18 +50,3 @@ void *freebsd_main(void *ptr) {
50 pthread_exit(NULL);
51 return NULL;
52 }
53 -
54 -int getsysctl(const char *name, void *ptr, size_t len)
55 -{
56 - size_t nlen = len;
57 -
58 - if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
59 - error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
60 - return 1;
61 - }
62 - if (unlikely(nlen != len)) {
63 - error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
64 - return 1;
65 - }
66 - return 0;
67 -}
src/plugin_freebsd.h
+15 -2
@@ -7,8 +7,21 @@
7
8 void *freebsd_main(void *ptr);
9
10 -int getsysctl(const char *name, void *ptr, size_t len);
11 -
10 extern int do_freebsd_sysctl(int update_every, usec_t dt);
11
12 +static inline int getsysctl(const char *name, void *ptr, size_t len)
13 +{
14 + size_t nlen = len;
15 +
16 + if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
17 + error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
18 + return 1;
19 + }
20 + if (unlikely(nlen != len)) {
21 + error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
22 + return 1;
23 + }
24 + return 0;
25 +}
26 +
27 #endif /* NETDATA_PLUGIN_FREEBSD_H */