rsyslog/bugfix-rsyslog-7.4.7-imjournal-add-monotonic-timestamp.patch

58 lines
1.8 KiB
Diff
Raw Normal View History

2020-05-11 15:20:45 +08:00
From cb6b411b6d9ca7520b7971c1e3de776dbebe497f Mon Sep 17 00:00:00 2001
From: wangshouping <wangshouping@huawei.com>
Date: Wed, 15 Apr 2020 02:57:21 -0400
Subject: [PATCH] bugfix-rsyslog-7.4.7-imjournal-add-monotonic-timestamp
2019-09-30 11:16:30 -04:00
2020-05-11 15:20:45 +08:00
Signed-off-by: wangshouping <wangshouping@huawei.com>
2019-09-30 11:16:30 -04:00
---
plugins/imjournal/imjournal.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c
2020-05-11 15:20:45 +08:00
index 29dcec1..3a93b37 100644
2019-09-30 11:16:30 -04:00
--- a/plugins/imjournal/imjournal.c
+++ b/plugins/imjournal/imjournal.c
2020-05-11 15:20:45 +08:00
@@ -386,6 +386,7 @@ readjournal(void)
2019-09-30 11:16:30 -04:00
struct timeval tv;
uint64_t timestamp;
+ uint64_t monotonic_timestamp;
2020-05-11 15:20:45 +08:00
struct fjson_object *json = NULL;
2019-09-30 11:16:30 -04:00
int r;
2020-05-11 15:20:45 +08:00
@@ -395,6 +396,9 @@ readjournal(void)
char *sys_iden;
2019-09-30 11:16:30 -04:00
char *sys_iden_help = NULL;
+ char *t;
+ char *tpmessage;
+
const void *get;
const void *pidget;
size_t length;
2020-05-11 15:20:45 +08:00
@@ -501,8 +505,19 @@ readjournal(void)
iRet = updateJournalCursor();
2019-09-30 11:16:30 -04:00
- /* submit message */
- enqMsg((uchar *)message, (uchar *) sys_iden_help, facility, severity, &tv, json, 0);
2020-05-11 15:20:45 +08:00
+ if (journalGetData("_SOURCE_MONOTONIC_TIMESTAMP", &get, &length) >= 0)
2019-09-30 11:16:30 -04:00
+ {
+ t = strndup(get+28, length-28);
+ monotonic_timestamp = atoll(t);
+ free(t);
+ tpmessage = (char *)malloc(strlen(message)+30);
+ int ret = sprintf(tpmessage,"[%5lu.%06lu] ",monotonic_timestamp/1000000, monotonic_timestamp%1000000);
+ memcpy(tpmessage+(ret > 30 ? 0 :(ret < 0 ? 0:ret)),message,strlen(message)+1);
+ enqMsg((uchar *)tpmessage, (uchar *) sys_iden_help, facility, severity, &tv, json, 0);
+ free(tpmessage);
+ }else
+ /* submit message */
+ enqMsg((uchar *)message, (uchar *) sys_iden_help, facility, severity, &tv, json, 0);
finalize_it:
free(sys_iden_help);
--
2020-05-11 15:20:45 +08:00
2.19.1
2019-09-30 11:16:30 -04:00