X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fcommon.c;h=98093b965cd4e70a8a62eb28a44abe4f473b20ee;hb=331ae4c0caccff0df4abac224de94c969b6f35cd;hp=ce348d79479ab1b3dd7564ba5f98733a999648a8;hpb=515257e187e280144a69109e047dfd6c726f4344;p=netdata.git diff --git a/src/common.c b/src/common.c index ce348d79..98093b96 100644 --- a/src/common.c +++ b/src/common.c @@ -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; @@ -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; @@ -1127,11 +1131,9 @@ long get_system_cpus(void) { 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;