static void dlt_user_log_reattach_to_daemon(void);
static int dlt_user_log_send_overflow(void);
static void dlt_user_trace_network_segmented_thread(void *unused);
+static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data);
static int dlt_user_queue_resend(void);
int dlt_user_check_library_version(const char *user_major_version,const char *user_minor_version){
dlt_user.dlt_is_file = 0;
dlt_user.overflow = 0;
+ dlt_user.overflow_counter = 0;
#ifdef DLT_SHM_ENABLE
memset(&(dlt_user.dlt_shm),0,sizeof(DltShm));
#endif
/* Try to delete existing pipe, ignore result of unlink */
unlink(filename);
- ret=mkfifo(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
+ ret=mkfifo(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP );
if (ret==-1)
{
sprintf(str,"Loging disabled, FIFO user %s cannot be created!\n",filename);
/* return 0; */ /* removed to prevent error, when FIFO already exists */
}
+ // S_IWGRP cannot be set by mkfifo (???), let's reassign right bits
+ ret=chmod(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP );
+ if (ret==-1)
+ {
+ sprintf(str,"FIFO user %s cannot be chmoded!\n", DLT_USER_DIR);
+ dlt_log(LOG_ERR, str);
+ return -1;
+ }
+
dlt_user.dlt_user_handle = open(filename, O_RDWR | O_CLOEXEC);
if (dlt_user.dlt_user_handle == DLT_FD_INIT)
{
dlt_log(LOG_WARNING, "Old message queue exists, trying to delete.\n");
if(mq_unlink(queue_name) < 0)
{
- dlt_log(LOG_CRIT, "Could not delete existing message queue!\n");
- dlt_log(LOG_CRIT, strerror(errno));
+ char str[256];
+ snprintf(str,255,"Could not delete existing message queue!: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
}
else // Retry
{
}
if(dlt_user.dlt_segmented_queue_read_handle < 0)
{
- dlt_log(LOG_CRIT, "Can't create message queue read handle!\n");
- dlt_log(LOG_CRIT, strerror(errno));
+ char str[256];
+ snprintf(str,255,"Can't create message queue read handle!: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
pthread_mutex_unlock(&mq_mutex);
return -1;
}
dlt_user.dlt_segmented_queue_write_handle = mq_open(queue_name, O_WRONLY|O_NONBLOCK);
if(dlt_user.dlt_segmented_queue_write_handle < 0)
{
- dlt_log(LOG_CRIT, "Can't open message queue write handle!\n");
- dlt_log(LOG_CRIT, strerror(errno));
+
+ char str[256];
+ snprintf(str,255,"Can't open message queue write handle!: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
pthread_mutex_unlock(&mq_mutex);
return -1;
}
}
/* Initialize LogLevel/TraceStatus field */
+ DLT_SEM_LOCK();
dlt_user.dlt_ll_ts = 0;
dlt_user.dlt_ll_ts_max_num_entries = 0;
dlt_user.dlt_ll_ts_num_entries = 0;
if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer), DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)==-1)
{
dlt_user_initialised = 0;
+ DLT_SEM_FREE();
return -1;
}
+ DLT_SEM_FREE();
signal(SIGPIPE,SIG_IGN); /* ignore pipe signals */
void dlt_user_atexit_handler(void)
{
+ if (dlt_user_initialised==0)
+ {
+ return;
+ }
/* Try to resend potential log messages in the user buffer */
int count = dlt_user_atexit_blow_out_user_buffer();
/* 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++)
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)
{
dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL;
dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
+ dlt_user.dlt_ll_ts[i].log_level_ptr = 0;
+ dlt_user.dlt_ll_ts[i].trace_status_ptr = 0;
+
dlt_user.dlt_ll_ts[i].context_description = 0;
dlt_user.dlt_ll_ts[i].injection_table = 0;
dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL;
dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
+ dlt_user.dlt_ll_ts[i].log_level_ptr = 0;
+ dlt_user.dlt_ll_ts[i].trace_status_ptr = 0;
+
dlt_user.dlt_ll_ts[i].context_description = 0;
dlt_user.dlt_ll_ts[i].injection_table = 0;
dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len]='\0';
}
+ if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0)
+ {
+ dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr = malloc(sizeof(int8_t));
+ if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0)
+ {
+ DLT_SEM_FREE();
+ return -1;
+ }
+ }
+ if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0)
+ {
+ dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr = malloc(sizeof(int8_t));
+ if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0)
+ {
+ DLT_SEM_FREE();
+ return -1;
+ }
+ }
+
if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)
{
dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel;
dlt_set_id(handle->contextID, contextid);
handle->log_level_pos = dlt_user.dlt_ll_ts_num_entries;
+ handle->log_level_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr;
+ handle->trace_status_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr;
+
log.context_description = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description;
+ *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level;
+ *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus;
+
if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)
{
log.log_level = loglevel;
DLT_SEM_LOCK();
+ handle->log_level_ptr = 0;
+ handle->trace_status_ptr = 0;
+
if (dlt_user.dlt_ll_ts)
{
/* Clear and free local stored context information */
free(dlt_user.dlt_ll_ts[handle->log_level_pos].context_description);
}
+ if (dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr!=0)
+ {
+ free(dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr);
+ dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr = 0;
+ }
+
+ if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr!=0)
+ {
+ free(dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr);
+ dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr = 0;
+ }
+
dlt_user.dlt_ll_ts[handle->log_level_pos].context_description = 0;
if (dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table)
{
dlt_user.dlt_ll_ts[i].log_level = loglevel;
dlt_user.dlt_ll_ts[i].trace_status = tracestatus;
+ if(dlt_user.dlt_ll_ts[i].log_level_ptr)
+ *(dlt_user.dlt_ll_ts[i].log_level_ptr) = loglevel;
+ if(dlt_user.dlt_ll_ts[i].trace_status_ptr)
+ *(dlt_user.dlt_ll_ts[i].trace_status_ptr) = tracestatus;
}
DLT_SEM_FREE();
/* Reattach to daemon if neccesary */
dlt_user_log_reattach_to_daemon();
- if (dlt_user.overflow)
+ if (dlt_user.overflow_counter)
{
if (dlt_user_log_send_overflow()==0)
{
- dlt_user.overflow=0;
- }
+ sprintf(str,"Buffer full! %u messages discarded!\n",dlt_user.overflow_counter);
+ dlt_log(LOG_ERR, str);
+ dlt_user.overflow_counter=0; }
}
/* log to FIFO */
(unsigned char *)&(userheader), sizeof(DltUserHeader),
msgdata, size, 0, 0)==-1)
{
- dlt_log(LOG_ERR,"Storing message to history buffer failed! Message discarded.\n");
+ if(dlt_user.overflow_counter==0)
+ {
+ dlt_log(LOG_ERR,"Buffer full! First message discarded!\n");
+ }
+ ret = DLT_RETURN_BUFFER_FULL;
}
DLT_SEM_FREE();
if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
{
- dlt_log(LOG_WARNING, "Failed to queue resending.\n");
+ ;//dlt_log(LOG_WARNING, "dlt_forward_msg: Failed to queue resending.\n");
}
}
switch (ret)
{
+ case DLT_RETURN_BUFFER_FULL:
+ {
+ /* Buffer full */
+ dlt_user.overflow_counter += 1;
+ return -1;
+ }
case DLT_RETURN_PIPE_FULL:
{
/* data could not be written */
- dlt_user.overflow = 1;
return -1;
}
case DLT_RETURN_PIPE_ERROR:
return -1;
}
- DLT_SEM_LOCK();
-
- if ((loglevel<=(int)(dlt_user.dlt_ll_ts[handle->log_level_pos].log_level) ) && (loglevel!=0))
+ if (handle->log_level_ptr && (loglevel<=(int)*(handle->log_level_ptr) ) && (loglevel!=0))
{
- DLT_SEM_FREE();
log->args_num = 0;
log->log_level = loglevel;
else log->size=0;
return 1;
}
- else
- {
- DLT_SEM_FREE();
- return 0;
- }
return -1;
}
return -1;
}
- type_info = DLT_TYPE_INFO_STRG;
+ type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_ASCII;
+
+ memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
+ log->size += sizeof(uint32_t);
+ }
+
+ arg_size = strlen(text) + 1;
+
+ memcpy((log->buffer)+log->size,&(arg_size),sizeof(uint16_t));
+ log->size += sizeof(uint16_t);
+
+ memcpy((log->buffer)+log->size,text,arg_size);
+ log->size += arg_size;
+
+ log->args_num ++;
+
+ return 0;
+}
+
+int dlt_user_log_write_utf8_string(DltContextData *log, const char *text)
+{
+ uint16_t arg_size;
+ uint32_t type_info;
+
+ if ((log==0) || (text==0))
+ {
+ return -1;
+ }
+
+ arg_size = strlen(text)+1;
+
+ if ((log->size+arg_size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ if (dlt_user.verbose_mode)
+ {
+ if ((log->size+arg_size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_UTF8;
memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
log->size += sizeof(uint32_t);
return -1;
}
- DLT_SEM_LOCK();
if (dlt_user.dlt_ll_ts==0)
{
- DLT_SEM_FREE();
return -1;
}
- if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+ if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
{
- DLT_SEM_FREE();
log.args_num = 0;
log.trace_status = nw_trace_type;
/* Send log */
return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
}
- else
- {
- DLT_SEM_FREE();
- }
return 0;
}
return -1;
}
- DLT_SEM_LOCK();
-
if (dlt_user.dlt_ll_ts==0)
{
- DLT_SEM_FREE();
return -1;
}
- if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+ if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
{
- DLT_SEM_FREE();
log.args_num = 0;
log.trace_status = nw_trace_type;
/* Send log */
return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
}
- else
- {
- DLT_SEM_FREE();
- }
/* Allow other threads to log between chunks */
pthread_yield();
- DLT_SEM_LOCK();
-
if (dlt_user.dlt_ll_ts==0)
{
- DLT_SEM_FREE();
return -1;
}
- if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+ if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
{
- DLT_SEM_FREE();
log.args_num = 0;
log.trace_status = nw_trace_type;
/* Send log */
return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
}
- else
- {
- DLT_SEM_FREE();
- }
return 0;
}
+
void dlt_user_trace_network_segmented_thread(void *unused)
{
/* Unused on purpose. */
s_segmented_data *data;
- while(1)
- {
- // Wait untill message queue is initialized
- pthread_mutex_lock(&mq_mutex);
- if(dlt_user.dlt_segmented_queue_read_handle < 0)
- {
- pthread_cond_wait(&mq_init_condition, &mq_mutex);
- }
- pthread_mutex_unlock(&mq_mutex);
+ while(1)
+ {
+ // Wait until message queue is initialized
+ pthread_mutex_lock(&mq_mutex);
+ if(dlt_user.dlt_segmented_queue_read_handle < 0)
+ {
+ pthread_cond_wait(&mq_init_condition, &mq_mutex);
+ }
+ pthread_mutex_unlock(&mq_mutex);
- ssize_t read = mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char *)&data,
- sizeof(s_segmented_data * ), NULL);
+ ssize_t read = mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char *)&data,
+ sizeof(s_segmented_data * ), NULL);
- if(read != sizeof(s_segmented_data *))
- {
- dlt_log(LOG_ERR, "NWTSegmented: Error while reading queue.\n");
- dlt_log(LOG_ERR, strerror(errno));
- continue;
- }
+ if(read != sizeof(s_segmented_data *))
+ {
- /* Indicator just to try to flush the buffer */
- if(data->payload_len == DLT_DELAYED_RESEND_INDICATOR_PATTERN)
- {
- // Sleep 100ms, to allow other process to read FIFO
- usleep(100*1000);
- if(dlt_user_log_resend_buffer() < 0)
- {
- // Requeue if still not empty
- dlt_user_queue_resend();
- }
- free(data);
- continue;
- }
+ char str[255];
+ snprintf(str,254,"NWTSegmented: Error while reading queue: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
+ continue;
+ }
- /* Segment the data and send the chunks */
- void *ptr = NULL;
- uint16_t offset = 0;
- uint16_t sequence = 0;
- do
- {
- uint16_t len = 0;
- if(offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len)
- {
- len = data->payload_len - offset;
- }
- else
- {
- len = DLT_MAX_TRACE_SEGMENT_SIZE;
- }
- /* If payload size aligns perfectly with segment size, avoid sendind empty segment */
- if(len == 0)
- {
- break;
- }
+ /* Indicator just to try to flush the buffer */
+ if(data->payload_len == DLT_DELAYED_RESEND_INDICATOR_PATTERN)
+ {
+ // Sleep 100ms, to allow other process to read FIFO
+ usleep(100*1000);
+ if(dlt_user_log_resend_buffer() < 0)
+ {
+ // Requeue if still not empty
+ 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;
+ }
- ptr = data->payload + offset;
- DltReturnValue err = dlt_user_trace_network_segmented_segment(data->id, data->handle, data->nw_trace_type, sequence++, len, ptr);
- if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
- {
- dlt_log(LOG_ERR,"NWTSegmented: Could not send segment. Aborting.\n");
- break; // Inner loop
- }
- offset += len;
- }while(ptr < data->payload + data->payload_len);
+ dlt_user_trace_network_segmented_thread_segmenter(data);
- /* Send the end message */
- DltReturnValue err = dlt_user_trace_network_segmented_end(data->id, data->handle, data->nw_trace_type);
- if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
- {
- dlt_log(LOG_ERR,"NWTSegmented: Could not send end segment.\n");
- }
+ /* Send the end message */
+ DltReturnValue err = dlt_user_trace_network_segmented_end(data->id, data->handle, data->nw_trace_type);
+ if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_ERR,"NWTSegmented: Could not send end segment.\n");
+ }
- /* Free resources */
- free(data->header);
- free(data->payload);
- free(data);
- }
+ /* Free resources */
+ free(data->header);
+ free(data->payload);
+ free(data);
+ }
}
+void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data)
+{
+ /* Segment the data and send the chunks */
+ void *ptr = NULL;
+ uint16_t offset = 0;
+ uint16_t sequence = 0;
+ do
+ {
+ uint16_t len = 0;
+ if(offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len)
+ {
+ len = data->payload_len - offset;
+ }
+ else
+ {
+ len = DLT_MAX_TRACE_SEGMENT_SIZE;
+ }
+ /* If payload size aligns perfectly with segment size, avoid sending empty segment */
+ if(len == 0)
+ {
+ break;
+ }
+
+ ptr = data->payload + offset;
+ DltReturnValue err = dlt_user_trace_network_segmented_segment(data->id, data->handle, data->nw_trace_type, sequence++, len, ptr);
+ if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_ERR,"NWTSegmented: Could not send segment. Aborting.\n");
+ break; // loop
+ }
+ offset += len;
+ }while(ptr < data->payload + data->payload_len);
+}
+
+
int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload)
{
/* Send as normal trace if possible */
/* Open queue if it is not open */
if(dlt_init_message_queue() < 0)
{
- dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
+ dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
+ free(thread_data->header);
+ free(thread_data->payload);
+ free(thread_data);
+
return -1;
}
}
free(thread_data->header);
free(thread_data->payload);
- free(thread_data);
- dlt_log(LOG_ERR, "NWTSegmented: Could not write into queue.\n");
- dlt_log(LOG_ERR, strerror(errno));
+ free(thread_data);
+ char str[256];
+ snprintf(str,255,"NWTSegmented: Could not write into queue: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
return -1;
}
+
+ //thread_data will be freed by the receiver function
+ //coverity[leaked_storage]
return 0;
}
*/
- DLT_SEM_LOCK();
-
if (dlt_user.dlt_ll_ts==0)
{
- DLT_SEM_FREE();
return -1;
}
- if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+ if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
{
- DLT_SEM_FREE();
log.args_num = 0;
log.trace_status = nw_trace_type;
/* Send log */
return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
}
- else
- {
- DLT_SEM_FREE();
- }
return 0;
}
int dlt_user_queue_resend(void)
{
+ static unsigned char dlt_user_queue_resend_error_counter = 0;
+
if(dlt_user.dlt_log_handle < 0)
{
// Fail silenty. FIFO is not open yet
* This will be freed in dlt_user_trace_network_segmented_thread
* */
s_segmented_data *resend_data = malloc(sizeof(s_segmented_data));
+
+ if (NULL == resend_data)
+ {
+ return -1;
+ }
+
resend_data->payload_len = DLT_DELAYED_RESEND_INDICATOR_PATTERN;
+
+
/* Open queue if it is not open */
if(dlt_init_message_queue() < 0)
{
- dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
+ if(!dlt_user_queue_resend_error_counter)
+ {
+ // log error only when problem occurred first time
+ dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
+ }
+ dlt_user_queue_resend_error_counter = 1;
+ free(resend_data);
return -1;
}
if(mq_send(dlt_user.dlt_segmented_queue_write_handle, (char *)&resend_data, sizeof(s_segmented_data *), 1) < 0)
{
- dlt_log(LOG_ERR,"Could not request resending.\n");
- dlt_log(LOG_ERR, strerror(errno));
+ if(!dlt_user_queue_resend_error_counter)
+ {
+ // log error only when problem occurred first time
+ char str[255];
+ snprintf(str,254,"Could not request resending.: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
+ }
+ dlt_user_queue_resend_error_counter = 1;
free(resend_data);
- DLT_SEM_FREE();
return -1;
}
+
+ dlt_user_queue_resend_error_counter = 0;
+
+ //thread_data will be freed by the receiver function
+ //coverity[leaked_storage]
return 0;
}
/* Reattach to daemon if neccesary */
dlt_user_log_reattach_to_daemon();
- if (dlt_user.overflow)
+ if (dlt_user.overflow_counter)
{
if (dlt_user_log_send_overflow()==0)
{
- dlt_user.overflow=0;
+ sprintf(str,"%u messages discarded!\n",dlt_user.overflow_counter);
+ dlt_log(LOG_ERR, str);
+ dlt_user.overflow_counter=0;
}
}
msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
log->buffer, log->size)==-1)
{
- dlt_log(LOG_ERR,"Storing message to history buffer failed! Message discarded.\n");
- ret = DLT_RETURN_BUFFER_FULL;
+ if(dlt_user.overflow_counter==0)
+ {
+
+ dlt_log(LOG_ERR,"Buffer full! Messages will be discarded.\n");
+ }
+ ret = DLT_RETURN_BUFFER_FULL;
}
DLT_SEM_FREE();
// Fail silenty if FIFO is not open
if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
{
- dlt_log(LOG_WARNING, "Failed to queue resending.\n");
+ ;//dlt_log(LOG_WARNING, "dlt_user_log_send_log: Failed to queue resending.\n");
}
}
case DLT_RETURN_BUFFER_FULL:
{
/* Buffer full */
+ dlt_user.overflow_counter += 1;
return DLT_RETURN_BUFFER_FULL;
}
case DLT_RETURN_PIPE_FULL:
{
/* data could not be written */
- dlt_user.overflow = 1;
return DLT_RETURN_PIPE_FULL;
}
case DLT_RETURN_PIPE_ERROR:
if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
{
- dlt_log(LOG_WARNING, "Failed to queue resending.\n");
+ ;//dlt_log(LOG_WARNING, "dlt_user_log_send_register_application: Failed to queue resending.\n");
}
}
if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
{
- dlt_log(LOG_WARNING, "Failed to queue resending.\n");
+ ;//dlt_log(LOG_WARNING, "dlt_user_log_send_register_context: Failed to queue resending.\n");
}
}
while ((int32_t)(sizeof(DltUserHeader)+offset)<=receiver->bytesRcvd);
/* Check for user header pattern */
- if (dlt_user_check_userheader(userheader)==0)
+ if (dlt_user_check_userheader(userheader)<0 ||
+ dlt_user_check_userheader(userheader)==0)
{
break;
}
{
dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = usercontextll->log_level;
dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = usercontextll->trace_status;
+ if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr)
+ *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = usercontextll->log_level;
+ if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr)
+ *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = usercontextll->trace_status;
}
}
/* Delayed injection callback call */
if(delayed_inject_buffer != 0 && delayed_injection_callback.injection_callback != 0) {
delayed_injection_callback.injection_callback(delayed_injection_callback.service_id, delayed_inject_buffer, delayed_inject_data_length);
- free(delayed_inject_buffer);
+ delayed_injection_callback.injection_callback = 0;
+ free(delayed_inject_buffer);
+ delayed_inject_buffer = NULL;
+
}
/* keep not read data in buffer */
for (num=0; num<dlt_user.dlt_ll_ts_num_entries; num++)
{
/* Re-register stored context */
- if ((dlt_user.appID[0]!='\0') && (dlt_user.dlt_ll_ts[num].contextID[0]!='\0') && (dlt_user.dlt_ll_ts))
+ if ((dlt_user.appID[0]!='\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0]!='\0'))
{
//dlt_set_id(log_new.appID, dlt_user.appID);
dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID);
int dlt_user_log_send_overflow(void)
{
DltUserHeader userheader;
+ DltUserControlMsgBufferOverflow userpayload;
DltReturnValue ret;
/* set userheader */
return 0;
}
+ /* set user message parameters */
+ userpayload.overflow_counter = dlt_user.overflow_counter;
+ dlt_set_id(userpayload.apid,dlt_user.appID);
+
/* log to FIFO */
- ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), 0, 0);
+ ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader),
+ &(userpayload), sizeof(DltUserControlMsgBufferOverflow));
return ((ret==DLT_RETURN_OK)?0:-1);
}