X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fcommon.c;h=e46397c624be004daa578e0539563b90bd5985e8;hb=b0648742235b8ed4e1b16977286b8de07e7054cf;hp=5b6c52505ea20f8bb7983c2620c98385f7316356;hpb=32fe91cb025e0f53e9430b4bf55d97f8c6f2a15d;p=netdata.git diff --git a/src/common.c b/src/common.c index 5b6c5250..e46397c6 100644 --- a/src/common.c +++ b/src/common.c @@ -8,10 +8,21 @@ # define MADV_DONTFORK INHERIT_NONE #endif /* __FreeBSD__ || __APPLE__*/ -char *global_host_prefix = ""; +char *netdata_configured_hostname = NULL; +char *netdata_configured_config_dir = NULL; +char *netdata_configured_log_dir = NULL; +char *netdata_configured_plugins_dir = NULL; +char *netdata_configured_web_dir = NULL; +char *netdata_configured_cache_dir = NULL; +char *netdata_configured_varlib_dir = NULL; +char *netdata_configured_home_dir = NULL; +char *netdata_configured_host_prefix = NULL; + int enable_ksm = 1; volatile sig_atomic_t netdata_exit = 0; +const char *os_type = NETDATA_OS_TYPE; +const char *program_version = VERSION; // ---------------------------------------------------------------------------- // memory allocation functions that handle failures @@ -1060,17 +1071,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,11 +1110,21 @@ 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 char filename[FILENAME_MAX + 1]; - snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix); + snprintfz(filename, FILENAME_MAX, "%s/proc/stat", netdata_configured_host_prefix); procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT); if(!ff) { @@ -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 @@ -1160,7 +1181,7 @@ pid_t get_system_pid_max(void) { read = 1; char filename[FILENAME_MAX + 1]; - snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix); + snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", netdata_configured_host_prefix); unsigned long long max = 0; if(read_single_number_file(filename, &max) != 0) { @@ -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;