diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-04 20:07:48 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-04 20:07:48 +0200 |
commit | 39c155ea0d8b24895017fd5cf48508924ce2016d (patch) | |
tree | 78512394533074c85ad3df2d3ae2ecc98c89dd29 /src/journal/sd-journal.c | |
parent | 667c24a6a86a5a26a906b7477ae81dcf4c73e64e (diff) |
journal: add sd_journal_get_timeout() call to public API
Let's do the wake-up logic on NFS internally, making things simpler for
users.
Diffstat (limited to 'src/journal/sd-journal.c')
-rw-r--r-- | src/journal/sd-journal.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 3eba4cd0d1..c1f69827e9 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -1994,6 +1994,30 @@ _public_ int sd_journal_get_events(sd_journal *j) { return POLLIN; } +_public_ int sd_journal_get_timeout(sd_journal *j, uint64_t *timeout_usec) { + int fd; + + if (!j) + return -EINVAL; + if (!timeout_usec) + return -EINVAL; + + fd = sd_journal_get_fd(j); + if (fd < 0) + return fd; + + if (!j->on_network) { + *timeout_usec = (uint64_t) -1; + return 0; + } + + /* If we are on the network we need to regularly check for + * changes manually */ + + *timeout_usec = j->last_process_usec + JOURNAL_FILES_RECHECK_USEC; + return 1; +} + static void process_inotify_event(sd_journal *j, struct inotify_event *e) { Directory *d; int r; @@ -2076,6 +2100,8 @@ _public_ int sd_journal_process(sd_journal *j) { if (!j) return -EINVAL; + j->last_process_usec = now(CLOCK_MONOTONIC); + for (;;) { struct inotify_event *e; ssize_t l; @@ -2109,6 +2135,7 @@ _public_ int sd_journal_process(sd_journal *j) { _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { int r; + uint64_t t; assert(j); @@ -2127,12 +2154,18 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { return determine_change(j); } - if (j->on_network) { - /* If we are on the network we need to regularly check - * for changes manually */ + r = sd_journal_get_timeout(j, &t); + if (r < 0) + return r; + + if (t != (uint64_t) -1) { + usec_t n; + + n = now(CLOCK_MONOTONIC); + t = t > n ? t - n : 0; - if (timeout_usec == (uint64_t) -1 || timeout_usec > JOURNAL_FILES_RECHECK_USEC) - timeout_usec = JOURNAL_FILES_RECHECK_USEC; + if (timeout_usec == (uint64_t) -1 || timeout_usec > t) + timeout_usec = t; } do { |