File 0002-imklog-added-klogKeepKernelTimestamp-option.patch of Package rsyslog.1232

From 1149eb6987df77d97466dcbcc30c577a67ff5fd7 Mon Sep 17 00:00:00 2001
From: Marius Tomaschewski <mt@suse.de>
Date: Wed, 21 Nov 2012 13:46:58 +0100
References: bnc#783967
Upstream: merged
Url: http://git.adiscon.com/?p=rsyslog.git;a=commit;h=318a6fb577a6e5af558b70232bb0a19871399d13
Subject: [PATCH] imklog: added $klogKeepKernelTimestamp option

When enabled, the kernel [timestamp] remains at begin of
each message, even it is used for the message time too.
---
 doc/imklog.html         |    5 +++++
 plugins/imklog/bsd.c    |    6 ++++--
 plugins/imklog/imklog.c |    3 +++
 plugins/imklog/imklog.h |    1 +
 4 Dateien geändert, 13 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

diff --git a/doc/imklog.html b/doc/imklog.html
index 2e3b3bc..268c661 100644
--- a/doc/imklog.html
+++ b/doc/imklog.html
@@ -65,6 +65,11 @@ Linux only, ignored on other platforms (but may be specified)</li>
 former klogd -2 option<br>
 Linux only, ignored on other platforms (but may be specified)<br style="font-weight: bold;">
 </li>
+<li><b>$klogKeepKernelTimestamp</b> [on/<b>off</b>]
+If enabled, this option causes to keep the [timestamp] provided by the kernel at the begin
+of in each message rather than to remove it, when it could be parsed and converted into
+local time for use as regular message time.
+</li>
 </ul>
 <b>Caveats/Known Bugs:</b>
 <p>This is obviously platform specific and requires platform
diff --git a/plugins/imklog/bsd.c b/plugins/imklog/bsd.c
index bb45c97..ec4110d 100644
--- a/plugins/imklog/bsd.c
+++ b/plugins/imklog/bsd.c
@@ -119,8 +119,10 @@ submitSyslog(int pri, uchar *buf)
 
 	/* we have a timestamp */
 	DBGPRINTF("kernel timestamp is %ld %ld\n", secs, nsecs);
-	bufsize= strlen((char*)buf);
-	memmove(buf+3, buf+i, bufsize - i + 1);
+	if(!bKeepKernelStamp) {
+		bufsize= strlen((char*)buf);
+		memmove(buf+3, buf+i, bufsize - i + 1);
+	}
 
 	clock_gettime(CLOCK_MONOTONIC, &monotonic);
 	clock_gettime(CLOCK_REALTIME, &realtime);
diff --git a/plugins/imklog/imklog.c b/plugins/imklog/imklog.c
index aa50008..563b499 100644
--- a/plugins/imklog/imklog.c
+++ b/plugins/imklog/imklog.c
@@ -77,6 +77,7 @@ int symbols_twice = 0;
 int use_syscall = 0;
 int symbol_lookup = 0; /* on recent kernels > 2.6, the kernel does this */
 int bPermitNonKernel = 0; /* permit logging of messages not having LOG_KERN facility */
+int bKeepKernelStamp = 0; /* keep the kernel timestamp in the message */
 int iFacilIntMsg; /* the facility to use for internal messages (set by driver) */
 uchar *pszPath = NULL;
 int console_log_level = -1;
@@ -305,6 +306,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
 	symfile = NULL;
 	symbol_lookup = 0;
 	bPermitNonKernel = 0;
+	bKeepKernelStamp = 0;
 	if(pszPath != NULL) {
 		free(pszPath);
 		pszPath = NULL;
@@ -332,6 +334,7 @@ CODEmodInit_QueryRegCFSLineHdlr
 	CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogpermitnonkernelfacility", 0, eCmdHdlrBinary, NULL, &bPermitNonKernel, STD_LOADABLE_MODULE_ID));
 	CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogconsoleloglevel", 0, eCmdHdlrInt, NULL, &console_log_level, STD_LOADABLE_MODULE_ID));
 	CHKiRet(omsdRegCFSLineHdlr((uchar *)"kloginternalmsgfacility", 0, eCmdHdlrFacility, NULL, &iFacilIntMsg, STD_LOADABLE_MODULE_ID));
+	CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogkeepkerneltimestamp", 0, eCmdHdlrBinary, NULL, &bKeepKernelStamp, STD_LOADABLE_MODULE_ID));
 	CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
 ENDmodInit
 /* vim:set ai:
diff --git a/plugins/imklog/imklog.h b/plugins/imklog/imklog.h
index 7a060df..03fb973 100644
--- a/plugins/imklog/imklog.h
+++ b/plugins/imklog/imklog.h
@@ -52,6 +52,7 @@ extern char *symfile;
 extern int console_log_level;
 extern int dbgPrintSymbols;
 extern uchar *pszPath;
+extern int bKeepKernelStamp;
 
 /* the functions below may be called by the drivers */
 rsRetVal imklogLogIntMsg(int priority, char *fmt, ...) __attribute__((format(printf,2, 3)));
-- 
1.7.10.4

openSUSE Build Service is sponsored by