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)
{
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");
}
}
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);
void dlt_user_trace_network_segmented_thread(void *unused)
{
- /* Unused on purpose. */
- (void) unused;
+ /* Unused on purpose. */
+ (void) unused;
- s_segmented_data *data;
+ s_segmented_data *data;
while(1)
{
- // Wait untill message queue is initialized
+ // Wait until message queue is initialized
pthread_mutex_lock(&mq_mutex);
if(dlt_user.dlt_segmented_queue_read_handle < 0)
{
if(read != sizeof(s_segmented_data *))
{
- dlt_log(LOG_ERR, "NWTSegmented: Error while reading queue.\n");
- dlt_log(LOG_ERR, strerror(errno));
+
+ char str[255];
+ snprintf(str,254,"NWTSegmented: Error while reading queue: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
continue;
}
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;
thread_data->payload_len);
if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
{
- dlt_log(LOG_ERR,"NWTSegmented: Could not send start segment. Aborting.\n");
- free(thread_data->header);
- free(thread_data->payload);
- free(thread_data);
+ dlt_log(LOG_ERR,"NWTSegmented: Could not send start segment. Aborting.\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;
}
if(dlt_init_message_queue() < 0)
{
dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
- free(resend_data);
+ 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));
+ char str[255];
+ snprintf(str,254,"Could not request resending.: %s \n",strerror(errno));
+ dlt_log(LOG_CRIT, str);
free(resend_data);
- DLT_SEM_FREE();
return -1;
}
+ //thread_data will be freed by the receiver function
+ //coverity[leaked_storage]
return 0;
}
// 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");
}
}
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;
}
/* 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 */