[systemd-commits] 2 commits - TODO man/journald.conf.xml src/journal src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Wed Jul 24 03:34:39 PDT 2013


 TODO                          |    2 --
 man/journald.conf.xml         |   14 +++++++++++---
 src/journal/journald-server.c |   26 ++++++++++++++++----------
 src/journal/journald-server.h |    2 +-
 src/shared/log.c              |   12 ++++++++----
 5 files changed, 36 insertions(+), 20 deletions(-)

New commits:
commit d07f7b9ef2835c290d6beadebd17d15308608eea
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 24 08:08:57 2013 +0200

    journal: immediately sync to disk as soon as we receieve an EMERG/ALERT/CRIT message

diff --git a/TODO b/TODO
index ba8bb8e..279ea60 100644
--- a/TODO
+++ b/TODO
@@ -74,8 +74,6 @@ Features:
 
 * journald: optionally, log debug messages to /run but everything else to /var
 
-* journald: optionally, when messages with a high log priority are logged, sync() immediately.
-
 * systemctl list-unit-files should list generated files (and probably with a new state "generated" for them, or so)
 
 * do we really need both hasprefix() and startswith()?
diff --git a/man/journald.conf.xml b/man/journald.conf.xml
index 487e8d6..9219b3d 100644
--- a/man/journald.conf.xml
+++ b/man/journald.conf.xml
@@ -348,9 +348,17 @@
                         <varlistentry>
                                 <term><varname>SyncIntervalSec=</varname></term>
 
-                                <listitem><para>The timeout before synchronizing journal
-                                data to disk. After syncing, journal files have
-                                the OFFLINE state. Default timeout is 5 minutes.
+                                <listitem><para>The timeout before
+                                synchronizing journal files to
+                                disk. After syncing, journal files are
+                                placed in the OFFLINE state. Note that
+                                syncing is unconditionally done
+                                immediately after a log message of
+                                priority CRIT, ALERT or EMERG has been
+                                logged, this setting hence applies
+                                only to messages of the levels ERR,
+                                WARNING, NOTICE, INFO, DEBUG. The
+                                default timeout is 5 minutes.
                                 </para></listitem>
                         </varlistentry>
 
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 60c32b1..821935c 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -352,13 +352,12 @@ void server_rotate(Server *s) {
 }
 
 void server_sync(Server *s) {
+        static const struct itimerspec sync_timer_disable = {};
         JournalFile *f;
         void *k;
         Iterator i;
         int r;
 
-        static const struct itimerspec sync_timer_disable = {};
-
         if (s->system_journal) {
                 r = journal_file_set_offline(s->system_journal);
                 if (r < 0)
@@ -443,7 +442,7 @@ bool shall_try_append_again(JournalFile *f, int r) {
         return true;
 }
 
-static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n) {
+static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n, int priority) {
         JournalFile *f;
         bool vacuumed = false;
         int r;
@@ -469,7 +468,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
 
         r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
         if (r >= 0) {
-                server_schedule_sync(s);
+                server_schedule_sync(s, priority);
                 return;
         }
 
@@ -499,7 +498,8 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
                         size += iovec[i].iov_len;
 
                 log_error("Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %s", n, size, strerror(-r));
-        }
+        } else
+                server_schedule_sync(s, priority);
 }
 
 static void dispatch_message_real(
@@ -509,6 +509,7 @@ static void dispatch_message_real(
                 struct timeval *tv,
                 const char *label, size_t label_len,
                 const char *unit_id,
+                int priority,
                 pid_t object_pid) {
 
         char    pid[sizeof("_PID=") + DECIMAL_STR_MAX(pid_t)],
@@ -523,7 +524,6 @@ static void dispatch_message_real(
                 o_owner_uid[sizeof("OBJECT_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)];
         uid_t object_uid;
         gid_t object_gid;
-
         char *x;
         sd_id128_t id;
         int r;
@@ -786,7 +786,7 @@ static void dispatch_message_real(
         else
                 journal_uid = 0;
 
-        write_to_journal(s, journal_uid, iovec, n);
+        write_to_journal(s, journal_uid, iovec, n, priority);
 }
 
 void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) {
@@ -820,7 +820,7 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format,
         ucred.uid = getuid();
         ucred.gid = getgid();
 
-        dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, 0);
+        dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, LOG_INFO, 0);
 }
 
 void server_dispatch_message(
@@ -886,7 +886,7 @@ void server_dispatch_message(
                                       "Suppressed %u messages from %s", rl - 1, path);
 
 finish:
-        dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id, object_pid);
+        dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id, priority, object_pid);
 }
 
 
@@ -1423,11 +1423,17 @@ static int server_open_sync_timer(Server *s) {
         return 0;
 }
 
-int server_schedule_sync(Server *s) {
+int server_schedule_sync(Server *s, int priority) {
         int r;
 
         assert(s);
 
+        if (priority <= LOG_CRIT) {
+                /* Immediately sync to disk when this is of priority CRIT, ALERT, EMERG */
+                server_sync(s);
+                return 0;
+        }
+
         if (s->sync_scheduled)
                 return 0;
 
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index 9ff3300..e856ef2 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -153,7 +153,7 @@ void server_done(Server *s);
 void server_sync(Server *s);
 void server_vacuum(Server *s);
 void server_rotate(Server *s);
-int server_schedule_sync(Server *s);
+int server_schedule_sync(Server *s, int priority);
 int server_flush_to_var(Server *s);
 int process_event(Server *s, struct epoll_event *ev);
 void server_maybe_append_tags(Server *s);

commit 8b18fdc19531ba56d0bdfe34c62870997a9bcc96
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 24 07:24:05 2013 +0200

    core: synchronously block when logging
    
    Previously, the logging sockets were asynchronous and if clogged we'd
    lose messages. We did this to be extra careful given that PID 1 might
    need to spawn the logging daemon as response to PID 1's own log messages
    and we really should avoid a deadlock in that case.
    
    As it turns out this causes loss of too many messages, hence make the
    socket blocking again, however put a time limit on it to avoid unbounded
    deadlocks in the unlikely case they happen.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=66664

diff --git a/src/shared/log.c b/src/shared/log.c
index 27317f7..8f4995a 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -115,16 +115,20 @@ void log_close_syslog(void) {
 
 static int create_log_socket(int type) {
         int fd;
+        struct timeval tv;
 
-        /* All output to the syslog/journal fds we do asynchronously,
-         * and if the buffers are full we just drop the messages */
-
-        fd = socket(AF_UNIX, type|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+        fd = socket(AF_UNIX, type|SOCK_CLOEXEC, 0);
         if (fd < 0)
                 return -errno;
 
         fd_inc_sndbuf(fd, SNDBUF_SIZE);
 
+        /* We need a blocking fd here since we'd otherwise lose
+        messages way too early. However, let's not hang forever in the
+        unlikely case of a deadlock. */
+        timeval_store(&tv, 1*USEC_PER_MINUTE);
+        setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+
         return fd;
 }
 



More information about the systemd-commits mailing list