if ((j->flags & SD_JOURNAL_SYSTEM_ONLY) &&
!(streq(filename, "system.journal") ||
- (startswith(filename, "system@") && endswith(filename, ".journal"))))
+ streq(filename, "system.journal~") ||
+ (startswith(filename, "system@") &&
+ (endswith(filename, ".journal") || endswith(filename, ".journal~")))))
return 0;
path = strjoin(prefix, "/", filename, NULL);
return 0;
}
- r = journal_file_open(path, O_RDONLY, 0, NULL, NULL, &f);
+ r = journal_file_open(path, O_RDONLY, 0, false, false, NULL, j->mmap, NULL, &f);
free(path);
if (r < 0) {
m->wd = inotify_add_watch(j->inotify_fd, m->path,
IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB|IN_DELETE|
IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|
- IN_DONT_FOLLOW|IN_ONLYDIR);
+ IN_ONLYDIR);
if (m->wd > 0 && hashmap_put(j->directories_by_wd, INT_TO_PTR(m->wd), m) < 0)
inotify_rm_watch(j->inotify_fd, m->wd);
if (r != 0 || !de)
break;
- if (dirent_is_file_with_suffix(de, ".journal")) {
+ if (dirent_is_file_with_suffix(de, ".journal") ||
+ 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));
m->wd = inotify_add_watch(j->inotify_fd, m->path,
IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB|IN_DELETE|
- IN_DONT_FOLLOW|IN_ONLYDIR);
+ IN_ONLYDIR);
if (m->wd > 0 && hashmap_put(j->directories_by_wd, INT_TO_PTR(m->wd), m) < 0)
inotify_rm_watch(j->inotify_fd, m->wd);
if (r != 0 || !de)
break;
- if (dirent_is_file_with_suffix(de, ".journal")) {
+ if (dirent_is_file_with_suffix(de, ".journal") ||
+ 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));
- } else if ((de->d_type == DT_DIR || de->d_type == DT_UNKNOWN) &&
+ } else if ((de->d_type == DT_DIR || de->d_type == DT_LNK || de->d_type == DT_UNKNOWN) &&
sd_id128_from_string(de->d_name, &id) >= 0) {
r = add_directory(j, m->path, de->d_name);
return 0;
}
-static sd_journal *journal_new(int flags) {
+static sd_journal *journal_new(int flags, const char *path) {
sd_journal *j;
j = new0(sd_journal, 1);
j->inotify_fd = -1;
j->flags = flags;
+ if (path) {
+ j->path = strdup(path);
+ if (!j->path) {
+ free(j);
+ return NULL;
+ }
+ }
+
j->files = hashmap_new(string_hash_func, string_compare_func);
if (!j->files) {
+ free(j->path);
free(j);
return NULL;
}
j->directories_by_path = hashmap_new(string_hash_func, string_compare_func);
if (!j->directories_by_path) {
hashmap_free(j->files);
+ free(j->path);
+ free(j);
+ return NULL;
+ }
+
+ j->mmap = mmap_cache_new();
+ if (!j->mmap) {
+ hashmap_free(j->files);
+ hashmap_free(j->directories_by_path);
+ free(j->path);
free(j);
return NULL;
}
SD_JOURNAL_SYSTEM_ONLY))
return -EINVAL;
- j = journal_new(flags);
+ j = journal_new(flags, NULL);
if (!j)
return -ENOMEM;
if (flags != 0)
return -EINVAL;
- j = journal_new(flags);
+ j = journal_new(flags, path);
if (!j)
return -ENOMEM;
sd_journal_flush_matches(j);
+ if (j->mmap)
+ mmap_cache_unref(j->mmap);
+
+ free(j->path);
free(j);
}
/* Iterate through all dirs again, to add them to the
* inotify */
- r = add_search_paths(j);
+ if (j->path)
+ r = add_root_directory(j, j->path);
+ else
+ r = add_search_paths(j);
if (r < 0)
return r;
if (d) {
sd_id128_t id;
- if (!(e->mask & IN_ISDIR) && e->len > 0 && endswith(e->name, ".journal")) {
+ if (!(e->mask & IN_ISDIR) && e->len > 0 &&
+ (endswith(e->name, ".journal") ||
+ endswith(e->name, ".journal~"))) {
/* Event for a journal file */