diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2013-09-13 02:39:42 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2013-09-13 02:39:42 +0200 |
commit | 7903677bfba6fd897010d9c5dbb56531bfe0d825 (patch) | |
tree | 110e409834bab0fb1edd8f869e911c8d8d510493 /plugins/imkmsg/kmsg.c | |
parent | ad777330629c31447018e47b4033a7ebaa9fe655 (diff) | |
parent | 15921d4e4e9d03e0cfd4ca5a9745c89b5dcd37c3 (diff) | |
download | rsyslog-7903677bfba6fd897010d9c5dbb56531bfe0d825.tar.gz rsyslog-7903677bfba6fd897010d9c5dbb56531bfe0d825.tar.bz2 rsyslog-7903677bfba6fd897010d9c5dbb56531bfe0d825.zip |
Merge branch 'v7-stable' into v7-stable-tlsfix
Conflicts:
ChangeLog
runtime/rsyslog.h
Diffstat (limited to 'plugins/imkmsg/kmsg.c')
-rw-r--r-- | plugins/imkmsg/kmsg.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/plugins/imkmsg/kmsg.c b/plugins/imkmsg/kmsg.c index f1815f25..172ff4d1 100644 --- a/plugins/imkmsg/kmsg.c +++ b/plugins/imkmsg/kmsg.c @@ -32,10 +32,9 @@ #include <errno.h> #include <string.h> #include <ctype.h> -#ifdef OS_LINUX #include <sys/klog.h> -#endif -#include <json/json.h> +#include <sys/sysinfo.h> +#include <json.h> #include "rsyslog.h" #include "srUtils.h" @@ -58,9 +57,8 @@ submitSyslog(uchar *buf) { long offs = 0; struct timeval tv; - long int timestamp = 0; - struct timespec monotonic; - struct timespec realtime; + struct sysinfo info; + unsigned long int timestamp = 0; char name[1024]; char value[1024]; char msg[1024]; @@ -87,12 +85,12 @@ submitSyslog(uchar *buf) /* get timestamp */ for (; isdigit(*buf); buf++) { - timestamp += (timestamp * 10) + (*buf - '0'); + timestamp = (timestamp * 10) + (*buf - '0'); } while (*buf != ';') { buf++; /* skip everything till the first ; */ - } + } buf++; /* skip ; */ /* get message */ @@ -131,10 +129,24 @@ submitSyslog(uchar *buf) } /* calculate timestamp */ - clock_gettime(CLOCK_MONOTONIC, &monotonic); - clock_gettime(CLOCK_REALTIME, &realtime); - tv.tv_sec = realtime.tv_sec + ((timestamp / 1000000l) - monotonic.tv_sec); - tv.tv_usec = (realtime.tv_nsec + ((timestamp / 1000000000l) - monotonic.tv_nsec)) / 1000; + sysinfo(&info); + gettimeofday(&tv, NULL); + + /* get boot time */ + tv.tv_sec -= info.uptime; + + tv.tv_sec += timestamp / 1000000; + tv.tv_usec += timestamp % 1000000; + + while (tv.tv_usec < 0) { + tv.tv_sec--; + tv.tv_usec += 1000000; + } + + while (tv.tv_usec >= 1000000) { + tv.tv_sec++; + tv.tv_usec -= 1000000; + } Syslog(priority, (uchar *)msg, &tv, json); } @@ -146,7 +158,6 @@ rsRetVal klogWillRun(modConfData_t *pModConf) { char errmsg[2048]; - int r; DEFiRet; fklog = open(_PATH_KLOG, O_RDONLY, 0); @@ -156,17 +167,6 @@ klogWillRun(modConfData_t *pModConf) ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); } - /* Set level of kernel console messaging.. */ - if(pModConf->console_log_level != -1) { - r = klogctl(8, NULL, pModConf->console_log_level); - if(r != 0) { - imkmsgLogIntMsg(LOG_WARNING, "imkmsg: cannot set console log level: %s", - rs_strerror_r(errno, errmsg, sizeof(errmsg))); - /* make sure we do not try to re-set! */ - pModConf->console_log_level = -1; - } - } - finalize_it: RETiRet; } |