diff options
author | ManikandanChockalingam <manikandan.chockalingam@in.bosch.com> | 2018-11-15 13:52:21 +0100 |
---|---|---|
committer | Christoph Lipka <clipka@users.noreply.github.com> | 2018-11-15 13:52:21 +0100 |
commit | 3cfb292aa43774428ce8dfe120fe16785942b086 (patch) | |
tree | 00841761981aead232f5e6995eefde6babaddeb4 /src/daemon | |
parent | 6cbaa4fd39fb584a227b8eb7a3331dcfce54d9a3 (diff) | |
download | DLT-daemon-3cfb292aa43774428ce8dfe120fe16785942b086.tar.gz |
Log storage - Updates (#82)
- improvements and refactor key creation
- Sync strategies added
Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
Signed-off-by: S. Hameed <shameed@jp.adit-jv.com>
Signed-off-by: Ravi Sankar P <ponnurangamravi.sankar@in.bosch.com>
Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/dlt-daemon.c | 13 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_client.c | 166 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_common.c | 8 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_offline_logstorage.c | 1127 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_offline_logstorage.h | 121 |
5 files changed, 1071 insertions, 364 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index c62ea82..2cf8632 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -719,11 +719,14 @@ int main(int argc, char* argv[]) if(daemon_local.flags.offlineLogstorageDirPath[0]) { - if(dlt_daemon_logstorage_setup_internal_storage(&daemon, - daemon_local.flags.offlineLogstorageDirPath, - daemon_local.flags.vflag)==-1) - { - dlt_log(LOG_INFO,"Setting up internal offline log storage failed!\n"); + if (dlt_daemon_logstorage_setup_internal_storage( + &daemon, + &daemon_local, + daemon_local.flags.offlineLogstorageDirPath, + daemon_local.flags.vflag) == -1) + { + dlt_log(LOG_INFO, + "Setting up internal offline log storage failed!\n"); } } diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index a265632..dd69326 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -2347,23 +2347,40 @@ int dlt_daemon_process_systemd_timer(DltDaemon *daemon, } #endif -void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose) +void dlt_daemon_control_service_logstorage(int sock, + DltDaemon *daemon, + DltDaemonLocal *daemon_local, + DltMessage *msg, + int verbose) { DltServiceOfflineLogstorage *req; int ret; + unsigned int connection_type = 0; + DltLogStorage *device = NULL; + int device_index = -1; + int i = 0; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL) || (msg->databuffer == NULL)) + if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL)) { - dlt_log(LOG_ERR, "Invalid function parameters used for dlt_daemon_control_service_logstorage\n"); + dlt_vlog(LOG_ERR, + "%s: Invalid function parameters\n", + __func__); return ; } - if(daemon_local->flags.offlineLogstorageMaxDevices <= 0) + if ((daemon_local->flags.offlineLogstorageMaxDevices <= 0) || (msg->databuffer == NULL)) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); - dlt_log(LOG_INFO, "Offline logstorage functionality not enabled or MAX device set is 0\n"); + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); + + dlt_log(LOG_INFO, + "Logstorage functionality not enabled or MAX device set is 0\n"); return; } @@ -2373,82 +2390,140 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo } req = (DltServiceOfflineLogstorage*) (msg->databuffer); - int device_index=-1; - int i=0; - for(i=0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) { + connection_type = daemon->storage_handle[i].connection_type; /* Check if the requested device path is already used as log storage device */ - if(strcmp(daemon->storage_handle[i].device_mount_point, - req->mount_point) == 0) + if (strncmp(daemon->storage_handle[i].device_mount_point, + req->mount_point, strlen(req->mount_point)) == 0) { device_index = i; break; } + /* Get first available device index here */ - if((daemon->storage_handle[i].connection_type != - DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && - (device_index == -1)) + if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && + (device_index == -1)) { device_index = i; } } - if((device_index) == -1) + /* It might be possible to sync all caches of all devices */ + if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) && + (strlen(req->mount_point) == 0)) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - dlt_log(LOG_WARNING, "MAX devices already in use \n"); - return; + /* It is expected to receive an empty mount point to sync all Logstorage + * devices in this case. */ + } + else + { + if (device_index == -1) + { + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); + dlt_log(LOG_WARNING, "MAX devices already in use \n"); + return; + } } - - /* Check for device connection request from log storage ctrl app */ + /* Check for device connection request from log storage ctrl app */ + device = &daemon->storage_handle[device_index]; if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { - ret = dlt_logstorage_device_connected(&(daemon->storage_handle[device_index]), req->mount_point); - if(ret != 0) + ret = dlt_logstorage_device_connected(device, req->mount_point); + + if (ret == 1) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_WARNING, + verbose); return; } - - /* Setup logstorage with config file settings */ - ret = dlt_logstorage_load_config(&(daemon->storage_handle[device_index])); - if(ret != 0) + else if (ret != 0) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); return; } - dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,DLT_SERVICE_RESPONSE_OK, verbose); + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_OK, + verbose); /* Check if log level of running application needs an update */ - dlt_daemon_logstorage_update_application_loglevel(daemon, device_index, verbose); + dlt_daemon_logstorage_update_application_loglevel(daemon, + daemon_local, + device_index, + verbose); } /* Check for device disconnection request from log storage ctrl app */ else if(req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED) { /* Check if log level of running application needs to be reset */ - dlt_daemon_logstorage_reset_application_loglevel(daemon, device_index, daemon_local->flags.offlineLogstorageMaxDevices, verbose); + dlt_daemon_logstorage_reset_application_loglevel( + daemon, + daemon_local, + device_index, + daemon_local->flags.offlineLogstorageMaxDevices, + verbose); dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]), DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); - dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_OK, + verbose); + } /* Check for cache synchronization request from log storage ctrl app */ else if(req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { - /* trigger logstorage to sync caches */ - if (dlt_daemon_logstorage_sync_cache(daemon, - daemon_local, - req->mount_point, - verbose) == 0) + int ret = 0; + if (device_index == -1) /* sync all Logstorage devices */ + { + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + { + if (daemon->storage_handle[i].connection_type == + DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + { + ret = dlt_daemon_logstorage_sync_cache( + daemon, + daemon_local, + daemon->storage_handle[i].device_mount_point, + verbose); + } + } + } + else + { + /* trigger logstorage to sync caches */ + ret = dlt_daemon_logstorage_sync_cache(daemon, + daemon_local, + req->mount_point, + verbose); + } + + if (ret == 0) { dlt_daemon_control_service_response(sock, daemon, @@ -2469,7 +2544,12 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo } else { - dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); } } diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index 3ba4c9b..990c029 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -973,9 +973,8 @@ DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon, /* 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 ((strncmp(daemon->ecuid, ecu, DLT_ID_SIZE) == 0) && - ((new_context == 1) || ((new_context == 0) && - (daemon->runtime_context_cfg_loaded == 0)))) + if ((new_context == 1) || + ((new_context == 0) && (daemon->runtime_context_cfg_loaded == 0))) { context->log_level = log_level; context->trace_status = trace_status; @@ -1785,6 +1784,3 @@ void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState) } } - - - diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c index f6642ba..fe4d8a7 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.c +++ b/src/daemon/dlt_daemon_offline_logstorage.c @@ -1,24 +1,24 @@ /** -* @licence app begin@ -* Copyright (C) 2013 - 2015 Advanced Driver Information Technology. -* This code is developed by Advanced Driver Information Technology. -* Copyright of Advanced Driver Information Technology, Bosch and DENSO. -* -* DLT offline log storage functionality source file. -* -* \copyright -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -* this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* -* -* \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015 -* \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015 -* -* \file: dlt_daemon_offline_logstorage.c -* For further information see http://www.genivi.org/. -* @licence end@ -*/ + * @licence app begin@ + * Copyright (C) 2013 - 2018 Advanced Driver Information Technology. + * This code is developed by Advanced Driver Information Technology. + * Copyright of Advanced Driver Information Technology, Bosch and DENSO. + * + * DLT offline log storage functionality source file. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015 + * \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015 + * + * \file: dlt_daemon_offline_logstorage.c + * For further information see http://www.genivi.org/. + * @licence end@ + */ #include <stdio.h> #include <stdlib.h> @@ -26,11 +26,248 @@ #include <syslog.h> #include "dlt_daemon_offline_logstorage.h" +#include "dlt_gateway_types.h" +#include "dlt_gateway.h" + +/** + * dlt_logstorage_split_ecuid + * + * Split keys with ECU ID alone + * + * @param key Key + * @param len Key length + * @param ecuid ECU ID from key stored here + * @param apid Application ID as .* stored here + * @param ctxid Context id as .* stored here + * @return 0 on success -1 on error + */ +STATIC DltReturnValue dlt_logstorage_split_ecuid(char *key, + int len, + char *ecuid, + char *appid, + char *ctxid) +{ + if ((len > (DLT_ID_SIZE + 2)) || (len < 2)) + { + return DLT_RETURN_ERROR; + } + + strncpy(ecuid, key, (len - 2)); + strncpy(appid, ".*", 2); + strncpy(ctxid, ".*", 2); + + return DLT_RETURN_OK; +} + +/** + * dlt_logstorage_split_ctid + * + * Split keys with Context ID alone + * + * @param key Key + * @param len Key length + * @param appid Application ID as .* stored here + * @param ctxid Context id from key stored here + * @return 0 on success -1 on error + */ +STATIC DltReturnValue dlt_logstorage_split_ctid(char *key, + int len, + char *appid, + char *ctxid) +{ + if ((len > (DLT_ID_SIZE + 2)) || (len < 1) ) + { + return DLT_RETURN_ERROR; + } + + strncpy(ctxid, (key + 2), (len - 1)); + strncpy(appid, ".*", 2); + + return DLT_RETURN_OK; +} + +/** + * dlt_logstorage_split_apid + * + * Split keys with Application ID alone + * + * @param key Key + * @param len Key length + * @param appid Application ID from key is stored here + * @param ctxid Context id as .* stored here + * @return 0 on success -1 on error + */ +STATIC DltReturnValue dlt_logstorage_split_apid(char *key, + int len, + char *appid, + char *ctxid) +{ + if ((len > (DLT_ID_SIZE + 2)) || (len < 2)) + { + return DLT_RETURN_ERROR; + } + + strncpy(appid, key + 1, (len - 2)); + strncpy(ctxid, ".*", 2); + + return DLT_RETURN_OK; +} + +/** + * dlt_logstorage_split_apid_ctid + * + * Split keys with Application ID and Context ID + * + * @param key Key + * @param len Key length + * @param appid Application ID from key is stored here + * @param ctxid CContext id from key is stored here + * @return 0 on success -1 on error + */ +STATIC DltReturnValue dlt_logstorage_split_apid_ctid(char *key, + int len, + char *appid, + char *ctxid) +{ + char *tok = NULL; + + if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) + { + return DLT_RETURN_ERROR; + } + + /* copy appid and ctxid */ + tok = strtok(key, ":"); + if (tok != NULL) + { + strncpy(appid, tok, DLT_ID_SIZE); + } + else + { + return DLT_RETURN_ERROR; + } + + tok = strtok(NULL, ":"); + if (tok != NULL) + { + strncpy(ctxid, tok, DLT_ID_SIZE); + } + else + { + return DLT_RETURN_ERROR; + } + + return DLT_RETURN_OK; +} + +/** + * dlt_logstorage_split_ecuid_apid + * + * Split keys with ECU ID and Application ID + * + * @param key Key + * @param len Key length + * @param ecuid ECU ID from key stored here + * @param appid Application ID from key is stored here + * @param ctxid CContext id as .* stored here + * @return 0 on success -1 on error + */ +STATIC DltReturnValue dlt_logstorage_split_ecuid_apid(char *key, + int len, + char *ecuid, + char *appid, + char *ctxid) +{ + char *tok = NULL; + + if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) + { + return DLT_RETURN_ERROR; + } + + /* copy appid and ctxid */ + tok = strtok(key, ":"); + if (tok != NULL) + { + strncpy(ecuid, tok, DLT_ID_SIZE); + } + else + { + return DLT_RETURN_ERROR; + } + + tok = strtok(NULL, ":"); + + if (tok != NULL) + { + strncpy(appid, tok, DLT_ID_SIZE); + } + else + { + return DLT_RETURN_ERROR; + } + strncpy(ctxid, ".*", 2); + return DLT_RETURN_OK; +} + +/** + * dlt_logstorage_split_multi + * + * Prepares keys with application ID alone, will use ecuid if provided + * (ecuid:apid::) or (:apid::) + * + * @param ecuid ECU ID + * @param apid Application ID + * @param key Prepared key stored here + * @return None + */ +STATIC DltReturnValue dlt_logstorage_split_multi(char *key, + int len, + char *ecuid, + char *appid, + char *ctxid) +{ + char *tok = NULL; + + if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) + { + return DLT_RETURN_ERROR; + } + + tok = strtok(key, ":"); + if (tok == NULL) + { + return DLT_RETURN_ERROR; + } + + len = strlen(tok); + if (key[len + 1] == ':') + { + strncpy(ecuid, tok, DLT_ID_SIZE); + + tok = strtok(NULL, ":"); + if (tok != NULL) + { + strncpy(ctxid, tok, DLT_ID_SIZE); + } + strncpy(appid, ".*", 2); + } + else + { + strncpy(ecuid, tok, DLT_ID_SIZE); + tok = strtok(NULL, ":"); + strncpy(appid, tok, DLT_ID_SIZE); + tok = strtok(NULL, ":"); + strncpy(ctxid, tok, DLT_ID_SIZE); + } + + return DLT_RETURN_OK; +} /** * dlt_logstorage_split_key -* + * * Split a given key into appid and ctxid. * If APID: - appid = APID and ctxid = .* * If :CTID - ctxid = CTID and appid = .* @@ -41,105 +278,323 @@ * @param ctxid Context id * @return 0 on success, -1 on error */ -int dlt_logstorage_split_key(char *key, char *appid, char *ctxid) +STATIC DltReturnValue dlt_logstorage_split_key(char *key, char *appid, char *ctxid, char *ecuid) { - char *tok = NULL; int len = 0; - int ret = 0; char *sep = NULL; - if (key == NULL) + if ((key == NULL) || (appid == NULL) || (ctxid == NULL) || (ecuid == NULL)) { - return -1; + return DLT_RETURN_WRONG_PARAMETER; } len = strlen(key); sep = strchr (key, ':'); - if(sep == NULL) + + if (sep == NULL) { - return -1; + return DLT_RETURN_WRONG_PARAMETER; } - /* key is context id only */ - if(key[0] == ':') + /* key is ecuid only ecuid::*/ + if ((key[len - 1] == ':') && (key[len - 2] == ':')) + { + return dlt_logstorage_split_ecuid(key, len, ecuid, appid, ctxid); + } + /* key is context id only ::apid*/ + else if ((key[0] == ':') && (key[1] == ':')) + { + return dlt_logstorage_split_ctid(key, len, appid, ctxid); + } + /* key is application id only :apid: */ + else if ((key[0] == ':') && key[len - 1] == ':') + { + return dlt_logstorage_split_apid(key, len, appid, ctxid); + } + /* key is :apid:ctid */ + else if ((key[0] == ':') && key[len - 1] != ':') + { + return dlt_logstorage_split_apid_ctid(key, len, appid, ctxid); + } + /* key is ecuid:apid: */ + else if ((key[0] != ':') && key[len - 1] == ':') { - if(len > (DLT_ID_SIZE+1)) - return -1; + return dlt_logstorage_split_ecuid_apid(key, len, ecuid, appid, ctxid); + } + /* key is either ecuid::ctid or ecuid:apid:ctid */ + else + { + return dlt_logstorage_split_multi(key, len, ecuid, appid, ctxid); + } +} - strncpy(ctxid,(key+1),(len-1)); - strncpy(appid, ".*",2); +/** + * Forward SET_LOG_LEVEL request to passive node + * + * @param daemon_local pointer to DltDaemonLocal structure + * @param apid Application ID + * @param ctid Context ID + * @param ecuid ECU ID + * @param loglevel requested log level + * @param verbose verbosity flag + */ +STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context( + DltDaemonLocal *daemon_local, + char *apid, + char *ctid, + char *ecuid, + int loglevel, + int verbose) +{ + // Need to be updated + // To avoid compiler warning + (void) daemon_local; + (void) apid; + (void) ctid; + (void) ecuid; + (void) loglevel; + (void) verbose; + + return DLT_RETURN_OK; +} + +/** + * dlt_daemon_logstorage_send_log_level + * + * Send new log level for the provided context, if ecuid is not daemon ecuid + * update log level of passive node + * + * @param daemon DltDaemon structure + * @param daemon_local DltDaemonLocal structure + * @param context DltDaemonContext structure + * @param ecuid ECU id + * @param loglevel log level to be set to context + * @param verbose If set to true verbose information is printed out + * @return 0 on success, -1 on error + */ +STATIC DltReturnValue dlt_daemon_logstorage_send_log_level(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + DltDaemonContext *context, + char *ecuid, + int loglevel, + int verbose) +{ + int old_log_level = -1; + int ll = DLT_LOG_DEFAULT; + + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || + (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) + { + dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); + return DLT_RETURN_WRONG_PARAMETER; } - /* key is application id only */ - else if (key[len-1] == ':') + + + if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) == 0) { - if(len > (DLT_ID_SIZE+1)) - return -1; + old_log_level = context->storage_log_level; + + context->storage_log_level = DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, + context->storage_log_level); + + if (context->storage_log_level > old_log_level) + { + if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) + { + dlt_log(LOG_ERR, "Unable to update log level\n"); + return DLT_RETURN_ERROR; + } + } - strncpy(appid,key,(len-1)); - strncpy(ctxid, ".*",2); } - /* key is appid:ctxid */ else { - if(len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) - return -1; - /* copy appid and ctxid */ - tok = strtok(key, ":"); - if (tok != NULL) - strncpy(appid,tok,DLT_ID_SIZE); - else - ret = -1; + old_log_level = context->log_level; + + ll = DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, context->log_level); + + if (ll > old_log_level) + { + return dlt_daemon_logstorage_update_passive_node_context(daemon_local, + context->apid, + context->ctid, + ecuid, + ll, + verbose); + } - tok = strtok(NULL, ":"); - if (tok != NULL) - strncpy(ctxid,tok,DLT_ID_SIZE); - else - ret = -1; } + return DLT_RETURN_OK; +} + +/** + * dlt_daemon_logstorage_reset_log_level + * + * The log levels are reset if log level provided is -1 (not sent to + * application in this case). Reset and sent to application if current log level + * provided is 0. + * + * @param daemon DltDaemon structure + * @param daemon_local DltDaemonLocal structure + * @param ecuid ECU ID + * @param loglevel log level to be set to context + * @param verbose If set to true verbose information is printed out + * @return 0 on success, -1 on error + */ +STATIC DltReturnValue dlt_daemon_logstorage_reset_log_level(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + DltDaemonContext *context, + char *ecuid, + int loglevel, + int verbose) +{ + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || + (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) + { + dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); + return DLT_RETURN_WRONG_PARAMETER; + } + + + /* Set storage level to -1, to clear log levels */ + context->storage_log_level = DLT_LOG_DEFAULT; + + if (loglevel == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL) + { + if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) == 0) + { + if (dlt_daemon_user_send_log_level(daemon, + context, + verbose) == DLT_RETURN_ERROR) + { + dlt_log(LOG_ERR, "Unable to update log level\n"); + return DLT_RETURN_ERROR; + } + } + else /* forward set log level to passive node */ + { + return dlt_daemon_logstorage_update_passive_node_context(daemon_local, + context->apid, + context->ctid, + ecuid, + DLT_LOG_DEFAULT, + verbose); + } + } + return DLT_RETURN_OK; +} + +/** + * dlt_daemon_logstorage_force_reset_level + * + * Force resetting of log level since have no data provided by passive node. + * + * @param daemon DltDaemon structure + * @param daemon_local DltDaemonLocal structure + * @param ecuid ECU ID + * @param loglevel log level to be set to context + * @param verbose If set to true verbose information is printed out + * @return 0 on success, -1 on error + */ +STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *apid, + char *ctxid, + char *ecuid, + int loglevel, + int verbose) +{ + int ll = DLT_LOG_DEFAULT; + int num = 0; + int i = 0; + DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = { 0 }; + + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || + (apid == NULL) || (ctxid == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) + { + dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); + return DLT_RETURN_WRONG_PARAMETER; + } + + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + { + num = dlt_logstorage_get_config(&(daemon->storage_handle[i]), config, apid, ctxid, ecuid); + if (num > 0) + { + break; /* found config */ + } + } + + if ((num == 0) || (config[0] == NULL )) + { + dlt_vlog(LOG_ERR, + "%s: No information about APID: %s, CTID: %s, ECU: %s in Logstorage configuration\n", + __func__, apid, ctxid, ecuid); + return DLT_RETURN_ERROR; + } + + if (loglevel == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL) + { + ll = config[0]->reset_log_level; + } + else + { + ll = config[0]->log_level; + } + + return dlt_daemon_logstorage_update_passive_node_context(daemon_local, apid, + ctxid, ecuid, ll, verbose); - return ret; } /** * dlt_logstorage_update_all_contexts * - * Update log level of all contexts of the application by updating the daemon internal table - * The compare flags (cmp_flag) indicates if Id has to be compared with application ID - * or Context id of the daemon internal table - * The log levels are reset if current log level provided is -1 (not sent to application in this case) - * Reset and sent to application if current log level provided is 0 + * Update log level of all contexts of the application by updating the daemon + * internal table. The compare flags (cmp_flag) indicates if Id has to be + * compared with application id or Context id of the daemon internal table. + * The log levels are reset if current log level provided is -1 (not sent to + * application in this case). Reset and sent to application if current log level + * provided is 0. * * @param daemon DltDaemon structure + * @param daemon_local DltDaemonLocal structure * @param id application id or context id * @param curr_log_level log level to be set to context * @param cmp_flag compare flag (1 id is apid, 2 id is ctxid) + * @param ecuid ecu id where application runs * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -int dlt_logstorage_update_all_contexts(DltDaemon *daemon, char *id, int curr_log_level, int cmp_flag, int verbose) +DltReturnValue dlt_logstorage_update_all_contexts(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *id, + int curr_log_level, + int cmp_flag, + char *ecuid, + int verbose) { - int i = 0; - char tmp_id[DLT_ID_SIZE+1]; - int old_log_level = -1; DltDaemonRegisteredUsers* user_list = NULL; + int i = 0; + char tmp_id[DLT_ID_SIZE + 1] = {'\0'}; - if((daemon == 0) || (id == NULL)) - return -1; - - if((cmp_flag < 0 ) || (cmp_flag > 2 )) - return -1; - - memset(tmp_id, 0, sizeof(tmp_id)); + if ((daemon == NULL) || (daemon_local == NULL) ||(id == NULL) || + (ecuid == NULL) || (cmp_flag < DLT_DAEMON_LOGSTORAGE_CMP_APID) || + (cmp_flag > DLT_DAEMON_LOGSTORAGE_CMP_CTID)) + { + dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__); + return DLT_RETURN_WRONG_PARAMETER; + } - user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose); + user_list = dlt_daemon_find_users_list(daemon, ecuid, verbose); if (user_list == NULL) { - return -1; + return DLT_RETURN_ERROR; } - for (i = 0 ; i < user_list->num_contexts ; i++) + for (i = 0; i < user_list->num_contexts; i++) { if (cmp_flag == 1) { @@ -150,106 +605,115 @@ int dlt_logstorage_update_all_contexts(DltDaemon *daemon, char *id, int curr_log dlt_set_id(tmp_id, user_list->contexts[i].ctid); } - if(strcmp(id, tmp_id) == 0) + if (strncmp(id, tmp_id, DLT_ID_SIZE) == 0) { - if(curr_log_level > 0) + if (curr_log_level > 0) { - old_log_level = user_list->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 (user_list->contexts[i].storage_log_level > old_log_level) - { - 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; - } - } + dlt_daemon_logstorage_send_log_level(daemon, + daemon_local, + &user_list->contexts[i], + ecuid, + curr_log_level, + verbose); } - else /* The request is to reset log levels */ + else /* The request is to reset log levels */ { - /* Set storage level to -1, to clear log levels */ - 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, - &user_list->contexts[i], - verbose) == -1) - { - dlt_log(LOG_ERR, "Unable to reset loglevel\n"); - return -1; - } - } - + dlt_daemon_logstorage_reset_log_level(daemon, + daemon_local, + &user_list->contexts[i], + ecuid, + curr_log_level, + verbose); } } } - return 0; + return DLT_RETURN_OK; } /** * dlt_logstorage_update_context * * Update log level of a context by updating the daemon internal table - * The log levels are reset if current log level provided is -1 (not sent to application in this case) + * The log levels are reset if current log level provided is -1 (not sent to + * application in this case) * Reset and sent to application if current log level provided is 0 * * @param daemon DltDaemon structure + * @param daemon_local DltDaemonLocal structure * @param apid application id * @param ctxid context id + * @param ecuid ecu id * @param curr_log_level log level to be set to context * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -int dlt_logstorage_update_context(DltDaemon *daemon, char *apid, char *ctxid, int curr_log_level , int verbose) +DltReturnValue dlt_logstorage_update_context(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *apid, + char *ctxid, + char *ecuid, + int curr_log_level, + int verbose) { DltDaemonContext *context = NULL; - int old_log_level = -1; - if((daemon == 0) || (apid == NULL) || (ctxid == NULL)) - return -1; - - context = dlt_daemon_context_find(daemon, apid, ctxid, daemon->ecuid, verbose); + if ((daemon == NULL) || (daemon_local == NULL) ||(apid == NULL) + || (ctxid == NULL) || (ecuid == NULL)) + { + dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__); + return DLT_RETURN_WRONG_PARAMETER; + } + context = dlt_daemon_context_find(daemon, apid, ctxid, ecuid, verbose); if (context != NULL) { - if(curr_log_level > 0) + if (curr_log_level > 0) { - old_log_level = context->storage_log_level; - - context->storage_log_level = DLT_OFFLINE_LOGSTORAGE_MAX(curr_log_level, context->storage_log_level); - if(context->storage_log_level > old_log_level) - { - if(dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) - { - dlt_log(LOG_ERR, "Unable to update loglevel\n"); - return -1; - } - } + return dlt_daemon_logstorage_send_log_level(daemon, + daemon_local, + context, + ecuid, + curr_log_level, + verbose); + } + else /* The request is to reset log levels */ + { + return dlt_daemon_logstorage_reset_log_level(daemon, + daemon_local, + context, + ecuid, + curr_log_level, + verbose); + } + } + else + { + if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) != 0) + { + // we intentionally have no data provided by passive node. + // We blindly send the log level or reset log level + return dlt_daemon_logstorage_force_reset_level(daemon, + daemon_local, + apid, + ctxid, + ecuid, + curr_log_level, + verbose); } else { - context->storage_log_level = -1; - - if(curr_log_level == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL) - { - if(dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) - { - dlt_log(LOG_ERR, "Unable to update loglevel\n"); - return -1; - } - } + dlt_vlog(LOG_WARNING, + "%s: No information about APID: %s, CTID: %s, ECU: %s\n", + __func__, + apid, + ctxid, + ecuid); + return DLT_RETURN_ERROR; } } - return 0; + + return DLT_RETURN_OK; } /** @@ -263,47 +727,82 @@ int dlt_logstorage_update_context(DltDaemon *daemon, char *apid, char *ctxid, in * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -int dlt_logstorage_update_context_loglevel(DltDaemon *daemon, char *key, int curr_log_level , int verbose) +DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *key, + int curr_log_level, + int verbose) { - - int cmp_flag=0; - char appid[DLT_ID_SIZE+1] = {'\0'}; - char ctxid[DLT_ID_SIZE+1] = {'\0'}; + int cmp_flag = 0; + char appid[DLT_ID_SIZE + 1] = {'\0'}; + char ctxid[DLT_ID_SIZE + 1] = {'\0'}; + char ecuid[DLT_ID_SIZE + 1] = {'\0'}; PRINT_FUNCTION_VERBOSE(verbose); - if((daemon == 0) || (key == NULL)) - return -1; - - memset(appid, 0, sizeof(appid)); - memset(ctxid, 0, sizeof(ctxid)); + if ((daemon == NULL) || (daemon_local == NULL) || (key == NULL)) + { + return DLT_RETURN_WRONG_PARAMETER; + } - if(dlt_logstorage_split_key(key, appid, ctxid) != 0) + if (dlt_logstorage_split_key(key, appid, ctxid, ecuid) != 0) { - dlt_log(LOG_ERR, "Error while updating application log levels (splt key)\n"); - return -1; + dlt_log(LOG_ERR, + "Error while updating application log levels (split key)\n"); + return DLT_RETURN_ERROR; } - if(strcmp(ctxid, ".*") == 0) /* wildcard for context id, find all contexts of given application id */ + if (ecuid[0] == '\0') /* ECU id was not specified in filter configuration */ { - cmp_flag = 1; + dlt_set_id(ecuid, daemon->ecuid); + } - if(dlt_logstorage_update_all_contexts(daemon, appid, curr_log_level, cmp_flag, verbose) != 0) - return -1; + /* wildcard for context id, find all contexts of given application id */ + if (strcmp(ctxid, ".*") == 0) + { + cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_APID; + + if (dlt_logstorage_update_all_contexts(daemon, + daemon_local, + appid, + curr_log_level, + cmp_flag, + ecuid, + verbose) != 0) + { + return DLT_RETURN_ERROR; + } } - else if(strcmp(appid, ".*") == 0) /* wildcard for application id, find all contexts with context id */ + /* wildcard for application id, find all contexts with context id */ + else if (strcmp(appid, ".*") == 0) { - cmp_flag = 2; - - if(dlt_logstorage_update_all_contexts(daemon, ctxid, curr_log_level, cmp_flag, verbose) != 0) - return -1; + cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_CTID; + + if (dlt_logstorage_update_all_contexts(daemon, + daemon_local, + ctxid, + curr_log_level, + cmp_flag, + ecuid, + verbose) != 0) + { + return DLT_RETURN_ERROR; + } } - else /* In case of given application id, context id pair, call available context find function */ + /* In case of given application id, context id pair, call available context + * find function */ + else if (dlt_logstorage_update_context(daemon, + daemon_local, + appid, + ctxid, + ecuid, + curr_log_level, + verbose) != 0) { - if(dlt_logstorage_update_context(daemon, appid, ctxid, curr_log_level, verbose) != 0) - return -1; + return DLT_RETURN_ERROR; } - return 0; + + return DLT_RETURN_OK; } /** @@ -311,135 +810,193 @@ int dlt_logstorage_update_context_loglevel(DltDaemon *daemon, char *key, int cur * * Reset storage log level of all running applications * 2 steps for resetting - * 1. Setup storage_loglevel of all contexts configured for the requested device to -1 + * 1. Setup storage_loglevel of all contexts configured for the requested device + * to -1 * 2. Re-run update log level for all other configured devices * * @param daemon Pointer to DLT Daemon structure + * @param daemon_local Pointer to DLT Daemon local structure * @param dev_num Number of attached DLT Logstorage device * @param max_device Maximum storage devices setup by the daemon * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, int dev_num, int max_device, int verbose) +void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + int dev_num, + int max_device, + int verbose) { DltLogStorage *handle = NULL; + DltLogStorageFilterList **tmp = NULL; int i = 0; - char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = {'\0'}; + char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {'\0'}; int num_device_configured = 0; + unsigned int status; PRINT_FUNCTION_VERBOSE(verbose); - if((daemon == 0) || (dev_num < 0)) + if ((daemon == NULL) || (daemon_local == NULL) || + (daemon->storage_handle == NULL) || (dev_num < 0)) { - dlt_log(LOG_ERR, "Invalid function parameters used for dlt_daemon_logstorage_reset_application_loglevel\n"); + dlt_vlog(LOG_ERR, + "Invalid function parameters used for %s\n", + __func__); return; } handle = &(daemon->storage_handle[dev_num]); - if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) - || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + + if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || + (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) { return; } /* First, check number of devices configured */ - for(i = 0; i<max_device; i++) + for (i = 0; i < max_device; i++) { - if(daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) + status = daemon->storage_handle[i].config_status; + + if (status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { - num_device_configured += 1; + num_device_configured++; } } - /* for all filters (keys) check if application context are already running and log level need to be reset*/ - for(i = 0; i < handle->num_filter_keys; i++) + /* for all filters (keys) check if application context are already running + * and log level need to be reset*/ + tmp = &(handle->config_list); + while (*(tmp) != NULL) { memset(key, 0, sizeof(key)); - strncpy(key, (handle->filter_keys + i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + strncpy(key, + (*tmp)->key, + DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); - if(num_device_configured == 1) + if (num_device_configured == 1) + { /* Reset context log level and send to application */ - dlt_logstorage_update_context_loglevel(daemon, key, DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL, verbose); - else - /* Reset context log level do not send to application as other devices can have same configuration */ - dlt_logstorage_update_context_loglevel(daemon, key, DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL, verbose); + dlt_logstorage_update_context_loglevel( + daemon, + daemon_local, + key, + DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL, + verbose); + } + else /* Reset context log level do not send to application as other + devices can have same configuration */ + { + dlt_logstorage_update_context_loglevel( + daemon, + daemon_local, + key, + DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL, + verbose); + } + tmp = &(*tmp)->next; } /* Re-run update log level for all other configured devices */ - for(i=0; i<max_device; i++) + for (i = 0; i < max_device; i++) { - if(i == dev_num) + status = daemon->storage_handle[i].config_status; + if (i == dev_num) + { continue; + } - if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) + if (status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { - dlt_daemon_logstorage_update_application_loglevel(daemon, i, verbose); + dlt_daemon_logstorage_update_application_loglevel(daemon, + daemon_local, + i, + verbose); } } + return; } /** * dlt_daemon_logstorage_update_application_loglevel * - * Update log level of all running applications with new filter configuration available due - * to newly attached DltLogstorage device. The log level is only updated when the current - * application log level is less than the log level obtained from the storage configuration file + * Update log level of all running applications with new filter configuration + * available due to newly attached DltLogstorage device. The log level is only + * updated when the current application log level is less than the log level + * obtained from the storage configuration file * * @param daemon Pointer to DLT Daemon structure + * @param daemon_local Pointer to DLT Daemon local structure * @param dev_num Number of attached DLT Logstorage device * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int dev_num, int verbose) +void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + int dev_num, + int verbose) { DltLogStorage *handle = NULL; - int i = 0; - char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = {'\0'}; - + DltLogStorageFilterList **tmp = NULL; + char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {'\0'}; PRINT_FUNCTION_VERBOSE(verbose); - if((daemon == 0) || (dev_num < 0)) + if ((daemon == NULL) || (dev_num < 0)) { - dlt_log(LOG_ERR, "Invalid function parameters used for dlt_daemon_logstorage_update_application_loglevel\n"); + dlt_vlog(LOG_ERR, + "Invalid function parameters used for %s\n", + __func__); return; } handle = &(daemon->storage_handle[dev_num]); - if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) - || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + + if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || + (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) { return; } - /* for all filters (keys) check if application or context already running and log level need to be updated*/ - for(i = 0; i < handle->num_filter_keys; i++) + /* for all filters (keys) check if application or context already running + * and log level need to be updated*/ + tmp = &(handle->config_list); + while (*(tmp) != NULL) { int log_level = -1; memset(key, 0, sizeof(key)); - strncpy(key, (handle->filter_keys + i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + strncpy(key, + (*tmp)->key, + DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); /* Obtain storage configuration data */ log_level = dlt_logstorage_get_loglevel_by_key(handle, key); - if(log_level < 0) + + if (log_level < 0) { dlt_log(LOG_ERR, "Failed to get log level by key \n"); - return; + return; } /* Update context log level with storage configuration log level */ - dlt_logstorage_update_context_loglevel(daemon, key, log_level, verbose); + dlt_logstorage_update_context_loglevel(daemon, + daemon_local, + key, + log_level, + verbose); + tmp = &(*tmp)->next; } + return; } /** * dlt_daemon_logstorage_get_loglevel * - * Obtain log level as a union of all configured storage devices and filters for the - * provided application id and context id + * Obtain log level as a union of all configured storage devices and filters for + * the provided application id and context id * * @param daemon Pointer to DLT Daemon structure * @param max_device Maximum storage devices setup by the daemon @@ -447,42 +1004,71 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int de * @param ctid Context ID * @return Log level on success, -1 on error */ -int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *apid, char *ctid) +int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, + int max_device, + char *apid, + char *ctid) { - DltLogStorageConfigData **config = NULL; + DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = {0}; int i = 0; int j = 0; int8_t storage_loglevel = -1; - int8_t retrvd_loglevel = -1; + int8_t configured_loglevel = -1; int num_config = 0; - if((daemon == 0) || (max_device == 0) || (apid == NULL) || (ctid == NULL)) - return -1; + if ((daemon == NULL) || (max_device == 0) || (apid == NULL) || (ctid == NULL)) + { + return DLT_RETURN_WRONG_PARAMETER; + } - for(i = 0; i<max_device; i++) + for (i = 0; i < max_device; i++) { - if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) + if (daemon->storage_handle[i].config_status == + DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { - config = dlt_logstorage_get_config(&(daemon->storage_handle[i]), apid, ctid, &num_config); - if(config != NULL) + num_config = dlt_logstorage_get_config(&(daemon->storage_handle[i]), + config, + apid, + ctid, + daemon->ecuid); + + if (num_config == 0) { - for(j = 0; j<num_config; j++) + dlt_log(LOG_DEBUG, "No valid filter configuration found\n"); + continue; + } + + for (j = 0; j < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; j++) + { + if (config[j] == NULL) { - retrvd_loglevel = config[j]->log_level; - storage_loglevel = DLT_OFFLINE_LOGSTORAGE_MAX(retrvd_loglevel, storage_loglevel); + continue; } - free(config); + + /* If logstorage configuration do not contain file name, + * then it is non verbose control filter, so return level as in this filter */ + if (config[j]->file_name == NULL) + { + storage_loglevel = config[j]->log_level; + break; + } + configured_loglevel = config[j]->log_level; + storage_loglevel = DLT_OFFLINE_LOGSTORAGE_MAX( + configured_loglevel, + storage_loglevel); } } } + return storage_loglevel; } /** * dlt_daemon_logstorage_write * - * Write log message to all attached storage device. If the called dlt_logstorage_write function is not able - * to write to the device, DltDaemon will disconnect this device. + * Write log message to all attached storage device. If the called + * dlt_logstorage_write function is not able to write to the device, DltDaemon + * will disconnect this device. * * @param daemon Pointer to Dlt Daemon structure * @param user_config DltDaemon configuration @@ -505,13 +1091,15 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, int i = 0; DltLogStorageUserConfig file_config; - if (daemon == NULL || (user_config->offlineLogstorageMaxDevices <= 0) - || data1 == NULL || data2 == NULL || data3 == NULL) + if ((daemon == NULL) || (user_config == NULL) || + (user_config->offlineLogstorageMaxDevices <= 0) || (data1 == NULL) || + (data2 == NULL) || (data3 == NULL)) { - dlt_log(LOG_INFO, - "dlt_daemon_logstorage_write: message type is not log. " - "Skip storing.\n"); + dlt_vlog(LOG_DEBUG, + "%s: message type is not LOG. Skip storing.\n", + __func__); return; + /* Log Level changed callback */ } /* Copy user configuration */ @@ -519,7 +1107,7 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, file_config.logfile_delimiter = user_config->offlineLogstorageDelimiter; file_config.logfile_maxcounter = user_config->offlineLogstorageMaxCounter; file_config.logfile_counteridxlen = - user_config->offlineLogstorageMaxCounterIdx; + user_config->offlineLogstorageMaxCounterIdx; for (i = 0; i < user_config->offlineLogstorageMaxDevices; i++) { @@ -541,8 +1129,8 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, /* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened, * therefore remove logstorage device */ dlt_logstorage_device_disconnected( - &(daemon->storage_handle[i]), - DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); + &(daemon->storage_handle[i]), + DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); } } } @@ -554,37 +1142,40 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, * Setup user defined path as offline log storage device * * @param daemon Pointer to Dlt Daemon structure + * @param daemon_local Pointer to Dlt Daemon local structure * @param path User configured internal storage path * @param verbose If set to true verbose information is printed out + * @return 0 on sucess, -1 otherwise */ -int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose) +int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *path, + int verbose) { int ret = 0; - if((path == NULL) || (daemon == NULL)) + PRINT_FUNCTION_VERBOSE(verbose); + + if ((path == NULL) || (daemon == NULL)) { - return -1; + return DLT_RETURN_WRONG_PARAMETER; } /* connect internal storage device */ /* Device index always used as 0 as it is setup on DLT daemon startup */ ret = dlt_logstorage_device_connected(&(daemon->storage_handle[0]), path); - if(ret != 0) - { - dlt_log(LOG_ERR,"dlt_daemon_logstorage_setup_emmc_support : Device connect failed\n"); - return -1; - } - /* setup logstorage with config file settings */ - ret = dlt_logstorage_load_config(&(daemon->storage_handle[0])); - if(ret != 0) + if (ret != 0) { - dlt_log(LOG_ERR,"dlt_daemon_logstorage_setup_emmc_support : Loading configuration file failed\n"); - return -1; + dlt_vlog(LOG_ERR, "%s: Device connect failed\n", __func__); + return DLT_RETURN_ERROR; } /* check if log level of running application need an update */ - dlt_daemon_logstorage_update_application_loglevel(daemon, 0, verbose); + dlt_daemon_logstorage_update_application_loglevel(daemon, + daemon_local, + 0, + verbose); return ret; } @@ -592,7 +1183,7 @@ int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size) { /* store given [KB] size in [Bytes] */ - g_logstorage_cache_max = size * 1000; + g_logstorage_cache_max = size * 1024; } int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, @@ -603,9 +1194,9 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); - if (daemon == NULL || daemon_local == NULL) + if ((daemon == NULL) || (daemon_local == NULL)) { - return -1; + return DLT_RETURN_WRONG_PARAMETER; } for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) @@ -615,8 +1206,8 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { dlt_logstorage_device_disconnected( - &daemon->storage_handle[i], - DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT); + &daemon->storage_handle[i], + DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT); } } @@ -633,9 +1224,9 @@ int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); - if (daemon == NULL || mnt_point == NULL) + if ((daemon == NULL) || (daemon_local == NULL) || (mnt_point == NULL)) { - return -1; + return DLT_RETURN_WRONG_PARAMETER; } if (strlen(mnt_point) > 0) /* mount point is given */ @@ -646,26 +1237,42 @@ int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, verbose); if (handle == NULL) { - return -1; + return DLT_RETURN_ERROR; } else { + handle->uconfig.logfile_counteridxlen = + daemon_local->flags.offlineLogstorageMaxCounterIdx; + handle->uconfig.logfile_delimiter = + daemon_local->flags.offlineLogstorageDelimiter; + handle->uconfig.logfile_maxcounter = + daemon_local->flags.offlineLogstorageMaxCounter; + handle->uconfig.logfile_timestamp = + daemon_local->flags.offlineLogstorageTimestamp; if (dlt_logstorage_sync_caches(handle) != 0) { - return -1; + return DLT_RETURN_ERROR; } } } else /* sync caches for all connected logstorage devices */ { - for(i=0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) { if (daemon->storage_handle[i].connection_type == - DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { + daemon->storage_handle[i].uconfig.logfile_counteridxlen = + daemon_local->flags.offlineLogstorageMaxCounterIdx; + daemon->storage_handle[i].uconfig.logfile_delimiter = + daemon_local->flags.offlineLogstorageDelimiter; + daemon->storage_handle[i].uconfig.logfile_maxcounter = + daemon_local->flags.offlineLogstorageMaxCounter; + daemon->storage_handle[i].uconfig.logfile_timestamp = + daemon_local->flags.offlineLogstorageTimestamp; if (dlt_logstorage_sync_caches(&daemon->storage_handle[i]) != 0) { - return -1; + return DLT_RETURN_ERROR; } } } @@ -680,28 +1287,28 @@ DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon, int verbose) { int i = 0; + int len = 0; int len1 = 0; int len2 = 0; PRINT_FUNCTION_VERBOSE(verbose); - if (daemon == NULL || daemon_local == NULL || mnt_point == NULL) + if ((daemon == NULL) || (daemon_local == NULL) || (mnt_point == NULL)) { return NULL; } len1 = strlen(mnt_point); - for(i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) { len2 = strlen(daemon->storage_handle[i].device_mount_point); /* Check if the requested device path is already used as log storage * device. Check for strlen first, to avoid comparison errors when * final '/' is given or not */ - if (strncmp(daemon->storage_handle[i].device_mount_point, - mnt_point, - len1 > len2 ? len2 : len1) == 0) + len = len1 > len2 ? len2 : len1; + if (strncmp(daemon->storage_handle[i].device_mount_point, mnt_point, len) == 0) { return &daemon->storage_handle[i]; } diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h index 3ab092a..f9d587d 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.h +++ b/src/daemon/dlt_daemon_offline_logstorage.h @@ -1,44 +1,44 @@ /** -* @licence app begin@ -* Copyright (C) 2013 - 2015 Advanced Driver Information Technology. -* This code is developed by Advanced Driver Information Technology. -* Copyright of Advanced Driver Information Technology, Bosch and DENSO. -* -* DLT offline log storage functionality header file. -* -* \copyright -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -* this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* -* -* \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015 -* \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015 -* -* \file: dlt_daemon_offline_logstorage.h -* For further information see http://www.genivi.org/. -* @licence end@ -*/ + * @licence app begin@ + * Copyright (C) 2013 - 2015 Advanced Driver Information Technology. + * This code is developed by Advanced Driver Information Technology. + * Copyright of Advanced Driver Information Technology, Bosch and DENSO. + * + * DLT offline log storage functionality header file. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015 + * \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015 + * + * \file: dlt_daemon_offline_logstorage.h + * For further information see http://www.genivi.org/. + * @licence end@ + */ /******************************************************************************* -* ** -* SRC-MODULE: dlt_daemon_offline_logstorage.h ** -* ** -* TARGET : linux ** -* ** -* PROJECT : DLT ** -* ** -* AUTHOR : Syed Hameed shameed@jp.adit-jv.com ** -* Christoph Lipka clipka@jp.adit-jv.com ** -* PURPOSE : ** -* ** -* REMARKS : ** -* ** -* PLATFORM DEPENDANT [yes/no]: yes ** -* ** -* TO BE CHANGED BY USER [yes/no]: no ** -* ** -******************************************************************************/ + * ** + * SRC-MODULE: dlt_daemon_offline_logstorage.h ** + * ** + * TARGET : linux ** + * ** + * PROJECT : DLT ** + * ** + * AUTHOR : Syed Hameed shameed@jp.adit-jv.com ** + * Christoph Lipka clipka@jp.adit-jv.com ** + * PURPOSE : ** + * ** + * REMARKS : ** + * ** + * PLATFORM DEPENDANT [yes/no]: yes ** + * ** + * TO BE CHANGED BY USER [yes/no]: no ** + * ** + ******************************************************************************/ /******************************************************************************* * Author Identity ** @@ -48,7 +48,7 @@ * -------- ------------------------- ---------------------------------- ** * sh Syed Hameed ADIT ** * cl Christoph Lipka ADIT ** - *******************************************************************************/ +*******************************************************************************/ #ifndef DLT_DAEMON_OFFLINE_LOGSTORAGE_H #define DLT_DAEMON_OFFLINE_LOGSTORAGE_H @@ -60,11 +60,14 @@ #define DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL -1 #define DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL 0 +#define DLT_DAEMON_LOGSTORAGE_CMP_APID 1 +#define DLT_DAEMON_LOGSTORAGE_CMP_CTID 2 + /** * dlt_daemon_logstorage_get_loglevel * - * Obtain log level as a union of all configured storage devices and filters for the - * provided application id and context id + * Obtain log level as a union of all configured storage devices and filters for + * the provided application id and context id * * @param daemon Pointer to DLT Daemon structure * @param max_device Maximum storage devices setup by the daemon @@ -72,35 +75,49 @@ * @param ctid Context ID * @return Log level on success, -1 on error */ -int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *apid, char *ctid); +int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, + int max_device, + char *apid, + char *ctid); /** * dlt_daemon_logstorage_reset_application_loglevel * * Reset storage log level of all running applications with -1 * * @param daemon Pointer to DLT Daemon structure + * @param daemon_local Pointer to DLT Daemon local structure * @param dev_num Number of attached DLT Logstorage device * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, int dev_num, int max_device, int verbose); +void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + int dev_num, + int max_device, + int verbose); /** * dlt_daemon_logstorage_update_application_loglevel * - * Update log level of all running applications with new filter configuration available due - * to newly attached DltLogstorage device. The log level is only updated when the current - * application log level is less than the log level obtained from the storage configuration file + * Update log level of all running applications with new filter configuration + * available due to newly attached DltLogstorage device. The log level is only + * updated when the current application log level is less than the log level + * obtained from the storage configuration file. * * @param daemon Pointer to DLT Daemon structure + * @param daemon_local Pointer to DLT Daemon local structure * @param dev_num Number of attached DLT Logstorage device * @param verbose if set to true verbose information is printed out */ -void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int dev_num, int verbose); +void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + int dev_num, + int verbose); /** * dlt_daemon_logstorage_write * - * Write log message to all attached storage device. If the called dlt_logstorage_write function is not able - * to write to the device, DltDaemon will disconnect this device. + * Write log message to all attached storage device. If the called + * dlt_logstorage_write function is not able to write to the device, + * DltDaemon will disconnect this device. * * @param daemon Pointer to Dlt Daemon structure * @param user_config DltDaemon configuration @@ -127,10 +144,14 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, * Setup user defined path as offline log storage device * * @param daemon Pointer to Dlt Daemon structure + * @param daemon_local Pointer to Dlt Daemon Local structure * @param path User configured internal storage path * @param verbose If set to true verbose information is printed out */ -int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose); +int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *path, + int verbose); /** * Set max size of logstorage cache. Stored internally in bytes |