summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorYusuke Sato <yusuke-sato@apn.alpine.co.jp>2018-05-18 14:35:31 +0900
committerChristoph Lipka <clipka@users.noreply.github.com>2018-05-18 07:35:31 +0200
commitf549f5527148b32a15489aae75c9e4557e19cbd4 (patch)
treef6586dd95fb402bfd396b006e876c2d18dc5d38b /src/daemon
parent89639e55c39687af398bdf9fbaf000338a5cb7db (diff)
downloadDLT-daemon-f549f5527148b32a15489aae75c9e4557e19cbd4.tar.gz
Introduce controlling entire system trace status feature from dlt-control (#57)
* dlt-control: Provision to control entire system trace status 1. support for setting trace status using wildcards for both app and context 2. support for setting entire system trace status *This Logic is as same as for changing log level. (SHA: a966393ad7003d02870bceffa08df5ddf4bbf864 dlt-control: Provision to control entire system log level) * dlt-daemon: Fix control entire log level / trace status issue In previous, dlt-control could send request to set all log level / trace status with DLT_LOG_DEFAULT / DLT_TRACE_STATUS_DEFAULT(-1). However, dlt-daemon could not accept these value. This change fix this issue so that setting log level/trace status of all registered contexts become possible. Signed-off-by: Yusuke Sato <yusuke-sato@apn.alpine.co.jp>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/dlt_daemon_client.c230
-rw-r--r--src/daemon/dlt_daemon_client.h9
-rw-r--r--src/daemon/dlt_daemon_common.c33
-rw-r--r--src/daemon/dlt_daemon_common.h15
4 files changed, 244 insertions, 43 deletions
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index e526bf0..7c6e1bd 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -595,6 +595,11 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca
dlt_daemon_control_set_all_log_level(sock, daemon, daemon_local, msg, verbose);
break;
}
+ case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS:
+ {
+ dlt_daemon_control_set_all_trace_status(sock, daemon, daemon_local, msg, verbose);
+ break;
+ }
case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE:
{
dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose);
@@ -1580,7 +1585,14 @@ void dlt_daemon_send_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daem
}
-void dlt_daemon_find_multiple_context_and_send(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int8_t app_flag, char *str, int8_t len, int8_t loglevel, int verbose)
+void dlt_daemon_find_multiple_context_and_send_log_level(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int8_t app_flag,
+ char *str,
+ int8_t len,
+ int8_t loglevel,
+ int verbose)
{
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1591,6 +1603,7 @@ void dlt_daemon_find_multiple_context_and_send(int sock, DltDaemon *daemon, DltD
if (daemon == 0)
{
+ dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
return;
}
@@ -1648,7 +1661,9 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLoca
req = (DltServiceSetLogLevel*) (msg->databuffer);
if (daemon_local->flags.enforceContextLLAndTS)
+ {
req->log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel);
+ }
dlt_set_id(apid, req->apid);
dlt_set_id(ctid, req->ctid);
@@ -1656,19 +1671,19 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLoca
ctxtid_length = strlen(ctid);
if ((appid_length != 0) && (apid[appid_length-1] == '*') && (ctid[0] == 0)) /*appid provided having '*' in it and ctid is null*/
{
- dlt_daemon_find_multiple_context_and_send(sock, daemon, daemon_local, 1, apid, appid_length-1, req->log_level, verbose);
+ dlt_daemon_find_multiple_context_and_send_log_level(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(sock, daemon, daemon_local, 0, ctid, ctxtid_length-1, req->log_level, verbose);
+ dlt_daemon_find_multiple_context_and_send_log_level(sock, daemon, daemon_local, 0, ctid, ctxtid_length-1, req->log_level, verbose);
}
else if ((appid_length != 0) && (apid[appid_length-1] != '*') && (ctid[0] == 0)) /*only app id case*/
{
- dlt_daemon_find_multiple_context_and_send(sock, daemon, daemon_local, 1, apid, DLT_ID_SIZE, req->log_level, verbose);
+ dlt_daemon_find_multiple_context_and_send_log_level(sock, daemon, daemon_local, 1, apid, DLT_ID_SIZE, req->log_level, verbose);
}
else if ((ctxtid_length != 0) && (ctid[ctxtid_length-1] != '*') && (apid[0] == 0)) /*only context id case*/
{
- dlt_daemon_find_multiple_context_and_send(sock, daemon, daemon_local, 0, ctid, DLT_ID_SIZE, req->log_level, verbose);
+ dlt_daemon_find_multiple_context_and_send_log_level(sock, daemon, daemon_local, 0, ctid, DLT_ID_SIZE, req->log_level, verbose);
}
else
{
@@ -1681,22 +1696,104 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLoca
}
else
{
- dlt_log(LOG_ERR, "Context not found!\n");
+ dlt_vlog(LOG_ERR, "Could not set log level: %d. Context [%.4s:%.4s] not found:", req->log_level, apid, ctid);
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_SET_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose);
}
}
}
-void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
+
+void dlt_daemon_send_trace_status(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltDaemonContext *context,
+ int8_t tracestatus,
+ int verbose)
{
PRINT_FUNCTION_VERBOSE(verbose);
- char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
- DltServiceSetLogLevel *req; /* request uses same struct as set log level */
- DltDaemonContext *context;
- int32_t id=DLT_SERVICE_ID_SET_TRACE_STATUS;
+ int32_t id = DLT_SERVICE_ID_SET_TRACE_STATUS;
+ int8_t old_trace_status = 0;
+
+ old_trace_status = context->trace_status;
+ context->trace_status = tracestatus; /* No endianess conversion necessary*/
+
+ if ((context->user_handle >= DLT_FD_MINIMUM) &&
+ (dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
+ }
+ else
+ {
+ dlt_log(LOG_ERR, "Trace status could not be sent!\n");
+ context->trace_status = old_trace_status;
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ }
+}
+
+void dlt_daemon_find_multiple_context_and_send_trace_status(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int8_t app_flag,
+ char *str,
+ int8_t len,
+ int8_t tracestatus,
+ int verbose)
+{
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ int count = 0;
+ DltDaemonContext *context = NULL;
+ char src_str[DLT_ID_SIZE +1] = {0};
+ int8_t ret = 0;
+
+ if (daemon == 0)
+ {
+ dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
+ return;
+ }
+
+ for (count = 0; count < daemon->num_contexts; count++)
+ {
+ context = &(daemon->contexts[count]);
- int8_t old_trace_status;
+ if (context)
+ {
+ if (app_flag == 1)
+ {
+ strncpy(src_str, context->apid, DLT_ID_SIZE);
+ }
+ else
+ {
+ strncpy(src_str, context->ctid, DLT_ID_SIZE);
+ }
+ ret = strncmp(src_str, str, len);
+ if (ret == 0)
+ {
+ dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, tracestatus, verbose);
+ }
+ else if ((ret > 0) && (app_flag == 1))
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+}
+
+void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
+{
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ char apid[DLT_ID_SIZE+1] = {0};
+ char ctid[DLT_ID_SIZE+1] = {0};
+ DltServiceSetLogLevel *req = NULL;
+ DltDaemonContext *context = NULL;
+ int8_t appid_length = 0;
+ int8_t ctxtid_length = 0;
if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
{
@@ -1709,38 +1806,46 @@ void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltDaemonL
}
req = (DltServiceSetLogLevel*) (msg->databuffer);
+ if (daemon_local->flags.enforceContextLLAndTS)
+ {
+ req->log_level = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
+ }
dlt_set_id(apid, req->apid);
dlt_set_id(ctid, req->ctid);
-
- context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
-
- /* Set log level */
- if (context!=0)
+ appid_length = strlen(apid);
+ ctxtid_length = strlen(ctid);
+ if ((appid_length != 0) && (apid[appid_length-1] == '*') && (ctid[0] == 0)) /*appid provided having '*' in it and ctid is null*/
{
- old_trace_status = context->trace_status;
- if (daemon_local->flags.enforceContextLLAndTS)
- context->trace_status = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
- else
- context->trace_status = req->log_level; /* No endianess conversion necessary */
+ 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);
+ }
+ else if ((appid_length != 0) && (apid[appid_length-1] != '*') && (ctid[0] == 0)) /*only app id case*/
+ {
+ dlt_daemon_find_multiple_context_and_send_trace_status(sock, daemon, daemon_local, 1, apid, DLT_ID_SIZE, req->log_level, verbose);
+ }
+ else if ((ctxtid_length != 0) && (ctid[ctxtid_length-1] != '*') && (apid[0] == 0)) /*only context id case*/
+ {
+ dlt_daemon_find_multiple_context_and_send_trace_status(sock, daemon, daemon_local, 0, ctid, DLT_ID_SIZE, req->log_level, verbose);
+ }
+ else
+ {
+ context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
- if ((context->user_handle >= DLT_FD_MINIMUM ) &&
- (dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
+ /* Set trace status */
+ if (context!=0)
{
- dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
+ dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, req->log_level, verbose);
}
else
{
- //dlt_log(LOG_ERR, "Trace Status could not be sent!\n");
- context->trace_status = old_trace_status;
- dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ dlt_vlog(LOG_ERR, "Could not set trace status: %d. Context [%.4s:%.4s] not found:", req->log_level, apid, ctid);
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_SET_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose);
}
}
- else
- {
- //dlt_log(LOG_ERR, "Context not found!\n");
- dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
- }
}
void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
@@ -1792,6 +1897,7 @@ void dlt_daemon_control_set_all_log_level(int sock, DltDaemon *daemon, DltDaemon
if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
{
+ dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
return;
}
@@ -1803,15 +1909,19 @@ void dlt_daemon_control_set_all_log_level(int sock, DltDaemon *daemon, DltDaemon
req = (DltServiceSetDefaultLogLevel*) (msg->databuffer);
/* No endianess conversion necessary */
- if ((req != NULL) && (req->log_level <= DLT_LOG_VERBOSE))
+ if ((req != NULL) && ((req->log_level <= DLT_LOG_VERBOSE) || (req->log_level == (uint8_t)DLT_LOG_DEFAULT)))
{
- if (daemon_local->flags.enforceContextLLAndTS)
+ if (daemon_local->flags.enforceContextLLAndTS)
+ {
loglevel = getStatus(req->log_level, daemon_local->flags.contextLogLevel);
- else
- loglevel = req->log_level; /* No endianess conversion necessary */
+ }
+ else
+ {
+ loglevel = req->log_level; /* No endianess conversion necessary */
+ }
/* Send Update to all contexts using the new log level */
- dlt_daemon_user_send_all_update(daemon, loglevel, verbose);
+ dlt_daemon_user_send_all_log_level_update(daemon, loglevel, verbose);
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
}
@@ -1861,6 +1971,50 @@ void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, Dl
}
}
+void dlt_daemon_control_set_all_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
+{
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ DltServiceSetDefaultLogLevel *req = NULL;
+ int32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS;
+ int8_t tracestatus = 0;
+
+ if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
+ return;
+ }
+
+ if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
+ {
+ return;
+ }
+
+ req = (DltServiceSetDefaultLogLevel*) (msg->databuffer);
+
+ /* No endianess conversion necessary */
+ if ((req != NULL) && ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT)))
+ {
+ if (daemon_local->flags.enforceContextLLAndTS)
+ {
+ tracestatus = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
+ }
+ else
+ {
+ tracestatus = req->log_level; /* No endianess conversion necessary */
+ }
+
+ /* Send Update to all contexts using the new log level */
+ dlt_daemon_user_send_all_trace_status_update(daemon, tracestatus, verbose);
+
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
+ }
+ else
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ }
+}
+
void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
{
PRINT_FUNCTION_VERBOSE(verbose);
diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h
index 275ee3e..b974b67 100644
--- a/src/daemon/dlt_daemon_client.h
+++ b/src/daemon/dlt_daemon_client.h
@@ -249,6 +249,15 @@ void dlt_daemon_control_set_all_log_level(int sock, DltDaemon *daemon, DltDaemon
*/
void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose);
/**
+ * Process and generate response to received set all trace status control message
+ * @param sock connection handle used for sending response
+ * @param daemon pointer to dlt daemon structure
+ * @param daemon_local pointer to dlt daemon local structure
+ * @param msg pointer to received control message
+ * @param verbose if set to true verbose information is printed out.
+ */
+void dlt_daemon_control_set_all_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose);
+/**
* Process and generate response to set timing packets control message
* @param sock connection handle used for sending response
* @param daemon pointer to dlt daemon structure
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 0f56cc3..40d8d5c 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -1287,7 +1287,7 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
}
}
-void dlt_daemon_user_send_all_update(DltDaemon *daemon, int8_t log_level, int verbose)
+void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, int8_t log_level, int verbose)
{
int32_t count = 0;
DltDaemonContext *context = NULL;
@@ -1316,6 +1316,37 @@ void dlt_daemon_user_send_all_update(DltDaemon *daemon, int8_t log_level, int ve
}
}
+void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trace_status, int verbose)
+{
+ int32_t count = 0;
+ DltDaemonContext *context = NULL;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if (daemon == NULL)
+ {
+ return;
+ }
+
+ dlt_vlog(LOG_NOTICE, "All trace status is updated -> %i\n", trace_status);
+
+ for (count = 0; count < daemon->num_contexts; count++)
+ {
+ context = &(daemon->contexts[count]);
+ if (context)
+ {
+ if (context->user_handle >= DLT_FD_MINIMUM)
+ {
+ context->trace_status = trace_status;
+ if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1)
+ {
+ dlt_vlog(LOG_WARNING, "Cannot send trace status %.4s:%.4s -> %i\n", context->apid, context->ctid, context->trace_status);
+ }
+ }
+ }
+ }
+}
+
void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose)
{
int32_t count;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 02d2860..d79febb 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -355,13 +355,20 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,i
void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose);
/**
- * Send user messages to all user applications context, or trace status
- * to update with the new log level
+ * Send user messages to all user applications context to update with the new log level
* @param daemon pointer to dlt daemon structure
- * @param log level to be set
+ * @param log_level new log level to be set
* @param verbose if set to true verbose information is printed out.
*/
-void dlt_daemon_user_send_all_update(DltDaemon *daemon, int8_t log_level, int verbose);
+void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, int8_t log_level, int verbose);
+
+/**
+ * Send user messages to all user applications context to update with the new trace status
+ * @param daemon pointer to dlt daemon structure
+ * @param trace_status new trace status to be set
+ * @param verbose if set to true verbose information is printed out.
+ */
+void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trace_status, int verbose);
/**
* Send user messages to all user applications the log status