summaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-06-28 16:18:18 +0200
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-07-25 13:09:07 +0200
commitfd6c274685e5fd66506f29dece45032650ce6a92 (patch)
treee621ab156449f2dbaefb7c965806ac28e1575df4 /src/system
parent277fca175316e182b5a1f1b854e6a0bc11654d6e (diff)
downloadDLT-daemon-fd6c274685e5fd66506f29dece45032650ce6a92.tar.gz
First version of journal support.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src/system')
-rw-r--r--src/system/CMakeLists.txt13
-rw-r--r--src/system/dlt-system-journal.c166
-rw-r--r--src/system/dlt-system-options.c16
-rw-r--r--src/system/dlt-system-process-handling.c5
-rw-r--r--src/system/dlt-system.conf14
-rw-r--r--src/system/dlt-system.h13
6 files changed, 222 insertions, 5 deletions
diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt
index 87c9c6f..e503688 100644
--- a/src/system/CMakeLists.txt
+++ b/src/system/CMakeLists.txt
@@ -14,15 +14,20 @@
# @licence end@
########
-if(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
+if(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD OR WITH_SYSTEMD_JOURNAL)
message( STATUS "Added ${systemd_SRCS} to dlt-system")
-endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
+endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD OR WITH_SYSTEMD_JOURNAL)
set(dlt_system_SRCS dlt-system dlt-system-options dlt-system-process-handling
dlt-system-filetransfer dlt-system-logfile dlt-system-processes dlt-system-shell
- dlt-system-syslog dlt-system-watchdog)
+ dlt-system-syslog dlt-system-watchdog dlt-system-journal)
add_executable(dlt-system ${dlt_system_SRCS} ${systemd_SRCS})
-target_link_libraries(dlt-system dlt z)
+if(WITH_SYSTEMD_JOURNAL)
+ target_link_libraries(dlt-system dlt z systemd-journal)
+else(WITH_SYSTEMD_JOURNAL)
+ target_link_libraries(dlt-system dlt z)
+endif(WITH_SYSTEMD_JOURNAL)
+
set_target_properties(dlt-system PROPERTIES LINKER_LANGUAGE C)
diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c
new file mode 100644
index 0000000..e5419d3
--- /dev/null
+++ b/src/system/dlt-system-journal.c
@@ -0,0 +1,166 @@
+/**
+ * @licence app begin@
+ * Copyright (C) 2013 BMW AG
+ *
+ * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+ * \author Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> BMW 2013
+ *
+ * \file dlt-system-journal.c
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt-system-journal.c **
+** **
+** TARGET : linux **
+** **
+** PROJECT : DLT **
+** **
+** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
+** **
+** PURPOSE : **
+** **
+** REMARKS : **
+** **
+** PLATFORM DEPENDANT [yes/no]: yes **
+** **
+** TO BE CHANGED BY USER [yes/no]: no **
+** **
+*******************************************************************************/
+#if defined(DLT_SYSTEMD_JOURNAL_ENABLE)
+
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <strings.h>
+#include <errno.h>
+
+#include "dlt-system.h"
+
+#include <systemd/sd-journal.h>
+
+extern DltSystemThreads threads;
+
+DLT_IMPORT_CONTEXT(dltsystem)
+DLT_DECLARE_CONTEXT(journalContext)
+
+int journal_checkUserBufferForFreeSpace()
+{
+ int total_size, used_size;
+
+ dlt_user_check_buffer(&total_size, &used_size);
+
+ if((total_size - used_size) < (total_size/2))
+ {
+ return -1;
+ }
+ return 1;
+}
+
+void journal_thread(void *v_conf)
+{
+ int r,r2,r3,r4,r5;
+ sd_journal *j;
+
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-journal, in thread."));
+
+ DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
+ DLT_REGISTER_CONTEXT(journalContext, conf->Journal.ContextId, "Journal Adapter");
+
+ r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY);
+ if (r < 0) {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-journal, cannot open journal."));
+ return;
+ }
+
+ // Uncomment if only new jornal entries should be shown
+ //sd_journal_seek_tail(j);
+
+ /* possible mapping of log levels */
+ /* journal log levels
+ 0 Emergency DLT_LOG_CRITICAL
+ 1 Alert DLT_LOG_CRITICAL
+ 2 Critical DLT_LOG_CRITICAL
+ 3 Error DLT_LOG_ERROR
+ 4 Warning DLT_LOG_WARNING
+ 5 Notice DLT_LOG_WARNING
+ 6 Informational DLT_LOG_INFO
+ 7 Debug DLT_LOG_DEBUG
+ */
+
+ while(!threads.shutdown)
+ {
+ const char *d2="",*d3="",*d4="",*d5="";
+ size_t l;
+ uint64_t time_usecs = 0;
+
+ // Jun 28 13:34:05 alexvbox systemd[1]: Started GENIVI DLT system.
+ if(sd_journal_next(j)>0)
+ {
+ sd_journal_get_realtime_usec(j, &time_usecs);
+ r2 = sd_journal_get_data(j, "_COMM",(const void **) &d2, &l);
+ r3 = sd_journal_get_data(j, "_PID",(const void **) &d3, &l);
+ r4 = sd_journal_get_data(j, "PRIORITY",(const void **) &d4, &l);
+ r5 = sd_journal_get_data(j, "MESSAGE",(const void **) &d5, &l);
+ if(r2>=0 && strlen(d2)>6) d2 +=6;
+ if(r3>=0 && strlen(d3)>5) d3 +=5;
+ if(r4>=0 && strlen(d4)>9) d4 +=9;
+ if(r5>=0 && strlen(d5)>8) d5 +=8;
+
+ if(r5>=0)
+ {
+ DLT_LOG(journalContext, DLT_LOG_INFO,
+ DLT_UINT64(time_usecs),DLT_STRING(d2),DLT_STRING(d3),DLT_STRING(d4),DLT_STRING(d5));
+ }
+
+ }
+ else
+ {
+ sd_journal_wait(j,1000000);
+ }
+
+ if(journal_checkUserBufferForFreeSpace()==-1)
+ {
+ // buffer is nearly full
+ // wait 500ms for writing next entry
+ struct timespec t;
+ t.tv_sec = 0;
+ t.tv_nsec = 1000000ul*500;
+ nanosleep(&t, NULL);
+ }
+
+
+ }
+
+ sd_journal_close(j);
+
+ DLT_UNREGISTER_CONTEXT(journalContext);
+
+}
+
+void start_systemd_journal(DltSystemConfiguration *conf)
+{
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-journal, start journal"));
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+ pthread_create(&pt, &t_attr, (void *)journal_thread, conf);
+ threads.threads[threads.count++] = pt;
+}
+
+#endif /* DLT_SYSTEMD_JOURNAL_ENABLE */
diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c
index 01a2215..1a35adc 100644
--- a/src/system/dlt-system-options.c
+++ b/src/system/dlt-system-options.c
@@ -138,6 +138,10 @@ void init_configuration(DltSystemConfiguration *config)
config->Syslog.ContextId = "SYSL";
config->Syslog.Port = 47111;
+ // Journal
+ config->Journal.Enable = 0;
+ config->Syslog.ContextId = "JOUR";
+
// File transfer
config->Filetransfer.Enable = 0;
config->Filetransfer.ContextId = "FILE";
@@ -253,6 +257,18 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name)
config->Syslog.Port = atoi(value);
}
+ // Journal
+ else if(strcmp(token, "JournalEnable") == 0)
+ {
+ config->Journal.Enable = atoi(value);
+ }
+ else if(strcmp(token, "JournalContextId") == 0)
+ {
+ config->Journal.ContextId = malloc(strlen(value)+1);
+ MALLOC_ASSERT(config->Journal.ContextId);
+ strcpy(config->Journal.ContextId, value);
+ }
+
// File transfer
else if(strcmp(token, "FiletransferEnable") == 0)
{
diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c
index e206db8..72a2785 100644
--- a/src/system/dlt-system-process-handling.c
+++ b/src/system/dlt-system-process-handling.c
@@ -134,6 +134,11 @@ void start_threads(DltSystemConfiguration *config)
if(config->Syslog.Enable)
start_syslog(config);
+
+#if defined(DLT_SYSTEMD_JOURNAL_ENABLE)
+ if(config->Journal.Enable)
+ start_systemd_journal(config);
+#endif
}
/**
diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf
index 1675cb6..9012db7 100644
--- a/src/system/dlt-system.conf
+++ b/src/system/dlt-system.conf
@@ -22,6 +22,20 @@ SyslogContextId = SYSL
SyslogPort = 47111
########################################################################
+# Systemd Journal Adapter configuration
+########################################################################
+
+# This feature is only available, when dlt is compiled with
+# the option "WITH_SYSTEMD_JOURNAL"
+
+# Enable the Systemd Journal Adapter (Default: 0)
+JournalEnable = 0
+
+# The Context Id of the journal adapter (Default: JOUR)
+JournalContextId = JOUR
+
+
+########################################################################
# Filetransfer Manager
########################################################################
diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h
index f949aea..28a1b46 100644
--- a/src/system/dlt-system.h
+++ b/src/system/dlt-system.h
@@ -86,13 +86,19 @@ typedef struct {
int Daemonize;
} DltSystemCliOptions;
-// Configuration file options
+// Configuration syslog options
typedef struct {
int Enable;
char *ContextId;
int Port;
} SyslogOptions;
+// Configuration journal options
+typedef struct {
+ int Enable;
+ char *ContextId;
+} JournalOptions;
+
typedef struct {
int Enable;
char *ContextId;
@@ -134,6 +140,7 @@ typedef struct {
typedef struct {
char *ApplicationId;
SyslogOptions Syslog;
+ JournalOptions Journal;
FiletransferOptions Filetransfer;
LogFileOptions LogFile;
LogProcessOptions LogProcesses;
@@ -171,4 +178,8 @@ void start_logprocess(DltSystemConfiguration *conf);
void start_systemd_watchdog(DltSystemConfiguration *conf);
#endif
+#if defined(DLT_SYSTEMD_JOURNAL_ENABLE)
+void start_systemd_journal(DltSystemConfiguration *conf);
+#endif
+
#endif /* DLT_SYSTEM_H_ */