1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

journal: automatically evolve FSS key even when nothing is logged

This commit is contained in:
Lennart Poettering 2012-08-21 01:29:17 +02:00
parent c05276f23e
commit 89fef99014
5 changed files with 55 additions and 16 deletions

View File

@ -211,6 +211,9 @@ int journal_file_maybe_append_tag(JournalFile *f, uint64_t realtime) {
if (!f->seal)
return 0;
if (realtime <= 0)
realtime = now(CLOCK_MONOTONIC);
r = journal_file_fsprg_need_evolve(f, realtime);
if (r <= 0)
return 0;
@ -517,3 +520,19 @@ int journal_file_parse_verification_key(JournalFile *f, const char *key) {
return 0;
}
bool journal_file_next_evolve_usec(JournalFile *f, usec_t *u) {
uint64_t epoch;
assert(f);
assert(u);
if (!f->seal)
return false;
epoch = FSPRG_GetEpoch(f->fsprg_state);
*u = (usec_t) (f->fss_start_usec + f->fss_interval_usec * epoch + f->fss_interval_usec);
return true;
}

View File

@ -40,3 +40,5 @@ int journal_file_parse_verification_key(JournalFile *f, const char *key);
int journal_file_fsprg_evolve(JournalFile *f, uint64_t realtime);
int journal_file_fsprg_seek(JournalFile *f, uint64_t epoch);
bool journal_file_next_evolve_usec(JournalFile *f, usec_t *u);

View File

@ -34,14 +34,6 @@
#include "compress.h"
#include "fsprg.h"
/* FIXME:
*
* - evolve key even if nothing happened in regular intervals
*
* - check with sparse
*
* */
static int journal_file_object_verify(JournalFile *f, Object *o) {
uint64_t i;

View File

@ -233,6 +233,7 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_VERIFY_KEY:
arg_action = ACTION_VERIFY;
arg_verify_key = optarg;
arg_local = true;
break;
case ARG_INTERVAL:

View File

@ -48,6 +48,7 @@
#include "journal-rate-limit.h"
#include "journal-internal.h"
#include "journal-vacuum.h"
#include "journal-authenticate.h"
#include "conf-parser.h"
#include "journald.h"
#include "virt.h"
@ -2969,8 +2970,26 @@ int main(int argc, char *argv[]) {
for (;;) {
struct epoll_event event;
int t;
r = epoll_wait(server.epoll_fd, &event, 1, -1);
#ifdef HAVE_GCRYPT
usec_t u;
if (server.system_journal &&
journal_file_next_evolve_usec(server.system_journal, &u)) {
usec_t n;
n = now(CLOCK_MONOTONIC);
if (n >= u)
t = 0;
else
t = (int) ((u - n + USEC_PER_MSEC - 1) / USEC_PER_MSEC);
} else
#endif
t = -1;
r = epoll_wait(server.epoll_fd, &event, 1, t);
if (r < 0) {
if (errno == EINTR)
@ -2979,14 +2998,20 @@ int main(int argc, char *argv[]) {
log_error("epoll_wait() failed: %m");
r = -errno;
goto finish;
} else if (r == 0)
break;
}
r = process_event(&server, &event);
if (r < 0)
goto finish;
else if (r == 0)
break;
if (r > 0) {
r = process_event(&server, &event);
if (r < 0)
goto finish;
else if (r == 0)
break;
}
#ifdef HAVE_GCRYPT
if (server.system_journal)
journal_file_maybe_append_tag(server.system_journal, 0);
#endif
}
log_debug("systemd-journald stopped as pid %lu", (unsigned long) getpid());