Merge lp:~s-launchpad-paulsd-com/rsyslog/trusty-proposed into lp:ubuntu/trusty-proposed/rsyslog

Proposed by Paul Donohue
Status: Needs review
Proposed branch: lp:~s-launchpad-paulsd-com/rsyslog/trusty-proposed
Merge into: lp:ubuntu/trusty-proposed/rsyslog
Diff against target: 1631 lines (+1432/-29)
13 files modified
.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c (+298/-0)
.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c (+488/-0)
.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h (+70/-0)
.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c (+295/-0)
.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h (+64/-0)
debian/changelog (+7/-0)
debian/patches/11-fix-infinite-loop-openvz-vms.patch (+157/-15)
plugins/imklog/bsd.c (+25/-2)
plugins/imklog/imklog.c (+2/-1)
plugins/imklog/imklog.h (+2/-1)
plugins/imkmsg/imkmsg.c (+2/-1)
plugins/imkmsg/imkmsg.h (+2/-1)
plugins/imkmsg/kmsg.c (+20/-8)
To merge this branch: bzr merge lp:~s-launchpad-paulsd-com/rsyslog/trusty-proposed
Reviewer Review Type Date Requested Status
Brian Murray Pending
Review via email: mp+245974@code.launchpad.net

Description of the change

Updated fix for infinite loop on OpenVZ VMs (LP: #1366829)

To post a comment you must log in.

Unmerged revisions

60. By Paul Donohue

Applied updated upstream patch fixing infinite loop on OpenVZ VMs.
(LP: #1366829)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog'
=== added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c'
--- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c 1970-01-01 00:00:00 +0000
+++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c 2015-01-09 16:11:08 +0000
@@ -0,0 +1,298 @@
1/* combined imklog driver for BSD and Linux
2 *
3 * This contains OS-specific functionality to read the BSD
4 * or Linux kernel log. For a general overview, see head comment in
5 * imklog.c. This started out as the BSD-specific drivers, but it
6 * turned out that on modern Linux the implementation details
7 * are very small, and so we use a single driver for both OS's with
8 * a little help of conditional compilation.
9 *
10 * Copyright 2008-2012 Adiscon GmbH
11 *
12 * This file is part of rsyslog.
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 * -or-
20 * see COPYING.ASL20 in the source distribution
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#ifdef HAVE_CONFIG_H
29# include "config.h"
30#endif
31#include <stdlib.h>
32#include <unistd.h>
33#include <fcntl.h>
34#include <errno.h>
35#include <string.h>
36#include <ctype.h>
37#ifdef OS_LINUX
38# include <sys/klog.h>
39#endif
40
41#include "rsyslog.h"
42#include "srUtils.h"
43#include "debug.h"
44#include "imklog.h"
45
46/* globals */
47static int fklog = -1; /* kernel log fd */
48
49#ifndef _PATH_KLOG
50# ifdef OS_LINUX
51# define _PATH_KLOG "/proc/kmsg"
52# else
53# define _PATH_KLOG "/dev/klog"
54# endif
55#endif
56
57
58#ifdef OS_LINUX
59/* submit a message to imklog Syslog() API. In this function, we check if
60 * a kernel timestamp is present and, if so, extract and strip it.
61 * Note that this is heavily Linux specific and thus is not compiled or
62 * used for BSD.
63 * Special thanks to Lennart Poettering for suggesting on how to convert
64 * the kernel timestamp to a realtime timestamp. This method depends on
65 * the fact the the kernel timestamp is written using the monotonic clock.
66 * Shall that change (very unlikely), this code must be changed as well. Note
67 * that due to the way we generate the delta, we are unable to write the
68 * absolutely correct timestamp (system call overhead of the clock calls
69 * prevents us from doing so). However, the difference is very minor.
70 * rgerhards, 2011-06-24
71 */
72static void
73submitSyslog(modConfData_t *pModConf, int pri, uchar *buf)
74{
75 long secs;
76 long usecs;
77 long secOffs;
78 long usecOffs;
79 unsigned i;
80 unsigned bufsize;
81 struct timespec monotonic, realtime;
82 struct timeval tv;
83 struct timeval *tp = NULL;
84
85 if(!pModConf->bParseKernelStamp)
86 goto done;
87
88 if(buf[3] != '[')
89 goto done;
90 DBGPRINTF("imklog: kernel timestamp detected, extracting it\n");
91
92 /* we now try to parse the timestamp. iff it parses, we assume
93 * it is a timestamp. Otherwise we know for sure it is no ts ;)
94 */
95 i = 4; /* space or first digit after '[' */
96 while(buf[i] && isspace(buf[i]))
97 ++i; /* skip space */
98 secs = 0;
99 while(buf[i] && isdigit(buf[i])) {
100 secs = secs * 10 + buf[i] - '0';
101 ++i;
102 }
103 if(buf[i] != '.') {
104 DBGPRINTF("no dot --> no kernel timestamp\n");
105 goto done; /* no TS! */
106 }
107
108 ++i; /* skip dot */
109 usecs = 0;
110 while(buf[i] && isdigit(buf[i])) {
111 usecs = usecs * 10 + buf[i] - '0';
112 ++i;
113 }
114 if(buf[i] != ']') {
115 DBGPRINTF("no trailing ']' --> no kernel timestamp\n");
116 goto done; /* no TS! */
117 }
118 ++i; /* skip ']' */
119
120 /* we have a timestamp */
121 DBGPRINTF("kernel timestamp is %ld %ld\n", secs, usecs);
122 if(!pModConf->bKeepKernelStamp) {
123 bufsize= strlen((char*)buf);
124 memmove(buf+3, buf+i, bufsize - i + 1);
125 }
126
127 clock_gettime(CLOCK_MONOTONIC, &monotonic);
128 clock_gettime(CLOCK_REALTIME, &realtime);
129 secOffs = realtime.tv_sec - monotonic.tv_sec;
130 usecOffs = (realtime.tv_nsec - monotonic.tv_nsec) / 1000;
131 if(usecOffs < 0) {
132 secOffs--;
133 usecOffs += 1000000l;
134 }
135
136 usecs += usecOffs;
137 if(usecs > 999999l) {
138 secs++;
139 usecs -= 1000000l;
140 }
141 secs += secOffs;
142 tv.tv_sec = secs;
143 tv.tv_usec = usecs;
144 tp = &tv;
145
146done:
147 Syslog(pri, buf, tp);
148}
149#else /* now comes the BSD "code" (just a shim) */
150static void
151submitSyslog(modConfData_t *pModConf, int pri, uchar *buf)
152{
153 Syslog(pri, buf, NULL);
154}
155#endif /* #ifdef LINUX */
156
157
158static uchar *GetPath(modConfData_t *pModConf)
159{
160 return pModConf->pszPath ? pModConf->pszPath : (uchar*) _PATH_KLOG;
161}
162
163/* open the kernel log - will be called inside the willRun() imklog
164 * entry point. -- rgerhards, 2008-04-09
165 */
166rsRetVal
167klogWillRun(modConfData_t *pModConf)
168{
169 char errmsg[2048];
170 int r;
171 DEFiRet;
172
173 fklog = open((char*)GetPath(pModConf), O_RDONLY, 0);
174 if (fklog < 0) {
175 imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log(%s): %s.",
176 GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg)));
177 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
178 }
179
180# ifdef OS_LINUX
181 /* Set level of kernel console messaging.. */
182 if(pModConf->console_log_level != -1) {
183 r = klogctl(8, NULL, pModConf->console_log_level);
184 if(r != 0) {
185 imklogLogIntMsg(LOG_WARNING, "imklog: cannot set console log level: %s",
186 rs_strerror_r(errno, errmsg, sizeof(errmsg)));
187 /* make sure we do not try to re-set! */
188 pModConf->console_log_level = -1;
189 }
190 }
191# endif /* #ifdef OS_LINUX */
192
193finalize_it:
194 RETiRet;
195}
196
197
198/* Read kernel log while data are available, split into lines.
199 */
200static void
201readklog(modConfData_t *pModConf)
202{
203 char *p, *q;
204 int len, i;
205 int iMaxLine;
206 uchar bufRcv[128*1024+1];
207 char errmsg[2048];
208 uchar *pRcv = NULL; /* receive buffer */
209
210 iMaxLine = klog_getMaxLine();
211
212 /* we optimize performance: if iMaxLine is below our fixed size buffer (which
213 * usually is sufficiently large), we use this buffer. if it is higher, heap memory
214 * is used. We could use alloca() to achive a similar aspect, but there are so
215 * many issues with alloca() that I do not want to take that route.
216 * rgerhards, 2008-09-02
217 */
218 if((size_t) iMaxLine < sizeof(bufRcv) - 1) {
219 pRcv = bufRcv;
220 } else {
221 if((pRcv = (uchar*) MALLOC(sizeof(uchar) * (iMaxLine + 1))) == NULL)
222 iMaxLine = sizeof(bufRcv) - 1; /* better this than noting */
223 }
224
225 len = 0;
226 for (;;) {
227 dbgprintf("imklog(BSD/Linux) waiting for kernel log line\n");
228 i = read(fklog, pRcv + len, iMaxLine - len);
229 if (i > 0) {
230 pRcv[i + len] = '\0';
231 } else {
232 if (i < 0 && errno != EINTR && errno != EAGAIN) {
233 imklogLogIntMsg(LOG_ERR,
234 "imklog: error reading kernel log - shutting down: %s",
235 rs_strerror_r(errno, errmsg, sizeof(errmsg)));
236 fklog = -1;
237 }
238 break;
239 }
240
241 for (p = (char*)pRcv; (q = strchr(p, '\n')) != NULL; p = q + 1) {
242 *q = '\0';
243 submitSyslog(pModConf, LOG_INFO, (uchar*) p);
244 }
245 len = strlen(p);
246 if (len >= iMaxLine - 1) {
247 submitSyslog(pModConf, LOG_INFO, (uchar*)p);
248 len = 0;
249 }
250 if(len > 0)
251 memmove(pRcv, p, len + 1);
252 }
253 if (len > 0)
254 submitSyslog(pModConf, LOG_INFO, pRcv);
255
256 if(pRcv != NULL && (size_t) iMaxLine >= sizeof(bufRcv) - 1)
257 free(pRcv);
258}
259
260
261/* to be called in the module's AfterRun entry point
262 * rgerhards, 2008-04-09
263 */
264rsRetVal klogAfterRun(modConfData_t *pModConf)
265{
266 DEFiRet;
267 if(fklog != -1)
268 close(fklog);
269# ifdef OS_LINUX
270 /* Turn on logging of messages to console, but only if a log level was speficied */
271 if(pModConf->console_log_level != -1)
272 klogctl(7, NULL, 0);
273# endif
274 RETiRet;
275}
276
277
278
279/* to be called in the module's WillRun entry point, this is the main
280 * "message pull" mechanism.
281 * rgerhards, 2008-04-09
282 */
283rsRetVal klogLogKMsg(modConfData_t *pModConf)
284{
285 DEFiRet;
286 readklog(pModConf);
287 RETiRet;
288}
289
290
291/* provide the (system-specific) default facility for internal messages
292 * rgerhards, 2008-04-14
293 */
294int
295klogFacilIntMsg(void)
296{
297 return LOG_SYSLOG;
298}
0299
=== added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c'
--- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c 1970-01-01 00:00:00 +0000
+++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c 2015-01-09 16:11:08 +0000
@@ -0,0 +1,488 @@
1/* The kernel log module.
2 *
3 * This is an abstracted module. As Linux and BSD kernel log is conceptually the
4 * same, we do not do different input plugins for them but use
5 * imklog in both cases, just with different "backend drivers" for
6 * the different platforms. This also enables a rsyslog.conf to
7 * be used on multiple platforms without the need to take care of
8 * what the kernel log is coming from.
9 *
10 * See platform-specific files (e.g. linux.c, bsd.c) in the plugin's
11 * working directory. For other systems with similar kernel logging
12 * functionality, no new input plugin shall be written but rather a
13 * driver be developed for imklog. Please note that imklog itself is
14 * mostly concerned with handling the interface. Any real action happens
15 * in the drivers, as things may be pretty different on different
16 * platforms.
17 *
18 * Please note that this file replaces the klogd daemon that was
19 * also present in pre-v3 versions of rsyslog.
20 *
21 * To test under Linux:
22 * echo test1 > /dev/kmsg
23 *
24 * Copyright (C) 2008-2014 Adiscon GmbH
25 *
26 * This file is part of rsyslog.
27 *
28 * Licensed under the Apache License, Version 2.0 (the "License");
29 * you may not use this file except in compliance with the License.
30 * You may obtain a copy of the License at
31 *
32 * http://www.apache.org/licenses/LICENSE-2.0
33 * -or-
34 * see COPYING.ASL20 in the source distribution
35 *
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an "AS IS" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
41 */
42#include "config.h"
43#include "rsyslog.h"
44#include <stdio.h>
45#include <assert.h>
46#include <string.h>
47#include <stdarg.h>
48#include <ctype.h>
49#include <stdlib.h>
50#include <sys/socket.h>
51
52#include "dirty.h"
53#include "cfsysline.h"
54#include "obj.h"
55#include "msg.h"
56#include "module-template.h"
57#include "datetime.h"
58#include "imklog.h"
59#include "net.h"
60#include "glbl.h"
61#include "prop.h"
62#include "errmsg.h"
63#include "unicode-helper.h"
64
65MODULE_TYPE_INPUT
66MODULE_TYPE_NOKEEP
67MODULE_CNFNAME("imklog")
68
69/* Module static data */
70DEF_IMOD_STATIC_DATA
71DEFobjCurrIf(datetime)
72DEFobjCurrIf(glbl)
73DEFobjCurrIf(prop)
74DEFobjCurrIf(net)
75DEFobjCurrIf(errmsg)
76
77/* config settings */
78typedef struct configSettings_s {
79 int bPermitNonKernel; /* permit logging of messages not having LOG_KERN facility */
80 int bParseKernelStamp; /* if try to parse kernel timestamps for message time */
81 int bKeepKernelStamp; /* keep the kernel timestamp in the message */
82 int iFacilIntMsg; /* the facility to use for internal messages (set by driver) */
83 uchar *pszPath;
84 int console_log_level; /* still used for BSD */
85} configSettings_t;
86static configSettings_t cs;
87
88static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
89static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */
90static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config parameters permitted? */
91
92/* module-global parameters */
93static struct cnfparamdescr modpdescr[] = {
94 { "logpath", eCmdHdlrGetWord, 0 },
95 { "permitnonkernelfacility", eCmdHdlrBinary, 0 },
96 { "consoleloglevel", eCmdHdlrInt, 0 },
97 { "parsekerneltimestamp", eCmdHdlrBinary, 0 },
98 { "keepkerneltimestamp", eCmdHdlrBinary, 0 },
99 { "internalmsgfacility", eCmdHdlrFacility, 0 }
100};
101static struct cnfparamblk modpblk =
102 { CNFPARAMBLK_VERSION,
103 sizeof(modpdescr)/sizeof(struct cnfparamdescr),
104 modpdescr
105 };
106
107static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this module */
108static prop_t *pLocalHostIP = NULL;
109
110static inline void
111initConfigSettings(void)
112{
113 cs.bPermitNonKernel = 0;
114 cs.bParseKernelStamp = 0;
115 cs.bKeepKernelStamp = 0;
116 cs.console_log_level = -1;
117 cs.pszPath = NULL;
118 cs.iFacilIntMsg = klogFacilIntMsg();
119}
120
121
122/* enqueue the the kernel message into the message queue.
123 * The provided msg string is not freed - thus must be done
124 * by the caller.
125 * rgerhards, 2008-04-12
126 */
127static rsRetVal
128enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity, struct timeval *tp)
129{
130 struct syslogTime st;
131 msg_t *pMsg;
132 DEFiRet;
133
134 assert(msg != NULL);
135 assert(pszTag != NULL);
136
137 if(tp == NULL) {
138 CHKiRet(msgConstruct(&pMsg));
139 } else {
140 datetime.timeval2syslogTime(tp, &st);
141 CHKiRet(msgConstructWithTime(&pMsg, &st, tp->tv_sec));
142 }
143 MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
144 MsgSetInputName(pMsg, pInputName);
145 MsgSetRawMsgWOSize(pMsg, (char*)msg);
146 MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */
147 MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
148 MsgSetRcvFromIP(pMsg, pLocalHostIP);
149 MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
150 MsgSetTAG(pMsg, pszTag, ustrlen(pszTag));
151 pMsg->iFacility = iFacility;
152 pMsg->iSeverity = iSeverity;
153 /* note: we do NOT use rate-limiting, as the kernel itself does rate-limiting */
154 CHKiRet(submitMsg2(pMsg));
155
156finalize_it:
157 RETiRet;
158}
159
160/* parse the PRI from a kernel message. At least BSD seems to have
161 * non-kernel messages inside the kernel log...
162 * Expected format: "<pri>". piPri is only valid if the function
163 * successfully returns. If there was a proper pri ppSz is advanced to the
164 * position right after ">".
165 * rgerhards, 2008-04-14
166 */
167static rsRetVal
168parsePRI(uchar **ppSz, int *piPri)
169{
170 DEFiRet;
171 int i;
172 uchar *pSz;
173
174 assert(ppSz != NULL);
175 pSz = *ppSz;
176 assert(pSz != NULL);
177 assert(piPri != NULL);
178
179 if(*pSz != '<' || !isdigit(*(pSz+1)))
180 ABORT_FINALIZE(RS_RET_INVALID_PRI);
181
182 ++pSz;
183 i = 0;
184 while(isdigit(*pSz)) {
185 i = i * 10 + *pSz++ - '0';
186 }
187
188 if(*pSz != '>')
189 ABORT_FINALIZE(RS_RET_INVALID_PRI);
190
191 /* OK, we have a valid PRI */
192 *piPri = i;
193 *ppSz = pSz + 1; /* update msg ptr to position after PRI */
194
195finalize_it:
196 RETiRet;
197}
198
199
200/* log an imklog-internal message
201 * rgerhards, 2008-04-14
202 */
203rsRetVal imklogLogIntMsg(int priority, char *fmt, ...)
204{
205 DEFiRet;
206 va_list ap;
207 uchar msgBuf[2048]; /* we use the same size as sysklogd to remain compatible */
208
209 va_start(ap, fmt);
210 vsnprintf((char*)msgBuf, sizeof(msgBuf) / sizeof(char), fmt, ap);
211 va_end(ap);
212
213 logmsgInternal(NO_ERRCODE ,priority, msgBuf, 0);
214
215 RETiRet;
216}
217
218
219/* log a kernel message. If tp is non-NULL, it contains the message creation
220 * time to use.
221 * rgerhards, 2008-04-14
222 */
223rsRetVal Syslog(int priority, uchar *pMsg, struct timeval *tp)
224{
225 int pri = -1;
226 rsRetVal localRet;
227 DEFiRet;
228
229 /* then check if we have two PRIs. This can happen in case of systemd,
230 * in which case the second PRI is the right one.
231 */
232 if(pMsg[3] == '<' || (pMsg[3] == ' ' && pMsg[4] == '<')) { /* could be a pri... */
233 uchar *pMsgTmp = pMsg + ((pMsg[3] == '<') ? 3 : 4);
234 localRet = parsePRI(&pMsgTmp, &pri);
235 if(localRet == RS_RET_OK && pri >= 8 && pri <= 192) {
236 /* *this* is our PRI */
237 DBGPRINTF("imklog detected secondary PRI(%d) in klog msg\n", pri);
238 pMsg = pMsgTmp;
239 priority = pri;
240 }
241 }
242 if(pri == -1) {
243 localRet = parsePRI(&pMsg, &priority);
244 if(localRet != RS_RET_INVALID_PRI && localRet != RS_RET_OK)
245 FINALIZE;
246 }
247 /* if we don't get the pri, we use whatever we were supplied */
248
249 /* ignore non-kernel messages if not permitted */
250 if(cs.bPermitNonKernel == 0 && pri2fac(priority) != LOG_KERN)
251 FINALIZE; /* silently ignore */
252
253 iRet = enqMsg((uchar*)pMsg, (uchar*) "kernel:", pri2fac(priority), pri2sev(priority), tp);
254
255finalize_it:
256 RETiRet;
257}
258
259
260/* helper for some klog drivers which need to know the MaxLine global setting. They can
261 * not obtain it themselfs, because they are no modules and can not query the object hander.
262 * It would probably be a good idea to extend the interface to support it, but so far
263 * we create a (sufficiently valid) work-around. -- rgerhards, 2008-11-24
264 */
265int klog_getMaxLine(void)
266{
267 return glbl.GetMaxLine();
268}
269
270
271BEGINrunInput
272CODESTARTrunInput
273 /* this is an endless loop - it is terminated when the thread is
274 * signalled to do so. This, however, is handled by the framework,
275 * right into the sleep below.
276 */
277 while(!pThrd->bShallStop) {
278 /* klogLogKMsg() waits for the next kernel message, obtains it
279 * and then submits it to the rsyslog main queue.
280 * rgerhards, 2008-04-09
281 */
282 CHKiRet(klogLogKMsg(runModConf));
283 }
284finalize_it:
285ENDrunInput
286
287
288BEGINbeginCnfLoad
289CODESTARTbeginCnfLoad
290 loadModConf = pModConf;
291 pModConf->pConf = pConf;
292 /* init our settings */
293 pModConf->pszPath = NULL;
294 pModConf->bPermitNonKernel = 0;
295 pModConf->bParseKernelStamp = 0;
296 pModConf->bKeepKernelStamp = 0;
297 pModConf->console_log_level = -1;
298 pModConf->bKeepKernelStamp = 0;
299 pModConf->iFacilIntMsg = klogFacilIntMsg();
300 loadModConf->configSetViaV2Method = 0;
301 bLegacyCnfModGlobalsPermitted = 1;
302 /* init legacy config vars */
303 initConfigSettings();
304ENDbeginCnfLoad
305
306
307BEGINsetModCnf
308 struct cnfparamvals *pvals = NULL;
309 int i;
310CODESTARTsetModCnf
311 pvals = nvlstGetParams(lst, &modpblk, NULL);
312 if(pvals == NULL) {
313 errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, "error processing module "
314 "config parameters [module(...)]");
315 ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
316 }
317
318 if(Debug) {
319 dbgprintf("module (global) param blk for imklog:\n");
320 cnfparamsPrint(&modpblk, pvals);
321 }
322
323 for(i = 0 ; i < modpblk.nParams ; ++i) {
324 if(!pvals[i].bUsed)
325 continue;
326 if(!strcmp(modpblk.descr[i].name, "logpath")) {
327 loadModConf->pszPath = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
328 } else if(!strcmp(modpblk.descr[i].name, "permitnonkernelfacility")) {
329 loadModConf->bPermitNonKernel = (int) pvals[i].val.d.n;
330 } else if(!strcmp(modpblk.descr[i].name, "parsekerneltimestamp")) {
331 loadModConf->bParseKernelStamp = (int) pvals[i].val.d.n;
332 } else if(!strcmp(modpblk.descr[i].name, "keepkerneltimestamp")) {
333 loadModConf->bKeepKernelStamp = (int) pvals[i].val.d.n;
334 } else if(!strcmp(modpblk.descr[i].name, "consoleloglevel")) {
335 loadModConf->console_log_level= (int) pvals[i].val.d.n;
336 } else if(!strcmp(modpblk.descr[i].name, "internalmsgfacility")) {
337 loadModConf->iFacilIntMsg = (int) pvals[i].val.d.n;
338 } else {
339 dbgprintf("imklog: program error, non-handled "
340 "param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
341 }
342 }
343
344 /* disable legacy module-global config directives */
345 bLegacyCnfModGlobalsPermitted = 0;
346 loadModConf->configSetViaV2Method = 1;
347
348finalize_it:
349 if(pvals != NULL)
350 cnfparamvalsDestruct(pvals, &modpblk);
351ENDsetModCnf
352
353
354BEGINendCnfLoad
355CODESTARTendCnfLoad
356 if(!loadModConf->configSetViaV2Method) {
357 /* persist module-specific settings from legacy config system */
358 loadModConf->bPermitNonKernel = cs.bPermitNonKernel;
359 loadModConf->bParseKernelStamp = cs.bParseKernelStamp;
360 loadModConf->bKeepKernelStamp = cs.bKeepKernelStamp;
361 loadModConf->iFacilIntMsg = cs.iFacilIntMsg;
362 loadModConf->console_log_level = cs.console_log_level;
363 if((cs.pszPath == NULL) || (cs.pszPath[0] == '\0')) {
364 loadModConf->pszPath = NULL;
365 if(cs.pszPath != NULL)
366 free(cs.pszPath);
367 } else {
368 loadModConf->pszPath = cs.pszPath;
369 }
370 cs.pszPath = NULL;
371 }
372
373 loadModConf = NULL; /* done loading */
374ENDendCnfLoad
375
376
377BEGINcheckCnf
378CODESTARTcheckCnf
379ENDcheckCnf
380
381
382BEGINactivateCnfPrePrivDrop
383CODESTARTactivateCnfPrePrivDrop
384 runModConf = pModConf;
385 iRet = klogWillRun(runModConf);
386ENDactivateCnfPrePrivDrop
387
388
389BEGINactivateCnf
390CODESTARTactivateCnf
391ENDactivateCnf
392
393
394BEGINfreeCnf
395CODESTARTfreeCnf
396ENDfreeCnf
397
398
399BEGINwillRun
400CODESTARTwillRun
401ENDwillRun
402
403
404BEGINafterRun
405CODESTARTafterRun
406 iRet = klogAfterRun(runModConf);
407ENDafterRun
408
409
410BEGINmodExit
411CODESTARTmodExit
412 if(pInputName != NULL)
413 prop.Destruct(&pInputName);
414 if(pLocalHostIP != NULL)
415 prop.Destruct(&pLocalHostIP);
416
417 /* release objects we used */
418 objRelease(glbl, CORE_COMPONENT);
419 objRelease(net, CORE_COMPONENT);
420 objRelease(datetime, CORE_COMPONENT);
421 objRelease(prop, CORE_COMPONENT);
422 objRelease(errmsg, CORE_COMPONENT);
423ENDmodExit
424
425
426BEGINqueryEtryPt
427CODESTARTqueryEtryPt
428CODEqueryEtryPt_STD_IMOD_QUERIES
429CODEqueryEtryPt_STD_CONF2_QUERIES
430CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES
431CODEqueryEtryPt_STD_CONF2_PREPRIVDROP_QUERIES
432ENDqueryEtryPt
433
434static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
435{
436 cs.bPermitNonKernel = 0;
437 cs.bParseKernelStamp = 0;
438 cs.bKeepKernelStamp = 0;
439 if(cs.pszPath != NULL) {
440 free(cs.pszPath);
441 cs.pszPath = NULL;
442 }
443 cs.iFacilIntMsg = klogFacilIntMsg();
444 return RS_RET_OK;
445}
446
447BEGINmodInit()
448CODESTARTmodInit
449 *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
450CODEmodInit_QueryRegCFSLineHdlr
451 CHKiRet(objUse(datetime, CORE_COMPONENT));
452 CHKiRet(objUse(glbl, CORE_COMPONENT));
453 CHKiRet(objUse(prop, CORE_COMPONENT));
454 CHKiRet(objUse(net, CORE_COMPONENT));
455 CHKiRet(objUse(errmsg, CORE_COMPONENT));
456
457 /* we need to create the inputName property (only once during our lifetime) */
458 CHKiRet(prop.CreateStringProp(&pInputName, UCHAR_CONSTANT("imklog"), sizeof("imklog") - 1));
459 CHKiRet(prop.CreateStringProp(&pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
460
461 /* init legacy config settings */
462 initConfigSettings();
463
464 CHKiRet(omsdRegCFSLineHdlr((uchar *)"debugprintkernelsymbols", 0, eCmdHdlrGoneAway,
465 NULL, NULL, STD_LOADABLE_MODULE_ID));
466 CHKiRet(regCfSysLineHdlr2((uchar *)"klogpath", 0, eCmdHdlrGetWord,
467 NULL, &cs.pszPath, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
468 CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbollookup", 0, eCmdHdlrGoneAway,
469 NULL, NULL, STD_LOADABLE_MODULE_ID));
470 CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbolstwice", 0, eCmdHdlrGoneAway,
471 NULL, NULL, STD_LOADABLE_MODULE_ID));
472 CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogusesyscallinterface", 0, eCmdHdlrGoneAway,
473 NULL, NULL, STD_LOADABLE_MODULE_ID));
474 CHKiRet(regCfSysLineHdlr2((uchar *)"klogpermitnonkernelfacility", 0, eCmdHdlrBinary,
475 NULL, &cs.bPermitNonKernel, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
476 CHKiRet(regCfSysLineHdlr2((uchar *)"klogconsoleloglevel", 0, eCmdHdlrInt,
477 NULL, &cs.console_log_level, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
478 CHKiRet(regCfSysLineHdlr2((uchar *)"kloginternalmsgfacility", 0, eCmdHdlrFacility,
479 NULL, &cs.iFacilIntMsg, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
480 CHKiRet(regCfSysLineHdlr2((uchar *)"klogparsekerneltimestamp", 0, eCmdHdlrBinary,
481 NULL, &cs.bParseKernelStamp, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
482 CHKiRet(regCfSysLineHdlr2((uchar *)"klogkeepkerneltimestamp", 0, eCmdHdlrBinary,
483 NULL, &cs.bKeepKernelStamp, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
484 CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
485 resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
486ENDmodInit
487/* vim:set ai:
488 */
0489
=== added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h'
--- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h 1970-01-01 00:00:00 +0000
+++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h 2015-01-09 16:11:08 +0000
@@ -0,0 +1,70 @@
1/* imklog.h
2 * These are the definitions for the klog message generation module.
3 *
4 * File begun on 2007-12-17 by RGerhards
5 * Major change: 2008-04-09: switched to a driver interface for
6 * several platforms
7 *
8 * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH.
9 *
10 * This file is part of rsyslog.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 * -or-
18 * see COPYING.ASL20 in the source distribution
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26#ifndef IMKLOG_H_INCLUDED
27#define IMKLOG_H_INCLUDED 1
28
29#include "rsyslog.h"
30#include "dirty.h"
31
32/* we need to have the modConf type present in all submodules */
33struct modConfData_s {
34 rsconf_t *pConf;
35 int iFacilIntMsg;
36 uchar *pszPath;
37 int console_log_level;
38 sbool bParseKernelStamp;
39 sbool bKeepKernelStamp;
40 sbool bPermitNonKernel;
41 sbool configSetViaV2Method;
42};
43
44/* interface to "drivers"
45 * the platform specific drivers must implement these entry points. Only one
46 * driver may be active at any given time, thus we simply rely on the linker
47 * to resolve the addresses.
48 * rgerhards, 2008-04-09
49 */
50rsRetVal klogLogKMsg(modConfData_t *pModConf);
51rsRetVal klogWillRun(modConfData_t *pModConf);
52rsRetVal klogAfterRun(modConfData_t *pModConf);
53int klogFacilIntMsg();
54
55/* the functions below may be called by the drivers */
56rsRetVal imklogLogIntMsg(int priority, char *fmt, ...) __attribute__((format(printf,2, 3)));
57rsRetVal Syslog(int priority, uchar *msg, struct timeval *tp);
58
59/* prototypes */
60extern int klog_getMaxLine(void); /* work-around for klog drivers to get configured max line size */
61extern int InitKsyms(modConfData_t*);
62extern void DeinitKsyms(void);
63extern int InitMsyms(void);
64extern void DeinitMsyms(void);
65extern char * ExpandKadds(char *, char *);
66extern void SetParanoiaLevel(int);
67
68#endif /* #ifndef IMKLOG_H_INCLUDED */
69/* vi:set ai:
70 */
071
=== added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c'
--- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c 1970-01-01 00:00:00 +0000
+++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c 2015-01-09 16:11:08 +0000
@@ -0,0 +1,295 @@
1/* The kernel log module.
2 *
3 * This is rsyslog Linux only module for reading structured kernel logs.
4 * Module is based on imklog module so it retains its structure
5 * and other part is currently in kmsg.c file instead of this (imkmsg.c)
6 * For more information see that file.
7 *
8 * To test under Linux:
9 * echo test1 > /dev/kmsg
10 *
11 * Copyright (C) 2008-2012 Adiscon GmbH
12 *
13 * This file is part of rsyslog.
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 * http://www.apache.org/licenses/LICENSE-2.0
20 * -or-
21 * see COPYING.ASL20 in the source distribution
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS,
25 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
28 */
29#include "config.h"
30#include "rsyslog.h"
31#include <stdio.h>
32#include <assert.h>
33#include <string.h>
34#include <stdarg.h>
35#include <ctype.h>
36#include <stdlib.h>
37#include <sys/socket.h>
38
39#include "dirty.h"
40#include "cfsysline.h"
41#include "obj.h"
42#include "msg.h"
43#include "module-template.h"
44#include "datetime.h"
45#include "imkmsg.h"
46#include "net.h"
47#include "glbl.h"
48#include "prop.h"
49#include "errmsg.h"
50#include "unicode-helper.h"
51
52MODULE_TYPE_INPUT
53MODULE_TYPE_NOKEEP
54MODULE_CNFNAME("imkmsg")
55
56/* Module static data */
57DEF_IMOD_STATIC_DATA
58DEFobjCurrIf(datetime)
59DEFobjCurrIf(glbl)
60DEFobjCurrIf(prop)
61DEFobjCurrIf(net)
62DEFobjCurrIf(errmsg)
63
64/* config settings */
65typedef struct configSettings_s {
66 int iFacilIntMsg; /* the facility to use for internal messages (set by driver) */
67} configSettings_t;
68static configSettings_t cs;
69
70static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
71static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */
72static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config parameters permitted? */
73
74static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this module */
75static prop_t *pLocalHostIP = NULL; /* a pseudo-constant propterty for 127.0.0.1 */
76
77static inline void
78initConfigSettings(void)
79{
80 cs.iFacilIntMsg = klogFacilIntMsg();
81}
82
83
84/* enqueue the the kernel message into the message queue.
85 * The provided msg string is not freed - thus must be done
86 * by the caller.
87 * rgerhards, 2008-04-12
88 */
89static rsRetVal
90enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity, struct timeval *tp, struct json_object *json)
91{
92 struct syslogTime st;
93 msg_t *pMsg;
94 DEFiRet;
95
96 assert(msg != NULL);
97 assert(pszTag != NULL);
98
99 if(tp == NULL) {
100 CHKiRet(msgConstruct(&pMsg));
101 } else {
102 datetime.timeval2syslogTime(tp, &st);
103 CHKiRet(msgConstructWithTime(&pMsg, &st, tp->tv_sec));
104 }
105 MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
106 MsgSetInputName(pMsg, pInputName);
107 MsgSetRawMsgWOSize(pMsg, (char*)msg);
108 MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */
109 MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
110 MsgSetRcvFromIP(pMsg, pLocalHostIP);
111 MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
112 MsgSetTAG(pMsg, pszTag, ustrlen(pszTag));
113 pMsg->iFacility = iFacility;
114 pMsg->iSeverity = iSeverity;
115 pMsg->json = json;
116 CHKiRet(submitMsg(pMsg));
117
118finalize_it:
119 RETiRet;
120}
121
122
123/* log an imkmsg-internal message
124 * rgerhards, 2008-04-14
125 */
126rsRetVal imkmsgLogIntMsg(int priority, char *fmt, ...)
127{
128 DEFiRet;
129 va_list ap;
130 uchar msgBuf[2048]; /* we use the same size as sysklogd to remain compatible */
131
132 va_start(ap, fmt);
133 vsnprintf((char*)msgBuf, sizeof(msgBuf) / sizeof(char), fmt, ap);
134 va_end(ap);
135
136 logmsgInternal(NO_ERRCODE ,priority, msgBuf, 0);
137
138 RETiRet;
139}
140
141
142/* log a message from /dev/kmsg
143 */
144rsRetVal Syslog(int priority, uchar *pMsg, struct timeval *tp, struct json_object *json)
145{
146 DEFiRet;
147 iRet = enqMsg((uchar*)pMsg, (uchar*) "kernel:", pri2fac(priority), pri2sev(priority), tp, json);
148 RETiRet;
149}
150
151
152/* helper for some klog drivers which need to know the MaxLine global setting. They can
153 * not obtain it themselfs, because they are no modules and can not query the object hander.
154 * It would probably be a good idea to extend the interface to support it, but so far
155 * we create a (sufficiently valid) work-around. -- rgerhards, 2008-11-24
156 */
157int klog_getMaxLine(void)
158{
159 return glbl.GetMaxLine();
160}
161
162
163BEGINrunInput
164CODESTARTrunInput
165 /* this is an endless loop - it is terminated when the thread is
166 * signalled to do so. This, however, is handled by the framework,
167 * right into the sleep below.
168 */
169 while(!pThrd->bShallStop) {
170 /* klogLogKMsg() waits for the next kernel message, obtains it
171 * and then submits it to the rsyslog main queue.
172 * rgerhards, 2008-04-09
173 */
174 CHKiRet(klogLogKMsg(runModConf));
175 }
176finalize_it:
177ENDrunInput
178
179
180BEGINbeginCnfLoad
181CODESTARTbeginCnfLoad
182 loadModConf = pModConf;
183 pModConf->pConf = pConf;
184 /* init our settings */
185 pModConf->iFacilIntMsg = klogFacilIntMsg();
186 loadModConf->configSetViaV2Method = 0;
187 bLegacyCnfModGlobalsPermitted = 1;
188 /* init legacy config vars */
189 initConfigSettings();
190ENDbeginCnfLoad
191
192
193BEGINendCnfLoad
194CODESTARTendCnfLoad
195 if(!loadModConf->configSetViaV2Method) {
196 /* persist module-specific settings from legacy config system */
197 loadModConf->iFacilIntMsg = cs.iFacilIntMsg;
198 }
199
200 loadModConf = NULL; /* done loading */
201ENDendCnfLoad
202
203
204BEGINcheckCnf
205CODESTARTcheckCnf
206ENDcheckCnf
207
208
209BEGINactivateCnfPrePrivDrop
210CODESTARTactivateCnfPrePrivDrop
211 runModConf = pModConf;
212 iRet = klogWillRun(runModConf);
213ENDactivateCnfPrePrivDrop
214
215
216BEGINactivateCnf
217CODESTARTactivateCnf
218ENDactivateCnf
219
220
221BEGINfreeCnf
222CODESTARTfreeCnf
223ENDfreeCnf
224
225
226BEGINwillRun
227CODESTARTwillRun
228ENDwillRun
229
230
231BEGINafterRun
232CODESTARTafterRun
233 iRet = klogAfterRun(runModConf);
234ENDafterRun
235
236
237BEGINmodExit
238CODESTARTmodExit
239 if(pInputName != NULL)
240 prop.Destruct(&pInputName);
241 if(pLocalHostIP != NULL)
242 prop.Destruct(&pLocalHostIP);
243
244 /* release objects we used */
245 objRelease(glbl, CORE_COMPONENT);
246 objRelease(net, CORE_COMPONENT);
247 objRelease(datetime, CORE_COMPONENT);
248 objRelease(prop, CORE_COMPONENT);
249 objRelease(errmsg, CORE_COMPONENT);
250ENDmodExit
251
252
253BEGINqueryEtryPt
254CODESTARTqueryEtryPt
255CODEqueryEtryPt_STD_IMOD_QUERIES
256CODEqueryEtryPt_STD_CONF2_QUERIES
257CODEqueryEtryPt_STD_CONF2_PREPRIVDROP_QUERIES
258ENDqueryEtryPt
259
260static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
261{
262 cs.iFacilIntMsg = klogFacilIntMsg();
263 return RS_RET_OK;
264}
265
266BEGINmodInit()
267CODESTARTmodInit
268 *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
269CODEmodInit_QueryRegCFSLineHdlr
270 CHKiRet(objUse(datetime, CORE_COMPONENT));
271 CHKiRet(objUse(glbl, CORE_COMPONENT));
272 CHKiRet(objUse(prop, CORE_COMPONENT));
273 CHKiRet(objUse(net, CORE_COMPONENT));
274 CHKiRet(objUse(errmsg, CORE_COMPONENT));
275
276 /* we need to create the inputName property (only once during our lifetime) */
277 CHKiRet(prop.CreateStringProp(&pInputName, UCHAR_CONSTANT("imkmsg"), sizeof("imkmsg") - 1));
278 CHKiRet(prop.CreateStringProp(&pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
279
280 /* init legacy config settings */
281 initConfigSettings();
282
283 CHKiRet(omsdRegCFSLineHdlr((uchar *)"debugprintkernelsymbols", 0, eCmdHdlrGoneAway,
284 NULL, NULL, STD_LOADABLE_MODULE_ID));
285 CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbollookup", 0, eCmdHdlrGoneAway,
286 NULL, NULL, STD_LOADABLE_MODULE_ID));
287 CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbolstwice", 0, eCmdHdlrGoneAway,
288 NULL, NULL, STD_LOADABLE_MODULE_ID));
289 CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogusesyscallinterface", 0, eCmdHdlrGoneAway,
290 NULL, NULL, STD_LOADABLE_MODULE_ID));
291 CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
292 resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
293ENDmodInit
294/* vim:set ai:
295 */
0296
=== added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h'
--- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h 1970-01-01 00:00:00 +0000
+++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h 2015-01-09 16:11:08 +0000
@@ -0,0 +1,64 @@
1/* imkmsg.h
2 * These are the definitions for the kmsg message generation module.
3 *
4 * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH.
5 *
6 * This file is part of rsyslog.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * -or-
14 * see COPYING.ASL20 in the source distribution
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22#ifndef IMKLOG_H_INCLUDED
23#define IMKLOG_H_INCLUDED 1
24
25#include "rsyslog.h"
26#include "dirty.h"
27
28/* we need to have the modConf type present in all submodules */
29struct modConfData_s {
30 rsconf_t *pConf;
31 int iFacilIntMsg;
32 uchar *pszPath;
33 int console_log_level;
34 sbool bPermitNonKernel;
35 sbool configSetViaV2Method;
36};
37
38/* interface to "drivers"
39 * the platform specific drivers must implement these entry points. Only one
40 * driver may be active at any given time, thus we simply rely on the linker
41 * to resolve the addresses.
42 * rgerhards, 2008-04-09
43 */
44rsRetVal klogLogKMsg(modConfData_t *pModConf);
45rsRetVal klogWillRun(modConfData_t *pModConf);
46rsRetVal klogAfterRun(modConfData_t *pModConf);
47int klogFacilIntMsg();
48
49/* the functions below may be called by the drivers */
50rsRetVal imkmsgLogIntMsg(int priority, char *fmt, ...) __attribute__((format(printf,2, 3)));
51rsRetVal Syslog(int priority, uchar *msg, struct timeval *tp, struct json_object *json);
52
53/* prototypes */
54extern int klog_getMaxLine(void); /* work-around for klog drivers to get configured max line size */
55extern int InitKsyms(modConfData_t*);
56extern void DeinitKsyms(void);
57extern int InitMsyms(void);
58extern void DeinitMsyms(void);
59extern char * ExpandKadds(char *, char *);
60extern void SetParanoiaLevel(int);
61
62#endif /* #ifndef IMKLOG_H_INCLUDED */
63/* vi:set ai:
64 */
065
=== modified file 'debian/changelog'
--- debian/changelog 2015-01-05 10:52:48 +0000
+++ debian/changelog 2015-01-09 16:11:08 +0000
@@ -1,3 +1,10 @@
1rsyslog (7.4.4-1ubuntu2.5) trusty-proposed; urgency=medium
2
3 * Applied updated upstream patch fixing infinite loop on OpenVZ VMs.
4 (LP: #1366829)
5
6 -- Paul Donohue <ubuntu-rsyslog@PaulSD.com> Fri, 09 Jan 2015 10:50:36 -0500
7
1rsyslog (7.4.4-1ubuntu2.4) trusty-proposed; urgency=medium8rsyslog (7.4.4-1ubuntu2.4) trusty-proposed; urgency=medium
29
3 * Applied upstream patch fixing infinite loop on OpenVZ VMs. Thanks to Paul10 * Applied upstream patch fixing infinite loop on OpenVZ VMs. Thanks to Paul
411
=== modified file 'debian/patches/11-fix-infinite-loop-openvz-vms.patch'
--- debian/patches/11-fix-infinite-loop-openvz-vms.patch 2015-01-05 10:52:48 +0000
+++ debian/patches/11-fix-infinite-loop-openvz-vms.patch 2015-01-09 16:11:08 +0000
@@ -3,27 +3,46 @@
3Author: Paul Donohue <git@PaulSD.com>3Author: Paul Donohue <git@PaulSD.com>
4Applied-Upstream: commit 86904f96805d70fad6b4b1b90e06dcb8f789605c4Applied-Upstream: commit 86904f96805d70fad6b4b1b90e06dcb8f789605c
55
6Index: rsyslog-7.4.4/plugins/imkmsg/kmsg.c6Index: rsyslog.trusty/plugins/imkmsg/kmsg.c
7===================================================================7===================================================================
8--- rsyslog-7.4.4.orig/plugins/imkmsg/kmsg.c8--- rsyslog.trusty.orig/plugins/imkmsg/kmsg.c
9+++ rsyslog-7.4.4/plugins/imkmsg/kmsg.c9+++ rsyslog.trusty/plugins/imkmsg/kmsg.c
10@@ -157,6 +157,7 @@ submitSyslog(uchar *buf)10@@ -155,18 +155,41 @@ submitSyslog(uchar *buf)
11 /* open the kernel log - will be called inside the willRun() imkmsg entry point
12 */
11 rsRetVal13 rsRetVal
12 klogWillRun(modConfData_t *pModConf)14-klogWillRun(modConfData_t *pModConf)
15+klogWillRunPrePrivDrop(modConfData_t *pModConf)
13 {16 {
14+ int i;
15 char errmsg[2048];17 char errmsg[2048];
16 DEFiRet;18 DEFiRet;
17 19
18@@ -167,6 +168,16 @@ klogWillRun(modConfData_t *pModConf)20 fklog = open(_PATH_KLOG, O_RDONLY, 0);
21 if (fklog < 0) {
22- imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot open kernel log(%s): %s.",
23+ imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.",
24 _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));
19 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);25 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
20 }26 }
21 27
22+ /* make sure the kernel log is readable */28+finalize_it:
23+ /* this normally returns EINVAL - on an OpenVZ VM, we get EBADF */29+ RETiRet;
24+ i = read(fklog, NULL, 0);30+}
25+ if (i < 0 && errno == EBADF) {31+
26+ imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot read kernel log(%s): %s.",32+/* make sure the kernel log is readable after dropping privileges
33+ */
34+rsRetVal
35+klogWillRunPostPrivDrop(modConfData_t *pModConf)
36+{
37+ char errmsg[2048];
38+ int r;
39+ DEFiRet;
40+
41+ /* this normally returns EINVAL */
42+ /* on an OpenVZ VM, we get EPERM */
43+ r = read(fklog, NULL, 0);
44+ if (r < 0 && errno != EINVAL) {
45+ imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.",
27+ _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));46+ _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));
28+ fklog = -1;47+ fklog = -1;
29+ ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);48+ ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
@@ -32,10 +51,10 @@
32 finalize_it:51 finalize_it:
33 RETiRet;52 RETiRet;
34 }53 }
35Index: rsyslog-7.4.4/runtime/rsyslog.h54Index: rsyslog.trusty/runtime/rsyslog.h
36===================================================================55===================================================================
37--- rsyslog-7.4.4.orig/runtime/rsyslog.h56--- rsyslog.trusty.orig/runtime/rsyslog.h
38+++ rsyslog-7.4.4/runtime/rsyslog.h57+++ rsyslog.trusty/runtime/rsyslog.h
39@@ -358,7 +358,7 @@ enum rsRetVal_ /** return value. All58@@ -358,7 +358,7 @@ enum rsRetVal_ /** return value. All
40 RS_RET_VAR_NOT_FOUND = -2142, /**< variable not found */59 RS_RET_VAR_NOT_FOUND = -2142, /**< variable not found */
41 RS_RET_EMPTY_MSG = -2143, /**< provided (raw) MSG is empty */60 RS_RET_EMPTY_MSG = -2143, /**< provided (raw) MSG is empty */
@@ -45,3 +64,126 @@
45 RS_RET_ERR_AQ_CONLOG = -2146, /**< error aquiring console log (on solaris) */64 RS_RET_ERR_AQ_CONLOG = -2146, /**< error aquiring console log (on solaris) */
46 RS_RET_ERR_DOOR = -2147, /**< some problems with handling the Solaris door functionality */65 RS_RET_ERR_DOOR = -2147, /**< some problems with handling the Solaris door functionality */
47 RS_RET_NO_SRCNAME_TPL = -2150, /**< sourcename template was not specified where one was needed (omudpspoof spoof addr) */66 RS_RET_NO_SRCNAME_TPL = -2150, /**< sourcename template was not specified where one was needed (omudpspoof spoof addr) */
67Index: rsyslog.trusty/plugins/imklog/bsd.c
68===================================================================
69--- rsyslog.trusty.orig/plugins/imklog/bsd.c
70+++ rsyslog.trusty/plugins/imklog/bsd.c
71@@ -164,7 +164,7 @@ static uchar *GetPath(modConfData_t *pMo
72 * entry point. -- rgerhards, 2008-04-09
73 */
74 rsRetVal
75-klogWillRun(modConfData_t *pModConf)
76+klogWillRunPrePrivDrop(modConfData_t *pModConf)
77 {
78 char errmsg[2048];
79 int r;
80@@ -172,7 +172,7 @@ klogWillRun(modConfData_t *pModConf)
81
82 fklog = open((char*)GetPath(pModConf), O_RDONLY, 0);
83 if (fklog < 0) {
84- imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log(%s): %s.",
85+ imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.",
86 GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg)));
87 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
88 }
89@@ -192,6 +192,29 @@ klogWillRun(modConfData_t *pModConf)
90
91 finalize_it:
92 RETiRet;
93+}
94+
95+/* make sure the kernel log is readable after dropping privileges
96+ */
97+rsRetVal
98+klogWillRunPostPrivDrop(modConfData_t *pModConf)
99+{
100+ char errmsg[2048];
101+ int r;
102+ DEFiRet;
103+
104+ /* this normally returns EINVAL */
105+ /* on an OpenVZ VM, we get EPERM */
106+ r = read(fklog, NULL, 0);
107+ if (r < 0 && errno != EINVAL) {
108+ imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.",
109+ GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg)));
110+ fklog = -1;
111+ ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
112+ }
113+
114+finalize_it:
115+ RETiRet;
116 }
117
118
119Index: rsyslog.trusty/plugins/imklog/imklog.c
120===================================================================
121--- rsyslog.trusty.orig/plugins/imklog/imklog.c
122+++ rsyslog.trusty/plugins/imklog/imklog.c
123@@ -382,7 +382,7 @@ ENDcheckCnf
124 BEGINactivateCnfPrePrivDrop
125 CODESTARTactivateCnfPrePrivDrop
126 runModConf = pModConf;
127- iRet = klogWillRun(runModConf);
128+ iRet = klogWillRunPrePrivDrop(runModConf);
129 ENDactivateCnfPrePrivDrop
130
131
132@@ -398,6 +398,7 @@ ENDfreeCnf
133
134 BEGINwillRun
135 CODESTARTwillRun
136+ iRet = klogWillRunPostPrivDrop(runModConf);
137 ENDwillRun
138
139
140Index: rsyslog.trusty/plugins/imklog/imklog.h
141===================================================================
142--- rsyslog.trusty.orig/plugins/imklog/imklog.h
143+++ rsyslog.trusty/plugins/imklog/imklog.h
144@@ -48,8 +48,9 @@ struct modConfData_s {
145 * rgerhards, 2008-04-09
146 */
147 rsRetVal klogLogKMsg(modConfData_t *pModConf);
148-rsRetVal klogWillRun(modConfData_t *pModConf);
149 rsRetVal klogAfterRun(modConfData_t *pModConf);
150+rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf);
151+rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf);
152 int klogFacilIntMsg();
153
154 /* the functions below may be called by the drivers */
155Index: rsyslog.trusty/plugins/imkmsg/imkmsg.c
156===================================================================
157--- rsyslog.trusty.orig/plugins/imkmsg/imkmsg.c
158+++ rsyslog.trusty/plugins/imkmsg/imkmsg.c
159@@ -209,7 +209,7 @@ ENDcheckCnf
160 BEGINactivateCnfPrePrivDrop
161 CODESTARTactivateCnfPrePrivDrop
162 runModConf = pModConf;
163- iRet = klogWillRun(runModConf);
164+ iRet = klogWillRunPrePrivDrop(runModConf);
165 ENDactivateCnfPrePrivDrop
166
167
168@@ -225,6 +225,7 @@ ENDfreeCnf
169
170 BEGINwillRun
171 CODESTARTwillRun
172+ iRet = klogWillRunPostPrivDrop(runModConf);
173 ENDwillRun
174
175
176Index: rsyslog.trusty/plugins/imkmsg/imkmsg.h
177===================================================================
178--- rsyslog.trusty.orig/plugins/imkmsg/imkmsg.h
179+++ rsyslog.trusty/plugins/imkmsg/imkmsg.h
180@@ -42,7 +42,8 @@ struct modConfData_s {
181 * rgerhards, 2008-04-09
182 */
183 rsRetVal klogLogKMsg(modConfData_t *pModConf);
184-rsRetVal klogWillRun(modConfData_t *pModConf);
185+rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf);
186+rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf);
187 rsRetVal klogAfterRun(modConfData_t *pModConf);
188 int klogFacilIntMsg();
189
48190
=== modified file 'plugins/imklog/bsd.c'
--- plugins/imklog/bsd.c 2013-03-18 16:21:35 +0000
+++ plugins/imklog/bsd.c 2015-01-09 16:11:08 +0000
@@ -164,7 +164,7 @@
164 * entry point. -- rgerhards, 2008-04-09164 * entry point. -- rgerhards, 2008-04-09
165 */165 */
166rsRetVal166rsRetVal
167klogWillRun(modConfData_t *pModConf)167klogWillRunPrePrivDrop(modConfData_t *pModConf)
168{168{
169 char errmsg[2048];169 char errmsg[2048];
170 int r;170 int r;
@@ -172,7 +172,7 @@
172172
173 fklog = open((char*)GetPath(pModConf), O_RDONLY, 0);173 fklog = open((char*)GetPath(pModConf), O_RDONLY, 0);
174 if (fklog < 0) {174 if (fklog < 0) {
175 imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log(%s): %s.",175 imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.",
176 GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg)));176 GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg)));
177 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);177 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
178 }178 }
@@ -194,6 +194,29 @@
194 RETiRet;194 RETiRet;
195}195}
196196
197/* make sure the kernel log is readable after dropping privileges
198 */
199rsRetVal
200klogWillRunPostPrivDrop(modConfData_t *pModConf)
201{
202 char errmsg[2048];
203 int r;
204 DEFiRet;
205
206 /* this normally returns EINVAL */
207 /* on an OpenVZ VM, we get EPERM */
208 r = read(fklog, NULL, 0);
209 if (r < 0 && errno != EINVAL) {
210 imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.",
211 GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg)));
212 fklog = -1;
213 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
214 }
215
216finalize_it:
217 RETiRet;
218}
219
197220
198/* Read kernel log while data are available, split into lines.221/* Read kernel log while data are available, split into lines.
199 */222 */
200223
=== modified file 'plugins/imklog/imklog.c'
--- plugins/imklog/imklog.c 2014-10-02 11:32:50 +0000
+++ plugins/imklog/imklog.c 2015-01-09 16:11:08 +0000
@@ -382,7 +382,7 @@
382BEGINactivateCnfPrePrivDrop382BEGINactivateCnfPrePrivDrop
383CODESTARTactivateCnfPrePrivDrop383CODESTARTactivateCnfPrePrivDrop
384 runModConf = pModConf;384 runModConf = pModConf;
385 iRet = klogWillRun(runModConf);385 iRet = klogWillRunPrePrivDrop(runModConf);
386ENDactivateCnfPrePrivDrop386ENDactivateCnfPrePrivDrop
387387
388388
@@ -398,6 +398,7 @@
398398
399BEGINwillRun399BEGINwillRun
400CODESTARTwillRun400CODESTARTwillRun
401 iRet = klogWillRunPostPrivDrop(runModConf);
401ENDwillRun402ENDwillRun
402403
403404
404405
=== modified file 'plugins/imklog/imklog.h'
--- plugins/imklog/imklog.h 2013-03-18 16:21:35 +0000
+++ plugins/imklog/imklog.h 2015-01-09 16:11:08 +0000
@@ -48,8 +48,9 @@
48 * rgerhards, 2008-04-0948 * rgerhards, 2008-04-09
49 */49 */
50rsRetVal klogLogKMsg(modConfData_t *pModConf);50rsRetVal klogLogKMsg(modConfData_t *pModConf);
51rsRetVal klogWillRun(modConfData_t *pModConf);
52rsRetVal klogAfterRun(modConfData_t *pModConf);51rsRetVal klogAfterRun(modConfData_t *pModConf);
52rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf);
53rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf);
53int klogFacilIntMsg();54int klogFacilIntMsg();
5455
55/* the functions below may be called by the drivers */56/* the functions below may be called by the drivers */
5657
=== modified file 'plugins/imkmsg/imkmsg.c'
--- plugins/imkmsg/imkmsg.c 2014-10-02 11:32:50 +0000
+++ plugins/imkmsg/imkmsg.c 2015-01-09 16:11:08 +0000
@@ -209,7 +209,7 @@
209BEGINactivateCnfPrePrivDrop209BEGINactivateCnfPrePrivDrop
210CODESTARTactivateCnfPrePrivDrop210CODESTARTactivateCnfPrePrivDrop
211 runModConf = pModConf;211 runModConf = pModConf;
212 iRet = klogWillRun(runModConf);212 iRet = klogWillRunPrePrivDrop(runModConf);
213ENDactivateCnfPrePrivDrop213ENDactivateCnfPrePrivDrop
214214
215215
@@ -225,6 +225,7 @@
225225
226BEGINwillRun226BEGINwillRun
227CODESTARTwillRun227CODESTARTwillRun
228 iRet = klogWillRunPostPrivDrop(runModConf);
228ENDwillRun229ENDwillRun
229230
230231
231232
=== modified file 'plugins/imkmsg/imkmsg.h'
--- plugins/imkmsg/imkmsg.h 2012-10-29 16:30:14 +0000
+++ plugins/imkmsg/imkmsg.h 2015-01-09 16:11:08 +0000
@@ -42,7 +42,8 @@
42 * rgerhards, 2008-04-0942 * rgerhards, 2008-04-09
43 */43 */
44rsRetVal klogLogKMsg(modConfData_t *pModConf);44rsRetVal klogLogKMsg(modConfData_t *pModConf);
45rsRetVal klogWillRun(modConfData_t *pModConf);45rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf);
46rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf);
46rsRetVal klogAfterRun(modConfData_t *pModConf);47rsRetVal klogAfterRun(modConfData_t *pModConf);
47int klogFacilIntMsg();48int klogFacilIntMsg();
4849
4950
=== modified file 'plugins/imkmsg/kmsg.c'
--- plugins/imkmsg/kmsg.c 2015-01-05 10:52:48 +0000
+++ plugins/imkmsg/kmsg.c 2015-01-09 16:11:08 +0000
@@ -155,24 +155,36 @@
155/* open the kernel log - will be called inside the willRun() imkmsg entry point155/* open the kernel log - will be called inside the willRun() imkmsg entry point
156 */156 */
157rsRetVal157rsRetVal
158klogWillRun(modConfData_t *pModConf)158klogWillRunPrePrivDrop(modConfData_t *pModConf)
159{159{
160 int i;
161 char errmsg[2048];160 char errmsg[2048];
162 DEFiRet;161 DEFiRet;
163162
164 fklog = open(_PATH_KLOG, O_RDONLY, 0);163 fklog = open(_PATH_KLOG, O_RDONLY, 0);
165 if (fklog < 0) {164 if (fklog < 0) {
166 imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot open kernel log(%s): %s.",165 imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.",
167 _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));166 _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));
168 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);167 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);
169 }168 }
170169
171 /* make sure the kernel log is readable */170finalize_it:
172 /* this normally returns EINVAL - on an OpenVZ VM, we get EBADF */171 RETiRet;
173 i = read(fklog, NULL, 0);172}
174 if (i < 0 && errno == EBADF) {173
175 imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot read kernel log(%s): %s.",174/* make sure the kernel log is readable after dropping privileges
175 */
176rsRetVal
177klogWillRunPostPrivDrop(modConfData_t *pModConf)
178{
179 char errmsg[2048];
180 int r;
181 DEFiRet;
182
183 /* this normally returns EINVAL */
184 /* on an OpenVZ VM, we get EPERM */
185 r = read(fklog, NULL, 0);
186 if (r < 0 && errno != EINVAL) {
187 imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.",
176 _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));188 _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg)));
177 fklog = -1;189 fklog = -1;
178 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);190 ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG);

Subscribers

People subscribed via source and target branches

to all changes: