diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-10-05 15:00:04 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-10-05 15:00:04 +0200 |
commit | fbc90e0e3b7c6754cc426b183eeabea3e98359d8 (patch) | |
tree | f23203d80ae10237837f5541cd180585104b7694 | |
parent | 71a7aae2c7e3451293ad7e96b07efa5329e12b86 (diff) | |
download | DLT-daemon-fbc90e0e3b7c6754cc426b183eeabea3e98359d8.tar.gz |
Functionality log of processes from /proc added.
-rwxr-xr-x | include/dlt/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | include/dlt/dlt_version.h | 2 | ||||
-rw-r--r-- | src/system/dlt-system-log.c | 53 | ||||
-rw-r--r-- | src/system/dlt-system-log.h | 3 | ||||
-rwxr-xr-x | src/system/dlt-system.c | 49 | ||||
-rw-r--r-- | src/system/dlt-system.conf | 28 | ||||
-rw-r--r-- | src/system/dlt-system.h | 6 | ||||
-rw-r--r-- | src/system/dlt-system_cfg.h | 7 |
8 files changed, 121 insertions, 29 deletions
diff --git a/include/dlt/CMakeLists.txt b/include/dlt/CMakeLists.txt index 95b9929..2e50a8e 100755 --- a/include/dlt/CMakeLists.txt +++ b/include/dlt/CMakeLists.txt @@ -35,6 +35,6 @@ # @licence end@ ######## -install(FILES dlt.h dlt_user.h dlt_user_macros.h dlt_client.h dlt_protocol.h dlt_common.h dlt_types.h dlt_version.h dlt_shm.h +install(FILES dlt.h dlt_user.h dlt_user_macros.h dlt_client.h dlt_protocol.h dlt_common.h dlt_types.h dlt_version.h dlt_shm.h dlt_offline_trace.h dlt_filetransfer.h DESTINATION include/dlt COMPONENT devel) diff --git a/include/dlt/dlt_version.h b/include/dlt/dlt_version.h index 15d70c6..7aa3338 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-27-gc37ecb5" +#define PACKAGE_REVISION "v2.3.0-28-g71a7aae" #endif diff --git a/src/system/dlt-system-log.c b/src/system/dlt-system-log.c index 45ac901..de40176 100644 --- a/src/system/dlt-system-log.c +++ b/src/system/dlt-system-log.c @@ -2,6 +2,11 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <dirent.h> #include "dlt_common.h" #include "dlt_user.h" @@ -10,7 +15,7 @@ #include "dlt-system_cfg.h" #include "dlt-system-log.h" -void dlt_system_log_kernel_version(DltContext *context) { +void dlt_system_log_kernel_version(DltSystemOptions *options,DltContext *context) { FILE * pFile; char buffer[1024]; int bytes; @@ -29,3 +34,49 @@ void dlt_system_log_kernel_version(DltContext *context) { } } } + +void dlt_system_log_processes(DltSystemOptions *options,DltContext *context) { + FILE * pFile; + struct dirent *dp; + char filename[256]; + char buffer[1024]; + int bytes; + int num; + + /* go through all dlt files in directory */ + DIR *dir = opendir("/proc"); + while ((dp=readdir(dir)) != NULL) { + if(dp->d_name[0]>'0' && dp->d_name[0]<'9') { + sprintf(filename,"/proc/%s/stat",dp->d_name); + pFile = fopen(filename,"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_INT(atoi(dp->d_name)), DLT_STRING(buffer)); + } + } + sprintf(filename,"/proc/%s/cmdline",dp->d_name); + pFile = fopen(filename,"r"); + if(pFile>0) + { + bytes = fread(buffer,1,sizeof(buffer)-1,pFile); + fclose(pFile); + + if(bytes>0) { + for(num=0;num<bytes;num++) { + if(buffer[num]==0) { + buffer[num] = ' '; + } + } + buffer[bytes] = 0; + DLT_LOG(*context, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), DLT_STRING(buffer)); + } + } + } + } + closedir(dir); +} diff --git a/src/system/dlt-system-log.h b/src/system/dlt-system-log.h index 5ba291b..a26a994 100644 --- a/src/system/dlt-system-log.h +++ b/src/system/dlt-system-log.h @@ -1,6 +1,7 @@ #ifndef DLT_SYSTEM_LOG_H #define DLT_SYSTEM_LOG_H -extern void dlt_system_log_kernel_version(DltContext *context); +extern void dlt_system_log_kernel_version(DltSystemOptions *options,DltContext *context); +extern void dlt_system_log_processes(DltSystemOptions *options,DltContext *context); #endif /* DLT_SYSTEM_LOG_H */ diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c index ab9c2d9..f186721 100755 --- a/src/system/dlt-system.c +++ b/src/system/dlt-system.c @@ -97,6 +97,7 @@ DLT_DECLARE_CONTEXT(syslogContext); DLT_DECLARE_CONTEXT(kernelVersionContext); +DLT_DECLARE_CONTEXT(processesContext); void dlt_system_init_options(DltSystemOptions *options) { @@ -104,8 +105,10 @@ void dlt_system_init_options(DltSystemOptions *options) 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)); + options->LogKernelVersionMode = DEFAULT_LOG_KERNEL_VERSION_MODE; + strncpy(options->LogKernelVersionContextId,DEFAULT_LOG_KERNEL_VERSION_CONTEXT_ID,sizeof(options->LogKernelVersionContextId)); + options->LogProcessesMode = DEFAULT_LOG_PROCESSES_MODE; + strncpy(options->LogProcessesContextId,DEFAULT_LOG_PROCESSES_CONTEXT_ID,sizeof(options->LogProcessesContextId)); } int dlt_system_parse_options(DltSystemOptions *options,int argc, char* argv[]) @@ -205,14 +208,24 @@ int dlt_system_parse_configuration(DltSystemOptions *options) options->SyslogPort = atoi(value); printf("Option: %s=%s\n",token,value); } - else if(strcmp(token,"KernelVersionMode")==0) + else if(strcmp(token,"LogKernelVersionMode")==0) { - options->KernelVersionMode = atoi(value); + options->LogKernelVersionMode = atoi(value); printf("Option: %s=%s\n",token,value); } - else if(strcmp(token,"KernelVersionContextId")==0) + else if(strcmp(token,"LogKernelVersionContextId")==0) { - strncpy(options->KernelVersionContextId,value,sizeof(options->KernelVersionContextId)); + strncpy(options->LogKernelVersionContextId,value,sizeof(options->LogKernelVersionContextId)); + printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"LogProcessesMode")==0) + { + options->LogProcessesMode = atoi(value); + printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"LogProcessesContextId")==0) + { + strncpy(options->LogProcessesContextId,value,sizeof(options->LogProcessesContextId)); printf("Option: %s=%s\n",token,value); } else @@ -271,8 +284,11 @@ int main(int argc, char* argv[]) DLT_REGISTER_CONTEXT(syslogContext,options.SyslogContextId,"SYSLOG Adapter"); - if(options.KernelVersionMode != DLT_SYSTEM_MODE_OFF) - DLT_REGISTER_CONTEXT(kernelVersionContext,options.KernelVersionContextId,"Log Kernel version"); + if(options.LogKernelVersionMode != DLT_SYSTEM_MODE_OFF) + DLT_REGISTER_CONTEXT(kernelVersionContext,options.LogKernelVersionContextId,"Log Kernel version"); + + if(options.LogProcessesMode != DLT_SYSTEM_MODE_OFF) + DLT_REGISTER_CONTEXT(processesContext,options.LogProcessesContextId,"Log Processes"); /* create systemd socket */ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) @@ -320,9 +336,13 @@ int main(int argc, char* argv[]) /* 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); + if(((options.LogKernelVersionMode == DLT_SYSTEM_MODE_STARTUP) && firsttime) || + (options.LogKernelVersionMode == DLT_SYSTEM_MODE_REGULAR) ) { + dlt_system_log_kernel_version(&options,&kernelVersionContext); + } + if(((options.LogProcessesMode == DLT_SYSTEM_MODE_STARTUP) && firsttime) || + (options.LogProcessesMode == DLT_SYSTEM_MODE_REGULAR) ) { + dlt_system_log_processes(&options,&processesContext); } firsttime = 0; @@ -344,7 +364,7 @@ int main(int argc, char* argv[]) } else { - DLT_UNREGISTER_CONTEXT(syslogContext); + DLT_UNREGISTER_CONTEXT(processesContext); DLT_UNREGISTER_CONTEXT(syslogContext); DLT_UNREGISTER_APP(); exit(1); @@ -360,9 +380,12 @@ int main(int argc, char* argv[]) } } - if(options.KernelVersionMode != DLT_SYSTEM_MODE_OFF) + if(options.LogKernelVersionMode != DLT_SYSTEM_MODE_OFF) DLT_UNREGISTER_CONTEXT(kernelVersionContext); + if(options.LogProcessesMode != DLT_SYSTEM_MODE_OFF) + DLT_UNREGISTER_CONTEXT(processesContext); + DLT_UNREGISTER_CONTEXT(syslogContext); DLT_UNREGISTER_APP(); diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf index 59571bf..b47129d 100644 --- a/src/system/dlt-system.conf +++ b/src/system/dlt-system.conf @@ -9,22 +9,34 @@ ApplicationId = SYS ######################################################################## -# Kernel version +# 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 + +######################################################################## +# Log Kernel version ######################################################################## # Log the file /proc/version (Default: 1) # 0 = off, 1 = startup only, 2 = regular -KernelVersionMode = 2 +LogKernelVersionMode = 2 # The Context Id of the kernel version (Default: VERS) -KernelVersionContextId = VERS +LogKernelVersionContextId = VERS ######################################################################## -# Syslog Adapter configuration +# Log Processes ######################################################################## -# The Context Id of the syslog adapter (Default: SYSL) -SyslogContextId = SYSL +# Log the processes in /proc with info from /proc/x/stat (Default: 1) +# 0 = off, 1 = startup only, 2 = regular +LogProcessesMode = 2 + +# The Context Id of the kernel version (Default: PROC) +LogProcessesContextId = PROC -# 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 index 0c04be9..cd42bd7 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -10,8 +10,10 @@ typedef struct { char ApplicationId[256]; char SyslogContextId[256]; int SyslogPort; - int KernelVersionMode; - char KernelVersionContextId[256]; + int LogKernelVersionMode; + char LogKernelVersionContextId[256]; + int LogProcessesMode; + char LogProcessesContextId[256]; } DltSystemOptions; #endif /* DLT_SYSTEM_H */ diff --git a/src/system/dlt-system_cfg.h b/src/system/dlt-system_cfg.h index 733a8eb..5c47e00 100644 --- a/src/system/dlt-system_cfg.h +++ b/src/system/dlt-system_cfg.h @@ -6,5 +6,8 @@ #define DEFAULT_SYSLOG_PORT 47111 -#define DEFAULT_KERNEL_VERSION_MODE 1 -#define DEFAULT_KERNEL_VERSION_CONTEXT_ID "VERS" +#define DEFAULT_LOG_KERNEL_VERSION_MODE 1 +#define DEFAULT_LOG_KERNEL_VERSION_CONTEXT_ID "VERS" + +#define DEFAULT_LOG_PROCESSES_MODE 1 +#define DEFAULT_LOG_PROCESSES_CONTEXT_ID "PROC" |