X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fsd-journal.c;h=5e1fd4773e835d1534e54765bbeedab06df41940;hp=555c35ecc2f1f1365236bbcf653471e35034c6cf;hb=5ba081b0fb02380cee4c2ff5bc7e05f869eb8415;hpb=4b067dc9d2b8836a2250315445686ae83993a9b7 diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 555c35ecc..5e1fd4773 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -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) { @@ -680,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; @@ -696,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) { @@ -1299,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); @@ -1591,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; */ +/* } */