summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLassi Marttala <lassi.lm.marttala@partner.bmw.com>2012-02-21 10:56:16 +0100
committerChristian Muck <christian.muck@bmw.de>2012-04-04 14:30:01 +0200
commit83059468ecd8ca6a68901f20477615cb58808c94 (patch)
treef0809acf0e0c9d42ce823bb40ef528f924e1de41
parent71cc80ac25166a65b0cea363c4d77314bbaf7f5e (diff)
downloadDLT-daemon-83059468ecd8ca6a68901f20477615cb58808c94.tar.gz
GENDLT-15, Rename buffer size constant to avoid confusion.
Better error handling when writing to FIFO. Remove duplicate msg initialization. Optimize away multiple uses of strlen for one check. Signed-off-by: Christian Muck <christian.muck@bmw.de>
-rwxr-xr-xsrc/daemon/dlt_daemon_common.c34
-rwxr-xr-xsrc/daemon/dlt_daemon_common_cfg.h2
-rwxr-xr-xsrc/lib/dlt_user.c7
3 files changed, 20 insertions, 23 deletions
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index fe82ec1..7207b4c 100755
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -80,7 +80,7 @@
#include "dlt_user_shared.h"
#include "dlt_user_shared_cfg.h"
-static char str[DLT_DAEMON_TEXTBUFSIZE];
+static char str[DLT_DAEMON_COMMON_TEXTBUFSIZE];
sem_t dlt_daemon_mutex;
@@ -245,7 +245,7 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi
DltDaemonApplication *old;
int new_application;
int dlt_user_handle;
- char filename[DLT_DAEMON_TEXTBUFSIZE];
+ char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE];
if ((daemon==0) || (apid==0) || (apid[0]=='\0'))
{
@@ -412,7 +412,7 @@ int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int ver
{
FILE *fd;
ID4 apid;
- char buf[DLT_DAEMON_TEXTBUFSIZE];
+ char buf[DLT_DAEMON_COMMON_TEXTBUFSIZE];
char *ret;
char *pb;
@@ -728,7 +728,7 @@ int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose
{
FILE *fd;
ID4 apid, ctid;
- char buf[DLT_DAEMON_TEXTBUFSIZE];
+ char buf[DLT_DAEMON_COMMON_TEXTBUFSIZE];
char *ret;
char *pb;
int ll, ts;
@@ -1248,11 +1248,13 @@ void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltMessag
memcpy(userbuffer,ptr,data_length_inject); /* Copy received injection to send buffer */
/* write to FIFO */
- if (dlt_user_log_out3(context->user_handle, &(userheader), sizeof(DltUserHeader),
- &(usercontext), sizeof(DltUserControlMsgInjection),
- userbuffer, data_length_inject)!=DLT_RETURN_OK)
+ DltReturnValue ret =
+ dlt_user_log_out3(context->user_handle, &(userheader), sizeof(DltUserHeader),
+ &(usercontext), sizeof(DltUserControlMsgInjection),
+ userbuffer, data_length_inject);
+ if (ret != DLT_RETURN_OK)
{
- if (errno==EPIPE)
+ if (ret == DLT_RETURN_PIPE_ERROR)
{
/* Close connection */
close(context->user_handle);
@@ -1462,7 +1464,7 @@ void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltMessa
void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int verbose)
{
- char version[DLT_DAEMON_TEXTBUFSIZE];
+ char version[DLT_DAEMON_COMMON_TEXTBUFSIZE];
DltMessage msg;
uint32_t len;
DltServiceGetSoftwareVersionResponse *resp;
@@ -2273,14 +2275,6 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose)
return;
}
- /* prepare payload of data */
- msg.datasize = 0;
- if (msg.databuffer)
- {
- free(msg.databuffer);
- }
- msg.databuffer = 0;
-
/* send message */
/* prepare storage header */
@@ -2340,7 +2334,8 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose)
/* Send data */
ret=write(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
- ret=write(sock, msg.databuffer,msg.datasize);
+ if(msg.datasize > 0)
+ ret=write(sock, msg.databuffer,msg.datasize);
DLT_DAEMON_SEM_FREE();
}
@@ -2356,7 +2351,8 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose)
/* Send data */
send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0);
- send(sock, msg.databuffer,msg.datasize,0);
+ if(msg.datasize > 0)
+ send(sock, msg.databuffer,msg.datasize,0);
DLT_DAEMON_SEM_FREE();
}
diff --git a/src/daemon/dlt_daemon_common_cfg.h b/src/daemon/dlt_daemon_common_cfg.h
index 5783708..ba28f24 100755
--- a/src/daemon/dlt_daemon_common_cfg.h
+++ b/src/daemon/dlt_daemon_common_cfg.h
@@ -80,7 +80,7 @@
#define DLT_RUNTIME_CONFIGURATION "/dlt-runtime.cfg"
/* Size of text buffer */
-#define DLT_DAEMON_TEXTBUFSIZE 255
+#define DLT_DAEMON_COMMON_TEXTBUFSIZE 255
/* Initial log level */
#define DLT_DAEMON_INITIAL_LOG_LEVEL DLT_LOG_INFO
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 568ae86..89daac2 100755
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -667,11 +667,12 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const
if (description!=0)
{
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = malloc(strlen(description)+1);
- strncpy(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description, description, strlen(description));
+ int desc_lne = strlen(description);
+ dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = malloc(desc_len+1);
+ strncpy(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description, description, strlen(desc_len));
/* Terminate transmitted string with 0 */
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[strlen(description)]='\0';
+ dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len]='\0';
}
if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)