X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fjournald.c;h=da9f52813dbf2a030634d6143e81a64771291f6c;hp=7ea68aab3cac7dd4c4de4ea4c4f45a28218516c8;hb=205c4d1d6a3f5343f970abf20283d69dcec359ed;hpb=66a78c2b95ba6cc0be15dab68c5af816fb5b7a33 diff --git a/src/journal/journald.c b/src/journal/journald.c index 7ea68aab3..da9f52813 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -111,6 +111,16 @@ struct StdoutStream { LIST_FIELDS(StdoutStream, stdout_stream); }; +static const char* const storage_table[] = { + [STORAGE_AUTO] = "auto", + [STORAGE_VOLATILE] = "volatile", + [STORAGE_PERSISTENT] = "persistent", + [STORAGE_NONE] = "none" +}; + +DEFINE_STRING_TABLE_LOOKUP(storage, Storage); +DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting"); + static int server_flush_to_var(Server *s); static uint64_t available_space(Server *s) { @@ -397,7 +407,6 @@ static void server_vacuum(Server *s) { free(p); } - if (s->runtime_journal) { if (asprintf(&p, "/run/log/journal/%s", ids) < 0) { log_error("Out of memory."); @@ -625,9 +634,7 @@ static void dispatch_message_real( retry: f = find_journal(s, realuid == 0 ? 0 : loginuid); - if (!f) - log_warning("Dropping message, as we can't find a place to store the data."); - else { + if (f) { r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL); if ((r == -E2BIG || /* hit limit */ @@ -1955,12 +1962,23 @@ static int system_journal_open(Server *s) { sd_id128_to_string(machine, ids); - if (!s->system_journal) { + if (!s->system_journal && + (s->storage == STORAGE_PERSISTENT || + s->storage == STORAGE_AUTO)) { + + /* If in auto mode: first try to create the machine + * path, but not the prefix. + * + * If in persistent mode: create /var/log/journal and + * the machine path */ + + if (s->storage & STORAGE_PERSISTENT) + (void) mkdir("/var/log/journal/", 0755); - /* First try to create the machine path, but not the prefix */ fn = strappend("/var/log/journal/", ids); if (!fn) return -ENOMEM; + (void) mkdir(fn, 0755); free(fn); @@ -1988,7 +2006,8 @@ static int system_journal_open(Server *s) { } } - if (!s->runtime_journal) { + if (!s->runtime_journal && + (s->storage != STORAGE_NONE)) { fn = join("/run/log/journal/", ids, "/system.journal", NULL); if (!fn) @@ -2039,7 +2058,6 @@ static int system_journal_open(Server *s) { } static int server_flush_to_var(Server *s) { - char path[] = "/run/log/journal/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; Object *o = NULL; int r; sd_id128_t machine; @@ -2048,6 +2066,10 @@ static int server_flush_to_var(Server *s) { assert(s); + if (s->storage != STORAGE_AUTO && + s->storage != STORAGE_PERSISTENT) + return 0; + if (!s->runtime_journal) return 0; @@ -2112,6 +2134,7 @@ finish: s->runtime_journal = NULL; if (r >= 0) { + char path[] = "/run/log/journal/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; sd_id128_to_string(machine, path + 17); rm_rf(path, false, true, false); } @@ -2125,6 +2148,10 @@ static int server_read_proc_kmsg(Server *s) { assert(s->proc_kmsg_fd >= 0); l = read(s->proc_kmsg_fd, s->proc_kmsg_buffer + s->proc_kmsg_length, sizeof(s->proc_kmsg_buffer) - 1 - s->proc_kmsg_length); + if (l == 0) /* the kernel is stupid and in some race + * conditions returns 0 in the middle of the + * stream. */ + return 0; if (l < 0) { if (errno == EAGAIN || errno == EINTR) @@ -2700,7 +2727,6 @@ static int server_init(Server *s) { s->rate_limit_burst = DEFAULT_RATE_LIMIT_BURST; s->forward_to_syslog = true; - s->import_proc_kmsg = true; s->max_level_store = LOG_DEBUG; s->max_level_syslog = LOG_DEBUG;