summaryrefslogtreecommitdiff
path: root/src/journal/journalctl.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/journalctl.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/journalctl.c')
-rw-r--r--src/journal/journalctl.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index ac0751c547..75a48c761c 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1838,7 +1838,7 @@ static int send_signal_and_wait(int sig, const char *watch_path) {
return -EOPNOTSUPP;
}
- start = now(CLOCK_REALTIME);
+ start = now(CLOCK_MONOTONIC);
/* This call sends the specified signal to journald, and waits
* for acknowledgment by watching the mtime of the specified
@@ -1846,16 +1846,14 @@ static int send_signal_and_wait(int sig, const char *watch_path) {
* then wait for the operation to complete. */
for (;;) {
- struct stat st;
+ usec_t tstamp;
/* See if a sync happened by now. */
- if (stat(watch_path, &st) < 0) {
- if (errno != ENOENT)
- return log_error_errno(errno, "Failed to stat %s: %m", watch_path);
- } else {
- if (timespec_load(&st.st_mtim) >= start)
- return 0;
- }
+ r = read_timestamp_file(watch_path, &tstamp);
+ if (r < 0 && r != -ENOENT)
+ return log_error_errno(errno, "Failed to read %s: %m", watch_path);
+ if (r >= 0 && tstamp >= start)
+ return 0;
/* Let's ask for a sync, but only once. */
if (!bus) {
@@ -1889,7 +1887,7 @@ static int send_signal_and_wait(int sig, const char *watch_path) {
if (watch_fd < 0)
return log_error_errno(errno, "Failed to create inotify watch: %m");
- r = inotify_add_watch(watch_fd, "/run/systemd/journal", IN_CREATE|IN_ATTRIB|IN_DONT_FOLLOW|IN_ONLYDIR);
+ r = inotify_add_watch(watch_fd, "/run/systemd/journal", IN_MOVED_TO|IN_DONT_FOLLOW|IN_ONLYDIR);
if (r < 0)
return log_error_errno(errno, "Failed to watch journal directory: %m");