summaryrefslogtreecommitdiffstats
path: root/src/journald/instutil.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2013-09-18 17:03:03 +0200
committerTomas Bzatek <tbzatek@redhat.com>2013-10-15 15:23:49 +0200
commit4bc2a81c75ec3625d72bbe5374a8b102dd3f97f1 (patch)
tree1effb045374bc5cd67eb83d375ecb78800ce72e2 /src/journald/instutil.c
parent650acac5a9bee23f4d820335811ba42cff3e1074 (diff)
downloadopenlmi-providers-4bc2a81c75ec3625d72bbe5374a8b102dd3f97f1.tar.gz
openlmi-providers-4bc2a81c75ec3625d72bbe5374a8b102dd3f97f1.tar.xz
openlmi-providers-4bc2a81c75ec3625d72bbe5374a8b102dd3f97f1.zip
journald: Support writing new records
This change adds ability to report new messages in the journal log. This is done by the LMI_JournalLogRecord.CreateInstance() method call taking only CreationClassName, LogCreationClassName, LogName and DataFormat key properties as mandatory, with no need to specify the MessageTimestamp and RecordID key properties. The returned instance will contain all the information with actual RecordID key property of the new record. As long as sd_journal_send() actually only queues the request, we need to watch for journal changes in order to find the new record. This is quite unfortunate as the daemon could be busy and we can't wait forever. Messages are available immediately usually, a timeout is set to 5 seconds for the moment. Record matching is done by comparing the message itself, the origin function name and PID. This brings sufficient amount of confidence though more sophisticated approach may be needed in future to ensure full uniqueness.
Diffstat (limited to 'src/journald/instutil.c')
-rw-r--r--src/journald/instutil.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/journald/instutil.c b/src/journald/instutil.c
index a38202a..e664621 100644
--- a/src/journald/instutil.c
+++ b/src/journald/instutil.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <syslog.h>
+#include <unistd.h>
#include <glib.h>
#include <konkret/konkret.h>
@@ -239,6 +240,34 @@ int create_LMI_JournalLogRecord(sd_journal *j,
return 1;
}
+int match_journal_record(sd_journal *j, const char *message, const char *code_func)
+{
+ gchar *msg = NULL;
+ gchar *pid = NULL;
+ gchar *cfunc = NULL;
+ char *conv_err = NULL;
+ long int pid_n;
+ int r;
+
+ r = dup_journal_data(j, "MESSAGE", &msg);
+ if (r < 0)
+ return r;
+ dup_journal_data(j, "_PID", &pid);
+ dup_journal_data(j, "CODE_FUNC", &cfunc);
+
+ if (pid)
+ pid_n = strtol(pid, &conv_err, 10);
+
+ r = msg && pid && cfunc &&
+ (strcmp(message, msg) == 0) && (strcmp(code_func, cfunc) == 0) &&
+ (conv_err == NULL || *conv_err == '\0') && (pid_n == getpid());
+
+ g_free(msg);
+ g_free(pid);
+ g_free(cfunc);
+
+ return r;
+}
void ind_init()
{