From 348fd7d744e9eafe67bab7e173e04ffce007508b Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 4 Nov 2019 14:12:37 -0800 Subject: [PATCH] Fixed signedness. It appears that using a signed int causes the reads from libsystemd-journal to return incorrect values when comparing time stamps. I've fixed them to unsigned ones and monitored the performance on 2 systems for 3 days and it no longer misbehaves. I've also made it use `atoll` instead of `atoi` to prevent incomplete results. --- src/tallow.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tallow.c b/src/tallow.c index d56ec3c..3ba4158 100644 --- a/src/tallow.c +++ b/src/tallow.c @@ -287,7 +287,7 @@ int main(void) int r; FILE *f; int timeout = 60; - long long int last_timestamp = 0; + long long unsigned int last_timestamp = 0; json_load_patterns(); @@ -396,11 +396,13 @@ int main(void) * this happens when the journal rotates - we get replayed events */ if (sd_journal_get_data(j, "_SOURCE_REALTIME_TIMESTAMP", &dt, &dl) == 0) { - long long int lt = atoi(dt + strlen("_SOURCE_REALTIME_TIMESTAMP=")); + long long unsigned int lt = atoll(dt + strlen("_SOURCE_REALTIME_TIMESTAMP=")); if (lt > last_timestamp) last_timestamp = lt; - else if (lt < last_timestamp) + else if (lt < last_timestamp) { + dbg("Discarding old entry: %llu - %llu\n", lt, last_timestamp); continue; + } } if (sd_journal_get_data(j, "MESSAGE", &d, &l) < 0) {