]> arthur.barton.de Git - netdata.git/blob - src/common.h
Merge pull request #1418 from l2isbad/freeradius_minor_bugfix
[netdata.git] / src / common.h
1 #ifndef NETDATA_COMMON_H
2 #define NETDATA_COMMON_H 1
3
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7
8 /* select the memory allocator, based on autoconf findings */
9 #if defined(ENABLE_JEMALLOC)
10
11 #if defined(HAVE_JEMALLOC_JEMALLOC_H)
12 #include <jemalloc/jemalloc.h>
13 #else
14 #include <malloc.h>
15 #endif
16
17 #elif defined(ENABLE_TCMALLOC)
18
19 #include <google/tcmalloc.h>
20
21 #else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
22
23 #if !(defined(__FreeBSD__) || defined(__APPLE__))
24 #include <malloc.h>
25 #endif /* __FreeBSD__ || __APPLE__ */
26
27 #endif
28
29 #include <pthread.h>
30 #include <errno.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <stddef.h>
36
37 #include <ctype.h>
38 #include <string.h>
39 #include <strings.h>
40
41 #include <arpa/inet.h>
42 #include <netinet/tcp.h>
43
44 #ifdef HAVE_NETINET_IN_H
45 #include <netinet/in.h>
46 #endif
47
48 #ifdef HAVE_RESOLV_H
49 #include <resolv.h>
50 #endif
51
52 #include <dirent.h>
53 #include <fcntl.h>
54 #include <getopt.h>
55 #include <grp.h>
56 #include <pwd.h>
57 #include <locale.h>
58
59 #ifdef HAVE_NETDB_H
60 #include <netdb.h>
61 #endif
62
63 #include <poll.h>
64 #include <signal.h>
65 #include <syslog.h>
66 #include <sys/mman.h>
67 #if !(defined(__FreeBSD__) || defined(__APPLE__))
68 #include <sys/prctl.h>
69 #endif /* __FreeBSD__ || __APPLE__*/
70 #include <sys/resource.h>
71 #include <sys/socket.h>
72 #include <sys/stat.h>
73 #include <sys/statvfs.h>
74 #include <sys/syscall.h>
75 #include <sys/time.h>
76 #include <sys/types.h>
77 #include <sys/wait.h>
78 #include <time.h>
79 #include <unistd.h>
80 #include <uuid/uuid.h>
81
82 // #1408
83 #ifdef MAJOR_IN_MKDEV
84 #include <sys/mkdev.h>
85 #endif
86 #ifdef MAJOR_IN_SYSMACROS
87 #include <sys/sysmacros.h>
88 #endif
89
90 /*
91 #include <mntent.h>
92 */
93
94 #ifdef STORAGE_WITH_MATH
95 #include <math.h>
96 #endif
97
98 #if defined(HAVE_INTTYPES_H)
99 #include <inttypes.h>
100 #elif defined(HAVE_STDINT_H)
101 #include <stdint.h>
102 #endif
103
104 #ifdef NETDATA_WITH_ZLIB
105 #include <zlib.h>
106 #endif
107
108 #if (SIZEOF_VOID_P == 8)
109 #define ENVIRONMENT64
110 #elif (SIZEOF_VOID_P == 4)
111 #define ENVIRONMENT32
112 #else
113 #error "Cannot detect if this is a 32 or 64 bit CPU"
114 #endif
115
116 #ifdef __GNUC__
117 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
118 #endif // __GNUC__
119
120 #include "avl.h"
121 #include "clocks.h"
122 #include "log.h"
123 #include "global_statistics.h"
124 #include "storage_number.h"
125 #include "web_buffer.h"
126 #include "web_buffer_svg.h"
127 #include "url.h"
128 #include "popen.h"
129
130 #include "procfile.h"
131 #include "appconfig.h"
132 #include "dictionary.h"
133 #include "proc_self_mountinfo.h"
134 #include "plugin_checks.h"
135 #include "plugin_idlejitter.h"
136 #include "plugin_nfacct.h"
137 #if !(defined(__FreeBSD__) || defined(__APPLE__))
138 #include "plugin_proc.h"
139 #else
140 #include "plugin_freebsd.h"
141 #endif /* __FreeBSD__ || __APPLE__*/
142 #include "plugin_tc.h"
143 #include "plugins_d.h"
144
145 #include "eval.h"
146 #include "health.h"
147
148 #include "rrd.h"
149 #include "rrd2json.h"
150
151 #include "web_client.h"
152 #include "web_server.h"
153
154 #include "registry.h"
155 #include "daemon.h"
156 #include "main.h"
157 #include "unit_test.h"
158
159 #include "ipc.h"
160 #include "backends.h"
161
162 #ifdef abs
163 #undef abs
164 #endif
165 #define abs(x) ((x < 0)? -x : x)
166
167 extern void netdata_fix_chart_id(char *s);
168 extern void netdata_fix_chart_name(char *s);
169
170 extern uint32_t simple_hash(const char *name);
171 extern uint32_t simple_uhash(const char *name);
172
173 extern void strreverse(char* begin, char* end);
174 extern char *mystrsep(char **ptr, char *s);
175 extern char *trim(char *s);
176
177 extern char *strncpyz(char *dst, const char *src, size_t n);
178 extern int  vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
179 extern int  snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
180
181 // memory allocation functions that handle failures
182 #ifdef NETDATA_LOG_ALLOCATIONS
183 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
184 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
185 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
186 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
187 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
188
189 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
190 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
191 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
192 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
193 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
194 #else
195 extern char *strdupz(const char *s);
196 extern void *callocz(size_t nmemb, size_t size);
197 extern void *mallocz(size_t size);
198 extern void *reallocz(void *ptr, size_t size);
199 extern void freez(void *ptr);
200 #endif
201
202 extern void json_escape_string(char *dst, const char *src, size_t size);
203
204 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
205 extern int savememory(const char *filename, void *mem, size_t size);
206
207 extern int fd_is_valid(int fd);
208
209 extern char *global_host_prefix;
210 extern int enable_ksm;
211
212 extern pid_t gettid(void);
213
214 extern int sleep_usec(usec_t usec);
215
216 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
217
218 extern int processors;
219 extern long get_system_cpus(void);
220
221 extern pid_t pid_max;
222 extern pid_t get_system_pid_max(void);
223
224 /* Number of ticks per second */
225 extern unsigned int hz;
226 extern void get_system_HZ(void);
227
228
229 /* fix for alpine linux */
230 #ifndef RUSAGE_THREAD
231 #ifdef RUSAGE_CHILDREN
232 #define RUSAGE_THREAD RUSAGE_CHILDREN
233 #endif
234 #endif
235
236 extern int read_single_number_file(const char *filename, unsigned long long *result);
237
238 #endif /* NETDATA_COMMON_H */