Added library link check and addressed review comments
[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 <assert.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <inttypes.h>
38 #include <limits.h>
39 #include <signal.h>
40 #include <stdarg.h>
41 #include <stddef.h>
42 #include <stdint.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #if HAVE_SYS_TYPES_H
47 #include <sys/types.h>
48 #endif
49 #if HAVE_SYS_STAT_H
50 #include <sys/stat.h>
51 #endif
52 #if HAVE_STRINGS_H
53 #include <strings.h>
54 #endif
55 #if HAVE_UNISTD_H
56 #include <unistd.h>
57 #endif
58 #if HAVE_SYS_WAIT_H
59 #include <sys/wait.h>
60 #endif
61 #ifndef WEXITSTATUS
62 #define WEXITSTATUS(stat_val) ((unsigned int)(stat_val) >> 8)
63 #endif
64 #ifndef WIFEXITED
65 #define WIFEXITED(stat_val) (((stat_val)&255) == 0)
66 #endif
67 #if HAVE_FCNTL_H
68 #include <fcntl.h>
69 #endif
70 #if TIME_WITH_SYS_TIME
71 #include <sys/time.h>
72 #include <time.h>
73 #else
74 #if HAVE_SYS_TIME_H
75 #include <sys/time.h>
76 #else
77 #include <time.h>
78 #endif
79 #endif
80 #if HAVE_SYS_SOCKET_H
81 #include <sys/socket.h>
82 #endif
83
84 #if NAN_STATIC_DEFAULT
85 #include <math.h>
86 /* #endif NAN_STATIC_DEFAULT*/
87 #elif NAN_STATIC_ISOC
88 #ifndef __USE_ISOC99
89 #define DISABLE_ISOC99 1
90 #define __USE_ISOC99 1
91 #endif /* !defined(__USE_ISOC99) */
92 #include <math.h>
93 #if DISABLE_ISOC99
94 #undef DISABLE_ISOC99
95 #undef __USE_ISOC99
96 #endif /* DISABLE_ISOC99 */
97 /* #endif NAN_STATIC_ISOC */
98 #elif NAN_ZERO_ZERO
99 #include <math.h>
100 #ifdef NAN
101 #undef NAN
102 #endif
103 #define NAN (0.0 / 0.0)
104 #ifndef isnan
105 #define isnan(f) ((f) != (f))
106 #endif /* !defined(isnan) */
107 #ifndef isfinite
108 #define isfinite(f) (((f) - (f)) == 0.0)
109 #endif
110 #ifndef isinf
111 #define isinf(f) (!isfinite(f) && !isnan(f))
112 #endif
113 #endif /* NAN_ZERO_ZERO */
114
115 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
116  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
117  * this too.. */
118 #if HAVE_ENDIAN_H
119 #include <endian.h>
120 #elif HAVE_SYS_ISA_DEFS_H
121 #include <sys/isa_defs.h>
122 #endif
123
124 #ifndef BYTE_ORDER
125 #if defined(_BYTE_ORDER)
126 #define BYTE_ORDER _BYTE_ORDER
127 #elif defined(__BYTE_ORDER)
128 #define BYTE_ORDER __BYTE_ORDER
129 #elif defined(__DARWIN_BYTE_ORDER)
130 #define BYTE_ORDER __DARWIN_BYTE_ORDER
131 #endif
132 #endif
133 #ifndef BIG_ENDIAN
134 #if defined(_BIG_ENDIAN)
135 #define BIG_ENDIAN _BIG_ENDIAN
136 #elif defined(__BIG_ENDIAN)
137 #define BIG_ENDIAN __BIG_ENDIAN
138 #elif defined(__DARWIN_BIG_ENDIAN)
139 #define BIG_ENDIAN __DARWIN_BIG_ENDIAN
140 #endif
141 #endif
142 #ifndef LITTLE_ENDIAN
143 #if defined(_LITTLE_ENDIAN)
144 #define LITTLE_ENDIAN _LITTLE_ENDIAN
145 #elif defined(__LITTLE_ENDIAN)
146 #define LITTLE_ENDIAN __LITTLE_ENDIAN
147 #elif defined(__DARWIN_LITTLE_ENDIAN)
148 #define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
149 #endif
150 #endif
151 #ifndef BYTE_ORDER
152 #if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
153 #undef BIG_ENDIAN
154 #define BIG_ENDIAN 4321
155 #define LITTLE_ENDIAN 1234
156 #define BYTE_ORDER BIG_ENDIAN
157 #elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
158 #undef LITTLE_ENDIAN
159 #define BIG_ENDIAN 4321
160 #define LITTLE_ENDIAN 1234
161 #define BYTE_ORDER LITTLE_ENDIAN
162 #endif
163 #endif
164 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
165 #error "Cannot determine byte order"
166 #endif
167
168 #if HAVE_DIRENT_H
169 #include <dirent.h>
170 #define NAMLEN(dirent) strlen((dirent)->d_name)
171 #else
172 #define dirent direct
173 #define NAMLEN(dirent) (dirent)->d_namlen
174 #if HAVE_SYS_NDIR_H
175 #include <sys/ndir.h>
176 #endif
177 #if HAVE_SYS_DIR_H
178 #include <sys/dir.h>
179 #endif
180 #if HAVE_NDIR_H
181 #include <ndir.h>
182 #endif
183 #endif
184
185 #if HAVE_SYS_PARAM_H
186 #include <sys/param.h>
187 #endif
188
189 #ifndef PACKAGE_NAME
190 #define PACKAGE_NAME "collectd"
191 #endif
192
193 #ifndef PREFIX
194 #define PREFIX "/opt/" PACKAGE_NAME
195 #endif
196
197 #ifndef SYSCONFDIR
198 #define SYSCONFDIR PREFIX "/etc"
199 #endif
200
201 #ifndef CONFIGFILE
202 #define CONFIGFILE SYSCONFDIR "/collectd.conf"
203 #endif
204
205 #ifndef LOCALSTATEDIR
206 #define LOCALSTATEDIR PREFIX "/var"
207 #endif
208
209 #ifndef PKGLOCALSTATEDIR
210 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
211 #endif
212
213 #ifndef PIDFILE
214 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
215 #endif
216
217 #ifndef PLUGINDIR
218 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
219 #endif
220
221 #ifndef PKGDATADIR
222 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
223 #endif
224
225 #ifndef COLLECTD_GRP_NAME
226 #define COLLECTD_GRP_NAME "collectd"
227 #endif
228
229 #ifndef COLLECTD_DEFAULT_INTERVAL
230 #define COLLECTD_DEFAULT_INTERVAL 10.0
231 #endif
232
233 #ifndef COLLECTD_USERAGENT
234 #define COLLECTD_USERAGENT PACKAGE_NAME "/" PACKAGE_VERSION
235 #endif
236
237 /* Only enable __attribute__() for compilers known to support it. */
238 #if !defined(__clang__) && !defined(__GNUC__)
239 #define __attribute__(x) /**/
240 #endif
241
242 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
243 #undef strcpy
244 #undef strcat
245 #undef strtok
246 #pragma GCC poison strcpy strcat strtok
247 #endif
248
249 /*
250  * Special hack for the perl plugin: Because the later included perl.h defines
251  * a macro which is never used, but contains `sprintf', we cannot poison that
252  * identifies just yet. The parl plugin will do that itself once perl.h is
253  * included.
254  */
255 #ifndef DONT_POISON_SPRINTF_YET
256 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
257 #undef sprintf
258 #pragma GCC poison sprintf
259 #endif
260 #endif
261
262 #ifndef GAUGE_FORMAT
263 #define GAUGE_FORMAT "%.15g"
264 #endif
265
266 #include "globals.h"
267
268 #endif /* COLLECTD_H */