X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournald.c;h=3267fffed9689418457a5ae4dc39306ec73463bf;hb=be3ea5eaf24f4507efe88b450f751da860a9d21c;hp=476d682fda61afe7895abb3518d7e4738c16cfdd;hpb=d2bd7630d7ebbf9a86cca96e39d56efd4558ead4;p=elogind.git diff --git a/src/journal/journald.c b/src/journal/journald.c index 476d682fd..3267fffed 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -87,6 +87,15 @@ static const char* const storage_table[] = { DEFINE_STRING_TABLE_LOOKUP(storage, Storage); DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting"); +static const char* const split_mode_table[] = { + [SPLIT_NONE] = "none", + [SPLIT_UID] = "uid", + [SPLIT_LOGIN] = "login" +}; + +DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode); +DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting"); + static uint64_t available_space(Server *s) { char ids[33], *p; const char *f; @@ -132,9 +141,10 @@ static uint64_t available_space(Server *s) { for (;;) { struct stat st; - struct dirent buf, *de; + struct dirent *de; + union dirent_storage buf; - r = readdir_r(d, &buf, &de); + r = readdir_r(d, &buf.de, &de); if (r != 0) break; @@ -304,7 +314,7 @@ static void server_rotate(Server *s) { Iterator i; int r; - log_info("Rotating..."); + log_debug("Rotating..."); if (s->runtime_journal) { r = journal_file_rotate(&s->runtime_journal, s->compress, false); @@ -338,7 +348,7 @@ static void server_rotate(Server *s) { log_error("Failed to create user journal: %s", strerror(-r)); else { hashmap_replace(s->user_journals, k, f); - server_fix_perms(s, s->system_journal, PTR_TO_UINT32(k)); + server_fix_perms(s, f, PTR_TO_UINT32(k)); } } } @@ -349,7 +359,7 @@ static void server_vacuum(Server *s) { sd_id128_t machine; int r; - log_info("Vacuuming..."); + log_debug("Vacuuming..."); r = sd_id128_get_machine(&machine); if (r < 0) { @@ -360,7 +370,8 @@ static void server_vacuum(Server *s) { sd_id128_to_string(machine, ids); if (s->system_journal) { - if (asprintf(&p, "/var/log/journal/%s", ids) < 0) { + p = strappend("/var/log/journal/", ids); + if (!p) { log_oom(); return; } @@ -372,7 +383,8 @@ static void server_vacuum(Server *s) { } if (s->runtime_journal) { - if (asprintf(&p, "/run/log/journal/%s", ids) < 0) { + p = strappend("/run/log/journal/", ids); + if (!p) { log_oom(); return; } @@ -442,7 +454,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned return; if (journal_file_rotate_suggested(f)) { - log_info("Journal header limits reached or header out-of-date, rotating."); + log_debug("Journal header limits reached or header out-of-date, rotating."); server_rotate(s); server_vacuum(s); vacuumed = true; @@ -473,11 +485,11 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned } if (r == -E2BIG || r == -EFBIG || r == EDQUOT || r == ENOSPC) - log_info("Allocation limit reached, rotating."); + log_debug("Allocation limit reached, rotating."); else if (r == -EHOSTDOWN) log_info("Journal file from other machine, rotating."); else if (r == -EBUSY) - log_info("Unlcean shutdown, rotating."); + log_info("Unclean shutdown, rotating."); else log_warning("Journal file corrupted, rotating."); @@ -489,7 +501,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned if (!f) return; - log_info("Retrying write."); + log_debug("Retrying write."); } } @@ -657,7 +669,10 @@ static void dispatch_message_real( assert(n <= m); - write_to_journal(s, realuid == 0 ? 0 : loginuid, iovec, n); + write_to_journal(s, + s->split_mode == SPLIT_NONE ? 0 : + (s->split_mode == SPLIT_UID ? realuid : + (realuid == 0 ? 0 : loginuid)), iovec, n); free(pid); free(uid); @@ -699,9 +714,11 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format, char_array_0(buffer); IOVEC_SET_STRING(iovec[n++], buffer); - snprintf(mid, sizeof(mid), "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(message_id)); - char_array_0(mid); - IOVEC_SET_STRING(iovec[n++], mid); + if (!sd_id128_equal(message_id, SD_ID128_NULL)) { + snprintf(mid, sizeof(mid), "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(message_id)); + char_array_0(mid); + IOVEC_SET_STRING(iovec[n++], mid); + } zero(ucred); ucred.pid = getpid(); @@ -812,9 +829,14 @@ static int system_journal_open(Server *s) { r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &s->system_journal); free(fn); - if (r >= 0) + if (r >= 0) { + char fb[FORMAT_BYTES_MAX]; + server_fix_perms(s, s->system_journal, 0); - else if (r < 0) { + server_driver_message(s, SD_ID128_NULL, "Allowing system journal files to grow to %s.", + format_bytes(fb, sizeof(fb), s->system_metrics.max_use)); + + } else if (r < 0) { if (r != -ENOENT && r != -EROFS) log_warning("Failed to open system journal: %s", strerror(-r)); @@ -861,8 +883,13 @@ static int system_journal_open(Server *s) { } } - if (s->runtime_journal) + if (s->runtime_journal) { + char fb[FORMAT_BYTES_MAX]; + server_fix_perms(s, s->runtime_journal, 0); + server_driver_message(s, SD_ID128_NULL, "Allowing runtime journal files to grow to %s.", + format_bytes(fb, sizeof(fb), s->runtime_metrics.max_use)); + } } return r; @@ -888,7 +915,7 @@ static int server_flush_to_var(Server *s) { if (!s->system_journal) return 0; - log_info("Flushing to /var..."); + log_debug("Flushing to /var..."); r = sd_id128_get_machine(&machine); if (r < 0) { @@ -916,7 +943,7 @@ static int server_flush_to_var(Server *s) { r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL); if (r == -E2BIG) { - log_info("Allocation limit reached."); + log_debug("Allocation limit reached."); journal_file_post_change(s->system_journal); server_rotate(s); @@ -952,7 +979,7 @@ static int process_event(Server *s, struct epoll_event *ev) { ssize_t n; if (ev->events != EPOLLIN) { - log_info("Got invalid event from epoll."); + log_error("Got invalid event from epoll."); return -EIO; } @@ -988,7 +1015,7 @@ static int process_event(Server *s, struct epoll_event *ev) { int r; if (ev->events != EPOLLIN) { - log_info("Got invalid event from epoll."); + log_error("Got invalid event from epoll."); return -EIO; } @@ -1002,7 +1029,7 @@ static int process_event(Server *s, struct epoll_event *ev) { ev->data.fd == s->syslog_fd) { if (ev->events != EPOLLIN) { - log_info("Got invalid event from epoll."); + log_error("Got invalid event from epoll."); return -EIO; } @@ -1130,7 +1157,7 @@ static int process_event(Server *s, struct epoll_event *ev) { } else if (ev->data.fd == s->stdout_fd) { if (ev->events != EPOLLIN) { - log_info("Got invalid event from epoll."); + log_error("Got invalid event from epoll."); return -EIO; } @@ -1141,7 +1168,7 @@ static int process_event(Server *s, struct epoll_event *ev) { StdoutStream *stream; if ((ev->events|EPOLLIN|EPOLLHUP) != (EPOLLIN|EPOLLHUP)) { - log_info("Got invalid event from epoll."); + log_error("Got invalid event from epoll."); return -EIO; } @@ -1394,7 +1421,7 @@ static int server_init(Server *s) { return 0; } -static void maybe_append_tags(Server *s) { +static void server_maybe_append_tags(Server *s) { #ifdef HAVE_GCRYPT JournalFile *f; Iterator i; @@ -1478,7 +1505,6 @@ int main(int argc, char *argv[]) { log_set_target(LOG_TARGET_SAFE); log_set_facility(LOG_SYSLOG); - log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); @@ -1539,7 +1565,8 @@ int main(int argc, char *argv[]) { break; } - maybe_append_tags(&server); + server_maybe_append_tags(&server); + server_maybe_warn_forward_syslog_missed(&server); } log_debug("systemd-journald stopped as pid %lu", (unsigned long) getpid());