diff options
author | Christian Muck <christian.muck@bmw.de> | 2011-11-10 08:50:03 +0100 |
---|---|---|
committer | Christian Muck <christian.muck@bmw.de> | 2011-11-10 08:50:03 +0100 |
commit | 575fa86ef3181e4ade5a6c341f86bb83558eca93 (patch) | |
tree | 9602a49dce7f85e740ffee68aee7682646661579 /src | |
parent | d34560e81667493a6c7d6a6254d88cf30804bb1c (diff) | |
parent | 8ecf985d996e8bf0241d75fddce3722f224e5014 (diff) | |
download | DLT-daemon-575fa86ef3181e4ade5a6c341f86bb83558eca93.tar.gz |
Merge branch 'master' of https://git.genivi.org/srv/git/DLT-daemon
Conflicts:
src/shared/dlt_shm.c
Diffstat (limited to 'src')
-rwxr-xr-x | src/daemon/dlt-daemon.c | 90 | ||||
-rwxr-xr-x | src/daemon/dlt-daemon.h | 3 | ||||
-rw-r--r-- | src/daemon/dlt.conf | 11 | ||||
-rwxr-xr-x | src/daemon/dlt_daemon_common.c | 9 | ||||
-rwxr-xr-x | src/shared/dlt_common.c | 83 | ||||
-rw-r--r-- | src/shared/dlt_shm.c | 131 |
6 files changed, 196 insertions, 131 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 4ab628f..fb8b2e6 100755 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -135,7 +135,6 @@ void usage() printf("DLT logging daemon\n"); printf("Options:\n"); printf(" -d Daemonize\n"); - printf(" -v Verbose mode\n"); printf(" -h Usage\n"); printf(" -c filename DLT daemon configuration file (Default: /etc/dlt.conf)\n"); } /* usage() */ @@ -158,15 +157,10 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[]) opterr = 0; - while ((c = getopt (argc, argv, "hvdc:")) != -1) + while ((c = getopt (argc, argv, "hdc:")) != -1) { switch (c) { - case 'v': - { - daemon_local->flags.vflag = 1; - break; - } case 'd': { daemon_local->flags.dflag = 1; @@ -230,6 +224,9 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->flags.offlineTraceDirectory[0] = 0; daemon_local->flags.offlineTraceFileSize = 1000000; daemon_local->flags.offlineTraceMaxSize = 0; + daemon_local->flags.loggingMode = 0; + daemon_local->flags.loggingLevel = 6; + strncpy(daemon_local->flags.loggingFilename,"/tmp/dlt.log",sizeof(daemon_local->flags.loggingFilename)); /* open configuration file */ if(daemon_local->flags.cvalue[0]) @@ -246,7 +243,6 @@ int option_file_parser(DltDaemonLocal *daemon_local) /* 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; @@ -275,100 +271,108 @@ int option_file_parser(DltDaemonLocal *daemon_local) if(strcmp(token,"Verbose")==0) { daemon_local->flags.vflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"PrintASCII")==0) { daemon_local->flags.aflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"PrintHex")==0) { daemon_local->flags.xflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"PrintHeadersOnly")==0) { daemon_local->flags.sflag = atoi(value); - printf("Option: %s=%s\n",token,value); - } - else if(strcmp(token,"Daemonize")==0) - { - daemon_local->flags.dflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"SendSerialHeader")==0) { daemon_local->flags.lflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"SendContextRegistration")==0) { daemon_local->flags.rflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"SendMessageTime")==0) { daemon_local->flags.sendMessageTime = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"RS232SyncSerialHeader")==0) { daemon_local->flags.mflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"TCPSyncSerialHeader")==0) { daemon_local->flags.nflag = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"RS232DeviceName")==0) { strncpy(daemon_local->flags.yvalue,value,sizeof(daemon_local->flags.yvalue)); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"RS232Baudrate")==0) { strncpy(daemon_local->flags.bvalue,value,sizeof(daemon_local->flags.bvalue)); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"ECUId")==0) { strncpy(daemon_local->flags.evalue,value,sizeof(daemon_local->flags.evalue)); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"PersistanceStoragePath")==0) { strncpy(daemon_local->flags.ivalue,value,sizeof(daemon_local->flags.ivalue)); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"LoggingMode")==0) + { + daemon_local->flags.loggingMode = atoi(value); + //printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"LoggingLevel")==0) + { + daemon_local->flags.loggingLevel = atoi(value); + //printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"LoggingFilename")==0) + { + strncpy(daemon_local->flags.loggingFilename,value,sizeof(daemon_local->flags.loggingFilename)); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"SharedMemorySize")==0) { daemon_local->flags.sharedMemorySize = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"OfflineTraceDirectory")==0) { strncpy(daemon_local->flags.offlineTraceDirectory,value,sizeof(daemon_local->flags.offlineTraceDirectory)); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"OfflineTraceFileSize")==0) { daemon_local->flags.offlineTraceFileSize = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else if(strcmp(token,"OfflineTraceMaxSize")==0) { daemon_local->flags.offlineTraceMaxSize = atoi(value); - printf("Option: %s=%s\n",token,value); + //printf("Option: %s=%s\n",token,value); } else { fprintf(stderr, "Unknown option: %s=%s\n",token,value); } } - //printf ("Token: %s\n",pch); - } else { @@ -414,8 +418,10 @@ int main(int argc, char* argv[]) return -1; } - /* Initialize logging facility */ - dlt_log_init(daemon_local.flags.dflag); + /* Initialize internal logging facility */ + dlt_log_set_filename(daemon_local.flags.loggingFilename); + dlt_log_set_level(daemon_local.flags.loggingLevel); + dlt_log_init(daemon_local.flags.loggingMode); /* Print version information */ dlt_get_version(version); @@ -545,22 +551,6 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in signal(SIGQUIT, dlt_daemon_signal_handler); signal(SIGINT, dlt_daemon_signal_handler); -#if 0 - /* open DLT output file */ - daemon_local->ohandle=-1; - if (daemon_local->flags.ovalue[0]) - { - daemon_local->ohandle = open(daemon_local->flags.ovalue,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ - if (daemon_local->ohandle == -1) - { - /* Return value ignored, dlt daemon will exit */ - dlt_file_free(&(daemon_local->file),daemon_local->flags.vflag); - sprintf(str,"Output file %s cannot be opened!\n",daemon_local->flags.ovalue); - dlt_log(LOG_ERR, str); - return -1; - } /* if */ - } /* if */ -#endif /* init offline trace */ if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) { diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 9d71a6e..bc3ba39 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -110,6 +110,9 @@ typedef struct char offlineTraceDirectory[256]; /**< (String: Directory) Store DLT messages to local directory (Default: /etc/dlt.conf) */
int offlineTraceFileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */
int offlineTraceMaxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */
+ int loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */
+ int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */
+ char loggingFilename[256]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */
} DltDaemonFlags;
/**
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf index 629794d..a410d19 100644 --- a/src/daemon/dlt.conf +++ b/src/daemon/dlt.conf @@ -30,6 +30,17 @@ SharedMemorySize = 40000 # Directory where to store the persistant configuration (Default: /tmp) # PersistanceStoragePath = /tmp +# The logging console for internal logging of dlt-daemon (Default: 0) +# 0 = log to stdout, 1 = log to syslog, 2 = log to file (see LoggingFilename) +LoggingMode = 2 + +# The internal log level, up to which logs are written (Default: 6) +# LOG_EMERG = 0, LOG_ALERT = 1, LOG_CRIT = 2, LOG_ERR = 3, LOG_WARNING = 4, LOG_NOTICE = 5, LOG_INFO = 6, LOG_DEBUG = 7 +LoggingLevel = 6 + +# The logging filename if internal logging mode is log to file (Default: /tmp/log) +LoggingFilename = /tmp/dlt.log + ######################################################################## # Offline Trace memory # ######################################################################## diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index dbb1e7a..4877825 100755 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -907,11 +907,13 @@ int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int ve if(strcmp(token,"LoggingMode")==0) { daemon->mode = atoi(value); - printf("Option: %s=%s\n",token,value); + sprintf(str,"Runtime Option: %s=%d\n",token,daemon->mode); + dlt_log(LOG_INFO, str); } else { - fprintf(stderr, "Unknown option: %s=%s\n",token,value); + sprintf(str,"Unknown option: %s=%s\n",token,value); + dlt_log(LOG_ERR, str); } } } @@ -924,7 +926,8 @@ int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int ve } else { - fprintf(stderr, "Cannot open configuration file: %s\n",filename); + sprintf(str,"Cannot open configuration file: %s\n",filename); + dlt_log(LOG_WARNING, str); } return 0; diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 4ac7dbe..bf363b7 100755 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -114,7 +114,11 @@ static char str[DLT_COMMON_BUFFER_LENGTH]; const char dltSerialHeader[DLT_ID_SIZE] = { 'D','L','S',1 }; char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D','L','S',1 }; -static int log_as_daemon = 0; +/* internal logging parameters */ +static int logging_mode = 0; +static int logging_level = 6; +static char logging_filename[256] = ""; +static FILE *logging_handle = 0; char *message_type[] = {"log","app_trace","nw_trace","control","","","",""}; char *log_info[] = {"","fatal","error","warn","info","debug","verbose","","","","","","","","",""}; @@ -1952,14 +1956,37 @@ int dlt_file_free(DltFile *file,int verbose) return dlt_message_free(&(file->msg),verbose); } +void dlt_log_set_level(int level) +{ + logging_level = level; +} + +void dlt_log_set_filename(const char *filename) +{ + strncpy(logging_filename,filename,sizeof(logging_filename)); +} + void dlt_log_init(int mode) { - log_as_daemon = mode; + logging_mode = mode; + + if(logging_mode == 2) + { + /* internal logging to file */ + logging_handle = fopen(logging_filename,"w"); + if (logging_handle == 0) + { + printf("Internal log file %s cannot be opened!\n",logging_filename); + return; + } + } } void dlt_log_free(void) { - /* Nothing to be done yet */ + if(logging_mode == 2) { + fclose(logging_handle); + } } int dlt_log(int prio, char *s) @@ -1970,68 +1997,80 @@ int dlt_log(int prio, char *s) { return -1; } + if(logging_level<prio) + { + return 0; + } switch (prio) { case LOG_EMERG: { - strcpy(logfmtstring,"DLT| EMERGENCY: %s"); + strncpy(logfmtstring,"DLT| EMERGENCY: %s",sizeof(logfmtstring)); break; } case LOG_ALERT: { - strcpy(logfmtstring,"DLT| ALERT: %s"); + strncpy(logfmtstring,"DLT| ALERT: %s",sizeof(logfmtstring)); break; } case LOG_CRIT: { - strcpy(logfmtstring,"DLT| CRITICAL: %s"); + strncpy(logfmtstring,"DLT| CRITICAL: %s",sizeof(logfmtstring)); break; } case LOG_ERR: { - strcpy(logfmtstring,"DLT| ERROR: %s"); + strncpy(logfmtstring,"DLT| ERROR: %s",sizeof(logfmtstring)); break; } case LOG_WARNING: { - strcpy(logfmtstring,"DLT| WARNING: %s"); + strncpy(logfmtstring,"DLT| WARNING: %s",sizeof(logfmtstring)); break; } case LOG_NOTICE: { - strcpy(logfmtstring,"DLT| NOTICE: %s"); + strncpy(logfmtstring,"DLT| NOTICE: %s",sizeof(logfmtstring)); break; } case LOG_INFO: { - strcpy(logfmtstring,"DLT| INFO: %s"); + strncpy(logfmtstring,"DLT| INFO: %s",sizeof(logfmtstring)); break; } case LOG_DEBUG: { - strcpy(logfmtstring,"DLT| DEBUG: %s"); + strncpy(logfmtstring,"DLT| DEBUG: %s",sizeof(logfmtstring)); break; } default: { - strcpy(logfmtstring,"DLT| %s"); + strncpy(logfmtstring,"DLT| %s",sizeof(logfmtstring)); break; } } + switch(logging_mode) + { + case 0: + /* log to stdout */ + printf(logfmtstring, s); + break; + case 1: + /* log to syslog */ #if !defined (__WIN32__) && !defined(_MSC_VER) - if (log_as_daemon) - { - openlog("DLT",LOG_PID,LOG_DAEMON); - syslog(prio, logfmtstring, s); - closelog(); - } - else + openlog("DLT",LOG_PID,LOG_DAEMON); + syslog(prio, logfmtstring, s); + closelog(); #endif - { - printf(logfmtstring, s); - } + break; + case 2: + /* log to file */ + if(logging_handle) + fprintf(logging_handle,logfmtstring, s); + break; + } return 0; } diff --git a/src/shared/dlt_shm.c b/src/shared/dlt_shm.c index 74e448e..5ad4775 100644 --- a/src/shared/dlt_shm.c +++ b/src/shared/dlt_shm.c @@ -73,6 +73,11 @@ #include <stdio.h> #include <string.h> +#if !defined(_MSC_VER) +#include <unistd.h> +#include <syslog.h> +#endif + #include <dlt_shm.h> #include <dlt_common.h> @@ -98,12 +103,13 @@ void dlt_shm_pv(int id,int operation) semaphor.sem_flg = SEM_UNDO; if(semop(id, &semaphor,1) == -1) { - perror("SHM: semop"); + dlt_log(LOG_ERR,"SHM: semop"); } } int dlt_shm_init_server(DltShm *buf,int key,int size) { struct shmid_ds shm_buf; + char str[256]; // Init parameters buf->shm = NULL; @@ -114,32 +120,32 @@ int dlt_shm_init_server(DltShm *buf,int key,int size) { // Create the segment. if ((buf->shmid = shmget(key, size, IPC_CREAT | 0666)) < 0) { - perror("SHM: shmget"); + dlt_log(LOG_ERR,"SHM: shmget"); return -1; /* ERROR */ } // get the size of shm if (shmctl(buf->shmid, IPC_STAT, &shm_buf)) { - perror("SHM: shmctl"); + dlt_log(LOG_ERR,"SHM: shmctl"); return -1; /* ERROR */ } // Now we attach the segment to our data space. if ((buf->shm = shmat(buf->shmid, NULL, 0)) == (char *) -1) { - perror("SHM: shmat"); + dlt_log(LOG_ERR,"SHM: shmat"); return -1; /* ERROR */ } // Init semaphore if( (buf->semid = semget(DLT_SHM_SEM,1,S_IRWXU|S_IRWXG|S_IRWXO|IPC_CREAT|IPC_EXCL)) == -1 ) { if( (buf->semid = semget(DLT_SHM_SEM,1,S_IRWXU|S_IRWXG|S_IRWXO|IPC_EXCL)) == -1 ) { - perror("SHM: semget"); + dlt_log(LOG_ERR,"SHM: semget"); return -1; /* ERROR */ } } if( semctl(buf->semid,0,SETVAL,(int)1) == -1 ) { - perror("SHM: semctl"); + dlt_log(LOG_ERR,"SHM: semctl"); return -1; /* ERROR */ } @@ -153,9 +159,8 @@ int dlt_shm_init_server(DltShm *buf,int key,int size) { // clear memory memset(buf->mem,0,buf->size); - //dlt_shm_status(buf); - //dlt_shm_info(buf); - printf("SHM: Size %d\n",buf->size); + snprintf(str,sizeof(str),"SHM: Size %d\n",buf->size); + dlt_log(LOG_INFO, str); return 0; /* OK */ } @@ -172,61 +177,69 @@ int dlt_shm_init_client(DltShm *buf,int key) { // Create the segment. if ((buf->shmid = shmget(key, 0, 0666)) < 0) { - perror("SHM: shmget"); + dlt_log(LOG_ERR,"SHM: shmget"); return -1; /* ERROR */ } // get the size of shm if (shmctl(buf->shmid, IPC_STAT, &shm_buf)) { - perror("SHM: shmctl"); - return -1; /* ERROR */ + dlt_log(LOG_ERR,"SHM: shmctl"); + return -1; /* ERROR */ } - // Now we attach the segment to our data space. - if ((buf->shm = shmat(buf->shmid, NULL, 0)) == (char *) -1) { - perror("shmat"); - return -1; /* ERROR */ - } + // Now we attach the segment to our data space. + if ((buf->shm = shmat(buf->shmid, NULL, 0)) == (char *) -1) { + dlt_log(LOG_ERR,"shmat"); + return -1; /* ERROR */ + } // Init semaphore if( (buf->semid = semget(DLT_SHM_SEM,0,0)) == -1 ) { - perror("SHM: semget"); - return -1; /* ERROR */ + dlt_log(LOG_ERR,"SHM: semget"); + return -1; /* ERROR */ } // Init pointers - buf->mem = (char*)(&(((int*)(buf->shm))[3])); - buf->size = shm_buf.shm_segsz - (buf->mem - buf->shm); + buf->mem = (char*)(&(((int*)(buf->shm))[3])); + buf->size = shm_buf.shm_segsz - (buf->mem - buf->shm); //dlt_shm_status(buf); - //dlt_shm_info(buf); + //dlt_shm_info(buf); return 0; /* OK */ } void dlt_shm_info(DltShm *buf) { + char str[256]; - printf("SHM: SHM id: %d\n",buf->shmid); - printf("SHM: Available size: %d\n",buf->size); - printf("SHM: SHM full start address: %lX\n",(unsigned long)buf->shm); - printf("SHM: SHM start address: %lX\n",(unsigned long)buf->mem); + snprintf(str,sizeof(str),"SHM: SHM id: %d\n",buf->shmid); + dlt_log(LOG_INFO, str); + snprintf(str,sizeof(str),"SHM: Available size: %d\n",buf->size); + dlt_log(LOG_INFO, str); + snprintf(str,sizeof(str),"SHM: SHM full start address: %lX\n",(unsigned long)buf->shm); + dlt_log(LOG_INFO, str); + snprintf(str,sizeof(str),"SHM: SHM start address: %lX\n",(unsigned long)buf->mem); + dlt_log(LOG_INFO, str); } void dlt_shm_status(DltShm *buf) { int write, read, count; + char str[256]; write = ((int*)(buf->shm))[0]; read = ((int*)(buf->shm))[1]; count = ((int*)(buf->shm))[2]; - printf("SHM: Write: %d\n",write); - printf("SHM: Read: %d\n",read); - printf("SHM: Count: %d\n",count); - + snprintf(str,sizeof(str),"SHM: Write: %d\n",write); + dlt_log(LOG_INFO, str); + snprintf(str,sizeof(str),"SHM: Read: %d\n",read); + dlt_log(LOG_INFO, str); + snprintf(str,sizeof(str),"SHM: Count: %d\n",count); + dlt_log(LOG_INFO, str); } int dlt_shm_get_total_size(DltShm *buf) @@ -268,7 +281,7 @@ int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const if(!buf->mem) { // shm not initialised - //printf("SHM: SHM not initialised\n"); + dlt_log(LOG_ERR,"SHM: SHM not initialised\n"); return -1; /* ERROR */ } @@ -284,13 +297,13 @@ int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const if(read==write && count) { // shm buffer is full DLT_SHM_SEM_FREE(buf->semid); - //printf("SHM is totally full\n"); + dlt_log(LOG_ERR,"SHM is totally full\n"); return -1; // ERROR } else if(write >= buf->size) { if((size1+size2+size3+sizeof(head)+sizeof(unsigned char)+sizeof(int)) > read) { DLT_SHM_SEM_FREE(buf->semid); - //printf("SHM is full at start\n"); + dlt_log(LOG_ERR,"SHM is full at start\n"); return -1; // ERROR } write = 0; @@ -298,7 +311,7 @@ int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const else if(read > write) { if((write + size1+size2+size3+sizeof(head)+sizeof(unsigned char)+sizeof(int)) > read) { DLT_SHM_SEM_FREE(buf->semid); - //printf("SHM is full at end\n"); + dlt_log(LOG_ERR,"SHM is full at end\n"); return -1; // ERROR } } @@ -309,7 +322,7 @@ int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const // try write at beginning if((size1+size2+size3+sizeof(head)+sizeof(unsigned char)+sizeof(int)) > read) { DLT_SHM_SEM_FREE(buf->semid); - //printf("SHM is full at start\n"); + dlt_log(LOG_ERR,"SHM is full at start\n"); return -1; // ERROR } // write zero status and size at end if possible @@ -360,7 +373,7 @@ int dlt_shm_pull(DltShm *buf,unsigned char *data, int max_size) if(!buf->mem) { // shm not initialised - printf("SHM: SHM not initialised\n"); + dlt_log(LOG_ERR,"SHM: SHM not initialised\n"); return -1; /* ERROR */ } @@ -401,20 +414,23 @@ int dlt_shm_pull(DltShm *buf,unsigned char *data, int max_size) if(status != 2 ) { //printf("Buffer is not fully written\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"Buffer is not fully written\n"); return -1; // ERROR } // plausibility check of buffer size if( (read+size) > buf->size) { - printf("SHM: Buffers size bigger than shm buffer\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"SHM: Buffers size bigger than shm buffer\n"); + dlt_shm_reset(buf); return -1; // ERROR } // check max read size if(size > max_size) { - printf("SHM: Buffer is bigger than max size\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"SHM: Buffer is bigger than max size\n"); + dlt_shm_reset(buf); return -1; // ERROR } @@ -448,7 +464,7 @@ int dlt_shm_copy(DltShm *buf,unsigned char *data, int max_size) if(!buf->mem) { // shm not initialised - printf("SHM: SHM not initialised\n"); + dlt_log(LOG_ERR,"SHM: SHM not initialised\n"); return -1; /* ERROR */ } @@ -488,22 +504,24 @@ int dlt_shm_copy(DltShm *buf,unsigned char *data, int max_size) // check status if(status != 2 ) { - //printf("Buffer is not fully written\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"Buffer is not fully written\n"); return -1; // ERROR } // plausibility check of buffer size if( (read+size) > buf->size) { - printf("SHM: Buffers size bigger than shm buffer\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"SHM: Buffers size bigger than shm buffer\n"); + dlt_shm_reset(buf); return -1; // ERROR } // check max read size if((size-sizeof(head)) > max_size) { - printf("SHM: Buffer is bigger than max size\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"SHM: Buffer is bigger than max size\n"); + dlt_shm_reset(buf); return -1; // ERROR } @@ -522,7 +540,7 @@ int dlt_shm_remove(DltShm *buf) if(!buf->mem) { // shm not initialised - printf("SHM: SHM not initialised\n"); + dlt_log(LOG_ERR,"SHM: SHM not initialised\n"); return -1; /* ERROR */ } @@ -562,15 +580,16 @@ int dlt_shm_remove(DltShm *buf) // check status if(status != 2 ) { - //printf("Buffer is not fully written\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"Buffer is not fully written\n"); return -1; // ERROR } // plausibility check of buffer size if( (read+size) > buf->size) { - printf("SHM: Buffers size bigger than shm buffer\n"); DLT_SHM_SEM_FREE(buf->semid); + dlt_log(LOG_ERR,"SHM: Buffers size bigger than shm buffer\n"); + dlt_shm_reset(buf); return -1; // ERROR } @@ -585,13 +604,13 @@ int dlt_shm_remove(DltShm *buf) int dlt_shm_reset(DltShm *buf) { - printf("SHM: Pointer corrupted; reset triggered.\n"); + dlt_log(LOG_ERR,"SHM: Pointer corrupted; reset triggered.\n"); /* reset pointers and counters */ DLT_SHM_SEM_GET(buf->semid); - ((int*)(buf->shm))[0] = 0; // pointer to write memory - ((int*)(buf->shm))[1] = 0; // pointer to read memory - ((int*)(buf->shm))[2] = 0; // number of packets + ((int*)(buf->shm))[0] = 0; // pointer to write memory + ((int*)(buf->shm))[1] = 0; // pointer to read memory + ((int*)(buf->shm))[2] = 0; // number of packets DLT_SHM_SEM_FREE(buf->semid); return 0; /* OK */ @@ -604,7 +623,7 @@ int dlt_shm_recover(DltShm *buf) { // initialise head head[3] = 0x01; - printf("SHM: Head not found; try to recover.\n"); + dlt_log(LOG_ERR,"SHM: Head not found; try to recover.\n"); /* try to find next valid message */ DLT_SHM_SEM_GET(buf->semid); @@ -658,22 +677,22 @@ int dlt_shm_recover(DltShm *buf) { int dlt_shm_free_server(DltShm *buf) { if(!buf->shm) { - printf("SHM: Shared memory segment not attached\n"); + dlt_log(LOG_ERR,"SHM: Shared memory segment not attached\n"); return -1; /* ERROR */ } if(shmdt(buf->shm)) { - perror("SHM: shmdt"); + dlt_log(LOG_ERR,"SHM: shmdt"); return -1; /* ERROR */ } if(shmctl(buf->shmid,IPC_RMID,NULL) == -1) { - perror("SHM: shmdt"); + dlt_log(LOG_ERR,"SHM: shmdt"); return -1; /* ERROR */ } if(semctl(buf->semid,0,IPC_RMID,(int)0) == -1) { - perror("SHM: shmdt"); + dlt_log(LOG_ERR,"SHM: shmdt"); return -1; /* ERROR */ } @@ -690,12 +709,12 @@ int dlt_shm_free_server(DltShm *buf) { int dlt_shm_free_client(DltShm *buf) { if(!buf->shm) { - printf("SHM: Shared memory segment not attached\n"); + dlt_log(LOG_ERR,"SHM: Shared memory segment not attached\n"); return -1; /* ERROR */ } if(shmdt(buf->shm)) { - perror("SHM: shmdt"); + dlt_log(LOG_ERR,"SHM: shmdt"); return -1; /* ERROR */ } |