1 /* This is the header file for the rsyslog runtime. It must be included
2  * if someone intends to use the runtime.
3  *
4  * Begun 2005-09-15 RGerhards
5  *
6  * Copyright (C) 2005-2019 by Rainer Gerhards and Adiscon GmbH
7  *
8  * This file is part of the rsyslog runtime library.
9  *
10  * The rsyslog runtime library is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * The rsyslog runtime library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the rsyslog runtime library.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * A copy of the GPL can be found in the file "COPYING" in this distribution.
24  * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
25  */
26 #ifndef INCLUDED_RSYSLOG_H
27 #define INCLUDED_RSYSLOG_H
28 #ifdef __GNUC__
29 	#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
30 	#pragma GCC diagnostic ignored "-Wredundant-decls" // TODO: remove!
31 	#pragma GCC diagnostic ignored "-Wstrict-prototypes" // TODO: remove!
32 	#pragma GCC diagnostic ignored "-Wswitch-default" // TODO: remove!
33 	#if __GNUC__ >= 8
34 		/* GCC, starting at least with version 8, is now really overdoing with it's
35 		 * warning messages. We turn those off that either cause an enormous amount
36 		 * of false positives or flag perfectly legal code as problematic.
37 		 */
38 		/* That one causes warnings when we use variable buffers for error
39 		 * messages which may be truncated in the very unlikely case of all
40 		 * vars using max value. If going over the max size, the engine will
41 		 * most likely truncate due to max message size anyhow. Also, sizing
42 		 * the buffers for max-max message size is a wast of (stack) memory.
43 		 */
44 		#pragma GCC diagnostic ignored "-Wformat-truncation"
45 		/* The next one flags variable initializations within out exception handling
46 		 * (iRet system) as problematic, even though variables are not used in those
47 		 * cases. This would be a good diagnostic if gcc would actually check that
48 		 * a variable is used uninitialized. Unfortunately it does not do that. But
49 		 * the static analyzers we use as part of CI do, so we are covered in any
50 		 * case.
51 		 * Unfortunately ignoring this diagnostic leads to two more info lines
52 		 * being emitted where nobody knows what the mean and why they appear :-(
53 		 */
54 		#pragma GCC diagnostic ignored "-Wjump-misses-init"
55 	#endif /* if __GNUC__ >= 8 */
56 
57 	/* define a couple of attributes to improve cross-platform builds */
58 	#if __GNUC__ > 6
59 		#define CASE_FALLTHROUGH __attribute__((fallthrough));
60 	#else
61 		#define CASE_FALLTHROUGH
62 	#endif
63 
64 	#define ATTR_NORETURN __attribute__ ((noreturn))
65 	#define ATTR_UNUSED __attribute__((unused))
66 	#define ATTR_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
67 
68 #else /* ifdef __GNUC__ */
69 
70 	#define CASE_FALLTHROUGH
71 	#define ATTR_NORETURN
72 	#define ATTR_UNUSED
73 	#define ATTR_NONNULL(...)
74 
75 #endif /* ifdef __GNUC__ */
76 
77 #if defined(_AIX)
78 #include <sys/select.h>
79 /* AIXPORT : start*/
80 #define SRC_FD          13
81 #define SRCMSG          (sizeof(srcpacket))
82 #endif
83 /* src end */
84 
85 #include <pthread.h>
86 #include "typedefs.h"
87 
88 #if defined(__GNUC__)
89 	#define PRAGMA_INGORE_Wswitch_enum	_Pragma("GCC diagnostic ignored \"-Wswitch-enum\"")
90 	#define PRAGMA_IGNORE_Wempty_body	_Pragma("GCC diagnostic ignored \"-Wempty-body\"")
91 	#define PRAGMA_IGNORE_Wsign_compare	_Pragma("GCC diagnostic ignored \"-Wsign-compare\"")
92 	#define PRAGMA_IGNORE_Wpragmas		_Pragma("GCC diagnostic ignored \"-Wpragmas\"")
93 	#define PRAGMA_IGNORE_Wmissing_noreturn _Pragma("GCC diagnostic ignored \"-Wmissing-noreturn\"")
94 	#define PRAGMA_IGNORE_Wexpansion_to_defined \
95 						_Pragma("GCC diagnostic ignored \"-Wexpansion-to-defined\"")
96 	#define PRAGMA_IGNORE_Wunknown_warning_option \
97 						_Pragma("GCC diagnostic ignored \"-Wunknown-warning-option\"")
98 	#define PRAGMA_IGNORE_Wunknown_attribute \
99 						_Pragma("GCC diagnostic ignored \"-Wunknown-attribute\"")
100 	#define PRAGMA_IGNORE_Wformat_nonliteral \
101 						_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
102 	#define PRAGMA_IGNORE_Wdeprecated_declarations \
103 						_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
104 	#define PRAGMA_DIAGNOSTIC_PUSH		_Pragma("GCC diagnostic push")
105 	#define PRAGMA_DIAGNOSTIC_POP		_Pragma("GCC diagnostic pop")
106 #else
107 	#define PRAGMA_INGORE_Wswitch_enum
108 	#define PRAGMA_IGNORE_Wsign_compare
109 	#define PRAGMA_IGNORE_Wformat_nonliteral
110 	#define PRAGMA_IGNORE_Wpragmas
111 	#define PRAGMA_IGNORE_Wmissing_noreturn
112 	#define PRAGMA_IGNORE_Wempty_body
113 	#define PRAGMA_IGNORE_Wdeprecated_declarations
114 	#define PRAGMA_IGNORE_Wexpansion_to_defined
115 	#define PRAGMA_IGNORE_Wunknown_attribute
116 	#define PRAGMA_IGNORE_Wunknown_warning_option
117 	#define PRAGMA_DIAGNOSTIC_PUSH
118 	#define PRAGMA_DIAGNOSTIC_POP
119 #endif
120 
121 /* ############################################################# *
122  * #                 Some constant values                      # *
123  * ############################################################# */
124 #define CONST_LEN_TIMESTAMP_3164 15 		/* number of chars (excluding \0!) in a RFC3164 timestamp */
125 #define CONST_LEN_TIMESTAMP_3339 32 		/* number of chars (excluding \0!) in a RFC3339 timestamp */
126 
127 #define CONST_LEN_CEE_COOKIE 5
128 #define CONST_CEE_COOKIE "@cee:"
129 
130 /* ############################################################# *
131  * #                    Config Settings                        # *
132  * ############################################################# */
133 #define RS_STRINGBUF_ALLOC_INCREMENT	128
134 /* MAXSIZE are absolute maxima, while BUFSIZE are just values after which
135  * processing is more time-intense. The BUFSIZE params currently add their
136  * value to the fixed size of the message object.
137  */
138 #define CONF_TAG_MAXSIZE		512	/* a value that is deemed far too large for any valid TAG */
139 #define CONF_HOSTNAME_MAXSIZE		512	/* a value that is deemed far too large for any valid HOSTNAME */
140 #define CONF_RAWMSG_BUFSIZE		101
141 #define CONF_TAG_BUFSIZE		32
142 #define CONF_PROGNAME_BUFSIZE		16
143 #define CONF_HOSTNAME_BUFSIZE		32
144 #define CONF_PROP_BUFSIZE		16	/* should be close to sizeof(ptr) or lighly above it */
145 #define CONF_IPARAMS_BUFSIZE		16	/* initial size of iparams array in wti (is automatically extended) */
146 #define	CONF_MIN_SIZE_FOR_COMPRESS	60 	/* config param: minimum message size to try compression. The smaller
147 	 * the message, the less likely is any compression gain. We check for
148 	 * gain before we submit the message. But to do so we still need to
149 	 * do the (costly) compress() call. The following setting sets a size
150 	 * for which no call to compress() is done at all. This may result in
151 	 * a few more bytes being transmited but better overall performance.
152 	 * Note: I have not yet checked the minimum UDP packet size. It might be
153 	 * that we do not save anything by compressing very small messages, because
154 	 * UDP might need to pad ;)
155 	 * rgerhards, 2006-11-30
156 	 */
157 
158 #define CONF_OMOD_NUMSTRINGS_MAXSIZE	5	/* cache for pointers to output module buffer pointers. All
159 	 * rsyslog-provided plugins do NOT need more than five buffers. If
160 	 * more are needed (future developments, third-parties), rsyslog
161 	 * must be recompiled with a larger parameter. Hardcoding this
162 	 * saves us some overhead, both in runtime in code complexity. As
163 	 * it is doubtful if ever more than 3 parameters are needed, the
164 	 * approach taken here is considered appropriate.
165 	 * rgerhards, 2010-06-24
166 	 */
167 #define CONF_NUM_MULTISUB		1024	/* default number of messages per multisub structure */
168 
169 /* ############################################################# *
170  * #                  End Config Settings                      # *
171  * ############################################################# */
172 
173 /* make sure we uses consistent macros, no matter what the
174  * platform gives us.
175  */
176 #undef LOG_NFACILITIES /* may be system defined, override */
177 #define LOG_NFACILITIES 24+1 /* plus one for our special "invld" facility! */
178 #define LOG_MAXPRI 191	/* highest supported valid PRI value --> RFC3164, RFC5424 */
179 #undef LOG_MAKEPRI
180 #define LOG_PRI_INVLD	(LOG_INVLD|LOG_DEBUG)
181 /* PRI is invalid --> special "invld.=debug" PRI code (rsyslog-specific) */
182 
183 #define	LOG_EMERG	0	/* system is unusable */
184 #define	LOG_ALERT	1	/* action must be taken immediately */
185 #define	LOG_CRIT	2	/* critical conditions */
186 #define	LOG_ERR		3	/* error conditions */
187 #define	LOG_WARNING	4	/* warning conditions */
188 #define	LOG_NOTICE	5	/* normal but significant condition */
189 #define	LOG_INFO	6	/* informational */
190 #define	LOG_DEBUG	7	/* debug-level messages */
191 
192 #define	LOG_KERN	(0<<3)	/* kernel messages */
193 #define	LOG_USER	(1<<3)	/* random user-level messages */
194 #define	LOG_MAIL	(2<<3)	/* mail system */
195 #define	LOG_DAEMON	(3<<3)	/* system daemons */
196 #define	LOG_AUTH	(4<<3)	/* security/authorization messages */
197 #define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
198 #define	LOG_LPR		(6<<3)	/* line printer subsystem */
199 #define	LOG_NEWS	(7<<3)	/* network news subsystem */
200 #define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
201 #if !defined(LOG_CRON)
202 #define	LOG_CRON	(9<<3)	/* clock daemon */
203 #endif
204 #define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
205 #define	LOG_FTP		(11<<3)	/* ftp daemon */
206 #if defined(_AIX)		/* AIXPORT : These are necessary for AIX */
207 #define	LOG_ASO		(12<<3) /* Active System Optimizer. Reserved for internal use */
208 #define	LOG_CAA		(15<<3) /* Cluster aware AIX subsystem */
209 #endif
210 #define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
211 #define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
212 #define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
213 #define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
214 #define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
215 #define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
216 #define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
217 #define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
218 #define LOG_FAC_INVLD   24
219 #define	LOG_INVLD	(LOG_FAC_INVLD<<3)	/* invalid facility/PRI code */
220 
221 /* we need to evaluate our argument only once, as otherwise we may
222  * have side-effects (this was seen in some version).
223  * Note: I know that "static inline" is not the right thing from a C99
224  * PoV, but some environments treat, even in C99 mode, compile
225  * non-static inline into the source even if not defined as "extern". This
226  * obviously results in linker errors. Using "static inline" as below together
227  * with "__attribute__((unused))" works in all cases. Note also that we
228  * cannot work around this in pri2fac, as we would otherwise need to evaluate
229  * pri more than once.
230  */
231 static inline syslog_pri_t __attribute__((unused))
pri2fac(const syslog_pri_t pri)232 pri2fac(const syslog_pri_t pri)
233 {
234 	unsigned fac = pri >> 3;
235 	return (fac > 23) ? LOG_FAC_INVLD : fac;
236 }
237 #define pri2sev(pri) ((pri) & 0x07)
238 
239 /* the rsyslog core provides information about present feature to plugins
240  * asking it. Below are feature-test macros which must be used to query
241  * features. Note that this must be powers of two, so that multiple queries
242  * can be combined. -- rgerhards, 2009-04-27
243  */
244 #define CORE_FEATURE_BATCHING	1
245 /*#define CORE_FEATURE_whatever 2 ... and so on ... */
246 
247 #ifndef _PATH_CONSOLE
248 #define _PATH_CONSOLE	"/dev/console"
249 #endif
250 
251 
252 /* The error codes below are orginally "borrowed" from
253  * liblogging. As such, we reserve values up to -2999
254  * just in case we need to borrow something more ;)
255 */
256 enum rsRetVal_				/** return value. All methods return this if not specified otherwise */
257 {
258 	/* the first two define are for errmsg.logError(), so that we can use the rsRetVal
259 	 * as an rsyslog error code. -- rgerhards, 20080-06-27
260 	 */
261 	RS_RET_NO_ERRCODE = -1,		/**< RESERVED for NO_ERRCODE errmsg.logError status name */
262 	RS_RET_INCLUDE_ERRNO = 1073741824, /* 2**30  - do NOT use error codes above this! */
263 	/* begin regular error codes */
264 	RS_RET_NOT_IMPLEMENTED = -7,	/**< implementation is missing (probably internal error or lazyness ;)) */
265 	RS_RET_OUT_OF_MEMORY = -6,	/**< memory allocation failed */
266 	RS_RET_PROVIDED_BUFFER_TOO_SMALL = -50, /*< the caller provided a buffer, but the called function sees
267 						  the size of this buffer is too small - operation not carried out */
268 	RS_RET_FILE_TRUNCATED = -51,	/**< (input) file was truncated, not an error but a status */
269 	RS_RET_TRUE = -3,		/**< to indicate a true state (can be used as TRUE, legacy) */
270 	RS_RET_FALSE = -2,		/**< to indicate a false state (can be used as FALSE, legacy) */
271 	RS_RET_NO_IRET = -8,	/**< This is a trick for the debuging system - it means no iRet is provided  */
272 	RS_RET_VALIDATION_RUN = -9,	/**< indicates a (config) validation run, processing not carried out */
273 	RS_RET_ERR = -3000,	/**< generic failure */
274 	RS_TRUNCAT_TOO_LARGE = -3001, /**< truncation operation where too many chars should be truncated */
275 	RS_RET_FOUND_AT_STRING_END = -3002, /**< some value found, but at the last pos of string */
276 	RS_RET_NOT_FOUND = -3003, /**< some requested value not found */
277 	RS_RET_MISSING_TRAIL_QUOTE = -3004, /**< an expected trailing quote is missing */
278 	RS_RET_NO_DIGIT = -3005,	/**< an digit was expected, but none found (mostly parsing) */
279 	RS_RET_NO_MORE_DATA = -3006,	/**< insufficient data, e.g. end of string during parsing */
280 	RS_RET_INVALID_IP = -3007,	/**< invalid ip found where valid was expected */
281 	RS_RET_OBJ_CREATION_FAILED = - 3008, /**< the creation of an object failed (no details available) */
282 	RS_RET_INOTIFY_INIT_FAILED = - 3009,
283 	/**< the initialization of an inotify instance failed (no details available) */
284 	RS_RET_FEN_INIT_FAILED = - 3010, /**< the initialization of a fen instance failed (no details available) */
285 	RS_RET_PARAM_ERROR = -1000,	/**< invalid parameter in call to function */
286 	RS_RET_MISSING_INTERFACE = -1001,/**< interface version mismatch, required missing */
287 	RS_RET_INVALID_CORE_INTERFACE = -1002,/**< interface provided by host invalid, can not be used */
288 	RS_RET_ENTRY_POINT_NOT_FOUND = -1003,/**< a requested entry point was not found */
289 	RS_RET_MODULE_ENTRY_POINT_NOT_FOUND = -1004,/**< a entry point requested from a module was not present in it */
290 	RS_RET_OBJ_NOT_AVAILABLE = -1005,
291 	/**< something could not be completed because the required object is not available*/
292 	RS_RET_LOAD_ERROR = -1006,/**< we had an error loading the object/interface and can not continue */
293 	RS_RET_MODULE_STILL_REFERENCED = -1007,
294 	/**< module could not be unloaded because it still is referenced by someone */
295 	RS_RET_OBJ_UNKNOWN = -1008,/**< object is unknown where required */
296 	RS_RET_OBJ_NOT_REGISTERED = -1009,/**< tried to unregister an object that is not registered */
297 	/* return states for config file processing */
298 	RS_RET_NONE = -2000,		/**< some value is not available - not necessarily an error */
299 	RS_RET_CONFLINE_UNPROCESSED = -2001,/**< config line was not processed, pass to other module */
300 	RS_RET_DISCARDMSG = -2002,	/**< discard message (no error state, processing request!) */
301 	RS_RET_INCOMPATIBLE = -2003,	/**< function not compatible with requested feature */
302 	RS_RET_NOENTRY = -2004,		/**< do not create an entry for (whatever) - not necessary an error */
303 	RS_RET_NO_SQL_STRING = -2005,	/**< string is not suitable for use as SQL */
304 	RS_RET_DISABLE_ACTION = -2006,  /**< action requests that it be disabled */
305 	RS_RET_SUSPENDED = -2007,  /**< something was suspended, not neccesarily an error */
306 	RS_RET_RQD_TPLOPT_MISSING = -2008,/**< a required template option is missing */
307 	RS_RET_INVALID_VALUE = -2009,/**< some value is invalid (e.g. user-supplied data) */
308 	RS_RET_INVALID_INT = -2010,/**< invalid integer */
309 	RS_RET_INVALID_CMD = -2011,/**< invalid command */
310 	RS_RET_VAL_OUT_OF_RANGE = -2012, /**< value out of range */
311 	RS_RET_FOPEN_FAILURE = -2013,	/**< failure during fopen, for example file not found - see errno */
312 	RS_RET_END_OF_LINKEDLIST = -2014,	/**< end of linked list, not an error, but a status */
313 	RS_RET_CHAIN_NOT_PERMITTED = -2015, /**< chaining (e.g. of config command handlers) not permitted */
314 	RS_RET_INVALID_PARAMS = -2016,/**< supplied parameters are invalid */
315 	RS_RET_EMPTY_LIST = -2017, /**< linked list is empty */
316 	RS_RET_FINISHED = -2018, /**< some opertion is finished, not an error state */
317 	RS_RET_INVALID_SOURCE = -2019, /**< source (address) invalid for some reason */
318 	RS_RET_ADDRESS_UNKNOWN = -2020, /**< an address is unknown - not necessarily an error */
319 	RS_RET_MALICIOUS_ENTITY = -2021, /**< there is an malicious entity involved */
320 	RS_RET_NO_KERNEL_LOGSRC = -2022, /**< no source for kernel logs can be obtained */
321 	RS_RET_TCP_SEND_ERROR = -2023, /**< error during TCP send process */
322 	RS_RET_GSS_SEND_ERROR = -2024, /**< error during GSS (via TCP) send process */
323 	RS_RET_TCP_SOCKCREATE_ERR = -2025, /**< error during creation of TCP socket */
324 	RS_RET_GSS_SENDINIT_ERROR = -2024, /**< error during GSS (via TCP) send initialization process */
325 	RS_RET_EOF = -2026, /**< end of file reached, not necessarily an error */
326 	RS_RET_IO_ERROR = -2027, /**< some kind of IO error happened */
327 	RS_RET_INVALID_OID = -2028, /**< invalid object ID */
328 	RS_RET_INVALID_HEADER = -2029, /**< invalid header */
329 	RS_RET_INVALID_HEADER_VERS = -2030, /**< invalid header version */
330 	RS_RET_INVALID_DELIMITER = -2031, /**< invalid delimiter, e.g. between params */
331 	RS_RET_INVALID_PROPFRAME = -2032, /**< invalid framing in serialized property */
332 	RS_RET_NO_PROPLINE = -2033, /**< line is not a property line */
333 	RS_RET_INVALID_TRAILER = -2034, /**< invalid trailer */
334 	RS_RET_VALUE_TOO_LOW = -2035, /**< a provided value is too low */
335 	RS_RET_FILE_PREFIX_MISSING = -2036, /**< a required file prefix (parameter?) is missing */
336 	RS_RET_INVALID_HEADER_RECTYPE = -2037, /**< invalid record type in header or invalid header */
337 	RS_RET_QTYPE_MISMATCH = -2038, /**< different qType when reading back a property type */
338 	RS_RET_NO_FILE_ACCESS = -2039, /**< covers EACCES error on file open() */
339 	RS_RET_FILE_NOT_FOUND = -2040, /**< file not found */
340 	RS_RET_TIMED_OUT = -2041, /**< timeout occured (not necessarily an error) */
341 	RS_RET_QSIZE_ZERO = -2042, /**< queue size is zero where this is not supported */
342 	RS_RET_ALREADY_STARTING = -2043, /**< something (a thread?) is already starting - not necessarily an error */
343 	RS_RET_NO_MORE_THREADS = -2044, /**< no more threads available, not necessarily an error */
344 	RS_RET_NO_FILEPREFIX = -2045, /**< file prefix is not specified where one is needed */
345 	RS_RET_CONFIG_ERROR = -2046, /**< there is a problem with the user-provided config settigs */
346 	RS_RET_OUT_OF_DESRIPTORS = -2047, /**< a descriptor table's space has been exhausted */
347 	RS_RET_NO_DRIVERS = -2048, /**< a required drivers missing */
348 	RS_RET_NO_DRIVERNAME = -2049, /**< driver name missing where one was required */
349 	RS_RET_EOS = -2050, /**< end of stream (of whatever) */
350 	RS_RET_SYNTAX_ERROR = -2051, /**< syntax error, eg. during parsing */
351 	RS_RET_INVALID_OCTAL_DIGIT = -2052, /**< invalid octal digit during parsing */
352 	RS_RET_INVALID_HEX_DIGIT = -2053, /**< invalid hex digit during parsing */
353 	RS_RET_INTERFACE_NOT_SUPPORTED = -2054, /**< interface not supported */
354 	RS_RET_OUT_OF_STACKSPACE = -2055, /**< a stack data structure is exhausted and can not be grown */
355 	RS_RET_STACK_EMPTY = -2056, /**< a pop was requested on a stack, but the stack was already empty */
356 	RS_RET_INVALID_VMOP = -2057, /**< invalid virtual machine instruction */
357 	RS_RET_INVALID_VAR = -2058, /**< a var or its content is unsuitable, eg. VARTYPE_NONE */
358 	RS_RET_INVALID_NUMBER = -2059, /**< number invalid during parsing */
359 	RS_RET_NOT_A_NUMBER = -2060, /**< e.g. conversion impossible because the string is not a number */
360 	RS_RET_OBJ_ALREADY_REGISTERED = -2061, /**< object (name) is already registered */
361 	RS_RET_OBJ_REGISTRY_OUT_OF_SPACE = -2062, /**< the object registry has run out of space */
362 	RS_RET_HOST_NOT_PERMITTED = -2063, /**< a host is not permitted to perform an action it requested */
363 	RS_RET_MODULE_LOAD_ERR = -2064, /**< module could not be loaded */
364 	RS_RET_MODULE_LOAD_ERR_PATHLEN = -2065, /**< module could not be loaded - path to long */
365 	RS_RET_MODULE_LOAD_ERR_DLOPEN = -2066, /**< module could not be loaded - problem in dlopen() */
366 	RS_RET_MODULE_LOAD_ERR_NO_INIT = -2067, /**< module could not be loaded - init() missing */
367 	RS_RET_MODULE_LOAD_ERR_INIT_FAILED = -2068, /**< module could not be loaded - init() failed */
368 	RS_RET_NO_SOCKET = -2069, /**< socket could not be obtained or was not provided */
369 	RS_RET_SMTP_ERROR = -2070, /**< error during SMTP transation */
370 	RS_RET_MAIL_NO_TO = -2071, /**< recipient for mail destination is missing */
371 	RS_RET_MAIL_NO_FROM = -2072, /**< sender for mail destination is missing */
372 	RS_RET_INVALID_PRI = -2073, /**< PRI value is invalid */
373 	RS_RET_MALICIOUS_HNAME = -2074, /**< remote peer is trying malicious things with its hostname */
374 	RS_RET_INVALID_HNAME = -2075, /**< remote peer's hostname invalid or unobtainable */
375 	RS_RET_INVALID_PORT = -2076, /**< invalid port value */
376 	RS_RET_COULD_NOT_BIND = -2077, /**< could not bind socket, defunct */
377 	RS_RET_GNUTLS_ERR = -2078, /**< (unexpected) error in GnuTLS call */
378 	RS_RET_MAX_SESS_REACHED = -2079, /**< max nbr of sessions reached, can not create more */
379 	RS_RET_MAX_LSTN_REACHED = -2080, /**< max nbr of listeners reached, can not create more */
380 	RS_RET_INVALID_DRVR_MODE = -2081, /**< tried to set mode not supported by driver */
381 	RS_RET_DRVRNAME_TOO_LONG = -2082, /**< driver name too long - should never happen */
382 	RS_RET_TLS_HANDSHAKE_ERR = -2083, /**< TLS handshake failed */
383 	RS_RET_TLS_CERT_ERR = -2084, /**< generic TLS certificate error */
384 	RS_RET_TLS_NO_CERT = -2085, /**< no TLS certificate available where one was expected */
385 	RS_RET_VALUE_NOT_SUPPORTED = -2086, /**< a provided value is not supported */
386 	RS_RET_VALUE_NOT_IN_THIS_MODE = -2087, /**< a provided value is invalid for the curret mode */
387 	RS_RET_INVALID_FINGERPRINT = -2088, /**< a fingerprint is not valid for this use case */
388 	RS_RET_CONNECTION_ABORTREQ = -2089, /**< connection was abort requested due to previous error */
389 	RS_RET_CERT_INVALID = -2090, /**< a x509 certificate failed validation */
390 	RS_RET_CERT_INVALID_DN = -2091, /**< distinguised name in x509 certificate is invalid (e.g. wrong escaping) */
391 	RS_RET_CERT_EXPIRED = -2092, /**< we are past a x.509 cert's expiration time */
392 	RS_RET_CERT_NOT_YET_ACTIVE = -2094, /**< x.509 cert's activation time not yet reached */
393 	RS_RET_SYS_ERR = -2095, /**< system error occured (e.g. time() returned -1, quite unexpected) */
394 	RS_RET_FILE_NO_STAT = -2096, /**< can not stat() a file */
395 	RS_RET_FILE_TOO_LARGE = -2097, /**< a file is larger than permitted */
396 	RS_RET_INVALID_WILDCARD = -2098, /**< a wildcard entry is invalid */
397 	RS_RET_CLOSED = -2099, /**< connection was closed */
398 	RS_RET_RETRY = -2100, /**< call should be retried (e.g. EGAIN on recv) */
399 	RS_RET_GSS_ERR = -2101, /**< generic error occured in GSSAPI subsystem */
400 	RS_RET_CERTLESS = -2102, /**< state: we run without machine cert (this may be OK) */
401 	RS_RET_NO_ACTIONS = -2103, /**< no active actions are configured (no output will be created) */
402 	RS_RET_CONF_FILE_NOT_FOUND = -2104, /**< config file or directory not found */
403 	RS_RET_QUEUE_FULL = -2105, /**< queue is full, operation could not be completed */
404 	RS_RET_ACCEPT_ERR = -2106, /**< error during accept() system call */
405 	RS_RET_INVLD_TIME = -2107, /**< invalid timestamp (e.g. could not be parsed) */
406 	RS_RET_NO_ZIP = -2108, /**< ZIP functionality is not present */
407 	RS_RET_CODE_ERR = -2109, /**< program code (internal) error */
408 	RS_RET_FUNC_NO_LPAREN = -2110, /**< left parenthesis missing after function call (rainerscript) */
409 	RS_RET_FUNC_MISSING_EXPR = -2111, /**< no expression after comma in function call (rainerscript) */
410 	RS_RET_INVLD_NBR_ARGUMENTS = -2112, /**< invalid number of arguments for function call (rainerscript) */
411 	RS_RET_INVLD_FUNC = -2113, /**< invalid function name for function call (rainerscript) */
412 	RS_RET_DUP_FUNC_NAME = -2114, /**< duplicate function name (rainerscript) */
413 	RS_RET_UNKNW_FUNC = -2115, /**< unkown function name (rainerscript) */
414 	RS_RET_ERR_RLIM_NOFILE = -2116, /**< error setting max. nbr open files process limit */
415 	RS_RET_ERR_CREAT_PIPE = -2117, /**< error during pipe creation */
416 	RS_RET_ERR_FORK = -2118, /**< error during fork() */
417 	RS_RET_ERR_WRITE_PIPE = -2119, /**< error writing to pipe */
418 	RS_RET_RSCORE_TOO_OLD = -2120, /**< rsyslog core is too old for ... (eg this plugin) */
419 	RS_RET_DEFER_COMMIT = -2121, /**< output plugin status: not yet committed (an OK state!) */
420 	RS_RET_PREVIOUS_COMMITTED = -2122, /**< output plugin status: previous record was committed (an OK state!) */
421 	RS_RET_ACTION_FAILED = -2123, /**< action failed and is now suspended */
422 	RS_RET_NON_SIZELIMITCMD = -2125, /**< size limit for file defined, but no size limit command given */
423 	RS_RET_SIZELIMITCMD_DIDNT_RESOLVE = -2126, /**< size limit command did not resolve situation */
424 	RS_RET_STREAM_DISABLED = -2127, /**< a file has been disabled (e.g. by size limit restriction) */
425 	RS_RET_FILENAME_INVALID = -2140, /**< filename invalid, not found, no access, ... */
426 	RS_RET_ZLIB_ERR = -2141, /**< error during zlib call */
427 	RS_RET_VAR_NOT_FOUND = -2142, /**< variable not found */
428 	RS_RET_EMPTY_MSG = -2143, /**< provided (raw) MSG is empty */
429 	RS_RET_PEER_CLOSED_CONN = -2144, /**< remote peer closed connection (information, no error) */
430 	RS_RET_ERR_OPEN_KLOG = -2145, /**< error opening or reading the kernel log socket */
431 	RS_RET_ERR_AQ_CONLOG = -2146, /**< error aquiring console log (on solaris) */
432 	RS_RET_ERR_DOOR = -2147, /**< some problems with handling the Solaris door functionality */
433 	RS_RET_NO_SRCNAME_TPL = -2150, /**< sourcename template was not specified where one was needed
434 (omudpspoof spoof addr) */
435 	RS_RET_HOST_NOT_SPECIFIED = -2151, /**< (target) host was not specified where it was needed */
436 	RS_RET_ERR_LIBNET_INIT = -2152, /**< error initializing libnet, e.g. because not running as root */
437 	RS_RET_FORCE_TERM = -2153,	/**< thread was forced to terminate by bShallShutdown, a state, not an error */
438 	RS_RET_RULES_QUEUE_EXISTS = -2154,/**< we were instructed to create a new
439 					   ruleset queue, but one already exists */
440 	RS_RET_NO_CURR_RULESET = -2155,/**< no current ruleset exists (but one is required) */
441 	RS_RET_NO_MSG_PASSING = -2156,
442 /*< output module interface parameter passing mode "MSG" is not available but required */
443 	RS_RET_RULESET_NOT_FOUND = -2157,/**< a required ruleset could not be found */
444 	RS_RET_NO_RULESET= -2158,/**< no ruleset name as specified where one was needed */
445 	RS_RET_PARSER_NOT_FOUND = -2159,/**< parser with the specified name was not found */
446 	RS_RET_COULD_NOT_PARSE = -2160,/**< (this) parser could not parse the message (no error, means try next one) */
447 	RS_RET_EINTR = -2161,		/**< EINTR occured during a system call (not necessarily an error) */
448 	RS_RET_ERR_EPOLL = -2162,	/**< epoll() returned with an unexpected error code */
449 	RS_RET_ERR_EPOLL_CTL = -2163,	/**< epol_ctll() returned with an unexpected error code */
450 	RS_RET_TIMEOUT = -2164,		/**< timeout occured during operation */
451 	RS_RET_RCV_ERR = -2165,		/**< error occured during socket rcv operation */
452 	RS_RET_NO_SOCK_CONFIGURED = -2166, /**< no socket (name) was configured where one is required */
453 	RS_RET_CONF_NOT_GLBL = -2167,	/**< $Begin not in global scope */
454 	RS_RET_CONF_IN_GLBL = -2168,	/**< $End when in global scope */
455 	RS_RET_CONF_INVLD_END = -2169,	/**< $End for wrong conf object (probably nesting error) */
456 	RS_RET_CONF_INVLD_SCOPE = -2170,
457 /*< config statement not valid in current scope (e.g. global stmt in action block) */
458 	RS_RET_CONF_END_NO_ACT = -2171,	/**< end of action block, but no actual action specified */
459 	RS_RET_NO_LSTN_DEFINED = -2172, /**< no listener defined (e.g. inside an input module) */
460 	RS_RET_EPOLL_CR_FAILED = -2173, /**< epoll_create() failed */
461 	RS_RET_EPOLL_CTL_FAILED = -2174, /**< epoll_ctl() failed */
462 	RS_RET_INTERNAL_ERROR = -2175, /**< rsyslogd internal error, unexpected code path reached */
463 	RS_RET_ERR_CRE_AFUX = -2176, /**< error creating AF_UNIX socket (and binding it) */
464 	RS_RET_RATE_LIMITED = -2177, /**< some messages discarded due to exceeding a rate limit */
465 	RS_RET_ERR_HDFS_WRITE = -2178, /**< error writing to HDFS */
466 	RS_RET_ERR_HDFS_OPEN = -2179, /**< error during hdfsOpen (e.g. file does not exist) */
467 	RS_RET_FILE_NOT_SPECIFIED = -2180, /**< file name not configured where this was required */
468 	RS_RET_ERR_WRKDIR = -2181, /**< problems with the rsyslog working directory */
469 	RS_RET_WRN_WRKDIR = -2182, /**< correctable problems with the rsyslog working directory */
470 	RS_RET_ERR_QUEUE_EMERGENCY = -2183, /**<  some fatal error caused queue to switch to emergency mode */
471 	RS_RET_OUTDATED_STMT = -2184, /**<  some outdated statement/functionality is being used in conf file */
472 	RS_RET_MISSING_WHITESPACE = -2185, /**<  whitespace is missing in some config construct */
473 	RS_RET_OK_WARN = -2186, /**<  config part: everything was OK, but a warning message was emitted */
474 
475 	RS_RET_INVLD_CONF_OBJ= -2200,	/**< invalid config object (e.g. $Begin conf statement) */
476 	/* UNUSED, WAS; RS_RET_ERR_LIBEE_INIT = -2201,	< cannot obtain libee ctx */
477 	RS_RET_ERR_LIBLOGNORM_INIT = -2202,/**< cannot obtain liblognorm ctx */
478 	RS_RET_ERR_LIBLOGNORM_SAMPDB_LOAD = -2203,/**< liblognorm sampledb load failed */
479 	RS_RET_CMD_GONE_AWAY = -2204,/**< config directive existed, but no longer supported */
480 	RS_RET_ERR_SCHED_PARAMS = -2205,/**< there is a problem with configured thread scheduling params */
481 	RS_RET_SOCKNAME_MISSING = -2206,/**< no socket name configured where one is required */
482 	RS_RET_CONF_PARSE_ERROR = -2207,/**< (fatal) error parsing config file */
483 	RS_RET_CONF_RQRD_PARAM_MISSING = -2208,/**< required parameter in config object is missing */
484 	RS_RET_MOD_UNKNOWN = -2209,/**< module (config name) is unknown */
485 	RS_RET_CONFOBJ_UNSUPPORTED = -2210,/**< config objects (v6 conf) are not supported here */
486 	RS_RET_MISSING_CNFPARAMS = -2211, /**< missing configuration parameters */
487 	RS_RET_NO_LISTNERS = -2212, /**< module loaded, but no listeners are defined */
488 	RS_RET_INVLD_PROTOCOL = -2213, /**< invalid protocol specified in config file */
489 	RS_RET_CNF_INVLD_FRAMING = -2214, /**< invalid framing specified in config file */
490 	RS_RET_LEGA_ACT_NOT_SUPPORTED = -2215, /**< the module (no longer) supports legacy action syntax */
491 	RS_RET_MAX_OMSR_REACHED = -2216, /**< max nbr of string requests reached, not supported by core */
492 	RS_RET_UID_MISSING = -2217,	/**< a user id is missing (but e.g. a password provided) */
493 	RS_RET_DATAFAIL = -2218,	/**< data passed to action caused failure */
494 	/* reserved for pre-v6.5 */
495 	RS_RET_DUP_PARAM = -2220, /**< config parameter is given more than once */
496 	RS_RET_MODULE_ALREADY_IN_CONF = -2221, /**< module already in current configuration */
497 	RS_RET_PARAM_NOT_PERMITTED = -2222, /**< legacy parameter no longer permitted (usally already set by v2) */
498 	RS_RET_NO_JSON_PASSING = -2223, /**< rsyslog core does not support JSON-passing plugin API */
499 	RS_RET_MOD_NO_INPUT_STMT = -2224, /**< (input) module does not support input() statement */
500 	RS_RET_NO_CEE_MSG = -2225, /**< the message being processed is NOT CEE-enhanced */
501 
502 	/**** up to 2290 is reserved for v6 use ****/
503 	RS_RET_RELP_ERR = -2291,	/**<< error in RELP processing */
504 	/**** up to 3000 is reserved for c7 use ****/
505 	RS_RET_JNAME_NO_ROOT = -2301, /**< root element is missing in JSON path */
506 	RS_RET_JNAME_INVALID = -2302, /**< JSON path is invalid */
507 	RS_RET_JSON_PARSE_ERR = -2303, /**< we had a problem parsing JSON (or extra data) */
508 	RS_RET_BSD_BLOCKS_UNSUPPORTED = -2304, /**< BSD-style config blocks are no longer supported */
509 	RS_RET_JNAME_NOTFOUND = -2305, /**< JSON name not found (does not exist) */
510 	RS_RET_INVLD_SETOP = -2305, /**< invalid variable set operation, incompatible type */
511 	RS_RET_RULESET_EXISTS = -2306,/**< ruleset already exists */
512 	RS_RET_DEPRECATED = -2307,/**< deprecated functionality is used */
513 	RS_RET_DS_PROP_SEQ_ERR = -2308,/**< property sequence error deserializing object */
514 	RS_RET_INVLD_PROP = -2309,/**< property name error (unknown name) */
515 	RS_RET_NO_RULEBASE = -2310,/**< mmnormalize: rulebase can not be found or otherwise invalid */
516 	RS_RET_INVLD_MODE = -2311,/**< invalid mode specified in configuration */
517 	RS_RET_INVLD_ANON_BITS = -2312,/**< mmanon: invalid number of bits to anonymize specified */
518 	RS_RET_REPLCHAR_IGNORED = -2313,/**< mmanon: replacementChar parameter is ignored */
519 	RS_RET_SIGPROV_ERR = -2320,/**< error in signature provider */
520 	RS_RET_CRYPROV_ERR = -2321,/**< error in cryptography encryption provider */
521 	RS_RET_EI_OPN_ERR = -2322,/**< error opening an .encinfo file */
522 	RS_RET_EI_NO_EXISTS = -2323,/**< .encinfo file does not exist (status, not necessarily error!)*/
523 	RS_RET_EI_WR_ERR = -2324,/**< error writing an .encinfo file */
524 	RS_RET_EI_INVLD_FILE = -2325,/**< header indicates the file is no .encinfo file */
525 	RS_RET_CRY_INVLD_ALGO = -2326,/**< user specified invalid (unkonwn) crypto algorithm */
526 	RS_RET_CRY_INVLD_MODE = -2327,/**< user specified invalid (unkonwn) crypto mode */
527 	RS_RET_QUEUE_DISK_NO_FN = -2328,/**< disk queue configured, but filename not set */
528 	RS_RET_CA_CERT_MISSING = -2329,/**< a CA cert is missing where one is required (e.g. TLS) */
529 	RS_RET_CERT_MISSING = -2330,/**< a cert is missing where one is required (e.g. TLS) */
530 	RS_RET_CERTKEY_MISSING = -2331,/**< a cert (private) key is missing where one is required (e.g. TLS) */
531 	RS_RET_STRUC_DATA_INVLD = -2349,/**< structured data is malformed */
532 
533 	/* up to 2350 reserved for 7.4 */
534 	RS_RET_QUEUE_CRY_DISK_ONLY = -2351,/**< crypto provider only supported for disk-associated queues */
535 	RS_RET_NO_DATA = -2352,/**< file has no data; more a state than a real error */
536 	RS_RET_RELP_AUTH_FAIL = -2353,/**< RELP peer authentication failed */
537 	RS_RET_ERR_UDPSEND = -2354,/**< sending msg via UDP failed */
538 	RS_RET_LAST_ERRREPORT = -2355,/**< module does not emit more error messages as limit is reached */
539 	RS_RET_READ_ERR = -2356,/**< read error occured (file i/o) */
540 	RS_RET_CONF_PARSE_WARNING = -2357,/**< warning parsing config file */
541 	RS_RET_CONF_WRN_FULLDLY_BELOW_HIGHWTR = -2358,/**< warning queue full delay mark below high wtr mark */
542 	RS_RET_RESUMED = -2359,/**< status: action was resumed (used for reporting) */
543 	RS_RET_RELP_NO_TLS = -2360,/**< librel does not support TLS (but TLS requested) */
544 	RS_RET_STATEFILE_WRONG_FNAME  = -2361,/**< state file is for wrong file */
545 	RS_RET_NAME_INVALID = -2362, /**< invalid name (in RainerScript) */
546 
547 	/* up to 2400 reserved for 7.5 & 7.6 */
548 	RS_RET_INVLD_OMOD = -2400, /**< invalid output module, does not provide proper interfaces */
549 	RS_RET_INVLD_INTERFACE_INPUT = -2401, /**< invalid value for "interface.input" parameter (ext progs) */
550 	RS_RET_PARSER_NAME_EXISTS = -2402, /**< parser name already exists */
551 	RS_RET_MOD_NO_PARSER_STMT = -2403, /**< (parser) module does not support parser() statement */
552 
553 	/* up to 2419 reserved for 8.4.x */
554 	RS_RET_IMFILE_WILDCARD = -2420, /**< imfile file name contains wildcard, which may be problematic */
555 	RS_RET_RELP_NO_TLS_AUTH = -2421,/**< librel does not support TLS authentication (but was requested) */
556 	RS_RET_KAFKA_ERROR = -2422,/**< error reported by Apache Kafka subsystem. See message for details. */
557 	RS_RET_KAFKA_NO_VALID_BROKERS = -2423,/**< no valid Kafka brokers configured/available */
558 	RS_RET_KAFKA_PRODUCE_ERR = -2424,/**< error during Kafka produce function */
559 	RS_RET_CONF_PARAM_INVLD = -2425,/**< config parameter is invalid */
560 	RS_RET_KSI_ERR = -2426,/**< error in KSI subsystem */
561 	RS_RET_ERR_LIBLOGNORM = -2427,/**< cannot obtain liblognorm ctx */
562 	RS_RET_CONC_CTRL_ERR = -2428,/**< error in lock/unlock/condition/concurrent-modification operation */
563 	RS_RET_SENDER_GONE_AWAY = -2429,/**< warning: sender not seen for configured amount of time */
564 	RS_RET_SENDER_APPEARED = -2430,/**< info: new sender appeared */
565 	RS_RET_FILE_ALREADY_IN_TABLE = -2431,/**< in imfile: table already contains to be added file */
566 	RS_RET_ERR_DROP_PRIV = -2432,/**< error droping privileges */
567 	RS_RET_FILE_OPEN_ERROR = -2433, /**< error other than "not found" occured during open() */
568 	RS_RET_RENAME_TMP_QI_ERROR = -2435, /**< renaming temporary .qi file failed */
569 	RS_RET_ERR_SETENV = -2436, /**< error setting an environment variable */
570 	RS_RET_DIR_CHOWN_ERROR = -2437, /**< error during chown() */
571 	RS_RET_JSON_UNUSABLE = -2438, /**< JSON object is NULL or otherwise unusable */
572 	RS_RET_OPERATION_STATUS = -2439, /**< operational status (info) message, no error */
573 	RS_RET_UDP_MSGSIZE_TOO_LARGE = -2440, /**< a message is too large to be sent via UDP */
574 	RS_RET_NON_JSON_PROP = -2441, /**< a non-json property id is provided where a json one is requried */
575 	RS_RET_NO_TZ_SET = -2442, /**< system env var TZ is not set (status msg) */
576 	RS_RET_FS_ERR = -2443, /**< file-system error */
577 	RS_RET_POLL_ERR = -2444, /**< error in poll() system call */
578 	RS_RET_OVERSIZE_MSG = -2445, /**< message is too long (above configured max) */
579 	RS_RET_TLS_KEY_ERR = -2446, /**< TLS KEY has problems */
580 	RS_RET_RABBITMQ_CONN_ERR = -2447, /**< RabbitMQ Connection error */
581 	RS_RET_RABBITMQ_LOGIN_ERR = -2448, /**< RabbitMQ Login error */
582 	RS_RET_RABBITMQ_CHANNEL_ERR = -2449, /**< RabbitMQ Connection error */
583 	RS_RET_NO_WRKDIR_SET = -2450, /**< working directory not set, but desired by functionality */
584 	RS_RET_ERR_QUEUE_FN_DUP = -2451, /**< duplicate queue file name */
585 	RS_RET_REDIS_ERROR = -2452, /**< redis-specific error. See message foe details. */
586 	RS_RET_REDIS_AUTH_FAILED = -2453, /**< redis authentication failure */
587 	RS_RET_FAUP_INIT_OPTIONS_FAILED = -2454, /**< could not initialize faup options */
588 
589 	/* RainerScript error messages (range 1000.. 1999) */
590 	RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */
591 	RS_RET_FIELD_NOT_FOUND = 1002, /**< field() function did not find requested field */
592 
593 	/* some generic error/status codes */
594 	RS_RET_OK = 0,			/**< operation successful */
595 	RS_RET_OK_DELETE_LISTENTRY = 1,
596 /*< operation successful, but callee requested the deletion of an entry (special state) */
597 	RS_RET_TERMINATE_NOW = 2,	/**< operation successful, function is requested to terminate
598 					(mostly used with threads) */
599 	RS_RET_NO_RUN = 3,		/**< operation successful, but function does not like to be executed */
600 	RS_RET_IDLE = 4,		/**< operation successful, but callee is idle (e.g. because queue is empty) */
601 	RS_RET_TERMINATE_WHEN_IDLE = 5	/**< operation successful, function is requested to terminate when idle */
602 };
603 
604 /* some helpful macros to work with srRetVals.
605  * Be sure to call the to-be-returned variable always "iRet" and
606  * the function finalizer always "finalize_it".
607  */
608 #ifdef HAVE_BUILTIN_EXCEPT
609 #	define CHKiRet(code) if(__builtin_expect(((iRet = code) != RS_RET_OK), 0)) goto finalize_it
610 #	define likely(x)      __builtin_expect(!!(x), 1)
611 #	define unlikely(x)    __builtin_expect(!!(x), 0)
612 #else
613 #	define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it
614 #	define likely(x)      (x)
615 #	define unlikely(x)    (x)
616 #endif
617 
618 # define CHKiConcCtrl(code)  { int tmp_CC; \
619 	if ((tmp_CC = code) != 0) { \
620 		iRet = RS_RET_CONC_CTRL_ERR; \
621 		errno = tmp_CC; \
622 		goto finalize_it; \
623 	} \
624 }
625 
626 /* macro below is to be used if we need our own handling, eg for cleanup */
627 #define CHKiRet_Hdlr(code) if((iRet = code) != RS_RET_OK)
628 /* macro below is to handle failing malloc/calloc/strdup... which we almost always handle in the same way... */
629 #define CHKmalloc(operation) if((operation) == NULL) ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY)
630 /* macro below is used in conjunction with CHKiRet_Hdlr, else use ABORT_FINALIZE */
631 #define FINALIZE goto finalize_it;
632 #define DEFiRet rsRetVal iRet = RS_RET_OK
633 #define RETiRet return iRet
634 
635 #define ABORT_FINALIZE(errCode)			\
636 	do {					\
637 		iRet = errCode;			\
638 		goto finalize_it;		\
639 	} while (0)
640 
641 /** Object ID. These are for internal checking. Each
642  * object is assigned a specific ID. This is contained in
643  * all Object structs (just like C++ RTTI). We can use
644  * this field to see if we have been passed a correct ID.
645  * Other than that, there is currently no other use for
646  * the object id.
647  */
648 enum rsObjectID
649 {
650 	OIDrsFreed = -1,		/**< assigned, when an object is freed. If this
651 				 *   is seen during a method call, this is an
652 				 *   invalid object pointer!
653 				 */
654 	OIDrsInvalid = 0,	/**< value created by calloc(), so do not use ;) */
655 	/* The 0x3412 is a debug aid. It helps us find object IDs in memory
656 	 * dumps (on X86, this is 1234 in the dump ;)
657 	 * If you are on an embedded device and you would like to save space
658 	 * make them 1 byte only.
659 	 */
660 	OIDrsCStr = 0x34120001,
661 	OIDrsPars = 0x34120002
662 };
663 typedef enum rsObjectID rsObjID;
664 
665 /* support to set object types */
666 #ifdef NDEBUG
667 #define rsSETOBJTYPE(pObj, type)
668 #define rsCHECKVALIDOBJECT(x, type)
669 #else
670 #define rsSETOBJTYPE(pObj, type) pObj->OID = type;
671 #define rsCHECKVALIDOBJECT(x, type) {assert(x != NULL); assert(x->OID == type);}
672 #endif
673 
674 /**
675  * This macro should be used to free objects.
676  * It aids in interpreting dumps during debugging.
677  */
678 #ifdef NDEBUG
679 #define RSFREEOBJ(x) free(x)
680 #else
681 #define RSFREEOBJ(x) {(x)->OID = OIDrsFreed; free(x);}
682 #endif
683 
684 extern pthread_attr_t default_thread_attr;
685 #ifdef HAVE_PTHREAD_SETSCHEDPARAM
686 extern struct sched_param default_sched_param;
687 extern int default_thr_sched_policy;
688 #endif
689 
690 /* The following structure defines immutable parameters which need to
691  * be passed as action parameters.
692  *
693  * Note that output plugins may request multiple templates. Let's say
694  * an output requests n templates. Than the overall table must hold
695  * n*nbrMsgs records, and each messages begins on a n-boundary. There
696  * is a macro defined below to access the proper element.
697  *
698  * WARNING: THIS STRUCTURE IS PART OF THE ***OUTPUT MODULE INTERFACE***
699  * It is passed into the doCommit() function. Do NOT modify it until
700  * absolutely necessary - all output plugins need to be changed!
701  *
702  * If a change is "just" for internal working, consider adding a
703  * separate parameter outside of this structure. Of course, it is
704  * best to avoid this as well ;-)
705  * rgerhards, 2013-12-04
706  */
707 struct actWrkrIParams {
708 	uchar *param;
709 	uint32_t lenBuf;  /* length of string buffer (if string ptr) */
710 	uint32_t lenStr;  /* length of current string (if string ptr) */
711 };
712 
713 /* macro to access actWrkrIParams base object:
714  * param is ptr to base address
715  * nActTpls is the number of templates the action has requested
716  * iMsg is the message index
717  * iTpl is the template index
718  * This macro can be used for read and write access.
719  */
720 #define actParam(param, nActTpls, iMsg, iTpl) (param[(iMsg*nActTpls)+iTpl])
721 
722 /* for the time being, we do our own portability handling here. It
723  * looks like autotools either does not yet support checks for it, or
724  * I wasn't smart enough to find them ;) rgerhards, 2007-07-18
725  */
726 #ifndef __GNUC__
727 #  define  __attribute__(x)  /*NOTHING*/
728 #endif
729 
730 #if !defined(O_CLOEXEC) && !defined(_AIX)
731 /* of course, this limits the functionality... */
732 #  define O_CLOEXEC 0
733 #endif
734 
735 /* some constants */
736 #define MUTEX_ALREADY_LOCKED	0
737 #define LOCK_MUTEX		1
738 
739 
740 #include "debug.h"
741 #include "obj.h"
742 
743 /* the variable below is a trick: before we can init the runtime, the caller
744  * may want to set a module load path. We can not do this via the glbl class
745  * because it needs an initialized runtime system (and may at some point in time
746  * even be loaded itself). So this is a no-go. What we do is use a single global
747  * variable which may be provided with a pointer by the caller. This variable
748  * resides in rsyslog.c, the main runtime file. We have not seen any realy valule
749  * in providing object access functions. If you don't like that, feel free to
750  * add them. -- rgerhards, 2008-04-17
751  */
752 extern uchar *glblModPath; /* module load path */
753 extern void (*glblErrLogger)(const int, const int, const uchar*);
754 
755 /* some runtime prototypes */
756 void processImInternal(void);
757 rsRetVal rsrtInit(const char **ppErrObj, obj_if_t *pObjIF);
758 rsRetVal rsrtExit(void);
759 int rsrtIsInit(void);
760 void rsrtSetErrLogger(void (*errLogger)(const int, const int, const uchar*));
761 
762 void dfltErrLogger(const int, const int, const uchar *errMsg);
763 
764 
765 /* this define below is (later) intended to be used to implement empty
766  * structs. TODO: check if compilers supports this and, if not, define
767  * a dummy variable. This requires review of where in code empty structs
768  * are already defined. -- rgerhards, 2010-07-26
769  */
770 #ifdef OS_SOLARIS
771 #define EMPTY_STRUCT  int remove_me_when_first_real_member_is_added;
772 #else
773 #define EMPTY_STRUCT
774 #endif
775 
776 /* TODO: remove this -- this is only for transition of the config system */
777 extern rsconf_t *ourConf; /* defined by syslogd.c, a hack for functions that do not
778 			     yet receive a copy, so that we can incrementially
779 			     compile and change... -- rgerhars, 2011-04-19 */
780 
781 
782 /* here we add some stuff from the compatibility layer. A separate include
783  * would be cleaner, but would potentially require changes all over the
784  * place. So doing it here is better. The respective replacement
785  * functions should usually be found under ./compat -- rgerhards, 2015-05-20
786  */
787 #ifndef HAVE_STRNDUP
788 char * strndup(const char *s, size_t n);
789 #endif
790 
791 #endif /* multi-include protection */
792