summaryrefslogtreecommitdiffstats
path: root/plugins/imklog/bsd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-11-22 08:57:57 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2012-11-22 08:57:57 +0100
commitb78af2aaf546cee90671513be39d8e3717f2ace6 (patch)
tree15dd12440f846df4964701c52eea8985a55432e8 /plugins/imklog/bsd.c
parentf040bde7a0454dfbc7def36a288bc70c58d878af (diff)
downloadrsyslog-b78af2aaf546cee90671513be39d8e3717f2ace6.tar.gz
rsyslog-b78af2aaf546cee90671513be39d8e3717f2ace6.tar.bz2
rsyslog-b78af2aaf546cee90671513be39d8e3717f2ace6.zip
bugfix: imklog mistakenly took kernel timestamp subseconds as nanoseconds
... actually, they are microseconds. So the fractional part of the timestamp was not properly formatted. Thanks to Marius Tomaschwesky for the bug report and the patch idea.
Diffstat (limited to 'plugins/imklog/bsd.c')
-rw-r--r--plugins/imklog/bsd.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/plugins/imklog/bsd.c b/plugins/imklog/bsd.c
index 06032373..17d4bead 100644
--- a/plugins/imklog/bsd.c
+++ b/plugins/imklog/bsd.c
@@ -76,9 +76,9 @@ static void
submitSyslog(int pri, uchar *buf)
{
long secs;
- long nsecs;
+ long usecs;
long secOffs;
- long nsecOffs;
+ long usecOffs;
unsigned i;
unsigned bufsize;
struct timespec monotonic, realtime;
@@ -109,9 +109,9 @@ submitSyslog(int pri, uchar *buf)
}
++i; /* skip dot */
- nsecs = 0;
+ usecs = 0;
while(buf[i] && isdigit(buf[i])) {
- nsecs = nsecs * 10 + buf[i] - '0';
+ usecs = usecs * 10 + buf[i] - '0';
++i;
}
if(buf[i] != ']') {
@@ -121,7 +121,7 @@ submitSyslog(int pri, uchar *buf)
++i; /* skip ']' */
/* we have a timestamp */
- DBGPRINTF("kernel timestamp is %ld %ld\n", secs, nsecs);
+ DBGPRINTF("kernel timestamp is %ld %ld\n", secs, usecs);
if(!bKeepKernelStamp) {
bufsize= strlen((char*)buf);
memmove(buf+3, buf+i, bufsize - i + 1);
@@ -130,20 +130,20 @@ submitSyslog(int pri, uchar *buf)
clock_gettime(CLOCK_MONOTONIC, &monotonic);
clock_gettime(CLOCK_REALTIME, &realtime);
secOffs = realtime.tv_sec - monotonic.tv_sec;
- nsecOffs = realtime.tv_nsec - monotonic.tv_nsec;
- if(nsecOffs < 0) {
+ usecOffs = (realtime.tv_nsec - monotonic.tv_nsec) / 1000;
+ if(usecOffs < 0) {
secOffs--;
- nsecOffs += 1000000000l;
+ usecOffs += 1000000l;
}
- nsecs +=nsecOffs;
- if(nsecs > 999999999l) {
+ usecs += usecOffs;
+ if(usecs > 999999l) {
secs++;
- nsecs -= 1000000000l;
+ usecs -= 1000000l;
}
secs += secOffs;
tv.tv_sec = secs;
- tv.tv_usec = nsecs / 1000;
+ tv.tv_usec = usecs;
tp = &tv;
done: