chiark / gitweb /
log: make internal log api log directly to the journal
[elogind.git] / src / journal / sd-journal.c
index bb3b0aebc511241ed964a1dca403d788f520b97e..5e1fd4773e835d1534e54765bbeedab06df41940 100644 (file)
@@ -349,7 +349,7 @@ static int find_location(sd_journal *j, JournalFile *f, direction_t direction, O
 
                         r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, j->current_location.monotonic, direction, &o, &p);
                         if (r <= 0)
-                                return r;
+                                return r == -ENOENT ? 0 : r;
                 }
 
                 LIST_FOREACH(matches, m, j->matches) {
@@ -372,6 +372,9 @@ static int find_location(sd_journal *j, JournalFile *f, direction_t direction, O
                         else
                                 r = journal_file_next_entry_for_data(f, NULL, 0, dp, direction, &c, &cp);
 
+                        if (r < 0)
+                                return r;
+
                         if (!term_match) {
                                 term_match = m;
 
@@ -485,7 +488,7 @@ static int next_with_matches(sd_journal *j, JournalFile *f, direction_t directio
 
                 /* Make sure we don't match the entry we are starting
                  * from. */
-                found = cp > *offset;
+                found = cp != *offset;
 
                 np = 0;
                 LIST_FOREACH(matches, m, j->matches) {
@@ -524,6 +527,9 @@ static int next_with_matches(sd_journal *j, JournalFile *f, direction_t directio
                          * matches are not OK */
 
                         r = journal_file_next_entry_for_data(f, c, cp, le64toh(c->entry.items[k].object_offset), direction, &qo, &q);
+                        if (r < 0)
+                                return r;
+
                         if (r > 0) {
 
                                 if (direction == DIRECTION_DOWN) {
@@ -677,14 +683,23 @@ _public_ int sd_journal_previous(sd_journal *j) {
         return real_journal_next(j, DIRECTION_UP);
 }
 
-_public_ int sd_journal_next_skip(sd_journal *j, uint64_t skip) {
+static int real_journal_next_skip(sd_journal *j, direction_t direction, uint64_t skip) {
         int c = 0, r;
 
         if (!j)
                 return -EINVAL;
 
-        while (skip > 0) {
-                r = sd_journal_next(j);
+        if (skip == 0) {
+                /* If this is not a discrete skip, then at least
+                 * resolve the current location */
+                if (j->current_location.type != LOCATION_DISCRETE)
+                        return real_journal_next(j, direction);
+
+                return 0;
+        }
+
+        do {
+                r = real_journal_next(j, direction);
                 if (r < 0)
                         return r;
 
@@ -693,30 +708,17 @@ _public_ int sd_journal_next_skip(sd_journal *j, uint64_t skip) {
 
                 skip--;
                 c++;
-        }
+        } while (skip > 0);
 
         return c;
 }
 
-_public_ int sd_journal_previous_skip(sd_journal *j, uint64_t skip) {
-        int c = 0, r;
-
-        if (!j)
-                return -EINVAL;
-
-        while (skip > 0) {
-                r = sd_journal_previous(j);
-                if (r < 0)
-                        return r;
-
-                if (r == 0)
-                        return c;
-
-                skip--;
-                c++;
-        }
+_public_ int sd_journal_next_skip(sd_journal *j, uint64_t skip) {
+        return real_journal_next_skip(j, DIRECTION_DOWN, skip);
+}
 
-        return 1;
+_public_ int sd_journal_previous_skip(sd_journal *j, uint64_t skip) {
+        return real_journal_next_skip(j, DIRECTION_UP, skip);
 }
 
 _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) {
@@ -1296,7 +1298,7 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12
                         return r;
 
                 if (!sd_id128_equal(id, o->entry.boot_id))
-                        return -ENOENT;
+                        return -ESTALE;
         }
 
         *ret = le64toh(o->entry.monotonic);
@@ -1588,27 +1590,27 @@ _public_ int sd_journal_process(sd_journal *j) {
         }
 }
 
-_public_ int sd_journal_query_unique(sd_journal *j, const char *field) {
-        if (!j)
-                return -EINVAL;
-        if (!field)
-                return -EINVAL;
-
-        return -ENOTSUP;
-}
-
-_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_t *l) {
-        if (!j)
-                return -EINVAL;
-        if (!data)
-                return -EINVAL;
-        if (!l)
-                return -EINVAL;
-
-        return -ENOTSUP;
-}
-
-_public_ void sd_journal_restart_unique(sd_journal *j) {
-        if (!j)
-                return;
-}
+/* _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { */
+/*         if (!j) */
+/*                 return -EINVAL; */
+/*         if (!field) */
+/*                 return -EINVAL; */
+
+/*         return -ENOTSUP; */
+/* } */
+
+/* _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_t *l) { */
+/*         if (!j) */
+/*                 return -EINVAL; */
+/*         if (!data) */
+/*                 return -EINVAL; */
+/*         if (!l) */
+/*                 return -EINVAL; */
+
+/*         return -ENOTSUP; */
+/* } */
+
+/* _public_ void sd_journal_restart_unique(sd_journal *j) { */
+/*         if (!j) */
+/*                 return; */
+/* } */