return 0;
}
+static bool whole_file_precedes_location(JournalFile *f, Location *l, direction_t direction) {
+ assert(f);
+ assert(l);
+
+ if (l->type != LOCATION_DISCRETE && l->type != LOCATION_SEEK)
+ return false;
+
+ if (l->seqnum_set && sd_id128_equal(l->seqnum_id, f->header->seqnum_id))
+ return direction == DIRECTION_DOWN ?
+ l->seqnum > le64toh(f->header->tail_entry_seqnum) :
+ l->seqnum < le64toh(f->header->head_entry_seqnum);
+
+ if (l->realtime_set)
+ return direction == DIRECTION_DOWN ?
+ l->realtime > le64toh(f->header->tail_entry_realtime) :
+ l->realtime < le64toh(f->header->head_entry_realtime);
+
+ return false;
+}
+
+static bool file_may_have_preceding_entry(JournalFile *f, JournalFile *of, uint64_t op, direction_t direction) {
+ Object *o;
+ int r;
+
+ assert(f);
+ assert(of);
+
+ r = journal_file_move_to_object(of, OBJECT_ENTRY, op, &o);
+ if (r < 0)
+ return true;
+
+ if (sd_id128_equal(f->header->seqnum_id, of->header->seqnum_id))
+ return direction == DIRECTION_DOWN ?
+ le64toh(o->entry.seqnum) >= le64toh(f->header->head_entry_seqnum) :
+ le64toh(o->entry.seqnum) <= le64toh(f->header->tail_entry_seqnum);
+
+ return direction == DIRECTION_DOWN ?
+ le64toh(o->entry.realtime) >= le64toh(f->header->head_entry_realtime) :
+ le64toh(o->entry.realtime) <= le64toh(f->header->tail_entry_realtime);
+}
+
_pure_ static int compare_with_location(JournalFile *af, Object *ao, Location *l) {
uint64_t a;
ORDERED_HASHMAP_FOREACH(f, j->files, i) {
bool found;
+ if (whole_file_precedes_location(f, &j->current_location, direction))
+ continue;
+
+ if (new_file && !file_may_have_preceding_entry(f, new_file, new_offset, direction))
+ continue;
+
r = next_beyond_location(j, f, direction, &o, &p);
if (r < 0) {
- log_debug_errno(-r, "Can't iterate through %s, ignoring: %m", f->path);
+ log_debug_errno(r, "Can't iterate through %s, ignoring: %m", f->path);
remove_file_real(j, f);
continue;
} else if (r == 0)
d = opendir(path);
if (!d) {
- log_debug("Failed to open %s: %m", path);
+ log_debug_errno(errno, "Failed to open %s: %m", path);
if (errno == ENOENT)
return 0;
return -errno;
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
- log_debug("Failed to read directory %s: %m", m->path);
+ log_debug_errno(errno, "Failed to read directory %s: %m", m->path);
return r;
}
if (!de)
dirent_is_file_with_suffix(de, ".journal~")) {
r = add_file(j, m->path, de->d_name);
if (r < 0) {
- log_debug("Failed to add file %s/%s: %s",
- m->path, de->d_name, strerror(-r));
+ log_debug_errno(r, "Failed to add file %s/%s: %m",
+ m->path, de->d_name);
r = set_put_error(j, r);
if (r < 0)
return r;
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
- log_debug("Failed to read directory %s: %m", m->path);
+ log_debug_errno(errno, "Failed to read directory %s: %m", m->path);
return r;
}
if (!de)
dirent_is_file_with_suffix(de, ".journal~")) {
r = add_file(j, m->path, de->d_name);
if (r < 0) {
- log_debug("Failed to add file %s/%s: %s",
- m->path, de->d_name, strerror(-r));
+ log_debug_errno(r, "Failed to add file %s/%s: %m",
+ m->path, de->d_name);
r = set_put_error(j, r);
if (r < 0)
return r;
r = add_directory(j, m->path, de->d_name);
if (r < 0)
- log_debug_errno(-r, "Failed to add directory %s/%s: %m", m->path, de->d_name);
+ log_debug_errno(r, "Failed to add directory %s/%s: %m", m->path, de->d_name);
}
}
STRV_FOREACH(path, paths) {
r = add_any_file(j, *path);
if (r < 0) {
- log_error_errno(-r, "Failed to open %s: %m", *path);
+ log_error_errno(r, "Failed to open %s: %m", *path);
goto fail;
}
}
if (e->mask & (IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB)) {
r = add_file(j, d->path, e->name);
if (r < 0) {
- log_debug("Failed to add file %s/%s: %s",
- d->path, e->name, strerror(-r));
+ log_debug_errno(r, "Failed to add file %s/%s: %m",
+ d->path, e->name);
set_put_error(j, r);
}
r = remove_file(j, d->path, e->name);
if (r < 0)
- log_debug_errno(-r, "Failed to remove file %s/%s: %m", d->path, e->name);
+ log_debug_errno(r, "Failed to remove file %s/%s: %m", d->path, e->name);
}
} else if (!d->is_root && e->len == 0) {
if (e->mask & (IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT)) {
r = remove_directory(j, d);
if (r < 0)
- log_debug_errno(-r, "Failed to remove directory %s: %m", d->path);
+ log_debug_errno(r, "Failed to remove directory %s: %m", d->path);
}
if (e->mask & (IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB)) {
r = add_directory(j, d->path, e->name);
if (r < 0)
- log_debug_errno(-r, "Failed to add directory %s/%s: %m", d->path, e->name);
+ log_debug_errno(r, "Failed to add directory %s/%s: %m", d->path, e->name);
}
}
}
_public_ int sd_journal_process(sd_journal *j) {
- uint8_t buffer[sizeof(struct inotify_event) + FILENAME_MAX] _alignas_(struct inotify_event);
bool got_something = false;
assert_return(j, -EINVAL);
j->last_process_usec = now(CLOCK_MONOTONIC);
for (;;) {
+ uint8_t buffer[INOTIFY_EVENT_MAX] _alignas_(struct inotify_event);
struct inotify_event *e;
ssize_t l;
got_something = true;
- e = (struct inotify_event*) buffer;
- while (l > 0) {
- size_t step;
-
+ FOREACH_INOTIFY_EVENT(e, buffer, l)
process_inotify_event(j, e);
-
- step = sizeof(struct inotify_event) + e->len;
- assert(step <= (size_t) l);
-
- e = (struct inotify_event*) ((uint8_t*) e + step);
- l -= step;
- }
}
}