Merge branch 'collectd-5.8'
[collectd.git] / src / daemon / collectd.h
1 /**
2  * collectd - src/collectd.h
3  * Copyright (C) 2005,2006  Florian octo Forster
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *   Florian octo Forster <octo at collectd.org>
25  **/
26
27 #ifndef COLLECTD_H
28 #define COLLECTD_H
29
30 #if HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <assert.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <inttypes.h>
38 #include <limits.h>
39 #include <signal.h>
40 #include <stdarg.h>
41 #include <stdbool.h>
42 #include <stddef.h>
43 #include <stdint.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #if HAVE_SYS_TYPES_H
48 #include <sys/types.h>
49 #endif
50 #if HAVE_SYS_STAT_H
51 #include <sys/stat.h>
52 #endif
53 #if HAVE_STRINGS_H
54 #include <strings.h>
55 #endif
56 #if HAVE_UNISTD_H
57 #include <unistd.h>
58 #endif
59 #if HAVE_SYS_WAIT_H
60 #include <sys/wait.h>
61 #endif
62 #ifndef WEXITSTATUS
63 #define WEXITSTATUS(stat_val) ((unsigned int)(stat_val) >> 8)
64 #endif
65 #ifndef WIFEXITED
66 #define WIFEXITED(stat_val) (((stat_val)&255) == 0)
67 #endif
68 #if HAVE_FCNTL_H
69 #include <fcntl.h>
70 #endif
71 #if TIME_WITH_SYS_TIME
72 #include <sys/time.h>
73 #include <time.h>
74 #else
75 #if HAVE_SYS_TIME_H
76 #include <sys/time.h>
77 #else
78 #include <time.h>
79 #endif
80 #endif
81 #if HAVE_SYS_SOCKET_H
82 #include <sys/socket.h>
83 #endif
84
85 #if NAN_STATIC_DEFAULT
86 #include <math.h>
87 /* #endif NAN_STATIC_DEFAULT*/
88 #elif NAN_STATIC_ISOC
89 #ifndef __USE_ISOC99
90 #define DISABLE_ISOC99 1
91 #define __USE_ISOC99 1
92 #endif /* !defined(__USE_ISOC99) */
93 #include <math.h>
94 #if DISABLE_ISOC99
95 #undef DISABLE_ISOC99
96 #undef __USE_ISOC99
97 #endif /* DISABLE_ISOC99 */
98 /* #endif NAN_STATIC_ISOC */
99 #elif NAN_ZERO_ZERO
100 #include <math.h>
101 #ifdef NAN
102 #undef NAN
103 #endif
104 #define NAN (0.0 / 0.0)
105 #ifndef isnan
106 #define isnan(f) ((f) != (f))
107 #endif /* !defined(isnan) */
108 #ifndef isfinite
109 #define isfinite(f) (((f) - (f)) == 0.0)
110 #endif
111 #ifndef isinf
112 #define isinf(f) (!isfinite(f) && !isnan(f))
113 #endif
114 #endif /* NAN_ZERO_ZERO */
115
116 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
117  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
118  * this too.. */
119 #if HAVE_ENDIAN_H
120 #include <endian.h>
121 #elif HAVE_SYS_ISA_DEFS_H
122 #include <sys/isa_defs.h>
123 #endif
124
125 #ifndef BYTE_ORDER
126 #if defined(_BYTE_ORDER)
127 #define BYTE_ORDER _BYTE_ORDER
128 #elif defined(__BYTE_ORDER)
129 #define BYTE_ORDER __BYTE_ORDER
130 #elif defined(__DARWIN_BYTE_ORDER)
131 #define BYTE_ORDER __DARWIN_BYTE_ORDER
132 #endif
133 #endif
134 #ifndef BIG_ENDIAN
135 #if defined(_BIG_ENDIAN)
136 #define BIG_ENDIAN _BIG_ENDIAN
137 #elif defined(__BIG_ENDIAN)
138 #define BIG_ENDIAN __BIG_ENDIAN
139 #elif defined(__DARWIN_BIG_ENDIAN)
140 #define BIG_ENDIAN __DARWIN_BIG_ENDIAN
141 #endif
142 #endif
143 #ifndef LITTLE_ENDIAN
144 #if defined(_LITTLE_ENDIAN)
145 #define LITTLE_ENDIAN _LITTLE_ENDIAN
146 #elif defined(__LITTLE_ENDIAN)
147 #define LITTLE_ENDIAN __LITTLE_ENDIAN
148 #elif defined(__DARWIN_LITTLE_ENDIAN)
149 #define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
150 #endif
151 #endif
152 #ifndef BYTE_ORDER
153 #if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
154 #undef BIG_ENDIAN
155 #define BIG_ENDIAN 4321
156 #define LITTLE_ENDIAN 1234
157 #define BYTE_ORDER BIG_ENDIAN
158 #elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
159 #undef LITTLE_ENDIAN
160 #define BIG_ENDIAN 4321
161 #define LITTLE_ENDIAN 1234
162 #define BYTE_ORDER LITTLE_ENDIAN
163 #endif
164 #endif
165 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
166 #error "Cannot determine byte order"
167 #endif
168
169 #if HAVE_DIRENT_H
170 #include <dirent.h>
171 #define NAMLEN(dirent) strlen((dirent)->d_name)
172 #else
173 #define dirent direct
174 #define NAMLEN(dirent) (dirent)->d_namlen
175 #if HAVE_SYS_NDIR_H
176 #include <sys/ndir.h>
177 #endif
178 #if HAVE_SYS_DIR_H
179 #include <sys/dir.h>
180 #endif
181 #if HAVE_NDIR_H
182 #include <ndir.h>
183 #endif
184 #endif
185
186 #if HAVE_SYS_PARAM_H
187 #include <sys/param.h>
188 #endif
189
190 #ifndef PACKAGE_NAME
191 #define PACKAGE_NAME "collectd"
192 #endif
193
194 #ifndef PREFIX
195 #define PREFIX "/opt/" PACKAGE_NAME
196 #endif
197
198 #ifndef SYSCONFDIR
199 #define SYSCONFDIR PREFIX "/etc"
200 #endif
201
202 #ifndef CONFIGFILE
203 #define CONFIGFILE SYSCONFDIR "/collectd.conf"
204 #endif
205
206 #ifndef LOCALSTATEDIR
207 #define LOCALSTATEDIR PREFIX "/var"
208 #endif
209
210 #ifndef PKGLOCALSTATEDIR
211 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
212 #endif
213
214 #ifndef PIDFILE
215 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
216 #endif
217
218 #ifndef PLUGINDIR
219 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
220 #endif
221
222 #ifndef PKGDATADIR
223 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
224 #endif
225
226 #ifndef COLLECTD_GRP_NAME
227 #define COLLECTD_GRP_NAME "collectd"
228 #endif
229
230 #ifndef COLLECTD_DEFAULT_INTERVAL
231 #define COLLECTD_DEFAULT_INTERVAL 10.0
232 #endif
233
234 #ifndef COLLECTD_USERAGENT
235 #define COLLECTD_USERAGENT PACKAGE_NAME "/" PACKAGE_VERSION
236 #endif
237
238 /* Only enable __attribute__() for compilers known to support it. */
239 #if !defined(__clang__) && !defined(__GNUC__)
240 #define __attribute__(x) /**/
241 #endif
242
243 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
244 #undef strcpy
245 #undef strcat
246 #undef strtok
247 #pragma GCC poison strcpy strcat strtok
248 #endif
249
250 /*
251  * Special hack for the perl plugin: Because the later included perl.h defines
252  * a macro which is never used, but contains `sprintf', we cannot poison that
253  * identifies just yet. The parl plugin will do that itself once perl.h is
254  * included.
255  */
256 #ifndef DONT_POISON_SPRINTF_YET
257 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
258 #undef sprintf
259 #pragma GCC poison sprintf
260 #endif
261 #endif
262
263 #ifndef GAUGE_FORMAT
264 #define GAUGE_FORMAT "%.15g"
265 #endif
266
267 #include "globals.h"
268
269 #endif /* COLLECTD_H */