summaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorChristian Muck <christian.muck@bmw.de>2012-06-04 09:08:52 +0200
committerChristian Muck <christian.muck@bmw.de>2012-06-13 23:52:51 +0200
commit85f564f2b4c580bc151d05559e6ed0614919da8a (patch)
tree96c41c00f70fb5545862cea3e62b26867117e33b /src/system
parentde0b686c504886187aa1e8ba4373daeff66283e5 (diff)
downloadDLT-daemon-85f564f2b4c580bc151d05559e6ed0614919da8a.tar.gz
[GDLT-90] Implemented systemd watchdog concept in dlt-system
Signed-off-by: Christian Muck <christian.muck@bmw.de>
Diffstat (limited to 'src/system')
-rw-r--r--src/system/CMakeLists.txt8
-rw-r--r--src/system/dlt-system-options.c2
-rw-r--r--src/system/dlt-system-process-handling.c4
-rw-r--r--src/system/dlt-system-watchdog.c197
-rw-r--r--src/system/dlt-system.c26
-rw-r--r--src/system/dlt-system.conf6
-rw-r--r--src/system/dlt-system.h3
7 files changed, 239 insertions, 7 deletions
diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt
index be8e1c9..87c9c6f 100644
--- a/src/system/CMakeLists.txt
+++ b/src/system/CMakeLists.txt
@@ -14,10 +14,14 @@
# @licence end@
########
+if(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
+ message( STATUS "Added ${systemd_SRCS} to dlt-system")
+endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
+
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)
-add_executable(dlt-system ${dlt_system_SRCS})
+ dlt-system-syslog dlt-system-watchdog)
+add_executable(dlt-system ${dlt_system_SRCS} ${systemd_SRCS})
target_link_libraries(dlt-system dlt z)
set_target_properties(dlt-system PROPERTIES LINKER_LANGUAGE C)
diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c
index 98de12d..65951a2 100644
--- a/src/system/dlt-system-options.c
+++ b/src/system/dlt-system-options.c
@@ -65,7 +65,7 @@ void usage(char *prog_name)
dlt_get_version(version);
printf("Usage: %s [options]\n", prog_name);
- printf("Application to transfer system information, logs and files.\n");
+ printf("Application to forward syslog messages to DLT, transfer system information, logs and files.\n");
printf("%s\n", version);
printf("Options:\n");
printf(" -d Daemonize. Detach from terminal and run in background.\n");
diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c
index 3837d35..2fd07fc 100644
--- a/src/system/dlt-system-process-handling.c
+++ b/src/system/dlt-system-process-handling.c
@@ -109,6 +109,10 @@ void start_threads(DltSystemConfiguration *config)
threads.threads[i] = 0;
}
+#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
+ start_systemd_watchdog(config);
+#endif
+
init_shell();
if(config->LogFile.Enable)
diff --git a/src/system/dlt-system-watchdog.c b/src/system/dlt-system-watchdog.c
new file mode 100644
index 0000000..c764978
--- /dev/null
+++ b/src/system/dlt-system-watchdog.c
@@ -0,0 +1,197 @@
+/**
+ * @licence app begin@
+ * Copyright (C) 2012 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 Lassi Marttala <lassi.lm.marttala@partner.bmw.de> BMW 2012
+ *
+ * \file dlt-system-logfile.c
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt-system-watchdog.c **
+** **
+** TARGET : linux **
+** **
+** PROJECT : DLT **
+** **
+** AUTHOR : Christian Muck <christian.muck@bmw.de> **
+** Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
+** **
+** PURPOSE : **
+** **
+** REMARKS : **
+** **
+** PLATFORM DEPENDANT [yes/no]: yes **
+** **
+** TO BE CHANGED BY USER [yes/no]: no **
+** **
+*******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/timerfd.h>
+#include "dlt.h"
+#include "sd-daemon.h"
+#include "dlt-system.h"
+
+DLT_DECLARE_CONTEXT(watchdogContext)
+DLT_IMPORT_CONTEXT(dltsystem)
+
+extern DltSystemThreads threads;
+
+typedef struct
+{
+ int timer_fd;
+ unsigned long long wakeups_missed;
+} PeriodicData;
+
+void wait_period (PeriodicData *info)
+{
+ unsigned long long missed;
+
+ read (info->timer_fd, &missed, sizeof (missed));
+
+ if (missed > 0)
+ {
+ info->wakeups_missed += (missed - 1);
+ }
+}
+
+int make_periodic(unsigned int period, PeriodicData *info)
+{
+ unsigned int ns;
+ unsigned int sec;
+ int fd;
+ struct itimerspec itval;
+
+ if (info==0)
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,
+ DLT_STRING("Invalid function parameters used for function make_periodic.\n"));
+ return -1;
+ }
+
+ /* Create the timer */
+ fd = timerfd_create (CLOCK_MONOTONIC, 0);
+
+ info->wakeups_missed = 0;
+ info->timer_fd = fd;
+
+ if (fd == -1)
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,
+ DLT_STRING("Can't create timer filedescriptor.\n"));
+ return -1;
+ }
+
+ /* Make the timer periodic */
+ sec = period/1000000;
+ ns = (period - (sec * 1000000)) * 1000;
+ itval.it_interval.tv_sec = sec;
+ itval.it_interval.tv_nsec = ns;
+ itval.it_value.tv_sec = sec;
+ itval.it_value.tv_nsec = ns;
+
+ return timerfd_settime (fd, 0, &itval, NULL);
+}
+
+void watchdog_thread(void *v_conf)
+{
+ char str[512];
+ char *watchdogUSec;
+ unsigned int watchdogTimeoutSeconds;
+ unsigned int notifiyPeriodNSec;
+ PeriodicData info;
+
+ DLT_REGISTER_CONTEXT(watchdogContext, "DOG","dlt system watchdog context.");
+
+ sleep(1);
+
+ DLT_LOG(watchdogContext, DLT_LOG_INFO,DLT_STRING("Watchdog thread started.\n"));
+
+ if (v_conf==0)
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,
+ DLT_STRING("Invalid function parameters used for function watchdog_thread.\n"));
+ return;
+ }
+
+
+ watchdogUSec = getenv("WATCHDOG_USEC");
+
+ if(watchdogUSec)
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING("watchdogusec: "),DLT_STRING(watchdogUSec));
+
+ watchdogTimeoutSeconds = atoi(watchdogUSec);
+
+ if( watchdogTimeoutSeconds > 0 ){
+
+ // Calculate half of WATCHDOG_USEC in ns for timer tick
+ notifiyPeriodNSec = watchdogTimeoutSeconds / 2 ;
+
+ sprintf(str,"systemd watchdog timeout: %i nsec - timer will be initialized: %i nsec\n", watchdogTimeoutSeconds, notifiyPeriodNSec );
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING(str));
+
+ if (make_periodic (notifiyPeriodNSec, &info) < 0 )
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,DLT_STRING("Could not initialize systemd watchdog timer\n"));
+ return;
+ }
+
+ while (1)
+ {
+ if(sd_notify(0, "WATCHDOG=1") < 0)
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,DLT_STRING("Could not reset systemd watchdog\n"));
+ }
+
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING("systemd watchdog waited periodic\n"));
+
+ /* Wait for next period */
+ wait_period(&info);
+ }
+ }
+ else
+ {
+ sprintf(str,"systemd watchdog timeout incorrect: %i\n", watchdogTimeoutSeconds);
+ DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING(str));
+ }
+ }
+ else
+ {
+ DLT_LOG(watchdogContext, DLT_LOG_ERROR,DLT_STRING("systemd watchdog timeout (WATCHDOG_USEC) is null\n"));
+ }
+
+}
+
+void start_systemd_watchdog(DltSystemConfiguration *conf)
+{
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,DLT_STRING("Creating thread for systemd watchdog\n"));
+
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+
+ if (pthread_create(&pt, &t_attr, (void *)watchdog_thread, conf) == 0)
+ {
+ threads.threads[threads.count++] = pt;
+ }
+ else
+ {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,DLT_STRING("Could not create thread for systemd watchdog\n"));
+ }
+}
diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c
index 6e1d22e..93e0873 100644
--- a/src/system/dlt-system.c
+++ b/src/system/dlt-system.c
@@ -48,12 +48,19 @@
#include <errno.h>
#include <signal.h>
+#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
+#include "sd-daemon.h"
+#endif
+
DLT_DECLARE_CONTEXT(dltsystem)
int main(int argc, char* argv[])
{
DltSystemCliOptions options;
DltSystemConfiguration config;
+#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
+ int ret;
+#endif
if(read_command_line(&options, argc, argv) < 0)
{
@@ -68,7 +75,24 @@ int main(int argc, char* argv[])
}
DLT_REGISTER_APP(config.ApplicationId, "DLT System Manager");
DLT_REGISTER_CONTEXT(dltsystem,"MGR", "Context of main dlt system manager");
- sleep(1);
+
+#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
+ ret = sd_booted();
+
+ if(ret == 0){
+ DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system not booted with systemd!\n"));
+ }
+ else if(ret < 0)
+ {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("sd_booted failed!\n"));
+ return -1;
+ }
+ else
+ {
+ DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system booted with systemd\n"));
+ }
+#endif
+
DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Configuration loaded."));
if(options.Daemonize > 0)
diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf
index cc8dc75..ee237a2 100644
--- a/src/system/dlt-system.conf
+++ b/src/system/dlt-system.conf
@@ -26,7 +26,7 @@ SyslogPort = 47111
########################################################################
# Enable the Filetransfer (Default: 0)
-FiletransferEnable = 1
+FiletransferEnable = 0
# The Context Id of the filetransfer (Default: FILE)
FiletransferContextId = FILE
@@ -73,7 +73,7 @@ FiletransferCompressionLevel = 5
########################################################################
# Enable the logging of files (Default: 0)
-LogFileEnable = 1
+LogFileEnable = 0
# Log different files
# Mode: 0 = off, 1 = startup only, 2 = regular
@@ -132,7 +132,7 @@ LogFileContextId = STAT
########################################################################
# Enable the logging of processes (Default: 0)
-LogProcessesEnable = 1
+LogProcessesEnable = 0
# The Context Id of the kernel version (Default: PROC)
LogProcessesContextId = PROC
diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h
index fd741dc..f949aea 100644
--- a/src/system/dlt-system.h
+++ b/src/system/dlt-system.h
@@ -167,5 +167,8 @@ void start_filetransfer(DltSystemConfiguration *conf);
void start_logfile(DltSystemConfiguration *conf);
void start_logprocess(DltSystemConfiguration *conf);
+#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
+void start_systemd_watchdog(DltSystemConfiguration *conf);
+#endif
#endif /* DLT_SYSTEM_H_ */