ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
923a60
From c87355bc80da9e2cba7f7723d7c6568dfa56f1a1 Mon Sep 17 00:00:00 2001
923a60
From: Vito Caputo <vito.caputo@coreos.com>
923a60
Date: Fri, 8 Jan 2016 12:11:44 -0800
923a60
Subject: [PATCH] journal: normalize priority of logging sources
923a60
923a60
The stream event source has a priority of SD_EVENT_PRIORITY_NORMAL+5,
923a60
and stdout source +10, but the native and syslog event sources are left
923a60
at the default of 0.
923a60
923a60
As a result, any heavy native or syslog logger can cause starvation of
923a60
the other loggers.  This is trivially demonstrated by running:
923a60
923a60
 dd if=/dev/urandom bs=8k | od | systemd-cat & # native spammer
923a60
 systemd-run echo hello & # stream logger
923a60
 journalctl --follow --output=verbose --no-pager --identifier=echo &
923a60
923a60
... and wait, and wait, the "hello" never comes.
923a60
923a60
Now kill %1, "hello" arrives finally.
923a60
923a60
Cherry-picked from: 48cef29504b1ffc0df9929f2d8b2af2ad74d2b4a
923a60
Related: #1318994
923a60
---
923a60
 src/journal/journald-native.c | 4 ++++
923a60
 src/journal/journald-stream.c | 2 +-
923a60
 src/journal/journald-syslog.c | 4 ++++
923a60
 3 files changed, 9 insertions(+), 1 deletion(-)
923a60
923a60
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
923a60
index 851625de04..2c9cf6e7a8 100644
923a60
--- a/src/journal/journald-native.c
923a60
+++ b/src/journal/journald-native.c
923a60
@@ -457,5 +457,9 @@ int server_open_native_socket(Server*s) {
923a60
         if (r < 0)
923a60
                 return log_error_errno(r, "Failed to add native server fd to event loop: %m");
923a60
 
923a60
+        r = sd_event_source_set_priority(s->native_event_source, SD_EVENT_PRIORITY_NORMAL+5);
923a60
+        if (r < 0)
923a60
+                return log_error_errno(r, "Failed to adjust native event source priority: %m");
923a60
+
923a60
         return 0;
923a60
 }
923a60
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
923a60
index 15a554c34d..b8607144b3 100644
923a60
--- a/src/journal/journald-stream.c
923a60
+++ b/src/journal/journald-stream.c
923a60
@@ -448,7 +448,7 @@ int server_open_stdout_socket(Server *s) {
923a60
         if (r < 0)
923a60
                 return log_error_errno(r, "Failed to add stdout server fd to event source: %m");
923a60
 
923a60
-        r = sd_event_source_set_priority(s->stdout_event_source, SD_EVENT_PRIORITY_NORMAL+10);
923a60
+        r = sd_event_source_set_priority(s->stdout_event_source, SD_EVENT_PRIORITY_NORMAL+5);
923a60
         if (r < 0)
923a60
                 return log_error_errno(r, "Failed to adjust priority of stdout server event source: %m");
923a60
 
923a60
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
923a60
index 4e118aabc0..8602b4a95d 100644
923a60
--- a/src/journal/journald-syslog.c
923a60
+++ b/src/journal/journald-syslog.c
923a60
@@ -421,6 +421,10 @@ int server_open_syslog_socket(Server *s) {
923a60
         if (r < 0)
923a60
                 return log_error_errno(r, "Failed to add syslog server fd to event loop: %m");
923a60
 
923a60
+        r = sd_event_source_set_priority(s->syslog_event_source, SD_EVENT_PRIORITY_NORMAL+5);
923a60
+        if (r < 0)
923a60
+                return log_error_errno(r, "Failed to adjust syslog event source priority: %m");
923a60
+
923a60
         return 0;
923a60
 }
923a60