ryantimwilson / rpms / systemd

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