From a966393ad7003d02870bceffa08df5ddf4bbf864 Mon Sep 17 00:00:00 2001 From: Manikandan C Date: Thu, 28 Jan 2016 13:57:07 +0530 Subject: dlt-control: Provision to control entire system log level 1. support for setting log level using wildcards for both app and context 2. support for setting entire system log level Signed-off-by: Manikandan C Change-Id: I92f8c5461903f092cd50f05f644013432940a87b --- src/daemon/dlt_daemon_client.c | 161 ++++++++++++++++++++++++++++++++++------- 1 file changed, 136 insertions(+), 25 deletions(-) (limited to 'src/daemon/dlt_daemon_client.c') diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index efd8dae..24be8e4 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -563,6 +563,11 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon_local, daemon->overflow_counter,"",verbose); break; } + case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL: + { + dlt_daemon_control_set_all_log_level(sock, daemon, daemon_local, msg, verbose); + break; + } case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE: { dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose); @@ -1524,18 +1529,87 @@ void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltDaemon } } -void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose) +void dlt_daemon_send_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltDaemonContext *context,int8_t loglevel, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE]; - DltServiceSetLogLevel *req; - DltDaemonContext *context; - int32_t id=DLT_SERVICE_ID_SET_LOG_LEVEL; + int32_t id = DLT_SERVICE_ID_SET_LOG_LEVEL; + int8_t old_log_level = 0; - int8_t old_log_level; + old_log_level = context->log_level; + context->log_level = loglevel; /* No endianess conversion necessary*/ - if ((daemon==0) || (msg==0)) + 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, "Log level could not be sent!\n"); + context->log_level = old_log_level; + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); + } + +} + +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) +{ + PRINT_FUNCTION_VERBOSE(verbose); + + int8_t count = 0; + DltDaemonContext *context = NULL; + char src_str[DLT_ID_SIZE +1] = {0}; + int8_t ret = 0; + + if (daemon == 0) + { + return; + } + + for (count = 0; count < daemon->num_contexts; count++) + { + context = &(daemon->contexts[count]); + + 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_log_level(sock, daemon, daemon_local, context, loglevel, verbose); + } + else if ((ret > 0) && (app_flag == 1)) + { + break; + } + else + { + continue; + } + } + } +} + +void dlt_daemon_control_set_log_level(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 == 0) || (msg == 0)) { return; } @@ -1544,32 +1618,39 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLoca 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*/ + { + dlt_daemon_find_multiple_context_and_send(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*/ { - old_log_level = context->log_level; - context->log_level = req->log_level; /* No endianess conversion necessary*/ + dlt_daemon_find_multiple_context_and_send(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); + } + 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); + } + 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 log level */ + if (context!=0) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); + dlt_daemon_send_log_level(sock, daemon, daemon_local, context, req->log_level, verbose); } else { - //dlt_log(LOG_ERR, "Log level could not be sent!\n"); - context->log_level = old_log_level; - dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_log(LOG_ERR, "Context not found!\n"); + 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_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose) @@ -1651,6 +1732,36 @@ void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltDa } } +void dlt_daemon_control_set_all_log_level(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_LOG_LEVEL; + int8_t loglevel = 0; + + if ((daemon==0) || (msg==0)) + { + return; + } + + req = (DltServiceSetDefaultLogLevel*) (msg->databuffer); + + /* No endianess conversion necessary */ + if ((req != NULL) && (req->log_level <= DLT_LOG_VERBOSE)) + { + 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_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_default_trace_status(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); -- cgit v1.2.1