From 882f404873ab8410455b17c3e7940e5c645bd143 Mon Sep 17 00:00:00 2001
From: Max Prokhorov <prokhorov.max@outlook.com>
Date: Sun, 22 Nov 2015 23:15:27 +0300
Subject: [PATCH] Fix imjournal state file issues
Derived from upstream:
* commit 64af99a:
imjournal: Initialize counter outside of while loop
* commit 8a10940:
bugfix: afterRun entry point not correctly called
The entry point was called at the wrong spot, only when the thread
had not already terminated by itself. This could cause various
cleanup to not be done.
closes https://github.com/rsyslog/rsyslog/issues/882
* fix a segfault in imuxsock triggered by 8a10940
---
plugins/imjournal/imjournal.c | 3 ++-
plugins/imuxsock/imuxsock.c | 4 ++++
threads.c | 9 +++++----
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c
index 36c7e04..65017c6 100755
--- a/plugins/imjournal/imjournal.c
+++ b/plugins/imjournal/imjournal.c
@@ -588,6 +588,7 @@ finalize_it:
}
BEGINrunInput
+ int count = 0;
CODESTARTrunInput
CHKiRet(ratelimitNew(&ratelimiter, "imjournal", NULL));
dbgprintf("imjournal: ratelimiting burst %d, interval %d\n", cs.ratelimitBurst,
@@ -603,7 +604,7 @@ CODESTARTrunInput
* signalled to do so. This, however, is handled by the framework.
*/
while (glbl.GetGlobalInputTermState() == 0) {
- int count = 0, r;
+ int r;
r = sd_journal_next(j);
if (r < 0) {
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index df504dd..f50b912 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -1419,6 +1419,10 @@ BEGINafterRun
int i;
CODESTARTafterRun
/* do cleanup here */
+ if(startIndexUxLocalSockets == 1 && nfd == 1) {
+ /* No sockets were configured, no cleanup needed. */
+ return RS_RET_OK;
+ }
/* Close the UNIX sockets. */
for (i = 0; i < nfd; i++)
if (listeners[i].fd != -1)
diff --git a/threads.c b/threads.c
index 990733a..a38b18f 100644
--- a/threads.c
+++ b/threads.c
@@ -79,6 +79,11 @@ static rsRetVal thrdDestruct(thrdInfo_t *pThis)
if(pThis->bIsActive == 1) {
thrdTerminate(pThis);
}
+
+ /* call cleanup function, if any */
+ if(pThis->pAfterRun != NULL)
+ pThis->pAfterRun(pThis);
+
pthread_mutex_destroy(&pThis->mutThrd);
pthread_cond_destroy(&pThis->condThrdTerm);
free(pThis->name);
@@ -148,10 +153,6 @@ rsRetVal thrdTerminate(thrdInfo_t *pThis)
}
pthread_join(pThis->thrdID, NULL); /* wait for input thread to complete */
- /* call cleanup function, if any */
- if(pThis->pAfterRun != NULL)
- pThis->pAfterRun(pThis);
-
RETiRet;
}
--
2.5.5