969aedaa483c0f1bddcfe7baa2052096c05cc783
[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_UNISTD_H
60 # include <unistd.h>
61 #endif
62 #if HAVE_SYS_WAIT_H
63 # include <sys/wait.h>
64 #endif
65 #ifndef WEXITSTATUS
66 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
67 #endif
68 #ifndef WIFEXITED
69 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
70 #endif
71 #if HAVE_SIGNAL_H
72 # include <signal.h>
73 #endif
74 #if HAVE_FCNTL_H
75 # include <fcntl.h>
76 #endif
77 #if HAVE_ERRNO_H
78 # include <errno.h>
79 #endif
80 #if HAVE_LIMITS_H
81 # include <limits.h>
82 #endif
83 #if TIME_WITH_SYS_TIME
84 # include <sys/time.h>
85 # include <time.h>
86 #else
87 # if HAVE_SYS_TIME_H
88 #  include <sys/time.h>
89 # else
90 #  include <time.h>
91 # endif
92 #endif
93
94 #if HAVE_ASSERT_H
95 # include <assert.h>
96 #else
97 # define assert(...) /* nop */
98 #endif
99
100 #if !defined(HAVE__BOOL) || !HAVE__BOOL
101 typedef int _Bool;
102 # undef HAVE__BOOL
103 # define HAVE__BOOL 1
104 #endif
105
106 #if NAN_STATIC_DEFAULT
107 # include <math.h>
108 /* #endif NAN_STATIC_DEFAULT*/
109 #elif NAN_STATIC_ISOC
110 # ifndef __USE_ISOC99
111 #  define DISABLE_ISOC99 1
112 #  define __USE_ISOC99 1
113 # endif /* !defined(__USE_ISOC99) */
114 # include <math.h>
115 # if DISABLE_ISOC99
116 #  undef DISABLE_ISOC99
117 #  undef __USE_ISOC99
118 # endif /* DISABLE_ISOC99 */
119 /* #endif NAN_STATIC_ISOC */
120 #elif NAN_ZERO_ZERO
121 # include <math.h>
122 # ifdef NAN
123 #  undef NAN
124 # endif
125 # define NAN (0.0 / 0.0)
126 # ifndef isnan
127 #  define isnan(f) ((f) != (f))
128 # endif /* !defined(isnan) */
129 # ifndef isfinite
130 #  define isfinite(f) (((f) - (f)) == 0.0)
131 # endif
132 # ifndef isinf
133 #  define isinf(f) (!isfinite(f) && !isnan(f))
134 # endif
135 #endif /* NAN_ZERO_ZERO */
136
137 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
138  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
139  * this too.. */
140 #if HAVE_ENDIAN_H
141 # include <endian.h>
142 #elif HAVE_SYS_ISA_DEFS_H
143 # include <sys/isa_defs.h>
144 #endif
145
146 #ifndef BYTE_ORDER
147 # if defined(_BYTE_ORDER)
148 #  define BYTE_ORDER _BYTE_ORDER
149 # elif defined(__BYTE_ORDER)
150 #  define BYTE_ORDER __BYTE_ORDER
151 # elif defined(__DARWIN_BYTE_ORDER)
152 #  define BYTE_ORDER __DARWIN_BYTE_ORDER
153 # endif
154 #endif
155 #ifndef BIG_ENDIAN
156 # if defined(_BIG_ENDIAN)
157 #  define BIG_ENDIAN _BIG_ENDIAN
158 # elif defined(__BIG_ENDIAN)
159 #  define BIG_ENDIAN __BIG_ENDIAN
160 # elif defined(__DARWIN_BIG_ENDIAN)
161 #  define BIG_ENDIAN __DARWIN_BIG_ENDIAN
162 # endif
163 #endif
164 #ifndef LITTLE_ENDIAN
165 # if defined(_LITTLE_ENDIAN)
166 #  define LITTLE_ENDIAN _LITTLE_ENDIAN
167 # elif defined(__LITTLE_ENDIAN)
168 #  define LITTLE_ENDIAN __LITTLE_ENDIAN
169 # elif defined(__DARWIN_LITTLE_ENDIAN)
170 #  define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
171 # endif
172 #endif
173 #ifndef BYTE_ORDER
174 # if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
175 #  undef BIG_ENDIAN
176 #  define BIG_ENDIAN 4321
177 #  define LITTLE_ENDIAN 1234
178 #  define BYTE_ORDER BIG_ENDIAN
179 # elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
180 #  undef LITTLE_ENDIAN
181 #  define BIG_ENDIAN 4321
182 #  define LITTLE_ENDIAN 1234
183 #  define BYTE_ORDER LITTLE_ENDIAN
184 # endif
185 #endif
186 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
187 # error "Cannot determine byte order"
188 #endif
189
190 #if HAVE_DIRENT_H
191 # include <dirent.h>
192 # define NAMLEN(dirent) strlen((dirent)->d_name)
193 #else
194 # define dirent direct
195 # define NAMLEN(dirent) (dirent)->d_namlen
196 # if HAVE_SYS_NDIR_H
197 #  include <sys/ndir.h>
198 # endif
199 # if HAVE_SYS_DIR_H
200 #  include <sys/dir.h>
201 # endif
202 # if HAVE_NDIR_H
203 #  include <ndir.h>
204 # endif
205 #endif
206
207 #if HAVE_STDARG_H
208 # include <stdarg.h>
209 #endif
210 #if HAVE_CTYPE_H
211 # include <ctype.h>
212 #endif
213 #if HAVE_SYS_PARAM_H
214 # include <sys/param.h>
215 #endif
216
217 #if HAVE_KSTAT_H
218 # include <kstat.h>
219 #endif
220
221 #ifndef PACKAGE_NAME
222 #define PACKAGE_NAME "collectd"
223 #endif
224
225 #ifndef PREFIX
226 #define PREFIX "/opt/" PACKAGE_NAME
227 #endif
228
229 #ifndef SYSCONFDIR
230 #define SYSCONFDIR PREFIX "/etc"
231 #endif
232
233 #ifndef CONFIGFILE
234 #define CONFIGFILE SYSCONFDIR"/collectd.conf"
235 #endif
236
237 #ifndef LOCALSTATEDIR
238 #define LOCALSTATEDIR PREFIX "/var"
239 #endif
240
241 #ifndef PKGLOCALSTATEDIR
242 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
243 #endif
244
245 #ifndef PIDFILE
246 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
247 #endif
248
249 #ifndef PLUGINDIR
250 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
251 #endif
252
253 #ifndef PKGDATADIR
254 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
255 #endif
256
257 #ifndef COLLECTD_GRP_NAME
258 # define COLLECTD_GRP_NAME "collectd"
259 #endif
260
261 #ifndef COLLECTD_DEFAULT_INTERVAL
262 # define COLLECTD_DEFAULT_INTERVAL 10.0
263 #endif
264
265  #ifndef COLLECTD_USERAGENT
266  # define COLLECTD_USERAGENT PACKAGE_NAME"/"PACKAGE_VERSION
267  #endif
268
269 /* Remove GNU specific __attribute__ settings when using another compiler */
270 #if !__GNUC__
271 # define __attribute__(x) /**/
272 #endif
273
274 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
275 # undef strcpy
276 # undef strcat
277 # undef strtok
278 # pragma GCC poison strcpy strcat strtok
279 #endif
280
281 /* 
282  * Special hack for the perl plugin: Because the later included perl.h defines
283  * a macro which is never used, but contains `sprintf', we cannot poison that
284  * identifies just yet. The parl plugin will do that itself once perl.h is
285  * included.
286  */
287 #ifndef DONT_POISON_SPRINTF_YET
288 # if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
289 #  undef sprintf
290 #  pragma GCC poison sprintf
291 # endif
292 #endif
293
294 /* Type for time as used by "utils_time.h" */
295 typedef uint64_t cdtime_t;
296
297 extern char     hostname_g[];
298 extern cdtime_t interval_g;
299 extern int      timeout_g;
300
301 #endif /* COLLECTD_H */