summaryrefslogtreecommitdiff
path: root/src/system/dlt-system-log.c
blob: de40176bcc2c1a19cbb39e1a920e0c097cef8bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <unistd.h>
#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"

#include "dlt-system.h"
#include "dlt-system_cfg.h"
#include "dlt-system-log.h"

void dlt_system_log_kernel_version(DltSystemOptions *options,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));				   	
			}
		}
}

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);	
}