diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 28 | ||||
-rw-r--r-- | src/daemon/dlt-daemon.c | 14 | ||||
-rw-r--r-- | src/examples/dlt-example-filetransfer.c | 41 | ||||
-rwxr-xr-x | src/shared/dlt_common.c | 4 | ||||
-rw-r--r-- | src/system/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/system/dlt-system-options.c | 2 | ||||
-rw-r--r-- | src/system/dlt-system-process-handling.c | 4 | ||||
-rw-r--r-- | src/system/dlt-system-watchdog.c | 197 | ||||
-rw-r--r-- | src/system/dlt-system.c | 26 | ||||
-rw-r--r-- | src/system/dlt-system.conf | 6 | ||||
-rw-r--r-- | src/system/dlt-system.h | 3 |
11 files changed, 290 insertions, 43 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7b84c0..a288381 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,11 +14,25 @@ # @licence end@ ######## -ADD_SUBDIRECTORY( lib ) -ADD_SUBDIRECTORY( console ) -ADD_SUBDIRECTORY( daemon ) -ADD_SUBDIRECTORY( examples ) -ADD_SUBDIRECTORY( adaptor ) -ADD_SUBDIRECTORY( tests ) -ADD_SUBDIRECTORY( system ) +add_subdirectory( lib ) +add_subdirectory( daemon ) +if( WITH_DLT_CONSOLE ) + add_subdirectory( console ) +endif( WITH_DLT_CONSOLE ) + +if( WITH_DLT_EXAMPLES ) + add_subdirectory( examples ) +endif( WITH_DLT_EXAMPLES ) + +if( WTIH_DLT_ADAPTOR ) + add_subdirectory( adaptor ) +endif( WTIH_DLT_ADAPTOR ) + +if( WITH_DLT_TESTS ) + add_subdirectory( tests ) +endif( WITH_DLT_TESTS ) + +if( WITH_DLT_SYSTEM ) + add_subdirectory( system ) +endif( WITH_DLT_SYSTEM ) diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 9ef5c6c..57a3d02 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -86,12 +86,7 @@ #include "dlt-daemon.h" #include "dlt-daemon_cfg.h" -#if defined(DLT_SYSTEMD_ENABLE) - #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) - #include <stdio.h> - #include <stdlib.h> - #endif - +#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE) #include "sd-daemon.h" #endif @@ -119,8 +114,13 @@ static pthread_t dlt_daemon_systemd_watchdog_thread_handle; */ void usage() { + char version[DLT_DAEMON_TEXTBUFSIZE]; + dlt_get_version(version); + + //printf("DLT logging daemon %s %s\n", _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE); + //printf("Compile options: %s %s %s %s",_DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, _DLT_SHM_ENABLE); + printf(version); printf("Usage: dlt-daemon [options]\n"); - printf("DLT logging daemon %s\n", _DLT_PACKAGE_REVISION); printf("Options:\n"); printf(" -d Daemonize\n"); printf(" -h Usage\n"); diff --git a/src/examples/dlt-example-filetransfer.c b/src/examples/dlt-example-filetransfer.c index adbe85b..b1d3e1a 100644 --- a/src/examples/dlt-example-filetransfer.c +++ b/src/examples/dlt-example-filetransfer.c @@ -82,11 +82,9 @@ void usage() dlt_get_version(version); - printf("Usage: dlt-example-filetransfer [options] <command>\n"); - printf("Filetransfer example"); + printf("Usage: dlt-example-filetransfer [options] absolute-path-to-file\n"); + printf("Simple filetransfer example"); printf("%s \n", version); - printf("Command:\n"); - printf("-f file - File to transfer (absolute path)\n"); printf("Options:\n"); printf("-a apid - Set application id to apid (default: FLTR)\n"); printf("-c ctid - Set context id to ctid (default: FLTR)\n"); @@ -108,10 +106,10 @@ int main(int argc, char* argv[]) char ctid[DLT_ID_SIZE]; //char version[255]; - + int index; int dflag = 0; int iflag = 0; - char *fvalue = 0; + char *file = 0; char *tvalue = 0; dlt_set_id(apid, FLTR_APP); @@ -131,11 +129,6 @@ int main(int argc, char* argv[]) iflag = 1; break; } - case 'f': - { - fvalue = optarg; - break; - } case 't': { tvalue = optarg; @@ -158,7 +151,7 @@ int main(int argc, char* argv[]) } case '?': { - if (optopt == 'a' || optopt == 'c' || optopt == 'f' || optopt == 't') + if (optopt == 'a' || optopt == 'c' || optopt == 't') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } @@ -177,6 +170,20 @@ int main(int argc, char* argv[]) } } + for (index = optind; index < argc; index++) + { + file = argv[index]; + } + + if (file == 0) + { + /* no message, show usage and terminate */ + fprintf(stderr,"ERROR: No absolute path to file specified\n"); + usage(); + return -1; + } + + if (tvalue) { timeout = atoi(tvalue); @@ -186,12 +193,6 @@ int main(int argc, char* argv[]) timeout = TIMEOUT; } - if (!fvalue) - { - usage(); - return -1; - } - //Register the application at the dlt-daemon dltResult = DLT_REGISTER_APP(apid,FLTR_APP_DESC); @@ -202,10 +203,10 @@ int main(int argc, char* argv[]) if( dltResult == 0 ){ if( iflag ) { - dlt_user_log_file_infoAbout(&fileContext,fvalue); + dlt_user_log_file_infoAbout(&fileContext,file); } - if( dlt_user_log_file_complete(&fileContext,fvalue,dflag,timeout) < 0 ) + if( dlt_user_log_file_complete(&fileContext,file,dflag,timeout) < 0 ) { printf("File couldn't be transferred. Please check the dlt log messages.\n"); } diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 896a047..69d601b 100755 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -3046,8 +3046,8 @@ speed_t dlt_convert_serial_speed(int baudrate) void dlt_get_version(char *buf) { - sprintf(buf,"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n", - _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE, _DLT_PACKAGE_REVISION, __DATE__ , __TIME__ ); + sprintf(buf,"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n", + _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE, _DLT_PACKAGE_REVISION, __DATE__ , __TIME__,_DLT_SYSTEMD_ENABLE,_DLT_SYSTEMD_WATCHDOG_ENABLE,_DLT_TEST_ENABLE,_DLT_SHM_ENABLE ); } void dlt_get_major_version(char *buf) 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_ */ |