]> arthur.barton.de Git - netdata.git/blob - src/common.h
Merge pull request #1441 from l2isbad/freeradius_bug_fix
[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 <net/if.h>
64
65 #include <poll.h>
66 #include <signal.h>
67 #include <syslog.h>
68 #include <sys/mman.h>
69 #if !(defined(__FreeBSD__) || defined(__APPLE__))
70 #include <sys/prctl.h>
71 #endif /* __FreeBSD__ || __APPLE__*/
72 #include <sys/resource.h>
73 #include <sys/socket.h>
74 #include <sys/stat.h>
75 #include <sys/statvfs.h>
76 #include <sys/syscall.h>
77 #include <sys/time.h>
78 #include <sys/types.h>
79 #include <sys/wait.h>
80 #include <time.h>
81 #include <unistd.h>
82 #include <uuid/uuid.h>
83
84 // #1408
85 #ifdef MAJOR_IN_MKDEV
86 #include <sys/mkdev.h>
87 #endif
88 #ifdef MAJOR_IN_SYSMACROS
89 #include <sys/sysmacros.h>
90 #endif
91
92 /*
93 #include <mntent.h>
94 */
95
96 #ifdef STORAGE_WITH_MATH
97 #include <math.h>
98 #endif
99
100 #if defined(HAVE_INTTYPES_H)
101 #include <inttypes.h>
102 #elif defined(HAVE_STDINT_H)
103 #include <stdint.h>
104 #endif
105
106 #ifdef NETDATA_WITH_ZLIB
107 #include <zlib.h>
108 #endif
109
110 #if (SIZEOF_VOID_P == 8)
111 #define ENVIRONMENT64
112 #elif (SIZEOF_VOID_P == 4)
113 #define ENVIRONMENT32
114 #else
115 #error "Cannot detect if this is a 32 or 64 bit CPU"
116 #endif
117
118 #ifdef __GNUC__
119 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
120 #endif // __GNUC__
121
122 #include "avl.h"
123 #include "clocks.h"
124 #include "log.h"
125 #include "global_statistics.h"
126 #include "storage_number.h"
127 #include "web_buffer.h"
128 #include "web_buffer_svg.h"
129 #include "url.h"
130 #include "popen.h"
131
132 #include "procfile.h"
133 #include "appconfig.h"
134 #include "dictionary.h"
135 #include "proc_self_mountinfo.h"
136 #include "plugin_checks.h"
137 #include "plugin_idlejitter.h"
138 #include "plugin_nfacct.h"
139 #if !(defined(__FreeBSD__) || defined(__APPLE__))
140 #include "plugin_proc.h"
141 #else
142 #include "plugin_freebsd.h"
143 #endif /* __FreeBSD__ || __APPLE__*/
144 #include "plugin_tc.h"
145 #include "plugins_d.h"
146
147 #include "socket.h"
148
149 #include "eval.h"
150 #include "health.h"
151
152 #include "rrd.h"
153 #include "rrd2json.h"
154
155 #include "web_client.h"
156 #include "web_server.h"
157
158 #include "registry.h"
159 #include "daemon.h"
160 #include "main.h"
161 #include "unit_test.h"
162
163 #include "ipc.h"
164 #include "backends.h"
165
166 #ifdef abs
167 #undef abs
168 #endif
169 #define abs(x) ((x < 0)? -x : x)
170
171 extern void netdata_fix_chart_id(char *s);
172 extern void netdata_fix_chart_name(char *s);
173
174 extern uint32_t simple_hash(const char *name);
175 extern uint32_t simple_uhash(const char *name);
176
177 extern void strreverse(char* begin, char* end);
178 extern char *mystrsep(char **ptr, char *s);
179 extern char *trim(char *s);
180
181 extern char *strncpyz(char *dst, const char *src, size_t n);
182 extern int  vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
183 extern int  snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
184
185 // memory allocation functions that handle failures
186 #ifdef NETDATA_LOG_ALLOCATIONS
187 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
188 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
189 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
190 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
191 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
192
193 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
194 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
195 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
196 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
197 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
198 #else
199 extern char *strdupz(const char *s);
200 extern void *callocz(size_t nmemb, size_t size);
201 extern void *mallocz(size_t size);
202 extern void *reallocz(void *ptr, size_t size);
203 extern void freez(void *ptr);
204 #endif
205
206 extern void json_escape_string(char *dst, const char *src, size_t size);
207
208 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
209 extern int savememory(const char *filename, void *mem, size_t size);
210
211 extern int fd_is_valid(int fd);
212
213 extern char *global_host_prefix;
214 extern int enable_ksm;
215
216 extern pid_t gettid(void);
217
218 extern int sleep_usec(usec_t usec);
219
220 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
221
222 extern int processors;
223 extern long get_system_cpus(void);
224
225 extern pid_t pid_max;
226 extern pid_t get_system_pid_max(void);
227
228 /* Number of ticks per second */
229 extern unsigned int hz;
230 extern void get_system_HZ(void);
231
232
233 /* fix for alpine linux */
234 #ifndef RUSAGE_THREAD
235 #ifdef RUSAGE_CHILDREN
236 #define RUSAGE_THREAD RUSAGE_CHILDREN
237 #endif
238 #endif
239
240 extern int read_single_number_file(const char *filename, unsigned long long *result);
241
242 #endif /* NETDATA_COMMON_H */