X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fsd-journal.c;h=7587211506f5f02d5503dc1c730201ebf88450aa;hp=6abbacf004f0b58a52065705c25e53acd001003f;hb=03e334a1c7dc8c20c38902aa039440763acc9b17;hpb=73e231abde39f22097df50542c745e01de879836 diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 6abbacf00..758721150 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -51,6 +51,8 @@ #define DEFAULT_DATA_THRESHOLD (64*1024) +static void remove_file_real(sd_journal *j, JournalFile *f); + static bool journal_pid_changed(sd_journal *j) { assert(j); @@ -871,9 +873,9 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc static int real_journal_next(sd_journal *j, direction_t direction) { JournalFile *f, *new_file = NULL; uint64_t new_offset = 0; - Object *o; - uint64_t p; + uint64_t p = 0; Iterator i; + Object *o; int r; assert_return(j, -EINVAL); @@ -885,6 +887,7 @@ static int real_journal_next(sd_journal *j, direction_t direction) { r = next_beyond_location(j, f, direction, &o, &p); if (r < 0) { log_debug("Can't iterate through %s, ignoring: %s", f->path, strerror(-r)); + remove_file_real(j, f); continue; } else if (r == 0) continue; @@ -1281,7 +1284,7 @@ static bool file_type_wanted(int flags, const char *filename) { } static int add_any_file(sd_journal *j, const char *path) { - JournalFile *f; + JournalFile *f = NULL; int r; assert(j); @@ -1339,7 +1342,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) { } static int remove_file(sd_journal *j, const char *prefix, const char *filename) { - char *path; + _cleanup_free_ char *path; JournalFile *f; assert(j); @@ -1351,10 +1354,17 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename) return -ENOMEM; f = hashmap_get(j->files, path); - free(path); if (!f) return 0; + remove_file_real(j, f); + return 0; +} + +static void remove_file_real(sd_journal *j, JournalFile *f) { + assert(j); + assert(f); + hashmap_remove(j->files, f->path); log_debug("File %s removed.", f->path); @@ -1372,8 +1382,6 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename) journal_file_close(f); j->current_invalidate_counter ++; - - return 0; } static int add_directory(sd_journal *j, const char *prefix, const char *dirname) { @@ -1842,8 +1850,7 @@ _public_ void sd_journal_close(sd_journal *j) { hashmap_free(j->directories_by_path); hashmap_free(j->directories_by_wd); - if (j->inotify_fd >= 0) - close_nointr_nofail(j->inotify_fd); + safe_close(j->inotify_fd); if (j->mmap) { log_debug("mmap cache statistics: %u hit, %u miss", mmap_cache_get_hit(j->mmap), mmap_cache_get_missed(j->mmap)); @@ -2293,8 +2300,6 @@ _public_ int sd_journal_process(sd_journal *j) { l -= step; } } - - return determine_change(j); } _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { @@ -2347,6 +2352,7 @@ _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, Iterator i; JournalFile *f; bool first = true; + uint64_t fmin = 0, tmax = 0; int r; assert_return(j, -EINVAL); @@ -2366,19 +2372,20 @@ _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, continue; if (first) { - if (from) - *from = fr; - if (to) - *to = t; + fmin = fr; + tmax = t; first = false; } else { - if (from) - *from = MIN(fr, *from); - if (to) - *to = MAX(t, *to); + fmin = MIN(fr, fmin); + tmax = MAX(t, tmax); } } + if (from) + *from = fmin; + if (to) + *to = tmax; + return first ? 0 : 1; }