summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManikandanChockalingam <manikandan.chockalingam@in.bosch.com>2018-10-30 02:51:50 +0100
committerChristoph Lipka <clipka@users.noreply.github.com>2018-10-30 10:51:50 +0900
commitac44c47265528ddd29afbb9a72bcf095a877ecd1 (patch)
tree99e4514402dfc5bdc7b2630e0fed656257b6b608 /src
parent10a2c7673d2ae9d9ef8d59a417b6554881531a66 (diff)
downloadDLT-daemon-ac44c47265528ddd29afbb9a72bcf095a877ecd1.tar.gz
dlt-daemon: per ECU list of user information (#80)
Prepare daemon to store applications/context information of other ECUs as well. This commit prepares the dlt-daemon to store logs from passive nodes in a logstorage device. Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com> Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/dlt-daemon.c123
-rw-r--r--src/daemon/dlt_daemon_client.c126
-rw-r--r--src/daemon/dlt_daemon_common.c810
-rw-r--r--src/daemon/dlt_daemon_common.h121
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c43
-rw-r--r--src/lib/dlt_client.c4
6 files changed, 883 insertions, 344 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index b9eb8eb..c62ea82 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -780,6 +780,17 @@ int main(int argc, char* argv[])
else
dlt_daemon_change_state(&daemon,DLT_DAEMON_STATE_BUFFER);
+ dlt_daemon_init_user_information(&daemon,
+ &daemon_local.pGateway,
+ daemon_local.flags.gatewayMode,
+ daemon_local.flags.vflag);
+
+ if (dlt_daemon_load_runtime_configuration(&daemon, daemon_local.flags.ivalue,daemon_local.flags.vflag)==-1)
+ {
+ dlt_log(LOG_ERR,"Could not load runtime config\n");
+ return -1;
+ }
+
dlt_daemon_log_internal(&daemon, &daemon_local, "Daemon launched. Starting to output traces...", daemon_local.flags.vflag);
/* Even handling loop. */
@@ -1597,8 +1608,8 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon,
/* check if file file descriptor was already used, and make it invalid if it
* is reused. */
/* This prevents sending messages to wrong file descriptor */
- dlt_daemon_applications_invalidate_fd(daemon, in_sock, verbose);
- dlt_daemon_contexts_invalidate_fd(daemon, in_sock, verbose);
+ dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
/* Set socket timeout in reception */
struct timeval timeout_send;
@@ -1881,8 +1892,8 @@ int dlt_daemon_process_control_connect(
/* check if file file descriptor was already used, and make it invalid if it
* is reused */
/* This prevents sending messages to wrong file descriptor */
- dlt_daemon_applications_invalidate_fd(daemon, in_sock, verbose);
- dlt_daemon_contexts_invalidate_fd(daemon, in_sock, verbose);
+ dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
if (dlt_connection_create(daemon_local,
&daemon_local->pEvent,
@@ -1936,8 +1947,8 @@ int dlt_daemon_process_app_connect(
/* check if file file descriptor was already used, and make it invalid if it
* is reused. This prevents sending messages to wrong file descriptor */
- dlt_daemon_applications_invalidate_fd(daemon, in_sock, verbose);
- dlt_daemon_contexts_invalidate_fd(daemon, in_sock, verbose);
+ dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon,daemon->ecuid, in_sock, verbose);
if (dlt_connection_create(daemon_local,
&daemon_local->pEvent,
@@ -2335,7 +2346,7 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon,
return -1;
}
- old_application = dlt_daemon_application_find(daemon, userapp.apid, verbose);
+ old_application = dlt_daemon_application_find(daemon, userapp.apid, daemon->ecuid, verbose);
if (old_application != NULL)
{
old_pid = old_application->pid;
@@ -2345,6 +2356,7 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon,
userapp.pid,
description,
rec->fd,
+ daemon->ecuid,
verbose);
/* send log state to new application */
@@ -2459,17 +2471,18 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon,
return -1;
}
- application = dlt_daemon_application_find(daemon, userctxt.apid, verbose);
+ application = dlt_daemon_application_find(daemon,
+ userctxt.apid,
+ daemon->ecuid,
+ verbose);
if (application == 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"ApID '%.4s' not found for new ContextID '%.4s' in %s\n",
userctxt.apid,
userctxt.ctid,
__func__);
- dlt_log(LOG_WARNING, local_str);
return 0;
}
@@ -2512,6 +2525,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon,
userctxt.log_level_pos,
application->user_handle,
description,
+ daemon->ecuid,
verbose);
if (context==0)
@@ -2618,17 +2632,15 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon,
DltDaemonApplication *application = NULL;
DltDaemonContext *context;
int i, offset_base;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL))
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_ERR,
"Invalid function parameters used for %s\n",
__func__);
-
- dlt_log(LOG_ERR, local_str);
return -1;
}
@@ -2641,53 +2653,62 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon,
return -1;
}
- if (daemon->num_applications > 0)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return -1;
+ }
+
+ if (user_list->num_applications > 0)
{
/* Delete this application and all corresponding contexts
* for this application from internal table.
*/
application = dlt_daemon_application_find(daemon,
userapp.apid,
+ daemon->ecuid,
verbose);
if (application)
{
/* Calculate start offset within contexts[] */
offset_base=0;
- for (i=0; i<(application-(daemon->applications)); i++)
+ for (i = 0; i < (application - (user_list->applications)); i++)
{
- offset_base+=daemon->applications[i].num_contexts;
+ offset_base += user_list->applications[i].num_contexts;
}
- for (i=application->num_contexts-1; i>=0; i--)
+ for (i = (application->num_contexts) - 1; i >= 0; i--)
{
- context = &(daemon->contexts[offset_base+i]);
+ context = &(user_list->contexts[offset_base + i]);
if (context)
{
/* Delete context */
- if (dlt_daemon_context_del(daemon, context, verbose) == -1)
+ if (dlt_daemon_context_del(daemon,
+ context,
+ daemon->ecuid,
+ verbose) == -1)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Can't delete CtID '%.4s' for ApID '%.4s' in %s\n",
context->ctid,
context->apid,
__func__);
- dlt_log(LOG_WARNING, local_str);
return -1;
}
}
}
/* Delete this application entry from internal table*/
- if (dlt_daemon_application_del(daemon, application, verbose)==-1)
+ if (dlt_daemon_application_del(daemon,
+ application,
+ daemon->ecuid,
+ verbose) == -1)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Can't delete ApID '%.4s' in %s\n",
application->apid,
__func__);
- dlt_log(LOG_WARNING, local_str);
return -1;
}
else
@@ -2722,12 +2743,10 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon,
if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL))
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_ERR,
"Invalid function parameters used for %s\n",
__func__);
- dlt_log(LOG_ERR, local_str);
return -1;
}
@@ -2743,20 +2762,19 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon,
context = dlt_daemon_context_find(daemon,
userctxt.apid,
userctxt.ctid,
+ daemon->ecuid,
verbose);
if (context)
{
/* Delete this connection entry from internal table*/
- if (dlt_daemon_context_del(daemon, context, verbose)==-1)
+ if (dlt_daemon_context_del(daemon, context, daemon->ecuid, verbose) == -1)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Can't delete CtID '%.4s' for ApID '%.4s' in %s\n",
userctxt.ctid,
userctxt.apid,
__func__);
- dlt_log(LOG_WARNING, local_str);
return -1;
}
else
@@ -3095,25 +3113,28 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon,
DltReceiver *rec,
int verbose)
{
- char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' };
uint32_t len = sizeof(DltUserControlMsgAppLogLevelTraceStatus);
DltUserControlMsgAppLogLevelTraceStatus userctxt;
DltDaemonApplication *application;
DltDaemonContext *context;
int i, offset_base;
int8_t old_log_level, old_trace_status;
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL))
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_ERR,
"Invalid function parameters used for %s\n",
__func__);
+ return DLT_RETURN_ERROR;
+ }
- dlt_log(LOG_ERR, local_str);
- return -1;
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return DLT_RETURN_ERROR;
}
memset(&userctxt, 0, len);
@@ -3123,27 +3144,28 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon,
DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0)
{
/* Not enough bytes received */
- return -1;
+ return DLT_RETURN_ERROR;
}
- if (daemon->num_applications>0)
+ if (user_list->num_applications > 0)
{
/* Get all contexts with application id matching the received application id */
application = dlt_daemon_application_find(daemon,
userctxt.apid,
+ daemon->ecuid,
verbose);
if (application)
{
/* Calculate start offset within contexts[] */
offset_base=0;
- for (i=0; i<(application-(daemon->applications)); i++)
+ for (i = 0; i < (application - (user_list->applications)); i++)
{
- offset_base+=daemon->applications[i].num_contexts;
+ offset_base += user_list->applications[i].num_contexts;
}
- for (i=0; i < application->num_contexts; i++)
+ for (i = 0; i < application->num_contexts; i++)
{
- context = &(daemon->contexts[offset_base+i]);
+ context = &(user_list->contexts[offset_base + i]);
if (context)
{
old_log_level = context->log_level;
@@ -3152,8 +3174,11 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon,
old_trace_status = context->trace_status;
context->trace_status = userctxt.trace_status; /* No endianess conversion necessary */
- /* The folowing function sends also the trace status */
- if (context->user_handle >= DLT_FD_MINIMUM && dlt_daemon_user_send_log_level(daemon, context, verbose)!=0)
+ /* The following function sends also the trace status */
+ if ((context->user_handle >= DLT_FD_MINIMUM) &&
+ (dlt_daemon_user_send_log_level(daemon,
+ context,
+ verbose) != 0))
{
context->log_level = old_log_level;
context->trace_status = old_trace_status;
@@ -3163,7 +3188,7 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon,
}
}
- return 0;
+ return DLT_RETURN_OK;
}
int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon,
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index dc07387..a265632 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -761,6 +761,8 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
uint32_t sid;
+ DltDaemonRegisteredUsers* user_list = NULL;
+
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
@@ -773,6 +775,12 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
return;
}
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return;
+ }
+
/* prepare pointer to message request */
req = (DltServiceGetLogInfoRequest*) (msg->databuffer);
@@ -792,13 +800,20 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
if (req->apid[0]!='\0')
{
- application = dlt_daemon_application_find(daemon, req->apid, verbose);
+ application = dlt_daemon_application_find(daemon,
+ req->apid,
+ daemon->ecuid,
+ verbose);
if (application)
{
num_applications = 1;
if (req->ctid[0]!='\0')
{
- context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose);
+ context = dlt_daemon_context_find(daemon,
+ req->apid,
+ req->ctid,
+ daemon->ecuid,
+ verbose);
num_contexts = ((context)?1:0);
}
@@ -816,8 +831,8 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
else
{
/* Request all applications and contexts */
- num_applications = daemon->num_applications;
- num_contexts = daemon->num_contexts;
+ num_applications = user_list->num_applications;
+ num_contexts = user_list->num_contexts;
}
/* prepare payload of data */
@@ -865,20 +880,20 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
else
{
/* One application, all contexts */
- if ((daemon->applications) && (application))
+ if ((user_list->applications) && (application))
{
/* Calculate start offset within contexts[] */
offset_base=0;
- for (i=0; i<(application-(daemon->applications)); i++)
+ for (i = 0; i < (application - (user_list->applications)); i++)
{
- offset_base+=daemon->applications[i].num_contexts;
+ offset_base += user_list->applications[i].num_contexts;
}
/* Iterate over all contexts belonging to this application */
for (j=0;j<application->num_contexts;j++)
{
- context = &(daemon->contexts[offset_base+j]);
+ context = &(user_list->contexts[offset_base + j]);
if (context)
{
resp.datasize+=sizeof(uint16_t) /* len_context_description */;
@@ -904,21 +919,22 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
else
{
/* All applications, all contexts */
- for (i=0;i<daemon->num_contexts;i++)
+ for (i = 0; i < user_list->num_contexts; i++)
{
resp.datasize+=sizeof(uint16_t) /* len_context_description */;
- if (daemon->contexts[i].context_description!=0)
+ if (user_list->contexts[i].context_description != 0)
{
- resp.datasize+=strlen(daemon->contexts[i].context_description); /* context_description */
+ resp.datasize +=
+ strlen(user_list->contexts[i].context_description);
}
}
- for (i=0;i<daemon->num_applications;i++)
+ for (i = 0; i < user_list->num_applications; i++)
{
- resp.datasize+=sizeof(uint16_t) /* len_app_description */;
- if (daemon->applications[i].application_description!=0)
+ resp.datasize += sizeof(uint16_t) /* len_app_description */;
+ if (user_list->applications[i].application_description != 0)
{
- resp.datasize+=strlen(daemon->applications[i].application_description); /* app_description */
+ resp.datasize += strlen(user_list->applications[i].application_description); /* app_description */
}
}
}
@@ -926,8 +942,9 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
if (verbose)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"Allocate %d bytes for response msg databuffer\n", resp.datasize);
- dlt_log(LOG_DEBUG, str);
+ dlt_vlog(LOG_DEBUG,
+ "Allocate %d bytes for response msg databuffer\n",
+ resp.datasize);
}
/* Allocate buffer for response message */
@@ -972,9 +989,9 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
}
else
{
- if (daemon->applications)
+ if (user_list->applications)
{
- apid = daemon->applications[i].apid;
+ apid = user_list->applications[i].apid;
}
else
{
@@ -983,19 +1000,22 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
}
}
- application = dlt_daemon_application_find(daemon, apid, verbose);
+ application = dlt_daemon_application_find(daemon,
+ apid,
+ daemon->ecuid,
+ verbose);
if (application)
{
/* Calculate start offset within contexts[] */
offset_base=0;
- for (j=0; j<(application-(daemon->applications)); j++)
+ for (j = 0; j < (application-(user_list->applications)); j++)
{
- offset_base+=daemon->applications[j].num_contexts;
+ offset_base += user_list->applications[j].num_contexts;
}
- dlt_set_id((char*)(resp.databuffer+offset),apid);
- offset+=sizeof(ID4);
+ dlt_set_id((char*)(resp.databuffer + offset), apid);
+ offset += sizeof(ID4);
#if (DLT_DEBUG_GETLOGINFO==1)
dlt_print_id(buf, apid);
@@ -1003,7 +1023,7 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
dlt_log(LOG_DEBUG, str);
#endif
- if (req->apid[0]!='\0')
+ if (req->apid[0] != '\0')
{
count_con_ids = num_contexts;
}
@@ -1012,34 +1032,35 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
count_con_ids = application->num_contexts;
}
- memcpy(resp.databuffer+offset,&count_con_ids,sizeof(uint16_t));
- offset+=sizeof(uint16_t);
+ memcpy(resp.databuffer + offset,&count_con_ids, sizeof(uint16_t));
+ offset += sizeof(uint16_t);
#if (DLT_DEBUG_GETLOGINFO==1)
snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"#ctid: %d \n", count_con_ids);
dlt_log(LOG_DEBUG, str);
#endif
- for (j=0;j<count_con_ids;j++)
+ for (j = 0;j < count_con_ids; j++)
{
#if (DLT_DEBUG_GETLOGINFO==1)
snprintf(str,DLT_DAEMON_TEXTBUFSIZE,"j: %d \n",j);
dlt_log(LOG_DEBUG, str);
#endif
- if (!((count_con_ids==1) && (req->apid[0]!='\0') && (req->ctid[0]!='\0')))
+ if (!((count_con_ids == 1) && (req->apid[0] != '\0') &&
+ (req->ctid[0] != '\0')))
{
- context = &(daemon->contexts[offset_base+j]);
+ context = &(user_list->contexts[offset_base + j]);
}
/* else: context was already searched and found
(one application (found) with one context (found))*/
if ((context) &&
- ((req->ctid[0]=='\0') ||
- ((req->ctid[0]!='\0') && (memcmp(context->ctid,req->ctid,DLT_ID_SIZE)==0)))
+ ((req->ctid[0]=='\0') || ((req->ctid[0]!='\0') &&
+ (memcmp(context->ctid,req->ctid,DLT_ID_SIZE)==0)))
)
{
- dlt_set_id((char*)(resp.databuffer+offset),context->ctid);
- offset+=sizeof(ID4);
+ dlt_set_id((char*)(resp.databuffer+offset), context->ctid);
+ offset += sizeof(ID4);
#if (DLT_DEBUG_GETLOGINFO==1)
dlt_print_id(buf, context->ctid);
@@ -1493,7 +1514,11 @@ void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltDaemon
}
/* At this point, apid and ctid is available */
- context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
+ context = dlt_daemon_context_find(daemon,
+ apid,
+ ctid,
+ daemon->ecuid,
+ verbose);
if (context==0)
{
@@ -1600,6 +1625,7 @@ void dlt_daemon_find_multiple_context_and_send_log_level(int sock,
DltDaemonContext *context = NULL;
char src_str[DLT_ID_SIZE +1] = {0};
int8_t ret = 0;
+ DltDaemonRegisteredUsers* user_list = NULL;
if (daemon == 0)
{
@@ -1607,9 +1633,15 @@ void dlt_daemon_find_multiple_context_and_send_log_level(int sock,
return;
}
- for (count = 0; count < daemon->num_contexts; count++)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return;
+ }
+
+ for (count = 0; count < user_list->num_contexts; count++)
{
- context = &(daemon->contexts[count]);
+ context = &(user_list->contexts[count]);
if (context)
{
@@ -1687,7 +1719,11 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLoca
}
else
{
- context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
+ context = dlt_daemon_context_find(daemon,
+ apid,
+ ctid,
+ daemon->ecuid,
+ verbose);
/* Set log level */
if (context!=0)
@@ -1746,6 +1782,7 @@ void dlt_daemon_find_multiple_context_and_send_trace_status(int sock,
DltDaemonContext *context = NULL;
char src_str[DLT_ID_SIZE +1] = {0};
int8_t ret = 0;
+ DltDaemonRegisteredUsers* user_list = NULL;
if (daemon == 0)
{
@@ -1753,9 +1790,15 @@ void dlt_daemon_find_multiple_context_and_send_trace_status(int sock,
return;
}
- for (count = 0; count < daemon->num_contexts; count++)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return;
+ }
+
+ for (count = 0; count < user_list->num_contexts; count++)
{
- context = &(daemon->contexts[count]);
+ context = &(user_list->contexts[count]);
if (context)
{
@@ -1820,6 +1863,7 @@ void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltDaemonL
dlt_daemon_find_multiple_context_and_send_trace_status(sock, daemon, daemon_local, 1, apid, appid_length-1, req->log_level, verbose);
}
else if ((ctxtid_length != 0) && (ctid[ctxtid_length-1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and appid is null*/
+
{
dlt_daemon_find_multiple_context_and_send_trace_status(sock, daemon, daemon_local, 0, ctid, ctxtid_length-1, req->log_level, verbose);
}
@@ -1833,7 +1877,7 @@ void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltDaemonL
}
else
{
- context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
+ context=dlt_daemon_context_find(daemon, apid, ctid, daemon->ecuid, verbose);
/* Set trace status */
if (context!=0)
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 73cd1d8..3ba4c9b 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -129,36 +129,41 @@ static int dlt_daemon_cmp_apid_ctid(const void *m1, const void *m2)
return ret;
}
-int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned long RingbufferMaxSize,unsigned long RingbufferStepSize,const char *runtime_directory,int InitialContextLogLevel, int InitialContextTraceStatus, int ForceLLTS, int verbose)
+DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon,
+ char *ecu,
+ int verbose)
{
PRINT_FUNCTION_VERBOSE(verbose);
- if (daemon == NULL || runtime_directory == NULL)
- return -1;
-
- int append_length = 0;
- daemon->num_contexts = 0;
- daemon->contexts = NULL;
-
- daemon->num_applications = 0;
- daemon->applications = NULL;
-
- daemon->default_log_level = InitialContextLogLevel;
- daemon->default_trace_status = InitialContextTraceStatus;
- daemon->force_ll_ts = ForceLLTS;
-
- daemon->overflow_counter = 0;
+ int i = 0;
- daemon->runtime_context_cfg_loaded = 0;
+ if (daemon == NULL || ecu == NULL)
+ {
+ dlt_vlog(LOG_ERR, "%s: Wrong parameters", __func__);
+ return (DltDaemonRegisteredUsers *) NULL;
+ }
- daemon->mode = DLT_USER_MODE_EXTERNAL;
+ for (i = 0; i < daemon->num_user_lists; i++)
+ {
+ if (strncmp(ecu, daemon->user_list[i].ecu, DLT_ID_SIZE) == 0)
+ {
+ return &daemon->user_list[i];
+ }
+ }
- daemon->connectionState = 0; /* no logger connected */
+ dlt_vlog(LOG_ERR, "Cannot find user list for ECU: %4s\n", ecu);
+ return (DltDaemonRegisteredUsers *) NULL;
+}
+int dlt_daemon_load_runtime_configuration(DltDaemon *daemon,const char *runtime_directory, int verbose)
+{
+ int append_length = 0;
- daemon->state = DLT_DAEMON_STATE_INIT; /* initial logging state */
+ if (daemon == NULL || runtime_directory == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
/* prepare filenames for configuration */
-
append_length = PATH_MAX - sizeof(DLT_RUNTIME_APPLICATION_CFG);
if(runtime_directory[0])
{
@@ -208,6 +213,33 @@ int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned l
/* load configuration if available */
dlt_daemon_configuration_load(daemon,daemon->runtime_configuration, verbose);
+ return DLT_RETURN_OK;
+}
+
+int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned long RingbufferMaxSize,unsigned long RingbufferStepSize,const char *runtime_directory,int InitialContextLogLevel, int InitialContextTraceStatus, int ForceLLTS, int verbose)
+{
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if (daemon == NULL || runtime_directory == NULL)
+ return -1;
+
+ daemon->user_list = NULL;
+ daemon->num_user_lists = 0;
+
+ daemon->default_log_level = InitialContextLogLevel;
+ daemon->default_trace_status = InitialContextTraceStatus;
+ daemon->force_ll_ts = ForceLLTS;
+
+ daemon->overflow_counter = 0;
+
+ daemon->runtime_context_cfg_loaded = 0;
+
+ daemon->mode = DLT_USER_MODE_EXTERNAL;
+
+ daemon->connectionState = 0; /* no logger connected */
+
+ daemon->state = DLT_DAEMON_STATE_INIT; /* initial logging state */
+
daemon->sendserialheader = 0;
daemon->timingpackets = 0;
@@ -227,18 +259,27 @@ int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned l
int dlt_daemon_free(DltDaemon *daemon, int verbose)
{
+ int i = 0;
+ DltDaemonRegisteredUsers *user_list = NULL;
+
PRINT_FUNCTION_VERBOSE(verbose);
- if (daemon == NULL)
+ if (daemon == NULL || daemon->user_list == NULL)
return -1;
- /* Free contexts */
- if (dlt_daemon_contexts_clear(daemon, verbose)==-1)
- return -1;
+ /* free all registered user information */
+ for (i = 0; i < daemon->num_user_lists; i++)
+ {
+ user_list = &daemon->user_list[i];
+ if (user_list != NULL)
+ {
+ /* ignore return values */
+ dlt_daemon_contexts_clear(daemon, user_list->ecu, verbose);
+ dlt_daemon_applications_clear(daemon, user_list->ecu, verbose);
+ }
+ }
- /* Free applications */
- if (dlt_daemon_applications_clear(daemon, verbose)==-1)
- return -1;
+ free(daemon->user_list);
/* free ringbuffer */
dlt_buffer_free_dynamic(&(daemon->client_ringbuffer));
@@ -246,75 +287,162 @@ int dlt_daemon_free(DltDaemon *daemon, int verbose)
return 0;
}
-int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon, int fd, int verbose)
+int dlt_daemon_init_user_information(DltDaemon *daemon,
+ DltGateway *gateway,
+ int gateway_mode,
+ int verbose)
+{
+ int nodes = 1;
+ int i = 1;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon == NULL) || ((gateway_mode == 1) && (gateway == NULL)))
+ {
+ return DLT_RETURN_ERROR;
+ }
+
+ if (gateway_mode == 0)
+ {
+ /* initialize application list */
+ daemon->user_list = calloc(nodes, sizeof(DltDaemonRegisteredUsers));
+ if (daemon->user_list == NULL)
+ {
+ dlt_log(LOG_ERR, "Allocating memory for user information");
+ return DLT_RETURN_ERROR;
+ }
+
+ dlt_set_id(daemon->user_list[0].ecu, daemon->ecuid);
+ daemon->num_user_lists = 1;
+ }
+ else /* gateway is active */
+ {
+ nodes += gateway->num_connections;
+
+ /* initialize application list */
+ daemon->user_list = calloc(nodes, sizeof(DltDaemonRegisteredUsers));
+ if (daemon->user_list == NULL)
+ {
+ dlt_log(LOG_ERR, "Allocating memory for user information");
+ return DLT_RETURN_ERROR;
+ }
+
+ dlt_set_id(daemon->user_list[0].ecu, daemon->ecuid);
+ daemon->num_user_lists = nodes;
+
+ for (i = 1; i < nodes; i++)
+ {
+ dlt_set_id(daemon->user_list[i].ecu, gateway->connections[i-1].ecuid);
+ }
+ }
+
+ return DLT_RETURN_OK;
+}
+
+int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,
+ char *ecu,
+ int fd,
+ int verbose)
{
int i;
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if (daemon == NULL)
- return -1;
+ if (daemon == NULL || ecu == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
- for (i=0; i<daemon->num_applications; i++)
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list != NULL)
{
- if (daemon->applications[i].user_handle==fd)
+ for (i=0; i<user_list->num_applications; i++)
{
- daemon->applications[i].user_handle = DLT_FD_INIT;
+ if (user_list->applications[i].user_handle == fd)
+ {
+ user_list->applications[i].user_handle = DLT_FD_INIT;
+ }
}
+
+ return DLT_RETURN_OK;
}
- return 0;
+ return DLT_RETURN_ERROR;
}
-int dlt_daemon_applications_clear(DltDaemon *daemon, int verbose)
+int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose)
{
int i;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if (daemon == NULL)
- return -1;
+ if ((daemon == NULL) || (daemon->user_list == NULL) || (ecu == NULL))
+ {
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
- for (i=0; i<daemon->num_applications; i++)
+ for (i=0; i < user_list->num_applications; i++)
{
- if (daemon->applications[i].application_description != NULL)
+ if (user_list->applications[i].application_description != NULL)
{
- free(daemon->applications[i].application_description);
- daemon->applications[i].application_description = NULL;
+ free(user_list->applications[i].application_description);
+ user_list->applications[i].application_description = NULL;
}
}
- if (daemon->applications != NULL)
+ if (user_list->applications != NULL)
{
- free(daemon->applications);
+ free(user_list->applications);
}
- daemon->applications = NULL;
- daemon->num_applications = 0;
+ user_list->applications = NULL;
+ user_list->num_applications = 0;
return 0;
}
-DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, char *description, int fd, int verbose)
+DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,
+ char *apid,
+ pid_t pid,
+ char *description,
+ int fd,
+ char *ecu,
+ int verbose)
{
DltDaemonApplication *application;
DltDaemonApplication *old;
int new_application;
int dlt_user_handle;
+ DltDaemonRegisteredUsers *user_list = NULL;
#ifndef DLT_USE_UNIX_SOCKET_IPC
(void) fd; /* To avoid compiler warning : unused variable */
char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE];
#endif
- if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0'))
+ if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0') || (ecu == NULL))
+ {
+ return (DltDaemonApplication*) NULL;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list == NULL)
{
return (DltDaemonApplication*) NULL;
}
- if (daemon->applications == NULL)
+ if (user_list->applications == NULL)
{
- daemon->applications = (DltDaemonApplication*) malloc(sizeof(DltDaemonApplication)*DLT_DAEMON_APPL_ALLOC_SIZE);
- if (daemon->applications == NULL)
+ user_list->applications = (DltDaemonApplication*)
+ malloc(sizeof(DltDaemonApplication) * DLT_DAEMON_APPL_ALLOC_SIZE);
+ if (user_list->applications == NULL)
{
return (DltDaemonApplication*) NULL;
}
@@ -323,31 +451,36 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
new_application=0;
/* Check if application [apid] is already available */
- application = dlt_daemon_application_find(daemon, apid, verbose);
+ application = dlt_daemon_application_find(daemon, apid, ecu, verbose);
if (application == NULL)
{
- daemon->num_applications += 1;
+ user_list->num_applications += 1;
- if (daemon->num_applications!=0)
+ if (user_list->num_applications != 0)
{
- if ((daemon->num_applications%DLT_DAEMON_APPL_ALLOC_SIZE)==0)
+ if ((user_list->num_applications % DLT_DAEMON_APPL_ALLOC_SIZE) == 0)
{
/* allocate memory in steps of DLT_DAEMON_APPL_ALLOC_SIZE, e.g. 100 */
- old = daemon->applications;
- daemon->applications = (DltDaemonApplication*) malloc(sizeof(DltDaemonApplication)*
- ((daemon->num_applications/DLT_DAEMON_APPL_ALLOC_SIZE)+1)*DLT_DAEMON_APPL_ALLOC_SIZE);
- if (daemon->applications == NULL)
+ old = user_list->applications;
+ user_list->applications = (DltDaemonApplication*)
+ malloc(sizeof(DltDaemonApplication) *
+ ((user_list->num_applications / DLT_DAEMON_APPL_ALLOC_SIZE) + 1) *
+ DLT_DAEMON_APPL_ALLOC_SIZE);
+
+ if (user_list->applications == NULL)
{
- daemon->applications = old;
- daemon->num_applications -= 1;
+ user_list->applications = old;
+ user_list->num_applications -= 1;
return (DltDaemonApplication*) NULL;
}
- memcpy(daemon->applications,old,sizeof(DltDaemonApplication)*daemon->num_applications);
+ memcpy(user_list->applications,
+ old,
+ sizeof(DltDaemonApplication) * user_list->num_applications);
free(old);
}
}
- application = &(daemon->applications[daemon->num_applications-1]);
+ application = &(user_list->applications[user_list->num_applications - 1]);
dlt_set_id(application->apid,apid);
application->pid = 0;
@@ -359,9 +492,11 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
} else if ((pid != application->pid) && (application->pid != 0)) {
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "Duplicate registration of ApplicationID: '%.4s'; registering from PID %d, existing from PID %d\n",apid, pid, application->pid);
- dlt_log(LOG_WARNING, str);
-
+ dlt_vlog(LOG_WARNING,
+ "Duplicate registration of ApplicationID: '%.4s'; registering from PID %d, existing from PID %d\n",
+ apid,
+ pid,
+ application->pid);
}
/* Store application description and pid of application */
@@ -373,23 +508,35 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
if (description != NULL)
{
- application->application_description = malloc(strlen(description)+1);
+ application->application_description = malloc(strlen(description) + 1);
if (application->application_description)
{
- strncpy(application->application_description,description,strlen(description));
- application->application_description[strlen(description)]='\0';
+ strncpy(application->application_description,
+ description,
+ strlen(description));
+ application->application_description[strlen(description)] = '\0';
+ }
+ else
+ {
+ dlt_log(LOG_ERR, "Cannot allocate memory to store application description\n");
+ free(application);
+ return (DltDaemonApplication*) NULL;
}
}
- if( application->user_handle != DLT_FD_INIT )
+ if (application->user_handle != DLT_FD_INIT)
{
- if( application->pid != pid )
+ if (application->pid != pid)
{
#ifndef DLT_USE_UNIX_SOCKET_IPC
- if ( close(application->user_handle) < 0 )
+ if (close(application->user_handle) < 0)
{
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "close() failed to %s/dltpipes/dlt%d, errno=%d (%s)!\n",dltFifoBaseDir,pid,errno,strerror(errno)); /* errno 2: ENOENT - No such file or directory */
- dlt_log(LOG_WARNING, str);
+ dlt_vlog(LOG_WARNING,
+ "close() failed to %s/dltpipes/dlt%d, errno=%d (%s)!\n",
+ dltFifoBaseDir,
+ pid,
+ errno,
+ strerror(errno)); /* errno 2: ENOENT - No such file or directory */
}
#endif
application->user_handle = DLT_FD_INIT;
@@ -398,7 +545,7 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
}
/* open user pipe only if it is not yet opened */
- if (application->user_handle == DLT_FD_INIT && pid != 0)
+ if ((application->user_handle == DLT_FD_INIT) && (pid != 0))
{
#ifdef DLT_USE_UNIX_SOCKET_IPC
dlt_user_handle = fd;
@@ -418,8 +565,8 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
#endif
/* check if file descriptor was already used, and make it invalid if it
* is reused. This prevents sending messages to wrong file descriptor */
- dlt_daemon_applications_invalidate_fd(daemon,dlt_user_handle,verbose);
- dlt_daemon_contexts_invalidate_fd(daemon,dlt_user_handle,verbose);
+ dlt_daemon_applications_invalidate_fd(daemon, ecu, dlt_user_handle, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon, ecu, dlt_user_handle, verbose);
application->user_handle = dlt_user_handle;
application->pid = pid;
@@ -428,27 +575,40 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid,
/* Sort */
if (new_application)
{
- qsort(daemon->applications,daemon->num_applications,sizeof(DltDaemonApplication),dlt_daemon_cmp_apid);
+ qsort(user_list->applications,
+ user_list->num_applications,
+ sizeof(DltDaemonApplication),
+ dlt_daemon_cmp_apid);
/* Find new position of application with apid*/
- application = dlt_daemon_application_find(daemon, apid, verbose);
+ application = dlt_daemon_application_find(daemon, apid, ecu, verbose);
}
return application;
}
-int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose)
+int dlt_daemon_application_del(DltDaemon *daemon,
+ DltDaemonApplication *application,
+ char *ecu,
+ int verbose)
{
int pos;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon == NULL) || (application == NULL))
+ if ((daemon == NULL) || (application == NULL) || (ecu == NULL))
+ {
+ return -1;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list == NULL)
{
return -1;
}
- if (daemon->num_applications > 0)
+ if (user_list->num_applications > 0)
{
/* Check if user handle is open; if yes, close it */
if (application->user_handle >= DLT_FD_MINIMUM)
@@ -466,41 +626,61 @@ int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *applicat
application->application_description = NULL;
}
- pos = application-(daemon->applications);
+ pos = application - (user_list->applications);
/* move all applications above pos to pos */
- memmove(&(daemon->applications[pos]),&(daemon->applications[pos+1]), sizeof(DltDaemonApplication)*((daemon->num_applications-1)-pos));
+ memmove(&(user_list->applications[pos]),
+ &(user_list->applications[pos+1]),
+ sizeof(DltDaemonApplication) * ((user_list->num_applications - 1) - pos));
/* Clear last application */
- memset(&(daemon->applications[daemon->num_applications-1]), 0, sizeof(DltDaemonApplication));
-
- daemon->num_applications--;
+ memset(&(user_list->applications[user_list->num_applications-1]),
+ 0,
+ sizeof(DltDaemonApplication));
+ user_list->num_applications--;
}
return 0;
}
-DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon, char *apid, int verbose)
+DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,
+ char *apid,
+ char *ecu,
+ int verbose)
{
DltDaemonApplication application;
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0') || (daemon->num_applications==0))
+ if ((daemon == NULL) || (daemon->user_list == NULL) || (apid == NULL) ||
+ (apid[0]=='\0') || (ecu == NULL))
+ {
+ return (DltDaemonApplication*) NULL;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list == NULL || (user_list->num_applications == 0))
{
return (DltDaemonApplication*) NULL;
}
/* Check, if apid is smaller than smallest apid or greater than greatest apid */
- if ((memcmp(apid,daemon->applications[0].apid, DLT_ID_SIZE) < 0) ||
- (memcmp(apid,daemon->applications[daemon->num_applications-1].apid, DLT_ID_SIZE) > 0))
+ if ((memcmp(apid, user_list->applications[0].apid, DLT_ID_SIZE) < 0) ||
+ (memcmp(apid,
+ user_list->applications[user_list->num_applications - 1].apid,
+ DLT_ID_SIZE) > 0))
{
return (DltDaemonApplication*) NULL;
}
dlt_set_id(application.apid, apid);
- return (DltDaemonApplication*)bsearch(&application, daemon->applications, daemon->num_applications, sizeof(DltDaemonApplication), dlt_daemon_cmp_apid);
+ return (DltDaemonApplication*)bsearch(&application,
+ user_list->applications,
+ user_list->num_applications,
+ sizeof(DltDaemonApplication),
+ dlt_daemon_cmp_apid);
}
int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int verbose)
@@ -520,7 +700,11 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve
if (fd == NULL)
{
- dlt_vlog(LOG_INFO, "DLT runtime-application load, cannot open file %s: %s\n", filename, strerror(errno));
+ dlt_vlog(LOG_WARNING,
+ "%s: cannot open file %s: %s\n",
+ __func__,
+ filename,
+ strerror(errno));
return -1;
}
@@ -531,16 +715,17 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve
memset(buf, 0, sizeof(buf));
/* Get line */
- ret=fgets(buf,sizeof(buf),fd);
+ ret = fgets(buf, sizeof(buf), fd);
if (NULL == ret)
{
/* fgets always null pointer if the last byte of the file is a new line
* We need to check here if there was an error or was it feof.*/
- if(ferror(fd))
+ if (ferror(fd))
{
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_applications_load fgets(buf,sizeof(buf),fd) returned NULL. %s\n",
+ dlt_vlog(LOG_WARNING,
+ "%s: fgets(buf,sizeof(buf),fd) returned NULL. %s\n",
+ __func__,
strerror(errno));
- dlt_log(LOG_WARNING, str);
fclose(fd);
return -1;
}
@@ -549,29 +734,40 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve
fclose(fd);
return 0;
}
- else {
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_applications_load fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n");
- dlt_log(LOG_WARNING, str);
+ else
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s: fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n",
+ __func__);
fclose(fd);
return -1;
}
}
- if (strcmp(buf,"") != 0)
+ if (strcmp(buf, "") != 0)
{
/* Split line */
- pb=strtok(buf,":");
- if(pb != NULL)
+ pb = strtok(buf, ":");
+ if (pb != NULL)
{
dlt_set_id(apid,pb);
- pb=strtok(NULL,":");
- if(pb != NULL)
+ pb = strtok(NULL,":");
+ if (pb != NULL)
{
/* pb contains now the description */
/* pid is unknown at loading time */
- if (dlt_daemon_application_add(daemon, apid, 0, pb, -1, verbose) == 0)
+ if (dlt_daemon_application_add(daemon,
+ apid,
+ 0,
+ pb,
+ -1,
+ daemon->ecuid,
+ verbose) == 0)
{
- dlt_log(LOG_WARNING, "dlt_daemon_applications_load dlt_daemon_application_add failed\n");
+ dlt_vlog(LOG_WARNING,
+ "%s: dlt_daemon_application_add failed for %4s\n",
+ __func__,
+ apid);
fclose(fd);
return -1;
}
@@ -590,50 +786,79 @@ int dlt_daemon_applications_save(DltDaemon *daemon, const char *filename, int ve
int i;
char apid[DLT_ID_SIZE+1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (filename == NULL) || (filename[0]=='\0'))
+ {
return -1;
+ }
memset(apid, 0, sizeof(apid));
- if ((daemon->applications != NULL) && (daemon->num_applications > 0))
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return -1;
+ }
+
+ if ((user_list->applications != NULL) && (user_list->num_applications > 0))
{
- fd=fopen(filename, "w");
+ fd = fopen(filename, "w");
if (fd != NULL)
{
- for (i=0; i<daemon->num_applications; i++)
+ for (i = 0; i < user_list->num_applications; i++)
{
- dlt_set_id(apid,daemon->applications[i].apid);
+ dlt_set_id(apid, user_list->applications[i].apid);
- if ((daemon->applications[i].application_description) &&
- (daemon->applications[i].application_description[0] != '\0'))
+ if ((user_list->applications[i].application_description) &&
+ (user_list->applications[i].application_description[0] != '\0'))
{
- fprintf(fd,"%s:%s:\n",apid, daemon->applications[i].application_description);
+ fprintf(fd,
+ "%s:%s:\n",
+ apid,
+ user_list->applications[i].application_description);
}
else
{
- fprintf(fd,"%s::\n",apid);
+ fprintf(fd, "%s::\n", apid);
}
}
fclose(fd);
}
+ else
+ {
+ dlt_vlog(LOG_ERR, "%s: open %s failed! No application information stored.\n",
+ __func__,
+ filename);
+ }
}
return 0;
}
-DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon, char *apid, char *ctid,int8_t log_level, int8_t trace_status, int log_level_pos, int user_handle, char *description, int verbose)
+DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,
+ char *apid,
+ char *ctid,
+ int8_t log_level,
+ int8_t trace_status,
+ int log_level_pos,
+ int user_handle,
+ char *description,
+ char *ecu,
+ int verbose)
{
DltDaemonApplication *application;
DltDaemonContext *context;
DltDaemonContext *old;
int new_context=0;
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0') || (ctid == NULL) || (ctid[0]=='\0'))
+ if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0') ||
+ (ctid == NULL) || (ctid[0]=='\0') || (ecu == NULL))
{
return (DltDaemonContext*) NULL;
}
@@ -648,48 +873,57 @@ DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon, char *apid, char *ct
return (DltDaemonContext*) NULL;
}
- if (daemon->contexts == NULL)
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list == NULL)
+ {
+ return (DltDaemonContext*) NULL;
+ }
+
+ if (user_list->contexts == NULL)
{
- daemon->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
- if (daemon->contexts == NULL)
+ user_list->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
+ if (user_list->contexts == NULL)
{
return (DltDaemonContext*) NULL;
}
}
/* Check if application [apid] is available */
- application = dlt_daemon_application_find(daemon, apid, verbose);
+ application = dlt_daemon_application_find(daemon, apid, ecu, verbose);
if (application == NULL)
{
return (DltDaemonContext*) NULL;
}
/* Check if context [apid, ctid] is already available */
- context = dlt_daemon_context_find(daemon, apid, ctid, verbose);
+ context = dlt_daemon_context_find(daemon, apid, ctid, ecu, verbose);
if (context == NULL)
{
- daemon->num_contexts += 1;
+ user_list->num_contexts += 1;
- if (daemon->num_contexts!=0)
+ if (user_list->num_contexts != 0)
{
- if ((daemon->num_contexts%DLT_DAEMON_CONTEXT_ALLOC_SIZE)==0)
+ if ((user_list->num_contexts % DLT_DAEMON_CONTEXT_ALLOC_SIZE) == 0)
{
/* allocate memory for context in steps of DLT_DAEMON_CONTEXT_ALLOC_SIZE, e.g 100 */
- old = daemon->contexts;
- daemon->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*
- ((daemon->num_contexts/DLT_DAEMON_CONTEXT_ALLOC_SIZE)+1)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
- if (daemon->contexts == NULL)
+ old = user_list->contexts;
+ user_list->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext) *
+ ((user_list->num_contexts / DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) * DLT_DAEMON_CONTEXT_ALLOC_SIZE);
+
+ if (user_list->contexts == NULL)
{
- daemon->contexts = old;
- daemon->num_contexts -= 1;
+ user_list->contexts = old;
+ user_list->num_contexts -= 1;
return (DltDaemonContext*) NULL;
}
- memcpy(daemon->contexts,old,sizeof(DltDaemonContext)*daemon->num_contexts);
+ memcpy(user_list->contexts,
+ old,
+ sizeof(DltDaemonContext) * user_list->num_contexts);
free(old);
}
}
- context = &(daemon->contexts[daemon->num_contexts-1]);
+ context = &(user_list->contexts[user_list->num_contexts - 1]);
dlt_set_id(context->apid,apid);
dlt_set_id(context->ctid,ctid);
@@ -717,7 +951,7 @@ DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon, char *apid, char *ct
}
}
- if (daemon->force_ll_ts)
+ if ((strncmp(daemon->ecuid, ecu, DLT_ID_SIZE) == 0) && (daemon->force_ll_ts))
{
if (log_level > daemon->default_log_level)
{
@@ -727,16 +961,21 @@ DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon, char *apid, char *ct
{
trace_status = daemon->default_trace_status;
}
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "Adapting ll_ts for context: %.4s:%.4s with %i %i\n", apid, ctid, log_level, trace_status);
- dlt_log(LOG_NOTICE, str);
+
+ dlt_vlog(LOG_NOTICE,
+ "Adapting ll_ts for context: %.4s:%.4s with %i %i\n",
+ apid,
+ ctid,
+ log_level,
+ trace_status);
}
/* Store log level and trace status,
if this is a new context, or
if this is an old context and the runtime cfg was not loaded */
-
- if ((new_context == 1) ||
- ((new_context == 0) && (daemon->runtime_context_cfg_loaded == 0)))
+ if ((strncmp(daemon->ecuid, ecu, DLT_ID_SIZE) == 0) &&
+ ((new_context == 1) || ((new_context == 0) &&
+ (daemon->runtime_context_cfg_loaded == 0))))
{
context->log_level = log_level;
context->trace_status = trace_status;
@@ -748,28 +987,43 @@ DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon, char *apid, char *ct
/* Sort */
if (new_context)
{
- qsort(daemon->contexts,daemon->num_contexts, sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid);
+ qsort(user_list->contexts,
+ user_list->num_contexts,
+ sizeof(DltDaemonContext),
+ dlt_daemon_cmp_apid_ctid);
/* Find new position of context with apid, ctid */
- context = dlt_daemon_context_find(daemon, apid, ctid, verbose);
+ context = dlt_daemon_context_find(daemon, apid, ctid, ecu, verbose);
}
return context;
}
-int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose)
+int dlt_daemon_context_del(DltDaemon *daemon,
+ DltDaemonContext* context,
+ char *ecu,
+ int verbose)
{
int pos;
DltDaemonApplication *application;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon == NULL) || (context == NULL))
+ if ((daemon == NULL) || (context == NULL) || (ecu == NULL))
+ {
return -1;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list == NULL)
+ {
+ return -1;
+ }
- if (daemon->num_contexts>0)
+ if (user_list->num_contexts > 0)
{
- application = dlt_daemon_application_find(daemon, context->apid, verbose);
+ application = dlt_daemon_application_find(daemon, context->apid, ecu, verbose);
/* Free description of context to be deleted */
if (context->context_description)
@@ -778,15 +1032,19 @@ int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int ver
context->context_description = NULL;
}
- pos = context-(daemon->contexts);
+ pos = context-(user_list->contexts);
/* move all contexts above pos to pos */
- memmove(&(daemon->contexts[pos]), &(daemon->contexts[pos+1]), sizeof(DltDaemonContext)*((daemon->num_contexts-1)-pos));
+ memmove(&(user_list->contexts[pos]),
+ &(user_list->contexts[pos + 1]),
+ sizeof(DltDaemonContext) * ((user_list->num_contexts - 1) - pos));
/* Clear last context */
- memset(&(daemon->contexts[daemon->num_contexts-1]), 0, sizeof(DltDaemonContext));
+ memset(&(user_list->contexts[user_list->num_contexts-1]),
+ 0,
+ sizeof(DltDaemonContext));
- daemon->num_contexts--;
+ user_list->num_contexts--;
/* Check if application [apid] is available */
if (application != NULL)
@@ -798,20 +1056,34 @@ int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int ver
return 0;
}
-DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon, char *apid, char *ctid, int verbose)
+DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,
+ char *apid,
+ char *ctid,
+ char *ecu,
+ int verbose)
{
DltDaemonContext context;
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0') || (ctid == NULL) || (ctid[0]=='\0') || (daemon->num_contexts==0))
+ if ((daemon == NULL) || (apid == NULL) || (apid[0]=='\0') ||
+ (ctid == NULL) || (ctid[0]=='\0') || (ecu == NULL))
+ {
+ return (DltDaemonContext*) NULL;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if ((user_list == NULL) || (user_list->num_contexts == 0))
{
return (DltDaemonContext*) NULL;
}
/* Check, if apid is smaller than smallest apid or greater than greatest apid */
- if ((memcmp(apid,daemon->contexts[0].apid,DLT_ID_SIZE)<0) ||
- (memcmp(apid,daemon->contexts[daemon->num_contexts-1].apid,DLT_ID_SIZE)>0))
+ if ((memcmp(apid, user_list->contexts[0].apid, DLT_ID_SIZE) < 0) ||
+ (memcmp(apid,
+ user_list->contexts[user_list->num_contexts-1].apid,
+ DLT_ID_SIZE) > 0))
{
return (DltDaemonContext*) NULL;
}
@@ -819,60 +1091,84 @@ DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon, char *apid, char *c
dlt_set_id(context.apid,apid);
dlt_set_id(context.ctid,ctid);
- return (DltDaemonContext*)bsearch(&context,daemon->contexts,daemon->num_contexts,sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid);
+ return (DltDaemonContext*)bsearch(&context,
+ user_list->contexts,
+ user_list->num_contexts,
+ sizeof(DltDaemonContext),
+ dlt_daemon_cmp_apid_ctid);
}
-int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon, int fd, int verbose)
+int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,
+ char *ecu,
+ int fd,
+ int verbose)
{
int i;
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if (daemon == NULL)
+ if ((daemon == NULL) || (ecu == NULL))
+ {
return -1;
+ }
- for (i=0; i<daemon->num_contexts; i++)
+ user_list = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (user_list != NULL)
{
- if (daemon->contexts[i].user_handle == fd)
+ for (i=0; i<user_list->num_contexts; i++)
{
- daemon->contexts[i].user_handle = DLT_FD_INIT;
+ if (user_list->contexts[i].user_handle == fd)
+ {
+ user_list->contexts[i].user_handle = DLT_FD_INIT;
+ }
}
+
+ return 0;
}
- return 0;
+ return -1;
}
-int dlt_daemon_contexts_clear(DltDaemon *daemon, int verbose)
+int dlt_daemon_contexts_clear(DltDaemon *daemon, char *ecu, int verbose)
{
int i;
+ DltDaemonRegisteredUsers *users = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
- if (daemon == NULL)
- return -1;
+ if (daemon == NULL || ecu == NULL)
+ {
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ users = dlt_daemon_find_users_list(daemon, ecu, verbose);
+ if (users == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
- for (i=0; i<daemon->num_contexts; i++)
+ for (i = 0; i < users->num_contexts; i++)
{
- if (daemon->contexts[i].context_description != NULL)
+ if (users->contexts[i].context_description != NULL)
{
- free(daemon->contexts[i].context_description);
- daemon->contexts[i].context_description = NULL;
+ free(users->contexts[i].context_description);
+ users->contexts[i].context_description = NULL;
}
}
- if (daemon->contexts)
+ if (users->contexts)
{
- free(daemon->contexts);
+ free(users->contexts);
+ users->contexts = NULL;
}
- daemon->contexts = NULL;
-
- for (i=0; i<daemon->num_applications; i++)
+ for (i = 0; i < users->num_applications; i++)
{
- daemon->applications[i].num_contexts = 0;
+ users->applications[i].num_contexts = 0;
}
- daemon->num_contexts = 0;
+ users->num_contexts = 0;
return 0;
}
@@ -889,13 +1185,18 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (filename == NULL) ||( filename[0]=='\0'))
+ {
return -1;
+ }
- fd=fopen(filename, "r");
+ fd = fopen(filename, "r");
if (fd == NULL)
{
- dlt_vlog(LOG_INFO, "DLT runtime-context load, cannot open file %s: %s\n", filename, strerror(errno));
+ dlt_vlog(LOG_WARNING,
+ "DLT runtime-context load, cannot open file %s: %s\n",
+ filename,
+ strerror(errno));
return -1;
}
@@ -906,16 +1207,18 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos
memset(buf, 0, sizeof(buf));
/* Get line */
- ret=fgets(buf,sizeof(buf),fd);
+ ret = fgets(buf,sizeof(buf),fd);
if (NULL == ret)
{
/* fgets always returns null pointer if the last byte of the file is a new line.
* We need to check here if there was an error or was it feof.*/
- if(ferror(fd))
+ if (ferror(fd))
{
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_contexts_load fgets(buf,sizeof(buf),fd) returned NULL. %s\n",
+ dlt_vlog(LOG_WARNING,
+ "%s fgets(buf,sizeof(buf),fd[%d]) returned NULL. %s\n",
+ __func__,
+ fd,
strerror(errno));
- dlt_log(LOG_WARNING, str);
fclose(fd);
return -1;
}
@@ -924,42 +1227,56 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos
fclose(fd);
return 0;
}
- else {
- snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_contexts_load fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n");
- dlt_log(LOG_WARNING, str);
+ else
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s fgets(buf,sizeof(buf),fd[%d]) returned NULL. Unknown error.\n",
+ __func__,
+ fd);
fclose(fd);
return -1;
}
}
- if (strcmp(buf,"")!=0)
+ if (strcmp(buf ,"") != 0)
{
/* Split line */
- pb=strtok(buf,":");
- if(pb != NULL)
+ pb = strtok(buf, ":");
+ if (pb != NULL)
{
- dlt_set_id(apid,pb);
- pb=strtok(NULL,":");
- if(pb != NULL)
+ dlt_set_id(apid, pb);
+ pb = strtok(NULL, ":");
+ if (pb != NULL)
{
- dlt_set_id(ctid,pb);
- pb=strtok(NULL,":");
- if(pb != NULL)
+ dlt_set_id(ctid, pb);
+ pb = strtok(NULL, ":");
+ if (pb != NULL)
{
- sscanf(pb,"%d",&ll);
- pb=strtok(NULL,":");
- if(pb != NULL)
+ sscanf(pb, "%d", &ll);
+ pb = strtok(NULL, ":");
+ if (pb != NULL)
{
- sscanf(pb,"%d",&ts);
- pb=strtok(NULL,":");
- if(pb != NULL)
+ sscanf(pb, "%d", &ts);
+ pb = strtok(NULL,":");
+ if (pb != NULL)
{
/* pb contains now the description */
/* log_level_pos, and user_handle are unknown at loading time */
- if (dlt_daemon_context_add(daemon, apid, ctid, (int8_t)ll, (int8_t)ts, 0, 0, pb, verbose) == NULL)
+ if (dlt_daemon_context_add(daemon,
+ apid,
+ ctid,
+ (int8_t)ll,
+ (int8_t)ts,
+ 0,
+ 0,
+ pb,
+ daemon->ecuid,
+ verbose) == NULL)
{
- dlt_log(LOG_WARNING, "dlt_daemon_contexts_load dlt_daemon_context_add failed\n");
+ dlt_vlog(LOG_WARNING,
+ "%s dlt_daemon_context_add failed\n",
+ __func__);
fclose(fd);
return -1;
}
@@ -981,42 +1298,58 @@ int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose
int i;
char apid[DLT_ID_SIZE+1], ctid[DLT_ID_SIZE+1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */
+ DltDaemonRegisteredUsers* user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (filename == NULL) || (filename[0]=='\0'))
+ {
+ return -1;
+ }
+
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
return -1;
+ }
memset(apid, 0, sizeof(apid));
memset(ctid, 0, sizeof(ctid));
- if ((daemon->contexts) && (daemon->num_contexts > 0))
+ if ((user_list->contexts) && (user_list->num_contexts > 0))
{
- fd=fopen(filename, "w");
+ fd = fopen(filename, "w");
if (fd != NULL)
{
- for (i=0; i<daemon->num_contexts; i++)
+ for (i = 0; i < user_list->num_contexts; i++)
{
- dlt_set_id(apid,daemon->contexts[i].apid);
- dlt_set_id(ctid,daemon->contexts[i].ctid);
+ dlt_set_id(apid, user_list->contexts[i].apid);
+ dlt_set_id(ctid, user_list->contexts[i].ctid);
- if ((daemon->contexts[i].context_description) &&
- (daemon->contexts[i].context_description[0]!='\0'))
+ if ((user_list->contexts[i].context_description) &&
+ (user_list->contexts[i].context_description[0] != '\0'))
{
fprintf(fd,"%s:%s:%d:%d:%s:\n",apid,ctid,
- (int)(daemon->contexts[i].log_level),
- (int)(daemon->contexts[i].trace_status),
- daemon->contexts[i].context_description);
+ (int)(user_list->contexts[i].log_level),
+ (int)(user_list->contexts[i].trace_status),
+ user_list->contexts[i].context_description);
}
else
{
fprintf(fd,"%s:%s:%d:%d::\n",apid,ctid,
- (int)(daemon->contexts[i].log_level),
- (int)(daemon->contexts[i].trace_status));
+ (int)(user_list->contexts[i].log_level),
+ (int)(user_list->contexts[i].trace_status));
}
}
fclose(fd);
}
+ else
+ {
+ dlt_vlog(LOG_ERR,
+ "%s: Cannot open %s. No context information stored\n",
+ __func__,
+ filename);
+ }
}
return 0;
@@ -1274,6 +1607,7 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
{
int32_t count;
DltDaemonContext *context;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1283,9 +1617,15 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
return;
}
- for (count=0; count<daemon->num_contexts; count ++)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return;
+ }
+
+ for (count = 0; count < user_list->num_contexts; count ++)
{
- context = &(daemon->contexts[count]);
+ context = &(user_list->contexts[count]);
if (context != NULL)
{
@@ -1294,7 +1634,9 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
{
if (context->user_handle >= DLT_FD_MINIMUM)
{
- if (dlt_daemon_user_send_log_level(daemon, context, verbose)==-1)
+ if (dlt_daemon_user_send_log_level(daemon,
+ context,
+ verbose) == -1)
{
dlt_vlog(LOG_WARNING, "Cannot update default of %.4s:%.4s\n", context->apid, context->ctid);
}
@@ -1308,6 +1650,7 @@ void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, int8_t log_lev
{
int32_t count = 0;
DltDaemonContext *context = NULL;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1316,15 +1659,23 @@ void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, int8_t log_lev
return;
}
- for (count = 0; count < daemon->num_contexts; count++)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
{
- context = &(daemon->contexts[count]);
+ return;
+ }
+
+ for (count = 0; count < user_list->num_contexts; count++)
+ {
+ context = &(user_list->contexts[count]);
if (context)
{
if (context->user_handle >= DLT_FD_MINIMUM)
{
context->log_level = log_level;
- if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1)
+ if (dlt_daemon_user_send_log_level(daemon,
+ context,
+ verbose) == -1)
{
dlt_vlog(LOG_WARNING, "Cannot send log level %.4s:%.4s -> %i\n", context->apid, context->ctid, context->log_level);
}
@@ -1337,6 +1688,7 @@ void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trac
{
int32_t count = 0;
DltDaemonContext *context = NULL;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1345,11 +1697,16 @@ void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trac
return;
}
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return;
+ }
dlt_vlog(LOG_NOTICE, "All trace status is updated -> %i\n", trace_status);
- for (count = 0; count < daemon->num_contexts; count++)
+ for (count = 0; count < user_list->num_contexts; count++)
{
- context = &(daemon->contexts[count]);
+ context = &(user_list->contexts[count]);
if (context)
{
if (context->user_handle >= DLT_FD_MINIMUM)
@@ -1368,6 +1725,7 @@ void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose)
{
int32_t count;
DltDaemonApplication *app;
+ DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1377,15 +1735,21 @@ void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose)
return;
}
- for (count=0; count<daemon->num_applications; count ++)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
+ {
+ return;
+ }
+
+ for (count = 0; count < user_list->num_applications; count ++)
{
- app = &(daemon->applications[count]);
+ app = &(user_list->applications[count]);
if (app != NULL)
{
if (app->user_handle >= DLT_FD_MINIMUM)
{
- if (dlt_daemon_user_send_log_state(daemon, app, verbose)==-1)
+ if (dlt_daemon_user_send_log_state(daemon, app, verbose) == -1)
{
dlt_vlog(LOG_WARNING, "Cannot send log state to Apid: %.4s, PID: %d\n",app->apid, app->pid);
}
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 5df66ed..bd81e0d 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -82,6 +82,7 @@
#include "dlt_common.h"
#include "dlt_user.h"
#include "dlt_offline_logstorage.h"
+#include "dlt_gateway_types.h"
#ifdef __cplusplus
extern "C" {
@@ -139,15 +140,25 @@ typedef struct
int8_t storage_log_level; /**< log level set for offline logstorage */
} DltDaemonContext;
+/*
+ * The parameter of registered users list
+ */
+typedef struct
+{
+ DltDaemonApplication *applications; /**< Pointer to applications */
+ int num_applications; /**< Number of available application */
+ DltDaemonContext *contexts; /**< Pointer to contexts */
+ int num_contexts; /**< Total number of all contexts in all applications in this list */
+ char ecu[DLT_ID_SIZE]; /**< ECU ID of where contexts are registered */
+} DltDaemonRegisteredUsers;
+
/**
* The parameters of a daemon.
*/
typedef struct
{
- int num_contexts; /**< Total number of all contexts in all applications */
- DltDaemonContext *contexts; /**< Pointer to contexts */
- int num_applications; /**< Number of available application */
- DltDaemonApplication *applications; /**< Pointer to applications */
+ DltDaemonRegisteredUsers *user_list; /**< registered users per ECU */
+ int num_user_lists; /** < number of context lists */
int8_t default_log_level; /**< Default log level (of daemon) */
int8_t default_trace_status; /**< Default trace status (of daemon) */
int8_t force_ll_ts; /**< Enforce ll and ts to not exceed default_log_level, default_trace_status */
@@ -189,7 +200,39 @@ int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned l
* @return negative value if there was an error
*/
int dlt_daemon_free(DltDaemon *daemon,int verbose);
-
+/**
+ * Initialize data structures to store information about applications running on same
+ * or passive node.
+ * @param daemon pointer to dlt daemon structure
+ * @param gateway pointer to dlt gateway structure
+ * @param gateway_mode mode of dlt daemon, specified in dlt.conf
+ * @param verbose if set to true verbose information is printed out
+ * @return DLT_RETURN_OK on success, DLT_RETURN_ERROR otherwise
+ */
+int dlt_daemon_init_user_information(DltDaemon *daemon,
+ DltGateway *gateway,
+ int gateway_mode,
+ int verbose);
+/**
+ * Find information about application/contexts for a specific ECU
+ * @param daemon pointer to dlt daemon structure
+ * @param ecu pointer to node name
+ * @param verbose if set to true verbose information is printed out
+ * @return pointer to user list, NULL otherwise
+ */
+DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon,
+ char *ecu,
+ int verbose);
+/**
+ * Loads the user saved configurations to daemon
+ * @param daemon pointer to dlt daemon structure
+ * @param runtime directory path
+ * @param verbose if set to true verbose information is printed out
+ * @return DLT_RETURN_OK on success, DLT_RETURN_ERROR otherwise
+ */
+int dlt_daemon_load_runtime_configuration(DltDaemon *daemon,
+ const char *runtime_directory,
+ int verbose);
/**
* Add (new) application to internal application management
* @param daemon pointer to dlt daemon structure
@@ -197,26 +240,41 @@ int dlt_daemon_free(DltDaemon *daemon,int verbose);
* @param pid process id of user application
* @param description description of application
* @param fd file descriptor of application
+ * @param ecu pointer to ecu id of node to add applications
* @param verbose if set to true verbose information is printed out.
* @return Pointer to added context, null pointer on error
*/
-DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, char *description, int fd, int verbose);
+DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,
+ char *apid,
+ pid_t pid,
+ char *description,
+ int fd,
+ char *ecu,
+ int verbose);
/**
* Delete application from internal application management
* @param daemon pointer to dlt daemon structure
* @param application pointer to application to be deleted
+ * @param ecu pointer to ecu id of node to delete applications
* @param verbose if set to true verbose information is printed out.
* @return negative value if there was an error
*/
-int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose);
+int dlt_daemon_application_del(DltDaemon *daemon,
+ DltDaemonApplication *application,
+ char *ecu,
+ int verbose);
/**
* Find application with specific application id
* @param daemon pointer to dlt daemon structure
* @param apid pointer to application id
+ * @param ecu pointer to ecu id of node to clear applications
* @param verbose if set to true verbose information is printed out.
* @return Pointer to application, null pointer on error or not found
*/
-DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose);
+DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,
+ char *apid,
+ char *ecu,
+ int verbose);
/**
* Load applications from file to internal context management
* @param daemon pointer to dlt daemon structure
@@ -236,18 +294,23 @@ int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int ver
/**
* Invalidate all applications fd, if fd is reused
* @param daemon pointer to dlt daemon structure
+ * @param ecu node these applications running on.
* @param fd file descriptor
* @param verbose if set to true verbose information is printed out.
* @return negative value if there was an error
*/
-int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose);
+int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,
+ char *ecu,
+ int fd,
+ int verbose);
/**
- * Clear all applications in internal application management
+ * Clear all applications in internal application management of specific ecu
* @param daemon pointer to dlt daemon structure
+ * @param ecu pointer to ecu id of node to clear applications
* @param verbose if set to true verbose information is printed out.
* @return negative value if there was an error
*/
-int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose);
+int dlt_daemon_applications_clear(DltDaemon *daemon,char *ecu, int verbose);
/**
* Add (new) context to internal context management
@@ -259,42 +322,66 @@ int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose);
* @param log_level_pos offset of context in context field on user application
* @param user_handle connection handle for connection to user application
* @param description description of context
+ * @param ecu pointer to ecu id of node to add application
* @param verbose if set to true verbose information is printed out.
* @return Pointer to added context, null pointer on error
*/
-DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,char *apid,char *ctid,int8_t log_level,int8_t trace_status,int log_level_pos, int user_handle,char *description,int verbose);
+DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,
+ char *apid,
+ char *ctid,
+ int8_t log_level,
+ int8_t trace_status,
+ int log_level_pos,
+ int user_handle,
+ char *description,
+ char *ecu,
+ int verbose);
/**
* Delete context from internal context management
* @param daemon pointer to dlt daemon structure
* @param context pointer to context to be deleted
+ * @param ecu pointer to ecu id of node to delete application
* @param verbose if set to true verbose information is printed out.
* @return negative value if there was an error
*/
-int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose);
+int dlt_daemon_context_del(DltDaemon *daemon,
+ DltDaemonContext* context,
+ char *ecu,
+ int verbose);
/**
* Find context with specific application id and context id
* @param daemon pointer to dlt daemon structure
* @param apid pointer to application id
* @param ctid pointer to context id
+ * @param ecu pointer to ecu id of node to clear applications
* @param verbose if set to true verbose information is printed out.
* @return Pointer to context, null pointer on error or not found
*/
-DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose);
+DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,
+ char *apid,
+ char *ctid,
+ char *ecu,
+ int verbose);
/**
* Invalidate all contexts fd, if fd is reused
* @param daemon pointer to dlt daemon structure
+ * @param ecu node these contexts running on.
* @param fd file descriptor
* @param verbose if set to true verbose information is printed out.
* @return negative value if there was an error
*/
-int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose);
+int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,
+ char *ecu,
+ int fd,
+ int verbose);
/**
- * Clear all contexts in internal context management
+ * Clear all contexts in internal context management of specific ecu
* @param daemon pointer to dlt daemon structure
+ * @param ecu pointer to ecu id of node to clear contexts
* @param verbose if set to true verbose information is printed out.
* @return negative value if there was an error
*/
-int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose);
+int dlt_daemon_contexts_clear(DltDaemon *daemon, char *ecu, int verbose);
/**
* Load contexts from file to internal context management
* @param daemon pointer to dlt daemon structure
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index 6e245eb..f6642ba 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -123,6 +123,7 @@ int dlt_logstorage_update_all_contexts(DltDaemon *daemon, char *id, int curr_log
int i = 0;
char tmp_id[DLT_ID_SIZE+1];
int old_log_level = -1;
+ DltDaemonRegisteredUsers* user_list = NULL;
if((daemon == 0) || (id == NULL))
return -1;
@@ -132,24 +133,39 @@ int dlt_logstorage_update_all_contexts(DltDaemon *daemon, char *id, int curr_log
memset(tmp_id, 0, sizeof(tmp_id));
- for(i = 0; i < daemon->num_contexts; i++)
+ user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
+ if (user_list == NULL)
{
- if(cmp_flag == 1)
- dlt_set_id(tmp_id, daemon->contexts[i].apid);
+ return -1;
+ }
+
+ for (i = 0 ; i < user_list->num_contexts ; i++)
+ {
+ if (cmp_flag == 1)
+ {
+ dlt_set_id(tmp_id, user_list->contexts[i].apid);
+ }
else
- dlt_set_id(tmp_id, daemon->contexts[i].ctid);
+ {
+ dlt_set_id(tmp_id, user_list->contexts[i].ctid);
+ }
if(strcmp(id, tmp_id) == 0)
{
if(curr_log_level > 0)
{
- old_log_level = daemon->contexts[i].storage_log_level;
+ old_log_level = user_list->contexts[i].storage_log_level;
- daemon->contexts[i].storage_log_level = DLT_OFFLINE_LOGSTORAGE_MAX(curr_log_level, daemon->contexts[i].storage_log_level);
+ user_list->contexts[i].storage_log_level =
+ DLT_OFFLINE_LOGSTORAGE_MAX(
+ curr_log_level,
+ user_list->contexts[i].storage_log_level);
- if(daemon->contexts[i].storage_log_level > old_log_level)
+ if (user_list->contexts[i].storage_log_level > old_log_level)
{
- if(dlt_daemon_user_send_log_level(daemon, &daemon->contexts[i], verbose) == -1)
+ if (dlt_daemon_user_send_log_level(daemon,
+ &user_list->contexts[i],
+ verbose) == -1)
{
dlt_log(LOG_ERR, "Unable to update loglevel\n");
return -1;
@@ -159,11 +175,13 @@ int dlt_logstorage_update_all_contexts(DltDaemon *daemon, char *id, int curr_log
else /* The request is to reset log levels */
{
/* Set storage level to -1, to clear log levels */
- daemon->contexts[i].storage_log_level = -1;
+ user_list->contexts[i].storage_log_level = -1;
if(curr_log_level == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL)
{
- if(dlt_daemon_user_send_log_level(daemon, &daemon->contexts[i], verbose) == -1)
+ if (dlt_daemon_user_send_log_level(daemon,
+ &user_list->contexts[i],
+ verbose) == -1)
{
dlt_log(LOG_ERR, "Unable to reset loglevel\n");
return -1;
@@ -198,8 +216,9 @@ int dlt_logstorage_update_context(DltDaemon *daemon, char *apid, char *ctxid, in
if((daemon == 0) || (apid == NULL) || (ctxid == NULL))
return -1;
- context = dlt_daemon_context_find(daemon, apid, ctxid, verbose);
- if(context != NULL)
+ context = dlt_daemon_context_find(daemon, apid, ctxid, daemon->ecuid, verbose);
+
+ if (context != NULL)
{
if(curr_log_level > 0)
{
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c
index 8a6595e..60a97f5 100644
--- a/src/lib/dlt_client.c
+++ b/src/lib/dlt_client.c
@@ -581,7 +581,7 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct
}
req = (DltServiceSetLogLevel *) payload;
-
+ memset(req, 0, sizeof(DltServiceSetLogLevel));
req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL;
dlt_set_id(req->apid,apid);
dlt_set_id(req->ctid,ctid);
@@ -656,7 +656,7 @@ DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char
}
req = (DltServiceSetLogLevel *) payload;
-
+ memset(req, 0, sizeof(DltServiceSetLogLevel));
req->service_id = DLT_SERVICE_ID_SET_TRACE_STATUS;
dlt_set_id(req->apid,apid);
dlt_set_id(req->ctid,ctid);