summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-08-02 09:37:51 +0200
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-08-07 14:26:56 +0200
commitd7f3cce7b39d567380a3cf8630a9312c3b5689a8 (patch)
tree3ee69cd6ea08551d37ec806c21efc65688dd21cb /src/daemon
parent8b5631a9595c53b2384cd8f79e64f6f0d0f777f2 (diff)
downloadDLT-daemon-d7f3cce7b39d567380a3cf8630a9312c3b5689a8.tar.gz
Bug 44 - Don't print "Buffer full" message from DLT daemon for each trace.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/dlt-daemon.c80
-rwxr-xr-xsrc/daemon/dlt-daemon.h1
-rw-r--r--src/daemon/dlt_daemon_common.c37
-rw-r--r--src/daemon/dlt_daemon_common.h7
4 files changed, 105 insertions, 20 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 64a8acd..a44d028 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -1522,6 +1522,7 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
int j, sent;
+ DltUserControlMsgBufferOverflow *userpayload;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1531,6 +1532,15 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *
return -1;
}
+ if (daemon_local->receiver.bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgBufferOverflow)))
+ {
+ /* Not enough bytes received */
+ return -1;
+ }
+
+ /* get the payload of the user message */
+ userpayload = (DltUserControlMsgBufferOverflow*) (daemon_local->receiver.buf+sizeof(DltUserHeader));
+
/* Store in daemon, that a message buffer overflow has occured */
daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
@@ -1545,7 +1555,7 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *
/* except the listener and ourselves */
if ((j != daemon_local->fp) && (j != daemon_local->sock))
{
- dlt_daemon_control_message_buffer_overflow(j, daemon, verbose);
+ dlt_daemon_control_message_buffer_overflow(j, daemon, userpayload->overflow_counter,userpayload->apid,verbose);
sent=1;
/* Reset overflow state */
daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
@@ -1556,11 +1566,17 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *
/* message was not sent, so store it in ringbuffer */
if (sent==0)
{
- dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_STORE_TO_BUFFER, daemon, verbose);
+ if(dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_STORE_TO_BUFFER, daemon, userpayload->overflow_counter,
+ userpayload->apid,verbose))
+ {
+ /* there was an error when storing message */
+ /* add the counter of lost messages to the daemon counter */
+ daemon->overflow_counter+=userpayload->overflow_counter;
+ }
}
/* keep not read data in buffer */
- if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader))==-1)
+ if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader)+sizeof(DltUserControlMsgBufferOverflow))==-1)
{
dlt_log(LOG_ERR,"Can't remove bytes from receiver for user message overflow\n");
return -1;
@@ -1569,6 +1585,49 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *
return 0;
}
+int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+{
+ int j, sent;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon==0) || (daemon_local==0))
+ {
+ dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_message_overflow()\n");
+ return -1;
+ }
+
+ /* Store in daemon, that a message buffer overflow has occured */
+ daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
+
+ /* look if TCP connection to client is available */
+ sent = 0;
+
+ for (j = 0; j <= daemon_local->fdmax; j++)
+ {
+ /* send to everyone! */
+ if (FD_ISSET(j, &(daemon_local->master)))
+ {
+ /* except the listener and ourselves */
+ if ((j != daemon_local->fp) && (j != daemon_local->sock))
+ {
+ dlt_daemon_control_message_buffer_overflow(j, daemon,daemon->overflow_counter,"", verbose);
+ sent=1;
+ /* Reset overflow state */
+ daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
+ } /* if */
+ } /* if */
+ } /* for */
+
+ /* message was not sent, so store it in ringbuffer */
+ if (sent==0)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
uint32_t len=0;
@@ -2004,6 +2063,17 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
sent = 1;
}
+ /* check if overflow occurred */
+ if(daemon->overflow_counter)
+ {
+ if(dlt_daemon_send_message_overflow(daemon,daemon_local,verbose)==0)
+ {
+ sprintf(str,"%u messages discarded!\n",daemon->overflow_counter);
+ dlt_log(LOG_ERR, str);
+ daemon->overflow_counter=0;
+ }
+ }
+
/* look if TCP connection to client is available */
for (j = 0;((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && (j <= daemon_local->fdmax); j++)
{
@@ -2080,7 +2150,9 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
0, 0
)<0)
{
- dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n");
+ if(daemon->overflow_counter==0)
+ dlt_log(LOG_ERR,"Buffer full! Messages will be discarded.\n");
+ daemon->overflow_counter+=1;
}
DLT_DAEMON_SEM_FREE();
}
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index b256cc3..f2b1dd9 100755
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -166,6 +166,7 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal
int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
+int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index afedff9..b817ce9 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -136,6 +136,7 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
+ daemon->overflow_counter = 0;
daemon->runtime_context_cfg_loaded = 0;
@@ -1266,7 +1267,7 @@ int dlt_daemon_control_process_control(int sock, DltDaemon *daemon, DltMessage *
}
case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW:
{
- dlt_daemon_control_message_buffer_overflow(sock, daemon, verbose);
+ dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon->overflow_counter,"",verbose);
break;
}
default:
@@ -2075,7 +2076,7 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *ms
dlt_message_free(&resp,0);
}
-void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int verbose)
+int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, unsigned int overflow_counter,char* apid, int verbose)
{
DltMessage msg;
DltServiceMessageBufferOverflowResponse *resp;
@@ -2084,14 +2085,14 @@ void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int
if (daemon==0)
{
- return;
+ return -1;
}
/* initialise new message */
if (dlt_message_init(&msg,0)==-1)
{
dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
- return;
+ return -1;
}
/* prepare payload of data */
@@ -2111,19 +2112,26 @@ void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int
{
dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
}
- return;
+ return -1;
}
resp = (DltServiceMessageBufferOverflowResponse*) msg.databuffer;
resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW;
resp->status = DLT_SERVICE_RESPONSE_OK;
resp->overflow = daemon->message_buffer_overflow;
+ resp->overflow_counter = overflow_counter;
/* send message */
- dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose);
+ if(dlt_daemon_control_send_control_message(sock,daemon,&msg,apid,"", verbose))
+ {
+ dlt_message_free(&msg,0);
+ return -1;
+ }
/* free message */
dlt_message_free(&msg,0);
+
+ return 0;
}
void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, uint32_t service_id, int8_t status , int verbose)
@@ -2171,7 +2179,7 @@ void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, uint32_t
dlt_message_free(&msg,0);
}
-void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* ctid, int verbose)
+int dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* ctid, int verbose)
{
ssize_t ret;
int32_t len;
@@ -2180,7 +2188,7 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe
if ((daemon==0) || (msg==0) || (appid==0) || (ctid==0))
{
- return;
+ return -1;
}
/* prepare storage header */
@@ -2188,7 +2196,7 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe
if (dlt_set_storageheader(msg->storageheader,daemon->ecuid)==-1)
{
- return;
+ return -1;
}
/* prepare standard header */
@@ -2239,7 +2247,7 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe
if (len>UINT16_MAX)
{
dlt_log(LOG_CRIT,"Huge control message discarded!\n");
- return;
+ return -1;
}
msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len));
@@ -2259,7 +2267,7 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe
{
dlt_log(LOG_CRIT,"dlt_daemon_control_send_control_message: write dltSerialHeader failed\n");
DLT_DAEMON_SEM_FREE();
- return;
+ return -1;
}
}
@@ -2269,14 +2277,14 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe
{
dlt_log(LOG_CRIT,"dlt_daemon_control_send_control_message: write msg->headerbuffer failed\n");
DLT_DAEMON_SEM_FREE();
- return;
+ return -1;
}
ret=write(sock, msg->databuffer,msg->datasize);
if (0 > ret)
{
dlt_log(LOG_CRIT,"dlt_daemon_control_send_control_message: write msg->databuffer failed\n");
DLT_DAEMON_SEM_FREE();
- return;
+ return -1;
}
DLT_DAEMON_SEM_FREE();
@@ -2316,10 +2324,11 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe
{
DLT_DAEMON_SEM_FREE();
dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n");
- return;
+ return -1;
}
DLT_DAEMON_SEM_FREE();
}
+ return 0;
}
void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose)
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 2798491..b93f0c2 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -133,6 +133,7 @@ typedef struct
int8_t default_log_level; /**< Default log level (of daemon) */
int8_t default_trace_status; /**< Default trace status (of daemon) */
int message_buffer_overflow; /**< Set to one, if buffer overflow has occured, zero otherwise */
+ unsigned int overflow_counter; /**< counts the number of lost messages. */
int runtime_context_cfg_loaded; /**< Set to one, if runtime context configuration has been loaded, zero otherwise */
char ecuid[DLT_ID_SIZE]; /**< ECU ID of daemon */
int sendserialheader; /**< 1: send serial header; 0 don't send serial header */
@@ -360,8 +361,9 @@ void dlt_daemon_control_service_response(int sock, DltDaemon *daemon, uint32_t s
* @param appid pointer to application id to be used in response message
* @param contid pointer to context id to be used in response message
* @param verbose if set to true verbose information is printed out.
+ * @return -1 if there is an error or buffer is full
*/
-void dlt_daemon_control_send_control_message(int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* contid, int verbose);
+int dlt_daemon_control_send_control_message(int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* contid, int verbose);
/**
* Process and generate response to received sw injection control message
@@ -438,8 +440,9 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *ms
* @param sock connection handle used for sending response
* @param daemon pointer to dlt daemon structure
* @param verbose if set to true verbose information is printed out.
+ * @return -1 if there is an error or buffer overflow, else 0
*/
-void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int verbose);
+int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, unsigned int overflow_counter,char* apid, int verbose);
/**
* Process reset to factory default control message
* @param daemon pointer to dlt daemon structure