X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcommon.c;h=57bcaaab5d73f28c30552e08c237cc0ed8677996;hb=6ee4780546b133905f488296747f915a5fbb9de1;hp=5b6c52505ea20f8bb7983c2620c98385f7316356;hpb=ca767bb2ebdd94667202e9946c9b8f712d89b5a8;p=netdata.git diff --git a/src/common.c b/src/common.c index 5b6c5250..57bcaaab 100644 --- a/src/common.c +++ b/src/common.c @@ -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;