X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fsd-journal.c;h=5e1fd4773e835d1534e54765bbeedab06df41940;hb=5ba081b0fb02380cee4c2ff5bc7e05f869eb8415;hp=fde1a0be881bd9694fd2842cf33a9f402b48b5c6;hpb=9c4e3f2624102c0b59cea78aabe4ed1f1d60064e;p=elogind.git diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index fde1a0be8..5e1fd4773 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -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; */ +/* } */