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 **/
27 #ifndef COLLECTD_H
28 #define COLLECTD_H
30 #if HAVE_CONFIG_H
31 # include "config.h"
32 #endif
34 #include <stdio.h>
35 #if HAVE_SYS_TYPES_H
36 # include <sys/types.h>
37 #endif
38 #if HAVE_SYS_STAT_H
39 # include <sys/stat.h>
40 #endif
41 #if STDC_HEADERS
42 # include <stdlib.h>
43 # include <stddef.h>
44 #else
45 # if HAVE_STDLIB_H
46 # include <stdlib.h>
47 # endif
48 #endif
49 #if HAVE_STRING_H
50 # if !STDC_HEADERS && HAVE_MEMORY_H
51 # include <memory.h>
52 # endif
53 # include <string.h>
54 #endif
55 #if HAVE_STRINGS_H
56 # include <strings.h>
57 #endif
58 #if HAVE_INTTYPES_H
59 # include <inttypes.h>
60 #endif
61 #if HAVE_STDINT_H
62 # include <stdint.h>
63 #endif
64 #if HAVE_UNISTD_H
65 # include <unistd.h>
66 #endif
67 #if HAVE_SYS_WAIT_H
68 # include <sys/wait.h>
69 #endif
70 #ifndef WEXITSTATUS
71 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
72 #endif
73 #ifndef WIFEXITED
74 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
75 #endif
76 #if HAVE_SIGNAL_H
77 # include <signal.h>
78 #endif
79 #if HAVE_FCNTL_H
80 # include <fcntl.h>
81 #endif
82 #if HAVE_ERRNO_H
83 # include <errno.h>
84 #endif
85 #if HAVE_LIMITS_H
86 # include <limits.h>
87 #endif
88 #if TIME_WITH_SYS_TIME
89 # include <sys/time.h>
90 # include <time.h>
91 #else
92 # if HAVE_SYS_TIME_H
93 # include <sys/time.h>
94 # else
95 # include <time.h>
96 # endif
97 #endif
99 #if HAVE_ASSERT_H
100 # include <assert.h>
101 #else
102 # define assert(...) /* nop */
103 #endif
105 #if !defined(HAVE__BOOL) || !HAVE__BOOL
106 typedef int _Bool;
107 # undef HAVE__BOOL
108 # define HAVE__BOOL 1
109 #endif
111 #if NAN_STATIC_DEFAULT
112 # include <math.h>
113 /* #endif NAN_STATIC_DEFAULT*/
114 #elif NAN_STATIC_ISOC
115 # ifndef __USE_ISOC99
116 # define DISABLE_ISOC99 1
117 # define __USE_ISOC99 1
118 # endif /* !defined(__USE_ISOC99) */
119 # include <math.h>
120 # if DISABLE_ISOC99
121 # undef DISABLE_ISOC99
122 # undef __USE_ISOC99
123 # endif /* DISABLE_ISOC99 */
124 /* #endif NAN_STATIC_ISOC */
125 #elif NAN_ZERO_ZERO
126 # include <math.h>
127 # ifdef NAN
128 # undef NAN
129 # endif
130 # define NAN (0.0 / 0.0)
131 # ifndef isnan
132 # define isnan(f) ((f) != (f))
133 # endif /* !defined(isnan) */
134 # ifndef isfinite
135 # define isfinite(f) (((f) - (f)) == 0.0)
136 # endif
137 # ifndef isinf
138 # define isinf(f) (!isfinite(f) && !isnan(f))
139 # endif
140 #endif /* NAN_ZERO_ZERO */
142 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
143 * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
144 * this too.. */
145 #if HAVE_ENDIAN_H
146 # include <endian.h>
147 #elif HAVE_SYS_ISA_DEFS_H
148 # include <sys/isa_defs.h>
149 #endif
151 #ifndef BYTE_ORDER
152 # if defined(_BYTE_ORDER)
153 # define BYTE_ORDER _BYTE_ORDER
154 # elif defined(__BYTE_ORDER)
155 # define BYTE_ORDER __BYTE_ORDER
156 # elif defined(__DARWIN_BYTE_ORDER)
157 # define BYTE_ORDER __DARWIN_BYTE_ORDER
158 # endif
159 #endif
160 #ifndef BIG_ENDIAN
161 # if defined(_BIG_ENDIAN)
162 # define BIG_ENDIAN _BIG_ENDIAN
163 # elif defined(__BIG_ENDIAN)
164 # define BIG_ENDIAN __BIG_ENDIAN
165 # elif defined(__DARWIN_BIG_ENDIAN)
166 # define BIG_ENDIAN __DARWIN_BIG_ENDIAN
167 # endif
168 #endif
169 #ifndef LITTLE_ENDIAN
170 # if defined(_LITTLE_ENDIAN)
171 # define LITTLE_ENDIAN _LITTLE_ENDIAN
172 # elif defined(__LITTLE_ENDIAN)
173 # define LITTLE_ENDIAN __LITTLE_ENDIAN
174 # elif defined(__DARWIN_LITTLE_ENDIAN)
175 # define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
176 # endif
177 #endif
178 #ifndef BYTE_ORDER
179 # if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
180 # undef BIG_ENDIAN
181 # define BIG_ENDIAN 4321
182 # define LITTLE_ENDIAN 1234
183 # define BYTE_ORDER BIG_ENDIAN
184 # elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
185 # undef LITTLE_ENDIAN
186 # define BIG_ENDIAN 4321
187 # define LITTLE_ENDIAN 1234
188 # define BYTE_ORDER LITTLE_ENDIAN
189 # endif
190 #endif
191 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
192 # error "Cannot determine byte order"
193 #endif
195 #if HAVE_DIRENT_H
196 # include <dirent.h>
197 # define NAMLEN(dirent) strlen((dirent)->d_name)
198 #else
199 # define dirent direct
200 # define NAMLEN(dirent) (dirent)->d_namlen
201 # if HAVE_SYS_NDIR_H
202 # include <sys/ndir.h>
203 # endif
204 # if HAVE_SYS_DIR_H
205 # include <sys/dir.h>
206 # endif
207 # if HAVE_NDIR_H
208 # include <ndir.h>
209 # endif
210 #endif
212 #if HAVE_STDARG_H
213 # include <stdarg.h>
214 #endif
215 #if HAVE_CTYPE_H
216 # include <ctype.h>
217 #endif
218 #if HAVE_SYS_PARAM_H
219 # include <sys/param.h>
220 #endif
222 #if HAVE_KSTAT_H
223 # include <kstat.h>
224 #endif
226 #ifndef PACKAGE_NAME
227 #define PACKAGE_NAME "collectd"
228 #endif
230 #ifndef PREFIX
231 #define PREFIX "/opt/" PACKAGE_NAME
232 #endif
234 #ifndef SYSCONFDIR
235 #define SYSCONFDIR PREFIX "/etc"
236 #endif
238 #ifndef CONFIGFILE
239 #define CONFIGFILE SYSCONFDIR"/collectd.conf"
240 #endif
242 #ifndef LOCALSTATEDIR
243 #define LOCALSTATEDIR PREFIX "/var"
244 #endif
246 #ifndef PKGLOCALSTATEDIR
247 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
248 #endif
250 #ifndef PIDFILE
251 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
252 #endif
254 #ifndef PLUGINDIR
255 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
256 #endif
258 #ifndef PKGDATADIR
259 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
260 #endif
262 #ifndef COLLECTD_GRP_NAME
263 # define COLLECTD_GRP_NAME "collectd"
264 #endif
266 #ifndef COLLECTD_DEFAULT_INTERVAL
267 # define COLLECTD_DEFAULT_INTERVAL 10.0
268 #endif
270 #ifndef COLLECTD_USERAGENT
271 # define COLLECTD_USERAGENT PACKAGE_NAME"/"PACKAGE_VERSION
272 #endif
274 /* Only enable __attribute__() for compilers known to support it. */
275 #if defined(__clang__)
276 # define clang_attr(x) __attribute__(x)
277 # define gcc_attr(x) /**/
278 #elif __GNUC__
279 # define clang_attr(x) /**/
280 # define gcc_attr(x) __attribute__(x)
281 #else
282 # define clang_attr(x) /**/
283 # define gcc_attr(x) /**/
284 # define __attribute__(x) /**/
285 #endif
287 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
288 # undef strcpy
289 # undef strcat
290 # undef strtok
291 # pragma GCC poison strcpy strcat strtok
292 #endif
294 /*
295 * Special hack for the perl plugin: Because the later included perl.h defines
296 * a macro which is never used, but contains `sprintf', we cannot poison that
297 * identifies just yet. The parl plugin will do that itself once perl.h is
298 * included.
299 */
300 #ifndef DONT_POISON_SPRINTF_YET
301 # if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
302 # undef sprintf
303 # pragma GCC poison sprintf
304 # endif
305 #endif
307 #ifndef GAUGE_FORMAT
308 # define GAUGE_FORMAT "%.15g"
309 #endif
311 /* Type for time as used by "utils_time.h" */
312 typedef uint64_t cdtime_t;
314 extern char hostname_g[];
315 extern cdtime_t interval_g;
316 extern int pidfile_from_cli;
317 extern int timeout_g;
319 #endif /* COLLECTD_H */