X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fjournald.c;h=18db31c3bc5218c89a60feff488901adc1f3732d;hp=fd292f019e2237b89fdd70d105d0be45717cc6c9;hb=4ca86bbc25540acc322679b98c4f18a540c100ee;hpb=b7def684941808600c344f0be7a2b9fcdda97e0f diff --git a/src/journal/journald.c b/src/journal/journald.c index fd292f019..18db31c3b 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -313,7 +313,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) { journal_file_close(f); } - r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, s->system_journal, &f); + r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, &s->system_metrics, s->system_journal, &f); free(p); if (r < 0) @@ -460,6 +460,71 @@ static char *shortened_cgroup_path(pid_t pid) { return path; } +static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n) { + JournalFile *f; + bool vacuumed = false; + int r; + + assert(s); + assert(iovec); + assert(n > 0); + + f = find_journal(s, uid); + if (!f) + return; + + if (journal_file_rotate_suggested(f)) { + log_info("Journal header limits reached or header out-of-date, rotating."); + server_rotate(s); + server_vacuum(s); + vacuumed = true; + + f = find_journal(s, uid); + if (!f) + return; + } + + for (;;) { + r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL); + if (r >= 0) + return; + + if (vacuumed || + (r != -E2BIG && /* hit limit */ + r != -EFBIG && /* hit fs limit */ + r != -EDQUOT && /* quota hit */ + r != -ENOSPC && /* disk full */ + r != -EBADMSG && /* corrupted */ + r != -ENODATA && /* truncated */ + r != -EHOSTDOWN && /* other machine */ + r != -EPROTONOSUPPORT && /* unsupported feature */ + r != -EBUSY && /* unclean shutdown */ + r != -ESHUTDOWN /* already archived */)) { + log_error("Failed to write entry, ignoring: %s", strerror(-r)); + return; + } + + if (r == -E2BIG || r == -EFBIG || r == EDQUOT || r == ENOSPC) + log_info("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."); + else + log_warning("Journal file corrupted, rotating."); + + server_rotate(s); + server_vacuum(s); + vacuumed = true; + + f = find_journal(s, uid); + if (!f) + return; + + log_info("Retrying write."); + } +} + static void dispatch_message_real( Server *s, struct iovec *iovec, unsigned n, unsigned m, @@ -480,8 +545,6 @@ static void dispatch_message_real( int r; char *t; uid_t loginuid = 0, realuid = 0; - JournalFile *f; - bool vacuumed = false; assert(s); assert(iovec); @@ -626,37 +689,7 @@ static void dispatch_message_real( assert(n <= m); -retry: - f = find_journal(s, realuid == 0 ? 0 : loginuid); - if (f) { - r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL); - - if ((r == -E2BIG || /* hit limit */ - r == -EFBIG || /* hit fs limit */ - r == -EDQUOT || /* quota hit */ - r == -ENOSPC || /* disk full */ - r == -EBADMSG || /* corrupted */ - r == -ENODATA || /* truncated */ - r == -EHOSTDOWN || /* other machine */ - r == -EPROTONOSUPPORT) && /* unsupported feature */ - !vacuumed) { - - if (r == -E2BIG) - log_info("Allocation limit reached, rotating."); - else - log_warning("Journal file corrupted, rotating."); - - server_rotate(s); - server_vacuum(s); - vacuumed = true; - - log_info("Retrying write."); - goto retry; - } - - if (r < 0) - log_error("Failed to write entry, ignoring: %s", strerror(-r)); - } + write_to_journal(s, realuid == 0 ? 0 : loginuid, iovec, n); free(pid); free(uid); @@ -835,7 +868,8 @@ static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned return; } - log_debug("Failed to forward syslog message: %m"); + if (errno != ENOENT) + log_debug("Failed to forward syslog message: %m"); } static void forward_syslog_raw(Server *s, int priority, const char *buffer, struct ucred *ucred, struct timeval *tv) { @@ -1980,13 +2014,10 @@ static int system_journal_open(Server *s) { if (!fn) return -ENOMEM; - r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, NULL, &s->system_journal); + r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, &s->system_metrics, NULL, &s->system_journal); free(fn); if (r >= 0) { - journal_default_metrics(&s->system_metrics, s->system_journal->fd); - - s->system_journal->metrics = s->system_metrics; s->system_journal->compress = s->compress; server_fix_perms(s, s->system_journal, 0); @@ -2012,7 +2043,7 @@ static int system_journal_open(Server *s) { * if it already exists, so that we can flush * it into the system journal */ - r = journal_file_open(fn, O_RDWR, 0640, NULL, &s->runtime_journal); + r = journal_file_open(fn, O_RDWR, 0640, &s->runtime_metrics, NULL, &s->runtime_journal); free(fn); if (r < 0) { @@ -2028,7 +2059,7 @@ static int system_journal_open(Server *s) { * it if necessary. */ (void) mkdir_parents(fn, 0755); - r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal); + r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, &s->runtime_metrics, NULL, &s->runtime_journal); free(fn); if (r < 0) { @@ -2038,9 +2069,6 @@ static int system_journal_open(Server *s) { } if (s->runtime_journal) { - journal_default_metrics(&s->runtime_metrics, s->runtime_journal->fd); - - s->runtime_journal->metrics = s->runtime_metrics; s->runtime_journal->compress = s->compress; server_fix_perms(s, s->runtime_journal, 0);