[systemd-commits] src/journal

Lennart Poettering lennart at kemper.freedesktop.org
Mon Oct 8 16:32:50 PDT 2012


 src/journal/journal-gatewayd.c |   32 +++++++++++++++++++++++++++++++-
 src/journal/journalctl.c       |    2 +-
 2 files changed, 32 insertions(+), 2 deletions(-)

New commits:
commit 7a69007a24cfff30158ea80665cb6c3c9d3251b0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Oct 9 01:31:27 2012 +0200

    journal: implement follow mode for HTTP GET in gatewayd

diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index 9599e89..b6a9a2a 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -47,6 +47,8 @@ typedef struct RequestMeta {
         uint64_t delta, size;
 
         int argument_parse_error;
+
+        bool follow;
 } RequestMeta;
 
 static const char* const mime_types[_OUTPUT_MODE_MAX] = {
@@ -194,8 +196,20 @@ static ssize_t request_reader_entries(
                 if (r < 0) {
                         log_error("Failed to advance journal pointer: %s", strerror(-r));
                         return MHD_CONTENT_READER_END_WITH_ERROR;
-                } else if (r == 0)
+                } else if (r == 0) {
+
+                        if (m->follow) {
+                                r = sd_journal_wait(m->journal, (uint64_t) -1);
+                                if (r < 0) {
+                                        log_error("Couldn't wait for journal event: %s", strerror(-r));
+                                        return MHD_CONTENT_READER_END_WITH_ERROR;
+                                }
+
+                                continue;
+                        }
+
                         return MHD_CONTENT_READER_END_OF_STREAM;
+                }
 
                 pos -= m->size;
                 m->delta += m->size;
@@ -356,6 +370,22 @@ static int request_parse_arguments_iterator(
                 return MHD_NO;
         }
 
+        if (streq(key, "follow")) {
+                if (isempty(value)) {
+                        m->follow = true;
+                        return MHD_YES;
+                }
+
+                r = parse_boolean(value);
+                if (r < 0) {
+                        m->argument_parse_error = r;
+                        return MHD_NO;
+                }
+
+                m->follow = r;
+                return MHD_YES;
+        }
+
         p = strjoin(key, "=", strempty(value), NULL);
         if (!p) {
                 m->argument_parse_error = log_oom();
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index cbf9833..b6f9b2f 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -915,7 +915,7 @@ int main(int argc, char *argv[]) {
 
                 r = sd_journal_wait(j, (uint64_t) -1);
                 if (r < 0) {
-                        log_error("Couldn't wait for log event: %s", strerror(-r));
+                        log_error("Couldn't wait for journal event: %s", strerror(-r));
                         goto finish;
                 }
         }



More information about the systemd-commits mailing list