diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-10-04 17:34:25 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-10-04 17:34:25 +0200 |
commit | 71a7aae2c7e3451293ad7e96b07efa5329e12b86 (patch) | |
tree | f2d75b369ca4f5ec9fb44e9a19566e70d87735d3 | |
parent | c37ecb5031eebc36bfba8be0d741ec858e8898f7 (diff) | |
download | DLT-daemon-71a7aae2c7e3451293ad7e96b07efa5329e12b86.tar.gz |
First version of DLT system mamager.
-rwxr-xr-x | include/dlt/dlt_version.h | 2 | ||||
-rwxr-xr-x | src/CMakeLists.txt | 1 | ||||
-rwxr-xr-x | src/system/CMakeLists.txt | 50 | ||||
-rw-r--r-- | src/system/dlt-system-log.c | 31 | ||||
-rw-r--r-- | src/system/dlt-system-log.h | 6 | ||||
-rwxr-xr-x | src/system/dlt-system.c | 370 | ||||
-rw-r--r-- | src/system/dlt-system.conf | 30 | ||||
-rw-r--r-- | src/system/dlt-system.h | 17 | ||||
-rw-r--r-- | src/system/dlt-system_cfg.h | 10 | ||||
-rw-r--r-- | testscripts/dlt.conf | 12 |
10 files changed, 522 insertions, 7 deletions
diff --git a/include/dlt/dlt_version.h b/include/dlt/dlt_version.h index 7d3b6c6..15d70c6 100755 --- a/include/dlt/dlt_version.h +++ b/include/dlt/dlt_version.h @@ -7,6 +7,6 @@ #define PACKAGE_MAJOR_VERSION "2" #define PACKAGE_MINOR_VERSION "3" #define PACKAGE_PATCH_LEVEL "0" -#define PACKAGE_REVISION "v2.3.0-25-g966bffa" +#define PACKAGE_REVISION "v2.3.0-27-gc37ecb5" #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 28a249a..1a824ce 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,4 +41,5 @@ ADD_SUBDIRECTORY( daemon ) ADD_SUBDIRECTORY( examples ) ADD_SUBDIRECTORY( adaptor ) ADD_SUBDIRECTORY( tests ) +ADD_SUBDIRECTORY( system ) diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt new file mode 100755 index 0000000..4c3e3c2 --- /dev/null +++ b/src/system/CMakeLists.txt @@ -0,0 +1,50 @@ +####### +# Dlt - Diagnostic Log and Trace +# @licence make begin@ + # + # Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + # + # This program is free software; you can redistribute it and/or modify it under the terms of the + # GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + # Public License, version 2.1, for more details. + # + # You should have received a copy of the GNU Lesser General Public License, version 2.1, along + # with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + # + # Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + # also be applicable to programs even in cases in which the program is not a library in the technical sense. + # + # Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + # license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + # license your linked modules under the GNU Lesser General Public License, version 2.1, you + # may use the program under the following exception. + # + # As a special exception, the copyright holders of DLT give you permission to combine DLT + # with software programs or libraries that are released under any license unless such a combination is not + # permitted by the license of such a software program or library. You may copy and distribute such a + # system following the terms of the GNU Lesser General Public License, version 2.1, including this + # special exception, for DLT and the licenses of the other code concerned. + # + # Note that people who make modified versions of DLT are not obligated to grant this special exception + # for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + # version 2.1, gives permission to release a modified version without this exception; this exception + # also makes it possible to release a modified version which carries forward this exception. + # + # @licence end@ +######## + +set(dlt_system_SRCS dlt-system dlt-system-log) +add_executable(dlt-system ${dlt_system_SRCS}) +IF(GPROF_DLT_SYSTEM) + SET(CMAKE_C_FLAGS "-pg") +ENDIF(GPROF_DLT_SYSTEM) +target_link_libraries(dlt-system dlt) +set_target_properties(dlt-system PROPERTIES LINKER_LANGUAGE C) + +install(TARGETS dlt-system + RUNTIME DESTINATION bin + COMPONENT base) + + diff --git a/src/system/dlt-system-log.c b/src/system/dlt-system-log.c new file mode 100644 index 0000000..45ac901 --- /dev/null +++ b/src/system/dlt-system-log.c @@ -0,0 +1,31 @@ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include "dlt_common.h" +#include "dlt_user.h" + +#include "dlt-system.h" +#include "dlt-system_cfg.h" +#include "dlt-system-log.h" + +void dlt_system_log_kernel_version(DltContext *context) { + FILE * pFile; + char buffer[1024]; + int bytes; + + pFile = fopen("/proc/version","r"); + + if(pFile>0) + { + bytes = fread(buffer,1,sizeof(buffer)-1,pFile); + + fclose(pFile); + + if(bytes>0) { + buffer[bytes] = 0; + DLT_LOG(*context, DLT_LOG_INFO, DLT_STRING(buffer)); + } + } +} diff --git a/src/system/dlt-system-log.h b/src/system/dlt-system-log.h new file mode 100644 index 0000000..5ba291b --- /dev/null +++ b/src/system/dlt-system-log.h @@ -0,0 +1,6 @@ +#ifndef DLT_SYSTEM_LOG_H +#define DLT_SYSTEM_LOG_H + +extern void dlt_system_log_kernel_version(DltContext *context); + +#endif /* DLT_SYSTEM_LOG_H */ diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c new file mode 100755 index 0000000..ab9c2d9 --- /dev/null +++ b/src/system/dlt-system.c @@ -0,0 +1,370 @@ +/* + * Dlt system manager to Dlt + * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@ + */ + +/******************************************************************************* +** ** +** SRC-MODULE: dlt-system.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 ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision: 1670 $ + * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ + * $LastChangedBy$ + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <errno.h> + +#include "dlt_common.h" +#include "dlt_user.h" + +#include "dlt-system.h" +#include "dlt-system_cfg.h" +#include "dlt-system-log.h" + +/* Port number, to which the syslogd-ng sends its log messages */ +#define MAXSTRLEN 1024 + +DLT_DECLARE_CONTEXT(syslogContext); +DLT_DECLARE_CONTEXT(kernelVersionContext); + +void dlt_system_init_options(DltSystemOptions *options) +{ + strncpy(options->ConfigurationFile,DEFAULT_CONFIGURATION_FILE,sizeof(options->ConfigurationFile)); + strncpy(options->ApplicationId,DEFAULT_APPLICATION_ID,sizeof(options->ApplicationId)); + strncpy(options->SyslogContextId,DEFAULT_SYSLOG_CONTEXT_ID,sizeof(options->SyslogContextId)); + options->SyslogPort = DEFAULT_SYSLOG_PORT; + options->KernelVersionMode = DEFAULT_KERNEL_VERSION_MODE; + strncpy(options->KernelVersionContextId,DEFAULT_KERNEL_VERSION_CONTEXT_ID,sizeof(options->KernelVersionContextId)); +} + +int dlt_system_parse_options(DltSystemOptions *options,int argc, char* argv[]) +{ + int opt; + char version[255]; + + while ((opt = getopt(argc, argv, "c:h")) != -1) + { + switch (opt) + { + case 'c': + { + strncpy(options->ConfigurationFile,optarg,sizeof(options->ConfigurationFile)); + break; + } + case 'h': + { + dlt_get_version(version); + + printf("Usage: dlt-system [options]\n"); + printf("System information manager and forwarder to DLT daemon.\n"); + printf("%s \n", version); + printf("Options:\n"); + printf("-c filename - Set configuration file (default: /etc/dlt-system.conf)\n"); + printf("-h - This help\n"); + return -1; + break; + } + default: /* '?' */ + { + fprintf(stderr, "Unknown option '%c'\n", optopt); + return -1; + } + } + } + + return 0; +} + +int dlt_system_parse_configuration(DltSystemOptions *options) +{ + FILE * pFile; + char line[1024]; + char token[1024]; + char value[1024]; + char *pch; + + /* open configuration file */ + pFile = fopen (options->ConfigurationFile,"r"); + + if (pFile!=NULL) + { + while(1) + { + /* fetch line from configuration file */ + if ( fgets (line , 1024 , pFile) != NULL ) + { + //printf("Line: %s\n",line); + pch = strtok (line," =\r\n"); + token[0]=0; + value[0]=0; + + while (pch != NULL) + { + if(strcmp(pch,"#")==0) + break; + + if(token[0]==0) + { + strncpy(token,pch,sizeof(token)); + } + else + { + strncpy(value,pch,sizeof(value)); + break; + } + + pch = strtok (NULL, " =\r\n"); + } + + if(token[0] && value[0]) + { + /* parse arguments here */ + if(strcmp(token,"ApplicationId")==0) + { + strncpy(options->ApplicationId,value,sizeof(options->ApplicationId)); + printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"SyslogContextId")==0) + { + strncpy(options->SyslogContextId,value,sizeof(options->SyslogContextId)); + printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"SyslogPort")==0) + { + options->SyslogPort = atoi(value); + printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"KernelVersionMode")==0) + { + options->KernelVersionMode = atoi(value); + printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"KernelVersionContextId")==0) + { + strncpy(options->KernelVersionContextId,value,sizeof(options->KernelVersionContextId)); + printf("Option: %s=%s\n",token,value); + } + else + { + fprintf(stderr, "Unknown option: %s=%s\n",token,value); + } + } + + } + else + { + break; + } + } + fclose (pFile); + } + else + { + fprintf(stderr, "Cannot open configuration file: %s\n",options->ConfigurationFile); + return -1; + } + + return 0; +} + +int main(int argc, char* argv[]) +{ + int sock; + int bytes_read; + socklen_t addr_len; + char recv_data[MAXSTRLEN]; + struct sockaddr_in client_addr, server_addr; + fd_set rfds; + struct timeval tv; + int retval; + uint32_t lasttime; + int firsttime = 1; + + DltSystemOptions options; + + /* init options */ + dlt_system_init_options(&options); + + /* parse command line options */ + if(dlt_system_parse_options(&options,argc,argv)) { + return -1; + } + + /* parse configuration file */ + if(dlt_system_parse_configuration(&options)) { + return -1; + } + + /* register application and contexts */ + DLT_REGISTER_APP(options.ApplicationId,"DLT System Manager"); + + DLT_REGISTER_CONTEXT(syslogContext,options.SyslogContextId,"SYSLOG Adapter"); + + if(options.KernelVersionMode != DLT_SYSTEM_MODE_OFF) + DLT_REGISTER_CONTEXT(kernelVersionContext,options.KernelVersionContextId,"Log Kernel version"); + + /* create systemd socket */ + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + { + perror("Socket"); + exit(1); + } + server_addr.sin_family = AF_INET; + server_addr.sin_port = htons(options.SyslogPort); + server_addr.sin_addr.s_addr = INADDR_ANY; + bzero(&(server_addr.sin_zero), 8); + if (bind(sock, (struct sockaddr *)&server_addr, + sizeof(struct sockaddr)) == -1) + { + perror("Bind"); + return -1; + } + addr_len = sizeof(struct sockaddr); + + /* Watch sockets to see when it has input. */ + FD_ZERO(&rfds); + FD_SET(sock, &rfds); + + lasttime = dlt_uptime(); + + while (1) + { + /* Wait up to one second. */ + tv.tv_sec = 0; + tv.tv_usec = (dlt_uptime()-lasttime+10000)*100; + + /* wait data to be received, or wait min time */ + retval = select(1, &rfds, NULL, NULL, &tv); + /* Don't rely on the value of tv now! */ + + if (retval == -1) + perror("select()"); + else if (retval) + printf("Data is available now.\n"); + //else + // printf("No data within one seconds.\n"); + + if((dlt_uptime()-lasttime) >= 10000) + { + /* one second elapsed */ + lasttime = dlt_uptime(); + + if(((options.KernelVersionMode == DLT_SYSTEM_MODE_STARTUP) && firsttime) || + (options.KernelVersionMode == DLT_SYSTEM_MODE_REGULAR) ) { + dlt_system_log_kernel_version(&kernelVersionContext); + } + + firsttime = 0; + } + + /* check syslog adapter socket */ + if(FD_ISSET(sock, &rfds)) + { + bytes_read = 0; + + bytes_read = recvfrom(sock, recv_data, MAXSTRLEN, 0, + (struct sockaddr *)&client_addr, &addr_len); + + if (bytes_read == -1) + { + if (errno == EINTR) + { + continue; + } + else + { + DLT_UNREGISTER_CONTEXT(syslogContext); + DLT_UNREGISTER_CONTEXT(syslogContext); + DLT_UNREGISTER_APP(); + exit(1); + } + } + + recv_data[bytes_read] = '\0'; + + if (bytes_read != 0) + { + DLT_LOG(syslogContext, DLT_LOG_INFO, DLT_STRING(recv_data)); + } + } + } + + if(options.KernelVersionMode != DLT_SYSTEM_MODE_OFF) + DLT_UNREGISTER_CONTEXT(kernelVersionContext); + + DLT_UNREGISTER_CONTEXT(syslogContext); + DLT_UNREGISTER_APP(); + + return 0; +} diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf new file mode 100644 index 0000000..59571bf --- /dev/null +++ b/src/system/dlt-system.conf @@ -0,0 +1,30 @@ +# Configuration file of DLT system manager +# + +######################################################################## +# General configuration +######################################################################## + +# The application Id used for the System manager (Default: SYS) +ApplicationId = SYS + +######################################################################## +# Kernel version +######################################################################## + +# Log the file /proc/version (Default: 1) +# 0 = off, 1 = startup only, 2 = regular +KernelVersionMode = 2 + +# The Context Id of the kernel version (Default: VERS) +KernelVersionContextId = VERS + +######################################################################## +# Syslog Adapter configuration +######################################################################## + +# The Context Id of the syslog adapter (Default: SYSL) +SyslogContextId = SYSL + +# The UDP port opened by DLT system mamager to receive system logs (Default: 47111) +SyslogPort = 47111 diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h new file mode 100644 index 0000000..0c04be9 --- /dev/null +++ b/src/system/dlt-system.h @@ -0,0 +1,17 @@ +#ifndef DLT_SYSTEM_H +#define DLT_SYSTEM_H + +#define DLT_SYSTEM_MODE_OFF 0 +#define DLT_SYSTEM_MODE_STARTUP 1 +#define DLT_SYSTEM_MODE_REGULAR 2 + +typedef struct { + char ConfigurationFile[256]; + char ApplicationId[256]; + char SyslogContextId[256]; + int SyslogPort; + int KernelVersionMode; + char KernelVersionContextId[256]; +} DltSystemOptions; + +#endif /* DLT_SYSTEM_H */ diff --git a/src/system/dlt-system_cfg.h b/src/system/dlt-system_cfg.h new file mode 100644 index 0000000..733a8eb --- /dev/null +++ b/src/system/dlt-system_cfg.h @@ -0,0 +1,10 @@ +#define DEFAULT_CONFIGURATION_FILE "/etc/dlt-system.conf" + +#define DEFAULT_APPLICATION_ID "SYS" + +#define DEFAULT_SYSLOG_CONTEXT_ID "SYSL" + +#define DEFAULT_SYSLOG_PORT 47111 + +#define DEFAULT_KERNEL_VERSION_MODE 1 +#define DEFAULT_KERNEL_VERSION_CONTEXT_ID "VERS" diff --git a/testscripts/dlt.conf b/testscripts/dlt.conf index ac4cdf8..629794d 100644 --- a/testscripts/dlt.conf +++ b/testscripts/dlt.conf @@ -19,29 +19,29 @@ # SendContextRegistration = 1 # Send automatic time packets every second if client is connected (Default: 0) -SendMessageTime = 1 +# SendMessageTime = 1 # Set ECU ID (Default: ECU1) ECUId = ENAT # Size of shared memory (Default: 100000) -SharedMemorySize = 4000000 +SharedMemorySize = 40000 # Directory where to store the persistant configuration (Default: /tmp) -PersistanceStoragePath = /home/alex/tmp +# PersistanceStoragePath = /tmp ######################################################################## # Offline Trace memory # ######################################################################## # Store DLT messages to local directory, if not set offline Trace is off (Default: off) -OfflineTraceDirectory = /home/alex/tmp +# OfflineTraceDirectory = /tmp # Maximum size in bytes of one trace file (Default: 1000000) -OfflineTraceFileSize = 1000000 +# OfflineTraceFileSize = 1000000 # Maximum size of all trace files (Default: 4000000) -OfflineTraceMaxSize = 4000000 +# OfflineTraceMaxSize = 4000000 ######################################################################## # Local console output configuration # |