daemon: Let all command line options override global options from the config.
[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 <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
98 #if HAVE_SYS_SOCKET_H
99 # include <sys/socket.h>
100 #endif
101
102 #if HAVE_ASSERT_H
103 # include <assert.h>
104 #else
105 # define assert(...) /* nop */
106 #endif
107
108 #if !defined(HAVE__BOOL) || !HAVE__BOOL
109 typedef int _Bool;
110 # undef HAVE__BOOL
111 # define HAVE__BOOL 1
112 #endif
113
114 #if NAN_STATIC_DEFAULT
115 # include <math.h>
116 /* #endif NAN_STATIC_DEFAULT*/
117 #elif NAN_STATIC_ISOC
118 # ifndef __USE_ISOC99
119 #  define DISABLE_ISOC99 1
120 #  define __USE_ISOC99 1
121 # endif /* !defined(__USE_ISOC99) */
122 # include <math.h>
123 # if DISABLE_ISOC99
124 #  undef DISABLE_ISOC99
125 #  undef __USE_ISOC99
126 # endif /* DISABLE_ISOC99 */
127 /* #endif NAN_STATIC_ISOC */
128 #elif NAN_ZERO_ZERO
129 # include <math.h>
130 # ifdef NAN
131 #  undef NAN
132 # endif
133 # define NAN (0.0 / 0.0)
134 # ifndef isnan
135 #  define isnan(f) ((f) != (f))
136 # endif /* !defined(isnan) */
137 # ifndef isfinite
138 #  define isfinite(f) (((f) - (f)) == 0.0)
139 # endif
140 # ifndef isinf
141 #  define isinf(f) (!isfinite(f) && !isnan(f))
142 # endif
143 #endif /* NAN_ZERO_ZERO */
144
145 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
146  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
147  * this too.. */
148 #if HAVE_ENDIAN_H
149 # include <endian.h>
150 #elif HAVE_SYS_ISA_DEFS_H
151 # include <sys/isa_defs.h>
152 #endif
153
154 #ifndef BYTE_ORDER
155 # if defined(_BYTE_ORDER)
156 #  define BYTE_ORDER _BYTE_ORDER
157 # elif defined(__BYTE_ORDER)
158 #  define BYTE_ORDER __BYTE_ORDER
159 # elif defined(__DARWIN_BYTE_ORDER)
160 #  define BYTE_ORDER __DARWIN_BYTE_ORDER
161 # endif
162 #endif
163 #ifndef BIG_ENDIAN
164 # if defined(_BIG_ENDIAN)
165 #  define BIG_ENDIAN _BIG_ENDIAN
166 # elif defined(__BIG_ENDIAN)
167 #  define BIG_ENDIAN __BIG_ENDIAN
168 # elif defined(__DARWIN_BIG_ENDIAN)
169 #  define BIG_ENDIAN __DARWIN_BIG_ENDIAN
170 # endif
171 #endif
172 #ifndef LITTLE_ENDIAN
173 # if defined(_LITTLE_ENDIAN)
174 #  define LITTLE_ENDIAN _LITTLE_ENDIAN
175 # elif defined(__LITTLE_ENDIAN)
176 #  define LITTLE_ENDIAN __LITTLE_ENDIAN
177 # elif defined(__DARWIN_LITTLE_ENDIAN)
178 #  define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
179 # endif
180 #endif
181 #ifndef BYTE_ORDER
182 # if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
183 #  undef BIG_ENDIAN
184 #  define BIG_ENDIAN 4321
185 #  define LITTLE_ENDIAN 1234
186 #  define BYTE_ORDER BIG_ENDIAN
187 # elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
188 #  undef LITTLE_ENDIAN
189 #  define BIG_ENDIAN 4321
190 #  define LITTLE_ENDIAN 1234
191 #  define BYTE_ORDER LITTLE_ENDIAN
192 # endif
193 #endif
194 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
195 # error "Cannot determine byte order"
196 #endif
197
198 #if HAVE_DIRENT_H
199 # include <dirent.h>
200 # define NAMLEN(dirent) strlen((dirent)->d_name)
201 #else
202 # define dirent direct
203 # define NAMLEN(dirent) (dirent)->d_namlen
204 # if HAVE_SYS_NDIR_H
205 #  include <sys/ndir.h>
206 # endif
207 # if HAVE_SYS_DIR_H
208 #  include <sys/dir.h>
209 # endif
210 # if HAVE_NDIR_H
211 #  include <ndir.h>
212 # endif
213 #endif
214
215 #if HAVE_STDARG_H
216 # include <stdarg.h>
217 #endif
218 #if HAVE_CTYPE_H
219 # include <ctype.h>
220 #endif
221 #if HAVE_SYS_PARAM_H
222 # include <sys/param.h>
223 #endif
224
225 #if HAVE_KSTAT_H
226 # include <kstat.h>
227 #endif
228
229 #ifndef PACKAGE_NAME
230 #define PACKAGE_NAME "collectd"
231 #endif
232
233 #ifndef PREFIX
234 #define PREFIX "/opt/" PACKAGE_NAME
235 #endif
236
237 #ifndef SYSCONFDIR
238 #define SYSCONFDIR PREFIX "/etc"
239 #endif
240
241 #ifndef CONFIGFILE
242 #define CONFIGFILE SYSCONFDIR"/collectd.conf"
243 #endif
244
245 #ifndef LOCALSTATEDIR
246 #define LOCALSTATEDIR PREFIX "/var"
247 #endif
248
249 #ifndef PKGLOCALSTATEDIR
250 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
251 #endif
252
253 #ifndef PIDFILE
254 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
255 #endif
256
257 #ifndef PLUGINDIR
258 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
259 #endif
260
261 #ifndef PKGDATADIR
262 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
263 #endif
264
265 #ifndef COLLECTD_GRP_NAME
266 # define COLLECTD_GRP_NAME "collectd"
267 #endif
268
269 #ifndef COLLECTD_DEFAULT_INTERVAL
270 # define COLLECTD_DEFAULT_INTERVAL 10.0
271 #endif
272
273  #ifndef COLLECTD_USERAGENT
274  # define COLLECTD_USERAGENT PACKAGE_NAME "/" PACKAGE_VERSION
275  #endif
276
277 /* Only enable __attribute__() for compilers known to support it. */
278 #if defined(__clang__)
279 # define clang_attr(x) __attribute__(x)
280 # define gcc_attr(x) /**/
281 #elif __GNUC__
282 # define clang_attr(x) /**/
283 # define gcc_attr(x) __attribute__(x)
284 #else
285 # define clang_attr(x) /**/
286 # define gcc_attr(x) /**/
287 # define __attribute__(x) /**/
288 #endif
289
290 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
291 # undef strcpy
292 # undef strcat
293 # undef strtok
294 # pragma GCC poison strcpy strcat strtok
295 #endif
296
297 /*
298  * Special hack for the perl plugin: Because the later included perl.h defines
299  * a macro which is never used, but contains `sprintf', we cannot poison that
300  * identifies just yet. The parl plugin will do that itself once perl.h is
301  * included.
302  */
303 #ifndef DONT_POISON_SPRINTF_YET
304 # if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
305 #  undef sprintf
306 #  pragma GCC poison sprintf
307 # endif
308 #endif
309
310 #ifndef GAUGE_FORMAT
311 # define GAUGE_FORMAT "%.15g"
312 #endif
313
314 /* Type for time as used by "utils_time.h" */
315 typedef uint64_t cdtime_t;
316
317 extern char     hostname_g[];
318 extern cdtime_t interval_g;
319 extern int      timeout_g;
320
321 #endif /* COLLECTD_H */