Hi,

here are two bugfixes for imjournal. The first one deals with an api change in a systestemd lib, the other is from Milan Bartos and adds a PID field that was missing.

Tomas
>From 4662184f709a9f389188c0e9635fb4da228248bd Mon Sep 17 00:00:00 2001
From: Tomas Heinrich <[email protected]>
Date: Sun, 12 May 2013 18:37:00 +0200
Subject: [PATCH 1/2] Fix a condition in imjournal

This prevented state file from being written with newer systemd.
Add some more debug information.
---
 plugins/imjournal/imjournal.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c
index 2af1958..090bfb8 100644
--- a/plugins/imjournal/imjournal.c
+++ b/plugins/imjournal/imjournal.c
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <sys/socket.h>
+#include <errno.h>
 
 #include "dirty.h"
 #include "cfsysline.h"
@@ -337,7 +338,9 @@ persistJournalState () {
 	char *cursor;
 	int ret = 0;
 
-	if ((ret = sd_journal_get_cursor(j, &cursor)) > 0) {
+	/* On success, sd_journal_get_cursor()  returns 1 in systemd
+	   197 or older and 0 in systemd 198 or newer */
+	if ((ret = sd_journal_get_cursor(j, &cursor)) >= 0) {
 		if ((sf = fopen(cs.stateFile, "wb")) != NULL) {
 			if (fprintf(sf, "%s", cursor) < 0) {
 				iRet = RS_RET_IO_ERROR;
@@ -345,9 +348,15 @@ persistJournalState () {
 			fclose(sf);
 			free(cursor);
 		} else {
+			char errmsg[256];
+			rs_strerror_r(errno, errmsg, sizeof(errmsg));
+			dbgprintf("fopen() failed: '%s'\n", errmsg);
 			iRet = RS_RET_FOPEN_FAILURE;
 		}
 	} else {
+		char errmsg[256];
+		rs_strerror_r(-(ret), errmsg, sizeof(errmsg));
+		dbgprintf("sd_journal_get_cursor() failed: '%s'\n", errmsg);
 		iRet = RS_RET_ERR;
 	}
 	RETiRet;
-- 
1.7.10.4

>From 2953ea56c17b3f806a53066b1bc63f4ddf2f2067 Mon Sep 17 00:00:00 2001
From: Milan Bartos <[email protected]>
Date: Mon, 13 May 2013 13:30:36 +0200
Subject: [PATCH 2/2] Add missing pid part of syslog tag.

---
 plugins/imjournal/imjournal.c |   27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 plugins/imjournal/imjournal.c

diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c
old mode 100644
new mode 100755
index 090bfb8..42d3cf6
--- a/plugins/imjournal/imjournal.c
+++ b/plugins/imjournal/imjournal.c
@@ -140,13 +140,16 @@ readjournal() {
 
 	/* Information from messages */
 	char *message;
+	char *sys_pid;
 	char *sys_iden;
 	char *sys_iden_help;
 
 	const void *get;
+	const void *pidget;
 	char *parse;
 	char *get2;
 	size_t length;
+	size_t pidlength;
 
 	const void *equal_sign;
 	struct json_object *jval;
@@ -204,7 +207,7 @@ readjournal() {
 		goto free_message;
 	}
 
-	/* Get message identifier and add ':' */
+	/* Get message identifier, client pid and add ':' */
 	if (sd_journal_get_data(j, "SYSLOG_IDENTIFIER", &get, &length) >= 0) {
 		sys_iden = strndup(get+18, length-18);
 	} else {
@@ -215,12 +218,30 @@ readjournal() {
 		goto free_message;
 	}
 
-	asprintf(&sys_iden_help, "%s:", sys_iden);
+	if (sd_journal_get_data(j, "SYSLOG_PID", &pidget, &pidlength) >= 0) {
+		sys_pid = strndup(pidget+11, pidlength-11);
+		if (sys_pid == NULL) {
+			iRet = RS_RET_OUT_OF_MEMORY;
+			free (sys_iden);
+			goto free_message;
+		}
+	} else {
+		sys_pid = NULL;
+	}
+
+	if (sys_pid) {
+		asprintf(&sys_iden_help, "%s[%s]:", sys_iden, sys_pid);
+	} else {
+		asprintf(&sys_iden_help, "%s:", sys_iden);
+	}
+
+	free (sys_iden);
+	free (sys_pid);
+
 	if (sys_iden_help == NULL) {
 		iRet = RS_RET_OUT_OF_MEMORY;
 		goto finalize_it;
 	}
-	free (sys_iden);
 
 	json = json_object_new_object();
 
-- 
1.7.10.4

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to