summaryrefslogtreecommitdiff
path: root/src/journal/journald-server.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-12 11:17:01 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-12 11:17:01 +0100
commit33d52ab92f2f0bfd706e6f343d172618d1e03f3d (patch)
tree15f21659f2e23491ef6dd7d390fde2945d9302d4 /src/journal/journald-server.c
parentb97e7fabaeaf12c88d6a10b2bfead54a77812105 (diff)
journald: rework --sync/--rotate logic to use CLOCK_MONOTONIC timestamp files
Previously, we'd rely on the mtime timestamps of the touch files to see if our sync/rotation requests were already suppressed. This means we rely on CLOCK_REALTIME timestamps. With this patch we instead store the CLOCK_MONOTONIC timestamp *in* the touch files, and avoid relying on mtime. This should make things more reliable when the clock or underlying mtime granularity is not very good. This also adds warning messages if writing any of the flag files fails.
Diffstat (limited to 'src/journal/journald-server.c')
-rw-r--r--src/journal/journald-server.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 70ff101d5f..762b810109 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -41,6 +41,7 @@
#include "dirent-util.h"
#include "extract-word.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "fs-util.h"
#include "hashmap.h"
@@ -1240,6 +1241,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
Server *s = userdata;
+ int r;
assert(s);
@@ -1249,13 +1251,16 @@ static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *
server_sync(s);
server_vacuum(s, false, false);
- (void) touch("/run/systemd/journal/flushed");
+ r = touch("/run/systemd/journal/flushed");
+ if (r < 0)
+ log_warning_errno(r, "Failed to touch /run/systemd/journal/flushed, ignoring: %m");
return 0;
}
static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
Server *s = userdata;
+ int r;
assert(s);
@@ -1264,7 +1269,9 @@ static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *
server_vacuum(s, true, true);
/* Let clients know when the most recent rotation happened. */
- (void) touch("/run/systemd/journal/rotated");
+ r = write_timestamp_file_atomic("/run/systemd/journal/rotated", now(CLOCK_MONOTONIC));
+ if (r < 0)
+ log_warning_errno(r, "Failed to write /run/systemd/journal/rotated, ignoring: %m");
return 0;
}
@@ -1282,6 +1289,7 @@ static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *
static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
Server *s = userdata;
+ int r;
assert(s);
@@ -1290,7 +1298,9 @@ static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo
server_sync(s);
/* Let clients know when the most recent sync happened. */
- (void) touch("/run/systemd/journal/synced");
+ r = write_timestamp_file_atomic("/run/systemd/journal/synced", now(CLOCK_MONOTONIC));
+ if (r < 0)
+ log_warning_errno(r, "Failed to write /run/systemd/journal/synced, ignoring: %m");
return 0;
}