naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
0b2ce7
From 980add7d84084a474c6c604c0670743c2d1e624c Mon Sep 17 00:00:00 2001
0b2ce7
From: David Tardon <dtardon@redhat.com>
0b2ce7
Date: Mon, 13 Mar 2023 14:32:20 +0100
0b2ce7
Subject: [PATCH] journald-server: always touch state file in signal handler
0b2ce7
0b2ce7
`journalctl --relinquish-var` waits on that file, so we must create if
0b2ce7
even if nothing has really happened.
0b2ce7
0b2ce7
RHEL-only
0b2ce7
0b2ce7
Related: #2174645
0b2ce7
---
0b2ce7
 src/journal/journald-server.c | 12 +++++++-----
0b2ce7
 1 file changed, 7 insertions(+), 5 deletions(-)
0b2ce7
0b2ce7
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
0b2ce7
index aa70db95cc..4788ff78bb 100644
0b2ce7
--- a/src/journal/journald-server.c
0b2ce7
+++ b/src/journal/journald-server.c
0b2ce7
@@ -1259,8 +1259,6 @@ static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo
0b2ce7
 }
0b2ce7
 
0b2ce7
 static void relinquish_var(Server *s) {
0b2ce7
-        int r;
0b2ce7
-
0b2ce7
         assert(s);
0b2ce7
 
0b2ce7
         if (s->storage == STORAGE_NONE)
0b2ce7
@@ -1278,15 +1276,15 @@ static void relinquish_var(Server *s) {
0b2ce7
         if (unlink("/run/systemd/journal/flushed") < 0 && errno != ENOENT)
0b2ce7
                 log_warning_errno(errno, "Failed to unlink /run/systemd/journal/flushed, ignoring: %m")  ;
0b2ce7
 
0b2ce7
-        r = write_timestamp_file_atomic("/run/systemd/journal/relinquished", now(CLOCK_MONOTONIC));
0b2ce7
-        if (r < 0)
0b2ce7
-                log_warning_errno(r, "Failed to write /run/systemd/journal/relinquished, ignoring: %m");
0b2ce7
+        /* NOTE: We don't create our own state file here, because dispatch_sigrtmin2() has to do it anyway.
0b2ce7
+         * But if this function is ever called from another place, the creation must be done here too. */
0b2ce7
 
0b2ce7
         return;
0b2ce7
 }
0b2ce7
 
0b2ce7
 static int dispatch_sigrtmin2(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
0b2ce7
         Server *s = userdata;
0b2ce7
+        int r;
0b2ce7
 
0b2ce7
         assert(s);
0b2ce7
         assert(si);
0b2ce7
@@ -1295,6 +1293,10 @@ static int dispatch_sigrtmin2(sd_event_source *es, const struct signalfd_siginfo
0b2ce7
 
0b2ce7
         relinquish_var(s);
0b2ce7
 
0b2ce7
+        r = write_timestamp_file_atomic("/run/systemd/journal/relinquished", now(CLOCK_MONOTONIC));
0b2ce7
+        if (r < 0)
0b2ce7
+                log_warning_errno(r, "Failed to write /run/systemd/journal/relinquished, ignoring: %m");
0b2ce7
+
0b2ce7
         return 0;
0b2ce7
 }
0b2ce7