From 1e17f03f95ba4cb6802664f9449ad804490bb557 Mon Sep 17 00:00:00 2001 From: Bui Nguyen Quoc Thanh Date: Fri, 29 May 2020 11:27:49 +0700 Subject: logstorage: fix syncbehaviour - In case sync is not ON_MSG, the newest file information does not need to be updated. Signed-off-by: Bui Nguyen Quoc Thanh --- src/offlinelogstorage/dlt_offline_logstorage.c | 70 ++++++++++++++++---------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 09f7c06..5b607f5 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -766,7 +766,9 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, return -1; } - if (data->file_name) { + if ((data->sync == DLT_LOGSTORAGE_SYNC_ON_MSG || + data->sync == DLT_LOGSTORAGE_SYNC_UNSET) && + (data->file_name)) { if (handle->newest_file_list != NULL) { tmp = handle->newest_file_list; while (tmp) { @@ -2091,36 +2093,52 @@ int dlt_logstorage_write(DltLogStorage *handle, if (config[i]->file_name == NULL) continue; - tmp = handle->newest_file_list; - while (tmp) { - if (strcmp(tmp->file_name, config[i]->file_name) == 0) { - found = 1; - break; + /* The newest file must be applied to only ON_MSG */ + if ((config[i]->sync == DLT_LOGSTORAGE_SYNC_ON_MSG || + config[i]->sync == DLT_LOGSTORAGE_SYNC_UNSET)) { + tmp = handle->newest_file_list; + while (tmp) { + if (strcmp(tmp->file_name, config[i]->file_name) == 0) { + found = 1; + break; + } + else { + tmp = tmp->next; + } } - else { - tmp = tmp->next; + if (!found) { + dlt_vlog(LOG_ERR, "Cannot find out record for filename [%s]\n", + config[i]->file_name); + return -1; } - } - if (!found) { - dlt_vlog(LOG_ERR, "Cannot find out record for filename [%s]\n", - config[i]->file_name); - return -1; - } - /* prepare log file (create and/or open)*/ - ret = config[i]->dlt_logstorage_prepare(config[i], - uconfig, - handle->device_mount_point, - size1 + size2 + size3, - tmp->newest_file); - if (tmp->newest_file == NULL || - strcmp(config[i]->working_file_name, tmp->newest_file) != 0) { - if (tmp->newest_file) { - free(tmp->newest_file); - tmp->newest_file = NULL; + /* prepare log file (create and/or open)*/ + ret = config[i]->dlt_logstorage_prepare(config[i], + uconfig, + handle->device_mount_point, + size1 + size2 + size3, + tmp->newest_file); + + if ((tmp->newest_file == NULL || + strcmp(config[i]->working_file_name, tmp->newest_file) != 0)) { + if (tmp->newest_file) { + free(tmp->newest_file); + tmp->newest_file = NULL; + } + tmp->newest_file = strdup(config[i]->working_file_name); } - tmp->newest_file = strdup(config[i]->working_file_name); } + else { + /* In case SyncBehaviour differs from ON_MSG, + * do not need to update the newest file name + */ + ret = config[i]->dlt_logstorage_prepare(config[i], + uconfig, + handle->device_mount_point, + size1 + size2 + size3, + NULL); + } + if (ret == 0) { /* log data (write) */ ret = config[i]->dlt_logstorage_write(config[i], -- cgit v1.2.1