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