summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/system/dlt-system-log.c46
-rw-r--r--src/system/dlt-system-log.h2
-rwxr-xr-xsrc/system/dlt-system.c63
-rw-r--r--src/system/dlt-system.conf22
-rw-r--r--src/system/dlt-system.h8
-rw-r--r--src/system/dlt-system_cfg.h1
6 files changed, 96 insertions, 46 deletions
diff --git a/src/system/dlt-system-log.c b/src/system/dlt-system-log.c
index 4539f88..1a5f4bc 100644
--- a/src/system/dlt-system-log.c
+++ b/src/system/dlt-system-log.c
@@ -142,48 +142,48 @@ void dlt_system_log_file(DltSystemOptions *options,DltContext *context,int num)
}
}
-void dlt_system_log_processes(DltSystemOptions *options,DltContext *context) {
+void dlt_system_log_process(DltSystemOptions *options,DltContext *context,int num) {
FILE * pFile;
struct dirent *dp;
char filename[256];
char buffer[1024];
int bytes;
- int num;
+ int found = 0;
/* 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));
- }
- }
+ if(dp->d_name[0]>'0' && dp->d_name[0]<'9') {
+ buffer[0] = 0;
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] = ' ';
- }
+ }
+ if((strcmp(options->LogProcessFilename[num],"*")==0) ||
+ (strcmp(buffer,options->LogProcessName[num])==0) ) {
+ found = 1;
+ sprintf(filename,"/proc/%s/%s",dp->d_name,options->LogProcessFilename[num]);
+ 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));
}
- buffer[bytes] = 0;
- DLT_LOG(*context, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), DLT_STRING(buffer));
}
+ break;
}
}
}
closedir(dir);
+
+ if(!found) {
+ DLT_LOG(*context, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING(options->LogProcessName[num]),DLT_STRING("not running!"));
+ }
}
diff --git a/src/system/dlt-system-log.h b/src/system/dlt-system-log.h
index 3081b5c..6eb8d62 100644
--- a/src/system/dlt-system-log.h
+++ b/src/system/dlt-system-log.h
@@ -5,6 +5,6 @@ extern void dlt_system_filetransfer_init(DltSystemOptions *options,DltSystemRunt
extern void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *runtime,DltContext *context);
extern void dlt_system_log_file(DltSystemOptions *options,DltContext *context,int num);
-extern void dlt_system_log_processes(DltSystemOptions *options,DltContext *context);
+extern void dlt_system_log_process(DltSystemOptions *options,DltContext *context,int num);
#endif /* DLT_SYSTEM_LOG_H */
diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c
index 1b3967c..2930a4a 100755
--- a/src/system/dlt-system.c
+++ b/src/system/dlt-system.c
@@ -112,8 +112,6 @@ void dlt_system_init_options(DltSystemOptions *options)
strncpy(options->FiletransferContextId,DEFAULT_FILETRANSFER_CONTEXT_ID,sizeof(options->FiletransferContextId));
options->FiletransferTimeStartup = DEFAULT_FILETRANSFER_TIME_STARTUP;
options->FiletransferTimeDelay = DEFAULT_FILETRANSFER_TIME_DELAY;
- options->LogProcessesMode = DEFAULT_LOG_PROCESSES_MODE;
- strncpy(options->LogProcessesContextId,DEFAULT_LOG_PROCESSES_CONTEXT_ID,sizeof(options->LogProcessesContextId));
options->LogFileNumber = 0;
for(num=0;num<DLT_SYSTEM_LOG_FILE_MAX;num++) {
options->LogFileFilename[num][0]=0;
@@ -121,6 +119,14 @@ void dlt_system_init_options(DltSystemOptions *options)
options->LogFileContextId[num][0]=0;
options->LogFileTimeDelay[num]=0;
}
+ options->LogProcessNumber = 0;
+ strncpy(options->LogProcessesContextId,DEFAULT_LOG_PROCESSES_CONTEXT_ID,sizeof(options->LogProcessesContextId));
+ for(num=0;num<DLT_SYSTEM_LOG_PROCESSES_MAX;num++) {
+ options->LogProcessName[num][0]=0;
+ options->LogProcessFilename[num][0]=0;
+ options->LogProcessMode[num]=0;
+ options->LogProcessTimeDelay[num]=0;
+ }
}
int dlt_system_parse_options(DltSystemOptions *options,int argc, char* argv[])
@@ -262,16 +268,33 @@ int dlt_system_parse_configuration(DltSystemOptions *options)
if(options->LogFileNumber < (DLT_SYSTEM_LOG_FILE_MAX-1) )
options->LogFileNumber++;
}
- else if(strcmp(token,"LogProcessesMode")==0)
+ else if(strcmp(token,"LogProcessesContextId")==0)
{
- options->LogProcessesMode = atoi(value);
+ strncpy(options->LogProcessesContextId,value,sizeof(options->LogProcessesContextId));
printf("Option: %s=%s\n",token,value);
}
- else if(strcmp(token,"LogProcessesContextId")==0)
+ else if(strcmp(token,"LogProcessName")==0)
{
- strncpy(options->LogProcessesContextId,value,sizeof(options->LogProcessesContextId));
+ strncpy(options->LogProcessName[options->LogProcessNumber],value,sizeof(options->LogProcessName[options->LogProcessNumber]));
+ printf("Option: %s=%s\n",token,value);
+ }
+ else if(strcmp(token,"LogProcessFilename")==0)
+ {
+ strncpy(options->LogProcessFilename[options->LogProcessNumber],value,sizeof(options->LogProcessFilename[options->LogProcessNumber]));
printf("Option: %s=%s\n",token,value);
}
+ else if(strcmp(token,"LogProcessMode")==0)
+ {
+ options->LogProcessMode[options->LogProcessNumber] = atoi(value);
+ printf("Option: %s=%s\n",token,value);
+ }
+ else if(strcmp(token,"LogProcessTimeDelay")==0)
+ {
+ options->LogProcessTimeDelay[options->LogProcessNumber] = atoi(value);
+ printf("Option: %s=%s\n",token,value);
+ if(options->LogProcessNumber < (DLT_SYSTEM_LOG_PROCESSES_MAX-1) )
+ options->LogProcessNumber++;
+ }
else
{
fprintf(stderr, "Unknown option: %s=%s\n",token,value);
@@ -330,8 +353,7 @@ int main(int argc, char* argv[])
DLT_REGISTER_CONTEXT(syslogContext,options.SyslogContextId,"SYSLOG Adapter");
- if(options.LogProcessesMode != DLT_SYSTEM_MODE_OFF)
- DLT_REGISTER_CONTEXT(processesContext,options.LogProcessesContextId,"Log Processes");
+ DLT_REGISTER_CONTEXT(processesContext,options.LogProcessesContextId,"Log Processes");
if(options.FiletransferDirectory[0]!=0)
DLT_REGISTER_CONTEXT(filetransferContext,options.FiletransferContextId,"Filetransfer");
@@ -343,6 +365,10 @@ int main(int argc, char* argv[])
}
+ for(num=0;num<options.LogProcessNumber;num++) {
+ runtime.timeLogProcessDelay[num]=0;
+ }
+
/* create systemd socket */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
@@ -414,7 +440,7 @@ int main(int argc, char* argv[])
}
}
- /* log kernel version */
+ /* log files */
for(num=0;num<options.LogFileNumber;num++) {
if(((options.LogFileMode[num] == DLT_SYSTEM_MODE_STARTUP) && firsttime) ||
(options.LogFileMode[num] == DLT_SYSTEM_MODE_REGULAR) ) {
@@ -429,10 +455,18 @@ int main(int argc, char* argv[])
}
/* log processes information */
- if(((options.LogProcessesMode == DLT_SYSTEM_MODE_STARTUP) && firsttime) ||
- (options.LogProcessesMode == DLT_SYSTEM_MODE_REGULAR) ) {
- dlt_system_log_processes(&options,&processesContext);
- }
+ for(num=0;num<options.LogProcessNumber;num++) {
+ if(((options.LogProcessMode[num] == DLT_SYSTEM_MODE_STARTUP) && firsttime) ||
+ (options.LogProcessMode[num] == DLT_SYSTEM_MODE_REGULAR) ) {
+ if(runtime.timeLogProcessDelay[num]<=0) {
+ dlt_system_log_process(&options,&processesContext,num);
+ runtime.timeLogProcessDelay[num]=options.LogProcessTimeDelay[num]-1;
+ }
+ else {
+ runtime.timeLogProcessDelay[num]--;
+ }
+ }
+ }
firsttime = 0;
}
@@ -466,8 +500,7 @@ int main(int argc, char* argv[])
}
}
- if(options.LogProcessesMode != DLT_SYSTEM_MODE_OFF)
- DLT_UNREGISTER_CONTEXT(processesContext);
+ DLT_UNREGISTER_CONTEXT(processesContext);
if(options.FiletransferDirectory[0]!=0)
DLT_UNREGISTER_CONTEXT(filetransferContext);
diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf
index f194bf5..53b1abd 100644
--- a/src/system/dlt-system.conf
+++ b/src/system/dlt-system.conf
@@ -97,10 +97,22 @@ LogFileContextId = IOM
# Log Processes
########################################################################
-# Log the processes in /proc with info from /proc/x/stat (Default: 0)
-# 0 = off, 1 = startup only, 2 = regular
-# LogProcessesMode = 1
-
# The Context Id of the kernel version (Default: PROC)
-# LogProcessesContextId = PROC
+LogProcessesContextId = PROC
+
+# Log different processes
+# Name: * = all process, X=alternative name (must correspind to /proc/X/cmdline
+# Filename: the filename in the subdirectory /proc/processid/
+# Mode: 0 = off, 1 = startup only, 2 = regular
+# TimeDelay: If mode regular is set, time delay is the number of seconds for next sent
+
+LogProcessName = *
+LogProcessFilename = stat
+LogProcessMode = 1
+LogProcessTimeDelay = 5
+
+LogProcessName = ./dlt-daemon
+LogProcessFilename = stat
+LogProcessMode = 2
+LogProcessTimeDelay = 1
diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h
index d548036..d0005fd 100644
--- a/src/system/dlt-system.h
+++ b/src/system/dlt-system.h
@@ -6,6 +6,7 @@
#define DLT_SYSTEM_MODE_REGULAR 2
#define DLT_SYSTEM_LOG_FILE_MAX 32
+#define DLT_SYSTEM_LOG_PROCESSES_MAX 32
typedef struct {
char ConfigurationFile[256];
@@ -21,8 +22,12 @@ typedef struct {
int LogFileMode[DLT_SYSTEM_LOG_FILE_MAX];
int LogFileTimeDelay[DLT_SYSTEM_LOG_FILE_MAX];
char LogFileContextId[DLT_SYSTEM_LOG_FILE_MAX][256];
- int LogProcessesMode;
char LogProcessesContextId[256];
+ int LogProcessNumber;
+ char LogProcessName[DLT_SYSTEM_LOG_PROCESSES_MAX][256];
+ char LogProcessFilename[DLT_SYSTEM_LOG_PROCESSES_MAX][256];
+ int LogProcessMode[DLT_SYSTEM_LOG_PROCESSES_MAX];
+ int LogProcessTimeDelay[DLT_SYSTEM_LOG_PROCESSES_MAX];
} DltSystemOptions;
typedef struct {
@@ -30,6 +35,7 @@ typedef struct {
int timeFiletransferDelay; /* time in seconds to start next filetransfer */
char filetransferFile[256];
int timeLogFileDelay[DLT_SYSTEM_LOG_FILE_MAX]; /* time in seconds to start next file log */
+ int timeLogProcessDelay[DLT_SYSTEM_LOG_PROCESSES_MAX]; /* time in seconds to start next process log */
int filetransferRunning; /* 0 = stooped, 1 = running */
int filetransferCountPackages; /* number of packets to be transfered */
int filetransferLastSentPackage; /* last packet sent starting from 1 */
diff --git a/src/system/dlt-system_cfg.h b/src/system/dlt-system_cfg.h
index 8c015c0..dbd6ce0 100644
--- a/src/system/dlt-system_cfg.h
+++ b/src/system/dlt-system_cfg.h
@@ -9,5 +9,4 @@
#define DEFAULT_FILETRANSFER_TIME_STARTUP 30
#define DEFAULT_FILETRANSFER_TIME_DELAY 10
-#define DEFAULT_LOG_PROCESSES_MODE 0
#define DEFAULT_LOG_PROCESSES_CONTEXT_ID "PROC"