summaryrefslogtreecommitdiff
path: root/src/journal-remote/journal-gatewayd.c
diff options
context:
space:
mode:
authorDan Dedrick <ddedrick@lexmark.com>2015-12-10 16:13:24 -0500
committerDan Dedrick <ddedrick@lexmark.com>2015-12-14 08:50:07 -0500
commit11bb5147b31c737e447166ba75d79f622ca120ca (patch)
tree8fd4528c26f7861b8d74c57768625ab788d2526b /src/journal-remote/journal-gatewayd.c
parentc57d67f718077aadee4e2d0940fb87f513b98671 (diff)
journal-gatewayd: timeout journal wait to allow thread cleanup
When a client connects with follow=1 and then disconnects we can get stuck in sd_journal_wait indefinitely if no journal messages are logged. Every time a client does this another thread is allocated and these continue to stack until either a journal message is logged or we run out of mapping to put a stack in. By adding a timeout if we don't see any journal messages in that timeout we will simply pop back out to microhttpd which will sanity check the connection for us and if it is still connected pop us back into the wait for more journal messages.
Diffstat (limited to 'src/journal-remote/journal-gatewayd.c')
-rw-r--r--src/journal-remote/journal-gatewayd.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c
index 006791a542..4e96fb0a4d 100644
--- a/src/journal-remote/journal-gatewayd.c
+++ b/src/journal-remote/journal-gatewayd.c
@@ -45,6 +45,8 @@
#include "sigbus.h"
#include "util.h"
+#define JOURNAL_WAIT_TIMEOUT (10*USEC_PER_SEC)
+
static char *arg_key_pem = NULL;
static char *arg_cert_pem = NULL;
static char *arg_trust_pem = NULL;
@@ -181,11 +183,13 @@ static ssize_t request_reader_entries(
} else if (r == 0) {
if (m->follow) {
- r = sd_journal_wait(m->journal, (uint64_t) -1);
+ r = sd_journal_wait(m->journal, (uint64_t) JOURNAL_WAIT_TIMEOUT);
if (r < 0) {
log_error_errno(r, "Couldn't wait for journal event: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}
+ if (r == SD_JOURNAL_NOP)
+ break;
continue;
}
@@ -241,6 +245,8 @@ static ssize_t request_reader_entries(
}
n = m->size - pos;
+ if (n < 1)
+ return 0;
if (n > max)
n = max;