3 * Module begun 2008-03-05 by Rainer Gerhards, based on some code
6 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
8 * This file is part of rsyslog.
10 * Rsyslog is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU 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.
15 * Rsyslog 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 General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
23 * A copy of the GPL can be found in the file "COPYING" in this distribution.
39 #include "stringbuf.h"
45 /* ------------------------------ methods ------------------------------ */
48 /* TODO: restructure this code some time. Especially look if we need
49 * to check errno and, if so, how to do that in a clean way.
51 static void __attribute__((format(printf, 2, 3)))
52 LogError(int __attribute__((unused)) iErrCode, char *fmt, ... )
62 /* Format parameters */
64 lenBuf = vsnprintf(buf, sizeof(buf), fmt, ap);
65 if(lenBuf >= sizeof(buf)) {
66 /* if our buffer was too small, we simply truncate. */
71 /* Log the error now */
72 buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
74 dbgprintf("Called LogError, msg: %s\n", buf);
77 snprintf(msg, sizeof(msg), "%s", buf);
79 rs_strerror_r(errno, errStr, sizeof(errStr));
80 snprintf(msg, sizeof(msg), "%s: %s", buf, errStr);
82 msg[sizeof(msg)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
84 logmsgInternal(LOG_SYSLOG|LOG_ERR, msg, ADDDATE);
90 /* queryInterface function
91 * rgerhards, 2008-03-05
93 BEGINobjQueryInterface(errmsg)
94 CODESTARTobjQueryInterface(errmsg)
95 if(pIf->ifVersion != errmsgCURR_IF_VERSION) { /* check for current version, increment on each change */
96 ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
99 /* ok, we have the right interface, so let's fill it
100 * Please note that we may also do some backwards-compatibility
101 * work here (if we can support an older interface version - that,
102 * of course, also affects the "if" above).
104 pIf->LogError = LogError;
106 ENDobjQueryInterface(errmsg)
109 /* Initialize the errmsg class. Must be called as the very first method
110 * before anything else is called inside this class.
111 * rgerhards, 2008-02-19
113 BEGINAbstractObjClassInit(errmsg, 1, OBJ_IS_CORE_MODULE) /* class, version */
114 /* request objects we use */
116 /* set our own handlers */
117 ENDObjClassInit(errmsg)