/* We return an error here only if we didn't manage to
memorize the real error. */
-static int set_put_error(Set* errors, int r) {
+static int set_put_error(sd_journal *j, int r) {
+ int k;
+
if (r >= 0)
return r;
- return set_put(errors, INT_TO_PTR(r));
+ k = set_ensure_allocated(&j->errors, trivial_hash_func, trivial_compare_func);
+ if (k < 0)
+ return k;
+
+ return set_put(j->errors, INT_TO_PTR(r));
}
static void detach_location(sd_journal *j) {
if (hashmap_size(j->files) >= JOURNAL_FILES_MAX) {
log_debug("Too many open journal files, not adding %s, ignoring.", path);
- return set_put_error(j->errors, -ETOOMANYREFS);
+ return set_put_error(j, -ETOOMANYREFS);
}
r = journal_file_open(path, O_RDONLY, 0, false, false, NULL, j->mmap, NULL, &f);
if (r < 0) {
log_debug("Failed to add file %s/%s: %s",
m->path, de->d_name, strerror(-r));
- r = set_put_error(j->errors, r);
+ r = set_put_error(j, r);
if (r < 0)
return r;
}
if (r < 0) {
log_debug("Failed to add file %s/%s: %s",
m->path, de->d_name, strerror(-r));
- r = set_put_error(j->errors, r);
+ r = set_put_error(j, r);
if (r < 0)
return r;
}
NULSTR_FOREACH(p, search_paths) {
r = add_root_directory(j, p);
- if (r < 0)
- return set_put_error(j->errors, r);
+ if (r < 0 && r != -ENOENT) {
+ r = set_put_error(j, r);
+ if (r < 0)
+ return r;
+ }
}
return 0;
j->files = hashmap_new(string_hash_func, string_compare_func);
j->directories_by_path = hashmap_new(string_hash_func, string_compare_func);
j->mmap = mmap_cache_new();
- j->errors = set_new(trivial_hash_func, trivial_compare_func);
- if (!j->files || !j->directories_by_path || !j->mmap || !j->errors)
+ if (!j->files || !j->directories_by_path || !j->mmap)
goto fail;
return j;
r = add_root_directory(j, path);
if (r < 0) {
- set_put_error(j->errors, r);
+ set_put_error(j, r);
goto fail;
}
if (!j)
return;
+ sd_journal_flush_matches(j);
+
while ((f = hashmap_steal_first(j->files)))
journal_file_close(f);
if (j->inotify_fd >= 0)
close_nointr_nofail(j->inotify_fd);
- sd_journal_flush_matches(j);
-
if (j->mmap)
mmap_cache_unref(j->mmap);
if (r < 0) {
log_debug("Failed to add file %s/%s: %s",
d->path, e->name, strerror(-r));
- set_put_error(j->errors, r);
+ set_put_error(j, r);
}
} else if (e->mask & (IN_DELETE|IN_MOVED_FROM|IN_UNMOUNT)) {