Skip to content

Commit

Permalink
Fixed signedness.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahkok committed Nov 4, 2019
1 parent 83201e8 commit 348fd7d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/tallow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 348fd7d

Please sign in to comment.