]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: ensure test-journal-stream doesn't get confused by crappy clocks 271/head
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jun 2015 18:37:19 +0000 (20:37 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Jun 2015 18:37:19 +0000 (20:37 +0200)
This ensures that we write strictly monotonic timestamps into the
journal files, to ensure that we can properly interleave everything
correctly.

See #175 for details.

src/journal/test-journal-stream.c

index e1146c692d32ee5cb2a61834d5e11c1701fca528..b5ecf2f375c8d614a8b80ce8fb87978123072c30 100644 (file)
@@ -80,6 +80,7 @@ int main(int argc, char *argv[]) {
         char *z;
         const void *data;
         size_t l;
+        dual_timestamp previous_ts = DUAL_TIMESTAMP_NULL;
 
         /* journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
@@ -101,6 +102,14 @@ int main(int argc, char *argv[]) {
 
                 dual_timestamp_get(&ts);
 
+                if (ts.monotonic <= previous_ts.monotonic)
+                        ts.monotonic = previous_ts.monotonic + 1;
+
+                if (ts.realtime <= previous_ts.realtime)
+                        ts.realtime = previous_ts.realtime + 1;
+
+                previous_ts = ts;
+
                 assert_se(asprintf(&p, "NUMBER=%u", i) >= 0);
                 iovec[0].iov_base = p;
                 iovec[0].iov_len = strlen(p);