X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fsd-journal.c;h=a346691e21e0be33b151d3052b82297bdecad779;hb=33b40551236a6c0c323226b78f1b1e5751a95ff5;hp=99bbf08be61030cd1fdee1fb0bc4e700bdcfcc1d;hpb=3c1668da6202f1ead3d4d3981b89e9da1a0e98e3;p=elogind.git diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 99bbf08be..a346691e2 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #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); @@ -2121,7 +2159,7 @@ _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, if (from) *from = MIN(fr, *from); if (to) - *to = MIN(t, *to); + *to = MAX(t, *to); } } @@ -2160,7 +2198,7 @@ _public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot if (from) *from = MIN(fr, *from); if (to) - *to = MIN(t, *to); + *to = MAX(t, *to); } } @@ -2214,6 +2252,8 @@ _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { return -EINVAL; if (isempty(field)) return -EINVAL; + if (!field_is_valid(field)) + return -EINVAL; f = strdup(field); if (!f) @@ -2257,7 +2297,7 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_ size_t ol; bool found; - /* Proceed to next data object in list the field's linked list */ + /* Proceed to next data object in the field's linked list */ if (j->unique_offset == 0) { r = journal_file_find_field_object(j->unique_file, j->unique_field, k, &o, NULL); if (r < 0) @@ -2335,10 +2375,17 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_ } } -void sd_journal_restart_unique(sd_journal *j) { +_public_ void sd_journal_restart_unique(sd_journal *j) { if (!j) return; 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; +}