diff options
author | Daniel Mack <github@zonque.org> | 2015-11-12 13:57:38 +0100 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-11-12 13:57:38 +0100 |
commit | 1f920a33814552fb7ddfba52e62ac9cbdf8184fe (patch) | |
tree | b4e3d384216e3c88ab0a2b51d6b36cc933e3a97f /src/journal | |
parent | aafdda22388a8a1b6966130ef4df0b59ee5fad72 (diff) | |
parent | 4de2402b603ea2f518f451d06f09e15aeae54fab (diff) |
Merge pull request #1863 from poettering/network-man
man patch fix, and port journalctl --sync to use CLOCK_MONOTONIC timestamp files
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journalctl.c | 18 | ||||
-rw-r--r-- | src/journal/journald-server.c | 18 |
2 files changed, 22 insertions, 14 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"); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 70ff101d5f..be913d26ef 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; } @@ -1660,7 +1670,7 @@ static int server_connect_notify(Server *s) { if (sd_watchdog_enabled(false, &s->watchdog_usec) > 0) { s->send_watchdog = true; - r = sd_event_add_time(s->event, &s->watchdog_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + s->watchdog_usec/2, s->watchdog_usec*3/4, dispatch_watchdog, s); + r = sd_event_add_time(s->event, &s->watchdog_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + s->watchdog_usec/2, s->watchdog_usec/4, dispatch_watchdog, s); if (r < 0) return log_error_errno(r, "Failed to add watchdog time event: %m"); } |