summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Brandner <simon.brandner@partner.bmw.de>2013-01-28 12:14:06 +0100
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-07-19 16:54:38 +0200
commite2943ff4cf2d7d2da4000e2ca35663a7c83675d7 (patch)
tree1a710a70a5190dacdb26c02da6cb570271f5d506
parent733a1111254882aec6ebc9c90bb690aaee3f2773 (diff)
downloadDLT-daemon-e2943ff4cf2d7d2da4000e2ca35663a7c83675d7.tar.gz
Semaphores and Pointer passing insteasd by value and otehr coverity issue fixes
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r--src/daemon/dlt-daemon.c14
-rw-r--r--src/daemon/dlt_daemon_common.c13
-rw-r--r--src/lib/dlt_user.c5
-rwxr-xr-xsrc/shared/dlt_common.c15
-rw-r--r--src/shared/dlt_offline_trace.c23
-rw-r--r--src/system/dlt-system-logfile.c18
-rw-r--r--src/system/dlt-system-process-handling.c10
-rw-r--r--src/system/dlt-system-processes.c16
-rwxr-xr-xsrc/tests/dlt-test-client.c2
9 files changed, 76 insertions, 40 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index ea9e43d..20cba66 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -1106,10 +1106,13 @@ void dlt_daemon_daemonize(int verbose)
/* Open standard descriptors stdin, stdout, stderr */
i=open("/dev/null",O_RDWR); /* open stdin */
- if(dup(i) < 0)
- dlt_log(LOG_ERR, "Failed to direct stdout to /dev/null.\n");/* stdout */
- if(dup(i) < 0)
- dlt_log(LOG_ERR, "Failed to direct stderr to /dev/null.\n"); /* stderr */
+ if (-1 < i)
+ {
+ if(dup(i) < 0)
+ dlt_log(LOG_ERR, "Failed to direct stdout to /dev/null.\n");/* stdout */
+ if(dup(i) < 0)
+ dlt_log(LOG_ERR, "Failed to direct stderr to /dev/null.\n"); /* stderr */
+ }
/* Set umask */
umask(DLT_DAEMON_UMASK);
@@ -1225,6 +1228,7 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon
if (dlt_receiver_receive_socket(&(daemon_local->receiverSock))<=0)
{
close(daemon_local->receiverSock.fd);
+ daemon_local->receiverSock.fd = 0;
FD_CLR(daemon_local->receiverSock.fd, &(daemon_local->master));
if (daemon_local->client_connections)
@@ -1252,7 +1256,7 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon
while (dlt_message_read(&(daemon_local->msg),(uint8_t*)daemon_local->receiverSock.buf,daemon_local->receiverSock.bytesRcvd,daemon_local->flags.nflag,daemon_local->flags.vflag)==0)
{
/* Check for control message */
- if (DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)))
+ if ( 0 != daemon_local->receiverSock.fd && DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)) )
{
dlt_daemon_control_process_control(daemon_local->receiverSock.fd, daemon, &(daemon_local->msg), daemon_local->flags.vflag);
}
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 12af44e..1b34f21 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -2523,13 +2523,20 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose)
/* Optional: Send serial header, if requested */
if (daemon->sendserialheader)
{
- send(sock, dltSerialHeader,sizeof(dltSerialHeader),0);
+ if ( -1 == send(sock, dltSerialHeader,sizeof(dltSerialHeader),0) )
+ dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send dltSerialHeader");
+
}
/* Send data */
- send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0);
+ if (-1 == send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0))
+ dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send DltStorageHeader");
+
if(msg.datasize > 0)
- send(sock, msg.databuffer,msg.datasize,0);
+ {
+ if (-1 == send(sock, msg.databuffer,msg.datasize,0) )
+ dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send databuffer");
+ }
DLT_DAEMON_SEM_FREE();
}
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 0728fb1..407154f 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -519,6 +519,7 @@ int dlt_free(void)
/* Ignore return value */
dlt_buffer_free_dynamic(&(dlt_user.startup_buffer));
+ DLT_SEM_LOCK();
if (dlt_user.dlt_ll_ts)
{
for (i=0;i<dlt_user.dlt_ll_ts_max_num_entries;i++)
@@ -536,6 +537,7 @@ int dlt_free(void)
dlt_user.dlt_ll_ts_max_num_entries = 0;
dlt_user.dlt_ll_ts_num_entries = 0;
}
+ DLT_SEM_FREE();
if (dlt_user.dlt_segmented_nwt_handle)
{
@@ -2142,7 +2144,8 @@ void dlt_user_trace_network_segmented_thread(void *unused)
if(dlt_user_log_resend_buffer() < 0)
{
// Requeue if still not empty
- dlt_user_queue_resend();
+ if ( dlt_user_queue_resend() < 0 )
+ dlt_log(LOG_WARNING, "Failed to queue resending in dlt_user_trace_network_segmented_thread.\n");
}
free(data);
continue;
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 7e9d852..fbc1934 100755
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -1484,7 +1484,8 @@ int dlt_file_read_header_raw(DltFile *file,int resync,int verbose)
else
{
/* go back to last file position */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (fseek(file->handle,file->file_position,SEEK_SET) < 0)
+ return -1;
}
}
@@ -1711,7 +1712,12 @@ int dlt_file_read(DltFile *file,int verbose)
}
/* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if ( fseek(file->handle,file->file_position,SEEK_SET) < 0 )
+ {
+ sprintf(str,"Seek failed to file_position %ld \n",file->file_position);
+ dlt_log(LOG_ERR, str);
+ return -1;
+ }
/* get file position at start of DLT message */
if (verbose)
@@ -1823,8 +1829,9 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose)
file->index = ptr;
}
- /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
- fseek(file->handle,file->file_position,SEEK_SET);
+ /* set to end of last successful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
+ if (fseek(file->handle,file->file_position,SEEK_SET) < 0)
+ return -1;
/* get file position at start of DLT message */
if (verbose)
diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c
index 72b31ad..80c328a 100644
--- a/src/shared/dlt_offline_trace.c
+++ b/src/shared/dlt_offline_trace.c
@@ -101,8 +101,10 @@ unsigned long dlt_offline_trace_get_total_size(DltOfflineTrace *trace) {
while ((dp=readdir(dir)) != NULL) {
if(strstr(dp->d_name,".dlt")) {
sprintf(filename,"%s/%s",trace->directory,dp->d_name);
- stat(filename,&status);
- size += status.st_size;
+ if ( 0 == stat(filename,&status) )
+ size += status.st_size;
+ else
+ printf("Offline trace file %s cannot be stat-ed",filename);
}
}
closedir(dir);
@@ -127,12 +129,17 @@ int dlt_offline_trace_delete_oldest_file(DltOfflineTrace *trace) {
while ((dp=readdir(dir)) != NULL) {
if(strstr(dp->d_name,".dlt")) {
sprintf(filename,"%s/%s",trace->directory,dp->d_name);
- stat(filename,&status);
- if(time_oldest == 0 || status.st_mtime < time_oldest) {
- time_oldest = status.st_mtime;
- size_oldest = status.st_size;
- strcpy(filename_oldest,filename);
- }
+ if (0 == stat(filename,&status))
+ {
+ if(time_oldest == 0 || status.st_mtime < time_oldest) {
+ time_oldest = status.st_mtime;
+ size_oldest = status.st_size;
+ strcpy(filename_oldest,filename);
+ }
+ }
+ else
+ printf("Old offline trace file %s cannot be stat-ed",filename);
+
}
}
closedir(dir);
diff --git a/src/system/dlt-system-logfile.c b/src/system/dlt-system-logfile.c
index 50964f2..1354b83 100644
--- a/src/system/dlt-system-logfile.c
+++ b/src/system/dlt-system-logfile.c
@@ -56,7 +56,7 @@ DLT_IMPORT_CONTEXT(dltsystem);
extern DltSystemThreads threads;
DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX];
-void send_file(LogFileOptions fileopt, int n)
+void send_file(LogFileOptions const *fileopt, int n)
{
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-logfile, sending file."));
@@ -66,7 +66,7 @@ void send_file(LogFileOptions fileopt, int n)
int bytes;
int seq = 1;
- pFile = fopen(fileopt.Filename[n],"r");
+ pFile = fopen((*fileopt).Filename[n],"r");
if(pFile != NULL)
{
@@ -91,19 +91,19 @@ void send_file(LogFileOptions fileopt, int n)
{
DLT_LOG(dltsystem, DLT_LOG_ERROR,
DLT_STRING("dlt-system-logfile, failed to open file."),
- DLT_STRING(fileopt.Filename[n]));
+ DLT_STRING((*fileopt).Filename[n]));
}
}
-void register_contexts(LogFileOptions fileopts)
+void register_contexts(LogFileOptions const *fileopts)
{
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-logfile, registering file contexts."));
int i;
- for(i = 0;i < fileopts.Count;i++)
+ for(i = 0;i < (*fileopts).Count;i++)
{
- DLT_REGISTER_CONTEXT(logfileContext[i], fileopts.ContextId[i],
- fileopts.Filename[i]);
+ DLT_REGISTER_CONTEXT(logfileContext[i], (*fileopts).ContextId[i],
+ (*fileopts).Filename[i]);
}
}
@@ -113,7 +113,7 @@ void logfile_thread(void *v_conf)
DLT_STRING("dlt-system-logfile, in thread."));
DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
- register_contexts(conf->LogFile);
+ register_contexts(&(conf->LogFile));
int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX];
int i;
@@ -130,7 +130,7 @@ void logfile_thread(void *v_conf)
if(logfile_delays[i] <= 0)
{
- send_file(conf->LogFile, i);
+ send_file(&(conf->LogFile), i);
logfile_delays[i] = conf->LogFile.TimeDelay[i];
if(conf->LogFile.Mode[i] == SEND_MODE_ONCE)
conf->LogFile.Mode[i] = SEND_MODE_OFF;
diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c
index 3ad7908..49c20e7 100644
--- a/src/system/dlt-system-process-handling.c
+++ b/src/system/dlt-system-process-handling.c
@@ -81,9 +81,16 @@ int daemonize()
close(i);
int fd = open("/dev/null",O_RDWR);
+ if(fd < 0)
+ {
+ return -1;
+ }
- if(fd < 0 || dup(fd) < 0 || dup(fd) < 0)
+ if(dup(fd) < 0 || dup(fd) < 0)
+ {
+ close(fd);
return -1;
+ }
/**
* Ignore signals related to child processes and
@@ -93,6 +100,7 @@ int daemonize()
signal(SIGTSTP, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
+ close(fd);
return 0;
}
diff --git a/src/system/dlt-system-processes.c b/src/system/dlt-system-processes.c
index ee37bfc..495c784 100644
--- a/src/system/dlt-system-processes.c
+++ b/src/system/dlt-system-processes.c
@@ -63,7 +63,7 @@ extern DltSystemThreads threads;
DLT_IMPORT_CONTEXT(dltsystem)
DLT_DECLARE_CONTEXT(procContext)
-void send_process(LogProcessOptions popts, int n)
+void send_process(LogProcessOptions const *popts, int n)
{
DLT_LOG(dltsystem, DLT_LOG_DEBUG,
DLT_STRING("dlt-system-processes, send process info."));
@@ -90,11 +90,11 @@ void send_process(LogProcessOptions popts, int n)
bytes = fread(buffer, 1, sizeof(buffer)-1, pFile);
fclose(pFile);
}
- if((strcmp(popts.Name[n], "*")==0) ||
- (strcmp(buffer, popts.Name[n])==0))
+ if((strcmp((*popts).Name[n], "*")==0) ||
+ (strcmp(buffer, (*popts).Name[n])==0))
{
found = 1;
- sprintf(filename, "/proc/%s/%s", dp->d_name,popts.Filename[n]);
+ sprintf(filename, "/proc/%s/%s", dp->d_name,(*popts).Filename[n]);
pFile = fopen(filename, "r");
if(pFile != NULL)
{
@@ -104,10 +104,10 @@ void send_process(LogProcessOptions popts, int n)
if(bytes>0)
{
buffer[bytes] = 0;
- DLT_LOG(procContext, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), DLT_STRING(popts.Filename[n]), DLT_STRING(buffer));
+ DLT_LOG(procContext, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), DLT_STRING((*popts).Filename[n]), DLT_STRING(buffer));
}
}
- if(strcmp(popts.Name[n], "*") !=0)
+ if(strcmp((*popts).Name[n], "*") !=0)
break;
}
}
@@ -121,7 +121,7 @@ void send_process(LogProcessOptions popts, int n)
}
if(!found) {
- DLT_LOG(procContext, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING(popts.Name[n]),DLT_STRING("not running!"));
+ DLT_LOG(procContext, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING((*popts).Name[n]),DLT_STRING("not running!"));
}
}
@@ -148,7 +148,7 @@ void logprocess_thread(void *v_conf)
if(process_delays[i] <= 0)
{
- send_process(conf->LogProcesses, i);
+ send_process(&(conf->LogProcesses), i);
process_delays[i] = conf->LogProcesses.TimeDelay[i];
if(conf->LogProcesses.Mode[i] == SEND_MODE_ONCE)
conf->LogProcesses.Mode[i] = SEND_MODE_OFF;
diff --git a/src/tests/dlt-test-client.c b/src/tests/dlt-test-client.c
index 3fb98cd..3855000 100755
--- a/src/tests/dlt-test-client.c
+++ b/src/tests/dlt-test-client.c
@@ -673,7 +673,7 @@ int dlt_testclient_message_callback(DltMessage *message, void *data)
/* Get length */
DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
- if ((length==datalength) && (length=10))
+ if ((length==datalength) && (10 == length))
{
dltdata->test_counter_macro[1]++;
}