]> arthur.barton.de Git - netdata.git/blobdiff - src/common.c
Minor cleanups and plugin structure changes
[netdata.git] / src / common.c
index e1925ff5e9ad95c12f1fca49c3c249a67830aa3c..98093b965cd4e70a8a62eb28a44abe4f473b20ee 100644 (file)
@@ -1,5 +1,10 @@
 #include "common.h"
 
+#ifdef __FreeBSD__
+#    define O_NOATIME     0
+#    define MADV_DONTFORK INHERIT_NONE
+#endif /* __FreeBSD__ */
+
 char *global_host_prefix = "";
 int enable_ksm = 1;
 
@@ -224,7 +229,7 @@ int sleep_usec(unsigned long long usec) {
 
     while (nanosleep(&req, &rem) == -1) {
         if (likely(errno == EINTR)) {
-            info("nanosleep() interrupted (while sleeping for %llu microseconds).", usec);
+            debug(D_SYSTEM, "nanosleep() interrupted (while sleeping for %llu microseconds).", usec);
             req.tv_sec = rem.tv_sec;
             req.tv_nsec = rem.tv_nsec;
         } else {
@@ -864,11 +869,9 @@ uint32_t simple_hash(const char *name) {
 */
 
 void strreverse(char *begin, char *end) {
-    char aux;
-
     while (end > begin) {
         // clearer code.
-        aux = *end;
+        char aux = *end;
         *end-- = *begin;
         *begin++ = aux;
     }
@@ -905,11 +908,10 @@ void *mymmap(const char *filename, size_t size, int flags, int ksm) {
 #ifdef MADV_MERGEABLE
     static int log_madvise_2 = 1, log_madvise_3 = 1;
 #endif
-    int fd;
     void *mem = NULL;
 
     errno = 0;
-    fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
+    int fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
     if (fd != -1) {
         if (lseek(fd, size, SEEK_SET) == (off_t) size) {
             if (write(fd, "", 1) == 1) {
@@ -1028,7 +1030,11 @@ int fd_is_valid(int fd) {
 }
 
 pid_t gettid(void) {
+#ifdef __FreeBSD__
+    return (pid_t)pthread_getthreadid_np();
+#else
     return (pid_t)syscall(SYS_gettid);
+#endif /* __FreeBSD__ */
 }
 
 char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
@@ -1090,14 +1096,12 @@ int snprintfz(char *dst, size_t n, const char *fmt, ...) {
 
 int processors = 1;
 long get_system_cpus(void) {
-    procfile *ff = NULL;
-
     processors = 1;
 
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix);
 
-    ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
+    procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
     if(!ff) {
         error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
         return processors;
@@ -1121,17 +1125,15 @@ long get_system_cpus(void) {
 
     procfile_close(ff);
 
-    info("System has %d processors.", processors);
+    debug(D_SYSTEM, "System has %d processors.", processors);
     return processors;
 }
 
 pid_t pid_max = 32768;
 pid_t get_system_pid_max(void) {
-    procfile *ff = NULL;
-
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix);
-    ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
+    procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
     if(!ff) {
         error("Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
         return pid_max;
@@ -1152,7 +1154,7 @@ pid_t get_system_pid_max(void) {
     }
 
     procfile_close(ff);
-    info("System supports %d pids.", pid_max);
+    debug(D_SYSTEM, "System supports %d pids.", pid_max);
     return pid_max;
 }