#include "sd-journal.h"
#include "journal-def.h"
#include "util.h"
+#include "sd-id128.h"
+
+typedef struct JournalCoursor {
+ sd_id128_t file_id;
+ sd_id128_t boot_id;
+ uint64_t seqnum;
+ uint64_t monotonic;
+ uint64_t realtime;
+ uint64_t xor_hash;
+} JournalCoursor;
typedef struct JournalFile JournalFile;
-int journal_file_open(sd_journal *j, const char *fname, int flags, mode_t mode, JournalFile **ret);
+int journal_file_open(const char *fname, int flags, mode_t mode, JournalFile **ret);
void journal_file_close(JournalFile *j);
log_parse_environment();
log_open();
- r = journal_file_open(NULL, "/var/log/journal/system.journal", O_RDONLY, 0644, &f);
+ r = journal_file_open("/var/log/journal/system.journal", O_RDONLY, 0644, &f);
if (r == -ENOENT)
- r = journal_file_open(NULL, "/run/log/journal/system.journal", O_RDONLY, 0644, &f);
+ r = journal_file_open("/run/log/journal/system.journal", O_RDONLY, 0644, &f);
if (r < 0) {
log_error("Failed to open journal: %s", strerror(-r));
static int open_system_journal(JournalFile **f) {
int r;
- r = journal_file_open(NULL, "/var/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
+ r = journal_file_open("/var/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
if (r == -ENOENT) {
mkdir_p("/run/log/journal", 0755);
- r = journal_file_open(NULL, "/run/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
+ r = journal_file_open("/run/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
}
return r;
#include "journal-private.h"
#include "lookup3.h"
#include "list.h"
+#include "hashmap.h"
#define DEFAULT_ARENA_MAX_SIZE (16ULL*1024ULL*1024ULL*1024ULL)
#define DEFAULT_ARENA_MIN_SIZE (256ULL*1024ULL)
#define DEFAULT_WINDOW_SIZE (128ULL*1024ULL*1024ULL)
struct JournalFile {
- sd_journal *journal;
-
int fd;
char *path;
struct stat last_stat;
};
struct sd_journal {
- LIST_HEAD(JournalFile, files);
+ Hashmap *files;
};
static const char signature[] = { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' };
void journal_file_close(JournalFile *f) {
assert(f);
- if (f->journal)
- LIST_REMOVE(JournalFile, files, f->journal->files, f);
-
if (f->fd >= 0)
close_nointr_nofail(f->fd);
}
int journal_file_open(
- sd_journal *j,
const char *fname,
int flags,
mode_t mode,
if (r < 0)
goto fail;
- if (j) {
- LIST_PREPEND(JournalFile, files, j->files, f);
- f->journal = j;
- }
-
if (ret)
*ret = f;
if (!j)
return -ENOMEM;
+ j->files = hashmap_new(string_hash_func, string_compare_func);
+ if (!j->files)
+ goto fail;
+
NULSTR_FOREACH(p, search_paths) {
DIR *d;
for (;;) {
struct dirent buf, *de;
int k;
+ JournalFile *f;
k = readdir_r(d, &buf, &de);
if (k != 0) {
goto fail;
}
- k = journal_file_open(j, fn, O_RDONLY, 0, NULL);
- if (k < 0 && r == 0)
- r = -k;
-
+ k = journal_file_open(fn, O_RDONLY, 0, &f);
free(fn);
- }
- }
- if (!j->files) {
- if (r >= 0)
- r = -ENOENT;
+ if (k < 0) {
- goto fail;
+ if (r == 0)
+ r = -k;
+ } else {
+ k = hashmap_put(j->files, f->path, f);
+ if (k < 0) {
+ journal_file_close(f);
+ closedir(d);
+
+ r = k;
+ goto fail;
+ }
+ }
+ }
}
*ret = j;
void sd_journal_close(sd_journal *j) {
assert(j);
- while (j->files)
- journal_file_close(j->files);
+ if (j->files) {
+ JournalFile *f;
+
+ while ((f = hashmap_steal_first(j->files)))
+ journal_file_close(f);
+
+ hashmap_free(j->files);
+ }
free(j);
}
log_set_max_level(LOG_DEBUG);
- assert_se(journal_file_open(NULL, "test", O_RDWR|O_CREAT, 0666, &f) == 0);
+ assert_se(journal_file_open("test", O_RDWR|O_CREAT, 0666, &f) == 0);
dual_timestamp_get(&ts);