Merge branch 'collectd-4.5' into collectd-4.6
[collectd.git] / src / collectd.h
1 /**
2  * collectd - src/collectd.h
3  * Copyright (C) 2005,2006  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #ifndef COLLECTD_H
23 #define COLLECTD_H
24
25 #if HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #if HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33 #if HAVE_SYS_STAT_H
34 # include <sys/stat.h>
35 #endif
36 #if STDC_HEADERS
37 # include <stdlib.h>
38 # include <stddef.h>
39 #else
40 # if HAVE_STDLIB_H
41 #  include <stdlib.h>
42 # endif
43 #endif
44 #if HAVE_STRING_H
45 # if !STDC_HEADERS && HAVE_MEMORY_H
46 #  include <memory.h>
47 # endif
48 # include <string.h>
49 #endif
50 #if HAVE_STRINGS_H
51 # include <strings.h>
52 #endif
53 #if HAVE_INTTYPES_H
54 # include <inttypes.h>
55 #endif
56 #if HAVE_STDINT_H
57 # include <stdint.h>
58 #endif
59 #if HAVE_STDBOOL_H
60 # include <stdbool.h>
61 #else
62 # ifndef HAVE__BOOL
63 #  ifdef __cplusplus
64 typedef bool _Bool;
65 #  else
66 #   define _Bool signed char
67 #  endif
68 # endif
69 # define bool _Bool
70 # define false 0
71 # define true 1
72 # define __bool_true_false_are_defined 1
73 #endif
74 #if HAVE_UNISTD_H
75 # include <unistd.h>
76 #endif
77 #if HAVE_SYS_WAIT_H
78 # include <sys/wait.h>
79 #endif
80 #ifndef WEXITSTATUS
81 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
82 #endif
83 #ifndef WIFEXITED
84 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
85 #endif
86 #if HAVE_SIGNAL_H
87 # include <signal.h>
88 #endif
89 #if HAVE_FCNTL_H
90 # include <fcntl.h>
91 #endif
92 #if HAVE_ERRNO_H
93 # include <errno.h>
94 #endif
95 #if HAVE_LIMITS_H
96 # include <limits.h>
97 #endif
98 #if TIME_WITH_SYS_TIME
99 # include <sys/time.h>
100 # include <time.h>
101 #else
102 # if HAVE_SYS_TIME_H
103 #  include <sys/time.h>
104 # else
105 #  include <time.h>
106 # endif
107 #endif
108
109 #if HAVE_ASSERT_H
110 # include <assert.h>
111 #else
112 # define assert(...) /* nop */
113 #endif
114
115 #if NAN_STATIC_DEFAULT
116 # include <math.h>
117 /* #endif NAN_STATIC_DEFAULT*/
118 #elif NAN_STATIC_ISOC
119 # ifndef __USE_ISOC99
120 #  define DISABLE_ISOC99 1
121 #  define __USE_ISOC99 1
122 # endif /* !defined(__USE_ISOC99) */
123 # include <math.h>
124 # if DISABLE_ISOC99
125 #  undef DISABLE_ISOC99
126 #  undef __USE_ISOC99
127 # endif /* DISABLE_ISOC99 */
128 /* #endif NAN_STATIC_ISOC */
129 #elif NAN_ZERO_ZERO
130 # include <math.h>
131 # ifdef NAN
132 #  undef NAN
133 # endif
134 # define NAN (0.0 / 0.0)
135 # ifndef isnan
136 #  define isnan(f) ((f) != (f))
137 # endif /* !defined(isnan) */
138 #endif /* NAN_ZERO_ZERO */
139
140 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
141  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
142  * this too.. */
143 #if HAVE_ENDIAN_H
144 # include <endian.h>
145 #elif HAVE_SYS_ISA_DEFS_H
146 # include <sys/isa_defs.h>
147 #endif
148
149 #ifndef BYTE_ORDER
150 # if defined(_BYTE_ORDER)
151 #  define BYTE_ORDER _BYTE_ORDER
152 # elif defined(__BYTE_ORDER)
153 #  define BYTE_ORDER __BYTE_ORDER
154 # elif defined(__DARWIN_BYTE_ORDER)
155 #  define BYTE_ORDER __DARWIN_BYTE_ORDER
156 # endif
157 #endif
158 #ifndef BIG_ENDIAN
159 # if defined(_BIG_ENDIAN)
160 #  define BIG_ENDIAN _BIG_ENDIAN
161 # elif defined(__BIG_ENDIAN)
162 #  define BIG_ENDIAN __BIG_ENDIAN
163 # elif defined(__DARWIN_BIG_ENDIAN)
164 #  define BIG_ENDIAN __DARWIN_BIG_ENDIAN
165 # endif
166 #endif
167 #ifndef LITTLE_ENDIAN
168 # if defined(_LITTLE_ENDIAN)
169 #  define LITTLE_ENDIAN _LITTLE_ENDIAN
170 # elif defined(__LITTLE_ENDIAN)
171 #  define LITTLE_ENDIAN __LITTLE_ENDIAN
172 # elif defined(__DARWIN_LITTLE_ENDIAN)
173 #  define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
174 # endif
175 #endif
176 #ifndef BYTE_ORDER
177 # if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
178 #  undef BIG_ENDIAN
179 #  define BIG_ENDIAN 4321
180 #  define LITTLE_ENDIAN 1234
181 #  define BYTE_ORDER BIG_ENDIAN
182 # elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
183 #  undef LITTLE_ENDIAN
184 #  define BIG_ENDIAN 4321
185 #  define LITTLE_ENDIAN 1234
186 #  define BYTE_ORDER LITTLE_ENDIAN
187 # endif
188 #endif
189 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
190 # error "Cannot determine byte order"
191 #endif
192
193 #if HAVE_DIRENT_H
194 # include <dirent.h>
195 # define NAMLEN(dirent) strlen((dirent)->d_name)
196 #else
197 # define dirent direct
198 # define NAMLEN(dirent) (dirent)->d_namlen
199 # if HAVE_SYS_NDIR_H
200 #  include <sys/ndir.h>
201 # endif
202 # if HAVE_SYS_DIR_H
203 #  include <sys/dir.h>
204 # endif
205 # if HAVE_NDIR_H
206 #  include <ndir.h>
207 # endif
208 #endif
209
210 #if HAVE_STDARG_H
211 # include <stdarg.h>
212 #endif
213 #if HAVE_CTYPE_H
214 # include <ctype.h>
215 #endif
216 #if HAVE_SYS_PARAM_H
217 # include <sys/param.h>
218 #endif
219
220 #if HAVE_KSTAT_H
221 # include <kstat.h>
222 #endif
223
224 #if HAVE_SENSORS_SENSORS_H
225 # include <sensors/sensors.h>
226 #endif
227
228 #ifndef PACKAGE_NAME
229 #define PACKAGE_NAME "collectd"
230 #endif
231
232 #ifndef PREFIX
233 #define PREFIX "/opt/" PACKAGE_NAME
234 #endif
235
236 #ifndef SYSCONFDIR
237 #define SYSCONFDIR PREFIX "/etc"
238 #endif
239
240 #ifndef CONFIGFILE
241 #define CONFIGFILE SYSCONFDIR"/collectd.conf"
242 #endif
243
244 #ifndef LOCALSTATEDIR
245 #define LOCALSTATEDIR PREFIX "/var"
246 #endif
247
248 #ifndef PKGLOCALSTATEDIR
249 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
250 #endif
251
252 #ifndef PIDFILE
253 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
254 #endif
255
256 #ifndef PLUGINDIR
257 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
258 #endif
259
260 #ifndef PKGDATADIR
261 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
262 #endif
263
264 #ifndef COLLECTD_GRP_NAME
265 # define COLLECTD_GRP_NAME "collectd"
266 #endif
267
268 #define STATIC_ARRAY_LEN(array) (sizeof (array) / sizeof ((array)[0]))
269
270 /* Remove GNU specific __attribute__ settings when using another compiler */
271 #if !__GNUC__
272 # define __attribute__(x) /**/
273 #endif
274
275 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
276 # undef strcpy
277 # undef strcat
278 # undef strtok
279 # pragma GCC poison strcpy strcat strtok
280 #endif
281
282 /* 
283  * Special hack for the perl plugin: Because the later included perl.h defines
284  * a macro which is never used, but contains `sprintf', we cannot poison that
285  * identifies just yet. The parl plugin will do that itself once perl.h is
286  * included.
287  */
288 #ifndef DONT_POISON_SPRINTF_YET
289 # if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
290 #  undef sprintf
291 #  pragma GCC poison sprintf
292 # endif
293 #endif
294
295 extern char hostname_g[];
296 extern int  interval_g;
297
298 #endif /* COLLECTD_H */