diff options
-rw-r--r-- | src/offlinelogstorage/dlt_offline_logstorage.c | 71 | ||||
-rw-r--r-- | src/offlinelogstorage/dlt_offline_logstorage_behavior.c | 49 |
2 files changed, 63 insertions, 57 deletions
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 5b607f5..5eaf107 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -766,9 +766,7 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, return -1; } - if ((data->sync == DLT_LOGSTORAGE_SYNC_ON_MSG || - data->sync == DLT_LOGSTORAGE_SYNC_UNSET) && - (data->file_name)) { + if (data->file_name) { if (handle->newest_file_list != NULL) { tmp = handle->newest_file_list; while (tmp) { @@ -2093,34 +2091,46 @@ int dlt_logstorage_write(DltLogStorage *handle, if (config[i]->file_name == NULL) continue; - /* 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; - } + tmp = handle->newest_file_list; + while (tmp) { + if (strcmp(tmp->file_name, config[i]->file_name) == 0) { + found = 1; + break; } - if (!found) { - dlt_vlog(LOG_ERR, "Cannot find out record for filename [%s]\n", + else { + tmp = tmp->next; + } + } + 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); + + /* In case the strategy is other than ON_MSG and UNSET, + * in the very first time of preparation, the working file name + * is not created yet. So check strategy and update it later in + * step prepare_on_msg. + */ + if (!config[i]->working_file_name) { + if (config[i]->sync == DLT_LOGSTORAGE_SYNC_UNSET || + config[i]->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) { + dlt_vlog(LOG_ERR, "Failed to prepare working file for %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); - + } + else { 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; @@ -2128,17 +2138,6 @@ int dlt_logstorage_write(DltLogStorage *handle, 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], diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c index 5f5c164..afbf8c4 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c @@ -441,7 +441,8 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, (*tmp)->idx = 1; (*tmp)->next = NULL; } - else { /* newest file available*/ + else { + /* newest file available*/ strcat(absolute_file_path, storage_path); strcat(absolute_file_path, (*newest)->name); @@ -457,8 +458,10 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, /* if size is enough, open it */ if ((ret == 0) && (s.st_size + msg_size < (int)config->file_size)) { config->log = fopen(absolute_file_path, "a+"); + config->current_write_file_offset = s.st_size; } - else { /* no space in file or file stats cannot be read */ + else { + /* no space in file or file stats cannot be read */ unsigned int idx = 0; /* get index of newest log file */ @@ -639,8 +642,8 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, int ret = 0; int start_index = 0; int end_index = 0; - int count; - int remain_file_size; + int count = 0; + int remain_file_size = 0; if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || (footer == NULL)) @@ -650,6 +653,22 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, } count = end_offset - start_offset; + + /* In case of cached-based strategy, the newest file information + * must be updated everytime of synchronization. + */ + if (config->log) { + fclose(config->log); + config->log = NULL; + config->current_write_file_offset = 0; + } + + if (dlt_logstorage_open_log_file(config, file_config, + dev_path, count, true) != 0) { + dlt_vlog(LOG_ERR, "%s: failed to open log file\n", __func__); + return -1; + } + remain_file_size = config->file_size - config->current_write_file_offset; if (count > remain_file_size) @@ -665,20 +684,8 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, if ((start_index >= 0) && (end_index > start_index) && (count > 0) && (count <= remain_file_size)) { - /* Prepare log file */ - if (config->log == NULL) - { - if (dlt_logstorage_prepare_on_msg(config, file_config, dev_path, - config->file_size, NULL) != 0) - { - dlt_vlog(LOG_ERR, "%s: failed to prepare log file\n", - __func__); - return -1; - } - } - - ret = fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, - config->log); + ret = fwrite((uint8_t*)config->cache + start_offset + start_index, + count, 1, config->log); dlt_logstorage_check_write_ret(config, ret); /* Close log file */ @@ -698,8 +705,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, } } - start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, - count); + start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, count); count = end_offset - start_offset - start_index; if ((start_index >= 0) && (count > 0)) @@ -708,7 +714,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, if (config->log == NULL) { if (dlt_logstorage_prepare_on_msg(config, file_config, dev_path, - config->file_size, NULL) != 0) + count, NULL) != 0) { dlt_vlog(LOG_ERR, "%s: failed to prepare log file\n", __func__); return -1; @@ -755,6 +761,7 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, return -1; } + /* This is for ON_MSG/UNSET strategy */ if (config->log == NULL) { /* open a new log file */ ret = dlt_logstorage_open_log_file(config, file_config, |