chiark / gitweb /
journal: if two entries match with everything but seqnums, they are still identical
authorLennart Poettering <lennart@poettering.net>
Fri, 14 Oct 2011 14:52:42 +0000 (16:52 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 Oct 2011 14:52:42 +0000 (16:52 +0200)
src/journal/sd-journal.c
src/journal/sd-journal.h

index 74abac88af74ad262d4649518fea1e8109ca570d..d580b8e76869fdf3dde25ee38f167c606ee49696 100644 (file)
@@ -48,28 +48,29 @@ struct sd_journal {
         LIST_HEAD(Match, matches);
 };
 
         LIST_HEAD(Match, matches);
 };
 
-int sd_journal_add_match(sd_journal *j, const char *field, const void *data, size_t size) {
+int sd_journal_add_match(sd_journal *j, const void *data, size_t size) {
         Match *m;
         Match *m;
-        char *e;
 
         assert(j);
 
         assert(j);
-        assert(field);
-        assert(data || size == 0);
+
+        if (size <= 0)
+                return -EINVAL;
+
+        assert(data);
 
         m = new0(Match, 1);
         if (!m)
                 return -ENOMEM;
 
 
         m = new0(Match, 1);
         if (!m)
                 return -ENOMEM;
 
-        m->size = strlen(field) + 1 + size;
+        m->size = size;
+
         m->data = malloc(m->size);
         if (!m->data) {
                 free(m);
                 return -ENOMEM;
         }
 
         m->data = malloc(m->size);
         if (!m->data) {
                 free(m);
                 return -ENOMEM;
         }
 
-        e = stpcpy(m->data, field);
-        *(e++) = '=';
-        memcpy(e, data, size);
+        memcpy(m->data, data, size);
 
         LIST_PREPEND(Match, matches, j->matches, m);
         return 0;
 
         LIST_PREPEND(Match, matches, j->matches, m);
         return 0;
@@ -93,7 +94,16 @@ static int compare_order(JournalFile *af, Object *ao, uint64_t ap,
         uint64_t a, b;
 
         /* We operate on two different files here, hence we can access
         uint64_t a, b;
 
         /* We operate on two different files here, hence we can access
-         * two objects at the same time, which we normally can't */
+         * two objects at the same time, which we normally can't.
+         *
+         * If contents and timestamps match, these entries are
+         * identical, even if the seqnum does not match */
+
+        if (sd_id128_equal(ao->entry.boot_id, bo->entry.boot_id) &&
+            ao->entry.monotonic == bo->entry.monotonic &&
+            ao->entry.realtime == bo->entry.realtime &&
+            ao->entry.xor_hash == bo->entry.xor_hash)
+                return 0;
 
         if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
 
 
         if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
 
@@ -106,6 +116,10 @@ static int compare_order(JournalFile *af, Object *ao, uint64_t ap,
                         return -1;
                 if (a > b)
                         return 1;
                         return -1;
                 if (a > b)
                         return 1;
+
+                /* Wow! This is weird, different data but the same
+                 * seqnums? Something is borked, but let's make the
+                 * best of it and compare by time. */
         }
 
         if (sd_id128_equal(ao->entry.boot_id, bo->entry.boot_id)) {
         }
 
         if (sd_id128_equal(ao->entry.boot_id, bo->entry.boot_id)) {
@@ -474,6 +488,8 @@ void sd_journal_close(sd_journal *j) {
                 hashmap_free(j->files);
         }
 
                 hashmap_free(j->files);
         }
 
+        sd_journal_flush_matches(j);
+
         free(j);
 }
 
         free(j);
 }
 
index 13b5f891d71503d8cc60526f973c9c87386e7ac6..6b451b57657c7c4802da839dcbc7912299b445f7 100644 (file)
@@ -35,6 +35,8 @@
  *   - implement stdout gateway
  *   - extend hash table/bisect table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
  *   - implement stdout gateway
  *   - extend hash table/bisect table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
+ *   - throttling
+ *   - enforce limit on open journal files in journald and journalctl
  */
 
 typedef struct sd_journal sd_journal;
  */
 
 typedef struct sd_journal sd_journal;
@@ -50,7 +52,7 @@ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret);
 int sd_journal_get_field(sd_journal *j, const char *field, const void **data, size_t *l);
 int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *l);
 
 int sd_journal_get_field(sd_journal *j, const char *field, const void **data, size_t *l);
 int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *l);
 
-int sd_journal_add_match(sd_journal *j, const char *field, const void *data, size_t size);
+int sd_journal_add_match(sd_journal *j, const void *data, size_t size);
 void sd_journal_flush_matches(sd_journal *j);
 
 int sd_journal_seek_head(sd_journal *j);
 void sd_journal_flush_matches(sd_journal *j);
 
 int sd_journal_seek_head(sd_journal *j);
@@ -64,6 +66,14 @@ int sd_journal_set_cursor(sd_journal *j, const char *cursor);
 
 int sd_journal_get_fd(sd_journal *j);
 
 
 int sd_journal_get_fd(sd_journal *j);
 
+enum {
+        SD_JOURNAL_NOP,
+        SD_JOURNAL_APPEND,
+        SD_JOURNAL_DROP
+};
+
+int sd_journal_process(sd_journal *j);
+
 #define SD_JOURNAL_FOREACH(j)                   \
         while (sd_journal_next(j) > 0)
 
 #define SD_JOURNAL_FOREACH(j)                   \
         while (sd_journal_next(j) > 0)