Commit 39c155ea authored by Lennart Poettering's avatar Lennart Poettering

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.
parent 667c24a6
This diff is collapsed.
...@@ -126,6 +126,8 @@ struct sd_journal { ...@@ -126,6 +126,8 @@ struct sd_journal {
size_t data_threshold; size_t data_threshold;
Set *errors; Set *errors;
usec_t last_process_usec;
}; };
char *journal_make_match_string(sd_journal *j); char *journal_make_match_string(sd_journal *j);
......
...@@ -97,4 +97,5 @@ global: ...@@ -97,4 +97,5 @@ global:
LIBSYSTEMD_JOURNAL_201 { LIBSYSTEMD_JOURNAL_201 {
global: global:
sd_journal_get_events; sd_journal_get_events;
sd_journal_get_timeout;
} LIBSYSTEMD_JOURNAL_198; } LIBSYSTEMD_JOURNAL_198;
...@@ -1994,6 +1994,30 @@ _public_ int sd_journal_get_events(sd_journal *j) { ...@@ -1994,6 +1994,30 @@ _public_ int sd_journal_get_events(sd_journal *j) {
return POLLIN; 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) { static void process_inotify_event(sd_journal *j, struct inotify_event *e) {
Directory *d; Directory *d;
int r; int r;
...@@ -2076,6 +2100,8 @@ _public_ int sd_journal_process(sd_journal *j) { ...@@ -2076,6 +2100,8 @@ _public_ int sd_journal_process(sd_journal *j) {
if (!j) if (!j)
return -EINVAL; return -EINVAL;
j->last_process_usec = now(CLOCK_MONOTONIC);
for (;;) { for (;;) {
struct inotify_event *e; struct inotify_event *e;
ssize_t l; ssize_t l;
...@@ -2109,6 +2135,7 @@ _public_ int sd_journal_process(sd_journal *j) { ...@@ -2109,6 +2135,7 @@ _public_ int sd_journal_process(sd_journal *j) {
_public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {
int r; int r;
uint64_t t;
assert(j); assert(j);
...@@ -2127,12 +2154,18 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { ...@@ -2127,12 +2154,18 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {
return determine_change(j); return determine_change(j);
} }
if (j->on_network) { r = sd_journal_get_timeout(j, &t);
/* If we are on the network we need to regularly check if (r < 0)
* for changes manually */ 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) if (timeout_usec == (uint64_t) -1 || timeout_usec > t)
timeout_usec = JOURNAL_FILES_RECHECK_USEC; timeout_usec = t;
} }
do { do {
......
...@@ -128,9 +128,10 @@ void sd_journal_restart_unique(sd_journal *j); ...@@ -128,9 +128,10 @@ void sd_journal_restart_unique(sd_journal *j);
int sd_journal_get_fd(sd_journal *j); int sd_journal_get_fd(sd_journal *j);
int sd_journal_get_events(sd_journal *j); int sd_journal_get_events(sd_journal *j);
int sd_journal_reliable_fd(sd_journal *j); int sd_journal_get_timeout(sd_journal *j, uint64_t *timeout_usec);
int sd_journal_process(sd_journal *j); int sd_journal_process(sd_journal *j);
int sd_journal_wait(sd_journal *j, uint64_t timeout_usec); int sd_journal_wait(sd_journal *j, uint64_t timeout_usec);
int sd_journal_reliable_fd(sd_journal *j);
int sd_journal_get_catalog(sd_journal *j, char **text); int sd_journal_get_catalog(sd_journal *j, char **text);
int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **ret); int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment