naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
803fb7
From be21e10cf30e66215e986ab900637b32e502a29a Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Tue, 10 Nov 2015 16:53:00 +0100
803fb7
Subject: [PATCH] journald: dispatch SIGTERM/SIGINT with a low priority
803fb7
803fb7
Let's make sure to process all queued log data before exiting, so that
803fb7
we don't unnecessary lose messages when shutting down.
803fb7
803fb7
https://github.com/systemd/systemd/pull/1812#issuecomment-155149871
803fb7
803fb7
Cherry-picked from: b374689c02c681671a3c3c0b0fd3add32386b442
803fb7
Related: #1318994
803fb7
---
803fb7
 src/journal/journald-server.c | 12 ++++++++++++
803fb7
 1 file changed, 12 insertions(+)
803fb7
803fb7
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
803fb7
index 275224dc9..2b7ecd09a 100644
803fb7
--- a/src/journal/journald-server.c
803fb7
+++ b/src/journal/journald-server.c
803fb7
@@ -1284,10 +1284,22 @@ static int setup_signals(Server *s) {
803fb7
         if (r < 0)
803fb7
                 return r;
803fb7
 
803fb7
+        /* Let's process SIGTERM late, so that we flush all queued
803fb7
+         * messages to disk before we exit */
803fb7
+        r = sd_event_source_set_priority(s->sigterm_event_source, SD_EVENT_PRIORITY_NORMAL+20);
803fb7
+        if (r < 0)
803fb7
+                return r;
803fb7
+
803fb7
+        /* When journald is invoked on the terminal (when debugging),
803fb7
+         * it's useful if C-c is handled equivalent to SIGTERM. */
803fb7
         r = sd_event_add_signal(s->event, &s->sigint_event_source, SIGINT, dispatch_sigterm, s);
803fb7
         if (r < 0)
803fb7
                 return r;
803fb7
 
803fb7
+        r = sd_event_source_set_priority(s->sigint_event_source, SD_EVENT_PRIORITY_NORMAL+20);
803fb7
+        if (r < 0)
803fb7
+                return r;
803fb7
+
803fb7
         return 0;
803fb7
 }
803fb7