summaryrefslogtreecommitdiff
path: root/src/journal/sd-journal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal/sd-journal.c')
-rw-r--r--src/journal/sd-journal.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index d5d2d78f1c..a346691e21 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -25,6 +25,8 @@
#include <unistd.h>
#include <sys/inotify.h>
#include <sys/poll.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
#include "sd-journal.h"
#include "journal-def.h"
@@ -35,9 +37,12 @@
#include "lookup3.h"
#include "compress.h"
#include "journal-internal.h"
+#include "missing.h"
#define JOURNAL_FILES_MAX 1024
+#define JOURNAL_FILES_RECHECK_USEC (2 * USEC_PER_SEC)
+
static void detach_location(sd_journal *j) {
Iterator i;
JournalFile *f;
@@ -1184,6 +1189,25 @@ _public_ int sd_journal_seek_tail(sd_journal *j) {
return 0;
}
+static void check_network(sd_journal *j, int fd) {
+ struct statfs sfs;
+
+ assert(j);
+
+ if (j->on_network)
+ return;
+
+ if (fstatfs(fd, &sfs) < 0)
+ return;
+
+ j->on_network =
+ sfs.f_type == CIFS_MAGIC_NUMBER ||
+ sfs.f_type == CODA_SUPER_MAGIC ||
+ sfs.f_type == NCP_SUPER_MAGIC ||
+ sfs.f_type == NFS_SUPER_MAGIC ||
+ sfs.f_type == SMB_SUPER_MAGIC;
+}
+
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
char *path;
int r;
@@ -1233,6 +1257,8 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
return r;
}
+ check_network(j, f->fd);
+
j->current_invalidate_counter ++;
log_debug("File %s got added.", f->path);
@@ -1366,6 +1392,8 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
}
}
+ check_network(j, dirfd(d));
+
closedir(d);
return 0;
@@ -1453,6 +1481,8 @@ static int add_root_directory(sd_journal *j, const char *p) {
}
}
+ check_network(j, dirfd(d));
+
closedir(d);
return 0;
@@ -2079,6 +2109,14 @@ _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 */
+
+ if (timeout_usec == (uint64_t) -1 || timeout_usec > JOURNAL_FILES_RECHECK_USEC)
+ timeout_usec = JOURNAL_FILES_RECHECK_USEC;
+ }
+
do {
r = fd_wait_for_event(j->inotify_fd, POLLIN, timeout_usec);
} while (r == -EINTR);
@@ -2344,3 +2382,10 @@ _public_ void sd_journal_restart_unique(sd_journal *j) {
j->unique_file = NULL;
j->unique_offset = 0;
}
+
+_public_ int sd_journal_reliable_fd(sd_journal *j) {
+ if (!j)
+ return -EINVAL;
+
+ return !j->on_network;
+}