]> arthur.barton.de Git - netdata.git/blob - src/common.h
more registry code cleanup and re-organization for better management
[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__)
140 #include "plugin_freebsd.h"
141 #elif defined(__APPLE__)
142 #include "plugin_macos.h"
143 #else
144 #include "plugin_proc.h"
145 #endif /* __FreeBSD__, __APPLE__*/
146 #include "plugin_tc.h"
147 #include "plugins_d.h"
148
149 #include "socket.h"
150
151 #include "eval.h"
152 #include "health.h"
153
154 #include "rrd.h"
155 #include "rrd2json.h"
156
157 #include "web_client.h"
158 #include "web_server.h"
159
160 #include "registry.h"
161 #include "daemon.h"
162 #include "main.h"
163 #include "unit_test.h"
164
165 #include "ipc.h"
166 #include "backends.h"
167
168 #ifdef abs
169 #undef abs
170 #endif
171 #define abs(x) ((x < 0)? -x : x)
172
173 #define GUID_LEN 36
174
175 extern void netdata_fix_chart_id(char *s);
176 extern void netdata_fix_chart_name(char *s);
177
178 extern uint32_t simple_hash(const char *name);
179 extern uint32_t simple_uhash(const char *name);
180
181 extern void strreverse(char* begin, char* end);
182 extern char *mystrsep(char **ptr, char *s);
183 extern char *trim(char *s);
184
185 extern char *strncpyz(char *dst, const char *src, size_t n);
186 extern int  vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
187 extern int  snprintfz(char *dst, size_t n, const char *fmt, ...) __attribute__ (( format (printf, 3, 4)));
188
189 // memory allocation functions that handle failures
190 #ifdef NETDATA_LOG_ALLOCATIONS
191 #define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
192 #define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
193 #define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
194 #define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
195 #define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
196
197 extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
198 extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
199 extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
200 extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
201 extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
202 #else
203 extern char *strdupz(const char *s) __attribute__((returns_nonnull, malloc));
204 extern void *callocz(size_t nmemb, size_t size) __attribute__((returns_nonnull, malloc));
205 extern void *mallocz(size_t size) __attribute__((returns_nonnull, malloc));
206 extern void *reallocz(void *ptr, size_t size) __attribute__((returns_nonnull, malloc));
207 extern void freez(void *ptr);
208 #endif
209
210 extern void json_escape_string(char *dst, const char *src, size_t size);
211
212 extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
213 extern int savememory(const char *filename, void *mem, size_t size);
214
215 extern int fd_is_valid(int fd);
216
217 extern char *global_host_prefix;
218 extern int enable_ksm;
219
220 extern pid_t gettid(void);
221
222 extern int sleep_usec(usec_t usec);
223
224 extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
225
226 extern int processors;
227 extern long get_system_cpus(void);
228
229 extern pid_t pid_max;
230 extern pid_t get_system_pid_max(void);
231
232 /* Number of ticks per second */
233 extern unsigned int hz;
234 extern void get_system_HZ(void);
235
236
237 /* fix for alpine linux */
238 #ifndef RUSAGE_THREAD
239 #ifdef RUSAGE_CHILDREN
240 #define RUSAGE_THREAD RUSAGE_CHILDREN
241 #endif
242 #endif
243
244 extern int read_single_number_file(const char *filename, unsigned long long *result);
245
246 #endif /* NETDATA_COMMON_H */