return 0;
}
-static uint64_t journal_file_seqnum(JournalFile *f) {
+static uint64_t journal_file_seqnum(JournalFile *f, uint64_t *seqnum) {
uint64_t r;
assert(f);
r = le64toh(f->header->seqnum) + 1;
+
+ if (seqnum) {
+ /* If an external seqno counter was passed, we update
+ * both the local and the external one, and set it to
+ * the maximum of both */
+
+ if (*seqnum + 1 > r)
+ r = *seqnum + 1;
+
+ *seqnum = r;
+ }
+
f->header->seqnum = htole64(r);
return r;
const dual_timestamp *ts,
uint64_t xor_hash,
const EntryItem items[], unsigned n_items,
+ uint64_t *seqno,
Object **ret, uint64_t *offset) {
uint64_t np;
uint64_t osize;
return r;
o->object.type = htole64(OBJECT_ENTRY);
- o->entry.seqnum = htole64(journal_file_seqnum(f));
+ o->entry.seqnum = htole64(journal_file_seqnum(f, seqno));
memcpy(o->entry.items, items, n_items * sizeof(EntryItem));
o->entry.realtime = htole64(ts ? ts->realtime : now(CLOCK_REALTIME));
o->entry.monotonic = htole64(ts ? ts->monotonic : now(CLOCK_MONOTONIC));
return 0;
}
-int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, Object **ret, uint64_t *offset) {
+int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset) {
unsigned i;
EntryItem *items;
int r;
items[i].object_offset = htole64(p);
}
- r = journal_file_append_entry_internal(f, ts, xor_hash, items, n_iovec, ret, offset);
+ r = journal_file_append_entry_internal(f, ts, xor_hash, items, n_iovec, seqno, ret, offset);
finish:
free(items);
uint64_t journal_file_entry_n_items(Object *o);
-int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, Object **ret, uint64_t *offset);
+int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset);
int journal_file_move_to_entry(JournalFile *f, uint64_t seqnum, Object **ret, uint64_t *offset);
const void *data;
size_t length;
char *cursor;
+ uint64_t realtime = 0, monotonic = 0;
r = sd_journal_get_cursor(j, &cursor);
if (r < 0) {
printf("entry: %s\n", cursor);
free(cursor);
+ sd_journal_get_realtime_usec(j, &realtime);
+ sd_journal_get_monotonic_usec(j, &monotonic);
+ printf("realtime: %llu\n"
+ "monotonic: %llu\n",
+ (unsigned long long) realtime,
+ (unsigned long long) monotonic);
+
SD_JOURNAL_FOREACH_FIELD(j, data, length)
printf("\t%.*s\n", (int) length, (const char*) data);
}
JournalFile *runtime_journal;
JournalFile *system_journal;
Hashmap *user_journals;
+
+ uint64_t seqnum;
} Server;
static void fix_perms(JournalFile *f, uid_t uid) {
if (asprintf(&p, "/var/log/journal/%s/user-%lu.journal", sd_id128_to_string(machine, ids), (unsigned long) uid) < 0)
return s->system_journal;
- r = journal_file_open(p, O_RDWR|O_CREAT, 0640, NULL, &f);
+ r = journal_file_open(p, O_RDWR|O_CREAT, 0640, s->system_journal, &f);
free(p);
if (r < 0)
if (!f)
log_warning("Dropping message, as we can't find a place to store the data.");
else {
- r = journal_file_append_entry(f, NULL, iovec, n, NULL, NULL);
+ r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
if (r < 0)
log_error("Failed to write entry, ignoring: %s", strerror(-r));
return 1;
}
+
+int sd_journal_seek_head(sd_journal *j) {
+ assert(j);
+ return -EINVAL;
+}
+
+int sd_journal_seek_tail(sd_journal *j) {
+ assert(j);
+ return -EINVAL;
+}
int sd_journal_seek_head(sd_journal *j);
int sd_journal_seek_tail(sd_journal *j);
-int sd_journal_seek_seqnum(sd_journal *j, uint64_t seqnum);
int sd_journal_seek_monotonic_usec(sd_journal *j, uint64_t usec);
int sd_journal_seek_realtime_usec(sd_journal *j, uint64_t usec);
iovec.iov_base = (void*) test;
iovec.iov_len = strlen(test);
- assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
iovec.iov_base = (void*) test2;
iovec.iov_len = strlen(test2);
- assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
iovec.iov_base = (void*) test;
iovec.iov_len = strlen(test);
- assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
journal_file_dump(f);