summaryrefslogtreecommitdiff
path: root/src/offlinelogstorage
diff options
context:
space:
mode:
Diffstat (limited to 'src/offlinelogstorage')
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.c722
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.h8
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.c586
3 files changed, 481 insertions, 835 deletions
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c
index 42fcfcb..8571b7a 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage.c
@@ -54,27 +54,22 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat
free(data->file_name);
data->file_name = NULL;
- if (data->ecuid != NULL)
- {
+ if (data->ecuid != NULL) {
free(data->ecuid);
data->ecuid = NULL;
}
if (data->log != NULL)
- {
fclose(data->log);
- }
- if (data->cache != NULL)
- {
+ if (data->cache != NULL) {
free(data->cache);
data->cache = NULL;
}
n = data->records;
- while (n)
- {
+ while (n) {
n1 = n;
n = n->next;
free(n1->name);
@@ -91,17 +86,16 @@ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list,
DltLogStorageUserConfig *uconfig = NULL;
char *dev_path = NULL;
- while (*(list) != NULL)
- {
+ while (*(list) != NULL) {
tmp = *list;
*list = (*list)->next;
- if (tmp->key != NULL)
- {
+
+ if (tmp->key != NULL) {
free(tmp->key);
tmp->key = NULL;
}
- if (tmp->data != NULL)
- {
+
+ if (tmp->data != NULL) {
/* sync data if necessary */
/* ignore return value */
tmp->data->dlt_logstorage_sync(tmp->data,
@@ -114,6 +108,7 @@ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list,
free(tmp->data);
tmp->data = NULL;
}
+
free(tmp);
tmp = NULL;
}
@@ -125,9 +120,7 @@ DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data,
DltLogStorageFilterConfig **listdata)
{
if (*(listdata) == NULL)
- {
return -1;
- }
(*listdata)->apids = NULL;
(*listdata)->ctids = NULL;
@@ -141,24 +134,16 @@ DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data,
memcpy(*listdata, data, sizeof(DltLogStorageFilterConfig));
if (data->apids != NULL)
- {
(*listdata)->apids = strdup(data->apids);
- }
if (data->ctids != NULL)
- {
(*listdata)->ctids = strdup(data->ctids);
- }
if (data->file_name != NULL)
- {
(*listdata)->file_name = strdup(data->file_name);
- }
if (data->ecuid != NULL)
- {
(*listdata)->ecuid = strdup(data->ecuid);
- }
return 0;
}
@@ -169,33 +154,28 @@ DLT_STATIC int dlt_logstorage_list_add(char *key,
{
DltLogStorageFilterList *tmp = NULL;
- while (*(list) != NULL)
- {
+ while (*(list) != NULL) {
/* if the key is already present then the data should be updated */
- if (strncmp((*list)->key, key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0)
- {
+ if (strncmp((*list)->key, key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0) {
if (dlt_logstorage_list_add_config(data, &((*list)->data)) != 0)
- {
return -1;
- }
+
return 0;
}
+
list = &(*list)->next;
}
tmp = calloc(1, sizeof(DltLogStorageFilterList));
if (tmp == NULL)
- {
return -1;
- }
tmp->key = strdup(key);
tmp->next = NULL;
tmp->data = calloc(1, sizeof(DltLogStorageFilterConfig));
- if (tmp->data == NULL)
- {
+ if (tmp->data == NULL) {
free(tmp->key);
free(tmp);
tmp->key = NULL;
@@ -203,8 +183,7 @@ DLT_STATIC int dlt_logstorage_list_add(char *key,
return -1;
}
- if (dlt_logstorage_list_add_config(data, &(tmp->data)) != 0)
- {
+ if (dlt_logstorage_list_add_config(data, &(tmp->data)) != 0) {
free(tmp->key);
free(tmp->data);
free(tmp);
@@ -222,16 +201,11 @@ DLT_STATIC int dlt_logstorage_list_add(char *key,
DLT_STATIC void *dlt_logstorage_list_find(char *key,
DltLogStorageFilterList **list)
{
- while (*(list) != NULL)
- {
+ while (*(list) != NULL) {
if (strncmp((*list)->key, key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0)
- {
return (*list)->data;
- }
else
- {
list = &(*list)->next;
- }
}
return NULL;
@@ -243,21 +217,16 @@ DLT_STATIC int dlt_logstorage_count_ids(const char *str)
{
if (str == NULL)
- {
return -1;
- }
- // delimiter is: ","
+ /* delimiter is: "," */
const char *p = str;
int i = 0;
int num = 1;
- while (p[i] != 0)
- {
+ while (p[i] != 0) {
if (p[i] == ',')
- {
num++;
- }
i++;
}
@@ -276,8 +245,7 @@ DLT_STATIC int dlt_logstorage_count_ids(const char *str)
*/
void dlt_logstorage_free(DltLogStorage *handle, int reason)
{
- if (handle == NULL)
- {
+ if (handle == NULL) {
dlt_vlog(LOG_ERR, "%s failed: handle is NULL\n", __func__);
return;
}
@@ -310,13 +278,10 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, char *value)
int num = 1;
if ((names == NULL) || (value == NULL))
- {
return -1;
- }
/* free, alloce'd memory to store new apid/ctid */
- if (*names != NULL)
- {
+ if (*names != NULL) {
free(*names);
*names = NULL;
}
@@ -324,35 +289,29 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, char *value)
len = strlen(value);
if (len == 0)
- {
return -1;
- }
/* count number of delimiters to get actual number off names */
num = dlt_logstorage_count_ids(value);
/* need to alloc space for 5 chars, 4 for the name and "," and "\0" */
*names = (char *)calloc(num * 5, sizeof(char));
+
if (*names == NULL)
- {
return -1;
- }
tok = strtok(value, ",");
i = 1;
- while (tok != NULL)
- {
+ while (tok != NULL) {
len = strlen(tok);
len = DLT_OFFLINE_LOGSTORAGE_MIN(len, 4);
strncpy((*names + y), tok, len);
if ((num > 1) && (i < num))
- {
strncpy((*names + y + len), ",", 1);
- }
y += len + 1;
@@ -383,32 +342,26 @@ DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value)
unsigned long size = 0;
if (value == NULL)
- {
return -1;
- }
*number = 0;
len = strlen(value);
/* check if string consists of digits only */
- for (i = 0 ; i < len ; i++)
- {
- if (isdigit(value[i] == 0))
- {
+ for (i = 0; i < len; i++)
+ if (isdigit(value[i] == 0)) {
dlt_log(LOG_ERR, "Invalid, is not a number \n");
return -1;
}
- }
size = strtoul(value, NULL, 10);
- if ((size == 0) || (size > UINT_MAX))
- {
+ if ((size == 0) || (size > UINT_MAX)) {
dlt_log(LOG_ERR, "Invalid, is not a number \n");
return -1;
}
- *number = (unsigned int) size;
+ *number = (unsigned int)size;
return 0;
}
@@ -426,7 +379,7 @@ DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value)
* @return: 0 on success, error on failure*
*/
DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list,
- int *numids)
+ int *numids)
{
char *token = NULL;
char *tmp_token = NULL;
@@ -436,38 +389,38 @@ DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list,
/* Duplicate the ids passed for using in strtok_r() */
ids_local = strdup(ids);
+
if (ids_local == NULL)
- {
return -1;
- }
token = strtok_r(ids_local, sep, &tmp_token);
- if (token == NULL)
- {
+
+ if (token == NULL) {
free(ids_local);
return -1;
}
- *list = (char *) calloc(DLT_OFFLINE_LOGSTORAGE_MAXIDS * (DLT_ID_SIZE + 1),
- sizeof(char));
- if (*(list) == NULL)
- {
+
+ *list = (char *)calloc(DLT_OFFLINE_LOGSTORAGE_MAXIDS * (DLT_ID_SIZE + 1),
+ sizeof(char));
+
+ if (*(list) == NULL) {
free(ids_local);
return -1;
}
- while (token != NULL )
- {
+ while (token != NULL) {
/* If it reached the max then other ids are ignored */
- if (*numids >= DLT_OFFLINE_LOGSTORAGE_MAXIDS)
- {
+ if (*numids >= DLT_OFFLINE_LOGSTORAGE_MAXIDS) {
free(ids_local);
return 0;
}
+
strncpy(((*list) + ((*numids) * (DLT_ID_SIZE + 1))), token,
DLT_ID_SIZE);
*numids = *numids + 1;
token = strtok_r(NULL, sep, &tmp_token);
}
+
free(ids_local);
return 0;
@@ -485,20 +438,19 @@ DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list,
* @return None
*/
DLT_STATIC void dlt_logstorage_create_keys_only_ctid(char *ecuid, char *ctid,
- char *key)
+ char *key)
{
char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 };
int curr_len = 0;
- if (ecuid != NULL)
- {
+ if (ecuid != NULL) {
strncpy(curr_str, ecuid, strlen(ecuid));
strncat(curr_str, "::", 2);
}
- else
- {
+ else {
strncpy(curr_str, "::", 2);
}
+
curr_len = strlen(ctid);
strncat(curr_str, ctid, curr_len);
curr_len = strlen(curr_str);
@@ -518,20 +470,19 @@ DLT_STATIC void dlt_logstorage_create_keys_only_ctid(char *ecuid, char *ctid,
* @return None
*/
DLT_STATIC void dlt_logstorage_create_keys_only_apid(char *ecuid, char *apid,
- char *key)
+ char *key)
{
char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 };
int curr_len = 0;
- if (ecuid != NULL)
- {
+ if (ecuid != NULL) {
strncpy(curr_str, ecuid, strlen(ecuid));
strncat(curr_str, ":", 1);
}
- else
- {
+ else {
strncpy(curr_str, ":", 1);
}
+
curr_len = strlen(apid);
strncat(curr_str, apid, curr_len);
strncat(curr_str, ":", 1);
@@ -553,20 +504,19 @@ DLT_STATIC void dlt_logstorage_create_keys_only_apid(char *ecuid, char *apid,
* @return None
*/
DLT_STATIC void dlt_logstorage_create_keys_multi(char *ecuid, char *apid,
- char *ctid, char *key)
+ char *ctid, char *key)
{
char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 };
int curr_len = 0;
- if (ecuid != NULL)
- {
+ if (ecuid != NULL) {
strncpy(curr_str, ecuid, strlen(ecuid));
strncat(curr_str, ":", 1);
}
- else
- {
+ else {
strncpy(curr_str, ":", 1);
}
+
curr_len = strlen(apid);
strncat(curr_str, apid, curr_len);
strncat(curr_str, ":", 1);
@@ -625,10 +575,10 @@ DLT_STATIC void dlt_logstorage_create_keys_only_ecu(char *ecuid, char *key)
* @return: 0 on success, error on failure*
*/
DLT_STATIC int dlt_logstorage_create_keys(char *apids,
- char *ctids,
- char *ecuid,
- char **keys,
- int *num_keys)
+ char *ctids,
+ char *ecuid,
+ char **keys,
+ int *num_keys)
{
int i, j;
int num_apids = 0;
@@ -641,35 +591,32 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids,
int num_currkey = 0;
/* Handle ecuid alone case here */
- if ((apids == NULL) && (ctids == NULL) && (ecuid != NULL))
- {
+ if ((apids == NULL) && (ctids == NULL) && (ecuid != NULL)) {
dlt_logstorage_create_keys_only_ecu(ecuid, curr_key);
*(num_keys) = 1;
- *(keys) = (char *) calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN,
- sizeof(char));
+ *(keys) = (char *)calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN,
+ sizeof(char));
+
if (*(keys) == NULL)
- {
return -1;
- }
+
strncpy(*keys, curr_key, strlen(curr_key));
return 0;
}
- if ((apids == NULL) || (ctids == NULL))
- {
- dlt_log(LOG_ERR,"Required inputs (apid and ctid) are NULL\n");
+ if ((apids == NULL) || (ctids == NULL)) {
+ dlt_log(LOG_ERR, "Required inputs (apid and ctid) are NULL\n");
return -1;
}
/* obtain key list and number of keys for application ids */
- if (dlt_logstorage_get_keys_list(apids, ",", &apid_list, &num_apids) != 0)
- {
+ if (dlt_logstorage_get_keys_list(apids, ",", &apid_list, &num_apids) != 0) {
dlt_log(LOG_ERR, "Failed to obtain appid, check configuration file \n");
return -1;
}
+
/* obtain key list and number of keys for context ids */
- if (dlt_logstorage_get_keys_list(ctids, ",", &ctid_list, &num_ctids) != 0)
- {
+ if (dlt_logstorage_get_keys_list(ctids, ",", &ctid_list, &num_ctids) != 0) {
dlt_log(LOG_ERR, "Failed to obtain ctid, check configuration file \n");
free(apid_list);
return -1;
@@ -678,40 +625,36 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids,
*(num_keys) = num_apids * num_ctids;
/* allocate memory for needed number of keys */
- *(keys) = (char *) calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN,
- sizeof(char));
- if (*(keys) == NULL)
- {
+ *(keys) = (char *)calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN,
+ sizeof(char));
+
+ if (*(keys) == NULL) {
free(apid_list);
free(ctid_list);
return -1;
}
/* store all combinations of apid ctid in keys */
- for (i = 0; i < num_apids; i++)
- {
+ for (i = 0; i < num_apids; i++) {
curr_apid = apid_list + (i * (DLT_ID_SIZE + 1));
- for (j = 0; j < num_ctids; j++)
- {
+
+ for (j = 0; j < num_ctids; j++) {
curr_ctid = ctid_list + (j * (DLT_ID_SIZE + 1));
+
if (strncmp(curr_apid, ".*", 2) == 0) /* only context id matters */
- {
dlt_logstorage_create_keys_only_ctid(ecuid, curr_ctid, curr_key);
- }
else if (strncmp(curr_ctid, ".*", 2) == 0) /* only app id matters*/
- {
dlt_logstorage_create_keys_only_apid(ecuid, curr_apid, curr_key);
- }
else /* key is combination of all */
- {
dlt_logstorage_create_keys_multi(ecuid, curr_apid, curr_ctid, curr_key);
- }
+
strncpy((*keys + (num_currkey * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)),
curr_key, strlen(curr_key));
num_currkey += 1;
memset(&curr_key[0], 0, sizeof(curr_key));
}
}
+
free(apid_list);
free(ctid_list);
@@ -728,15 +671,14 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids,
* @return 0 on success, -1 on error
*/
DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle,
- DltLogStorageFilterConfig *data)
+ DltLogStorageFilterConfig *data)
{
int ret = 0;
int num_keys = 0;
char *keys = NULL;
int idx = 0;
- if ((handle == NULL) || (data == NULL))
- {
+ if ((handle == NULL) || (data == NULL)) {
dlt_vlog(LOG_ERR, "Invalid parameters in %s\n", __func__);
return -1;
}
@@ -747,19 +689,16 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle,
&keys,
&num_keys);
- if (ret != 0)
- {
+ if (ret != 0) {
dlt_log(LOG_ERR, "Not able to create keys for hash table\n");
return -1;
}
/* hash_add */
- for (idx = 0 ; idx < num_keys ; idx++)
- {
+ for (idx = 0; idx < num_keys; idx++) {
if (dlt_logstorage_list_add(keys + (idx * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN),
data,
- &(handle->config_list)) != 0)
- {
+ &(handle->config_list)) != 0) {
dlt_log(LOG_ERR,
"Adding to hash table failed, returning failure\n");
@@ -795,78 +734,61 @@ DLT_STATIC int dlt_logstorage_validate_filter_name(char *name)
int control_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION);
if (name == NULL)
- {
return -1;
- }
len = strlen(name);
-
+
/* Check if section header is of format "FILTER" followed by a number */
if (strncmp(name,
DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION,
- config_sec_len) == 0)
- {
+ config_sec_len) == 0) {
for (idx = config_sec_len; idx < len - 1; idx++)
- {
if (!isdigit(name[idx]))
- {
return -1;
- }
- }
+
return 0;
}
/* Check if section header is of format "FILTER" followed by a number */
else if (strncmp(name,
- DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION,
- storage_sec_len) == 0)
+ DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION,
+ storage_sec_len) == 0)
{
for (idx = storage_sec_len; idx < len - 1; idx++)
- {
if (!isdigit(name[idx]))
- {
return -1;
- }
- }
+
return 0;
}
/* Check if section header is of format "FILTER" followed by a number */
else if (strncmp(name,
- DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION,
- control_sec_len) == 0)
+ DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION,
+ control_sec_len) == 0)
{
for (idx = control_sec_len; idx < len - 1; idx++)
- {
if (!isdigit(name[idx]))
- {
return -1;
- }
- }
+
return 0;
}
- else
- {
+ else {
return -1;
}
}
DLT_STATIC void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig *config,
- int strategy)
+ int strategy)
{
if (config == NULL)
- {
return;
- }
/* file based */
if ((strategy == DLT_LOGSTORAGE_SYNC_ON_MSG) ||
- (strategy == DLT_LOGSTORAGE_SYNC_UNSET))
- {
+ (strategy == DLT_LOGSTORAGE_SYNC_UNSET)) {
config->dlt_logstorage_prepare = &dlt_logstorage_prepare_on_msg;
config->dlt_logstorage_write = &dlt_logstorage_write_on_msg;
config->dlt_logstorage_sync = &dlt_logstorage_sync_on_msg;
}
- else /* cache based */
- {
+ else { /* cache based */
config->dlt_logstorage_prepare = &dlt_logstorage_prepare_msg_cache;
config->dlt_logstorage_write = &dlt_logstorage_write_msg_cache;
config->dlt_logstorage_sync = &dlt_logstorage_sync_msg_cache;
@@ -874,10 +796,9 @@ DLT_STATIC void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig *co
}
DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
- if ((config == NULL) || (value == NULL))
- {
+ if ((config == NULL) || (value == NULL)) {
dlt_log(LOG_ERR, "Not able to create keys for hash table\n");
return -1;
}
@@ -886,32 +807,26 @@ DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config,
}
DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
return dlt_logstorage_read_list_of_names(&config->ctids, value);
}
DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
- if (value == NULL)
- {
+ if (value == NULL) {
config->log_level = 0;
return -1;
}
- if (strcmp(value, "DLT_LOG_FATAL") == 0)
- {
+ if (strcmp(value, "DLT_LOG_FATAL") == 0) {
config->log_level = 1;
}
else if (strcmp(value, "DLT_LOG_ERROR") == 0)
@@ -934,8 +849,7 @@ DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config,
{
config->log_level = 6;
}
- else
- {
+ else {
config->log_level = -1;
dlt_log(LOG_ERR, "Invalid log level \n");
return -1;
@@ -945,21 +859,17 @@ DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config,
}
DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if (config == NULL)
- {
return -1;
- }
- if (value == NULL)
- {
+ if (value == NULL) {
config->reset_log_level = 0;
return -1;
}
- if (strcmp(value, "DLT_LOG_OFF") == 0)
- {
+ if (strcmp(value, "DLT_LOG_OFF") == 0) {
config->reset_log_level = DLT_LOG_OFF;
}
else if (strcmp(value, "DLT_LOG_FATAL") == 0)
@@ -986,8 +896,7 @@ DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *co
{
config->reset_log_level = DLT_LOG_VERBOSE;
}
- else
- {
+ else {
config->reset_log_level = -1;
dlt_log(LOG_ERR, "Invalid log level \n");
return -1;
@@ -997,17 +906,14 @@ DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *co
}
DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
int len;
if ((value == NULL) || (strcmp(value, "") == 0))
- {
return -1;
- }
- if (config->file_name != NULL)
- {
+ if (config->file_name != NULL) {
free(config->file_name);
config->file_name = NULL;
}
@@ -1015,19 +921,18 @@ DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config,
len = strlen(value);
/* do not allow the user to change directory by adding a relative path */
- if (strstr(value, "..") == NULL)
- {
+ if (strstr(value, "..") == NULL) {
config->file_name = calloc((len + 1), sizeof(char));
- if (config->file_name == NULL)
- {
+
+ if (config->file_name == NULL) {
dlt_log(LOG_ERR,
"Cannot allocate memory for filename\n");
return -1;
}
+
strncpy(config->file_name, value, len);
}
- else
- {
+ else {
dlt_log(LOG_ERR,
"Invalid filename, paths not accepted due to security issues\n");
return -1;
@@ -1037,34 +942,29 @@ DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config,
}
DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
return dlt_logstorage_read_number(&config->file_size, value);
}
DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
return dlt_logstorage_read_number(&config->num_files, value);
}
DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
+
return dlt_logstorage_read_number(&config->specific_size, value);
}
@@ -1081,47 +981,33 @@ DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig *conf
* @return 0 on success, -1 on error
*/
DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
- if (strcasestr(value, "ON_MSG") != NULL)
- {
+ if (strcasestr(value, "ON_MSG") != NULL) {
config->sync = DLT_LOGSTORAGE_SYNC_ON_MSG;
dlt_log(LOG_DEBUG, "ON_MSG found, ignore other if added\n");
}
- else /* ON_MSG not set, combination of cache based strategies possible */
- {
+ else { /* ON_MSG not set, combination of cache based strategies possible */
+
if (strcasestr(value, "ON_DAEMON_EXIT") != NULL)
- {
config->sync |= DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT;
- }
if (strcasestr(value, "ON_DEMAND") != NULL)
- {
config->sync |= DLT_LOGSTORAGE_SYNC_ON_DEMAND;
- }
if (strcasestr(value, "ON_DEVICE_DISCONNECT") != NULL)
- {
config->sync |= DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT;
- }
if (strcasestr(value, "ON_SPECIFIC_SIZE") != NULL)
- {
config->sync |= DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE;
- }
if (strcasestr(value, "ON_FILE_SIZE") != NULL)
- {
config->sync |= DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE;
- }
- if (config->sync == 0)
- {
+ if (config->sync == 0) {
dlt_log(LOG_WARNING,
"Unknown sync strategies. Set default ON_MSG\n");
config->sync = DLT_LOGSTORAGE_SYNC_ON_MSG;
@@ -1142,27 +1028,24 @@ DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *con
* @return 0 on success, -1 on error
*/
DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config,
- char *value)
+ char *value)
{
int len;
if ((config == NULL) || (value == NULL) || (value[0] == '\0'))
- {
return -1;
- }
- if (config->ecuid != NULL)
- {
+ if (config->ecuid != NULL) {
free(config->ecuid);
config->ecuid = NULL;
}
len = strlen(value);
config->ecuid = calloc((len + 1), sizeof(char));
+
if (config->ecuid == NULL)
- {
return -1;
- }
+
strncpy(config->ecuid, value, len);
return 0;
@@ -1216,9 +1099,9 @@ DLT_STATIC DltLogstorageFilterConf
.is_opt = 1
},
[DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = {
- .key = "SpecificSize",
- .func = dlt_logstorage_check_specificsize,
- .is_opt = 1
+ .key = "SpecificSize",
+ .func = dlt_logstorage_check_specificsize,
+ .is_opt = 1
}
};
@@ -1271,14 +1154,14 @@ DLT_STATIC DltLogstorageFilterConf
.is_opt = 0
},
[DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = {
- .key = NULL,
- .func = dlt_logstorage_check_specificsize,
- .is_opt = 1
+ .key = NULL,
+ .func = dlt_logstorage_check_specificsize,
+ .is_opt = 1
}
};
DLT_STATIC DltLogstorageFilterConf
-filter_nonverbose_control_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = {
+ filter_nonverbose_control_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = {
[DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = {
.key = "LogAppName",
.func = dlt_logstorage_check_apids,
@@ -1339,26 +1222,22 @@ filter_nonverbose_control_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = {
* @return 0 on success, -1 otherwise
*/
DLT_STATIC int dlt_logstorage_check_param(DltLogStorageFilterConfig *config,
- DltLogstorageFilterConfType ctype,
- char *value)
+ DltLogstorageFilterConfType ctype,
+ char *value)
{
if ((config == NULL) || (value == NULL))
- {
return -1;
- }
if (ctype < DLT_LOGSTORAGE_FILTER_CONF_COUNT)
- {
return filter_cfg_entries[ctype].func(config, value);
- }
return -1;
}
DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file,
- char *sec_name,
- int index,
- char *value)
+ char *sec_name,
+ int index,
+ char *value)
{
int ret = 0;
int config_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION);
@@ -1366,38 +1245,31 @@ DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file,
int control_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION);
if ((config_file == NULL) || (sec_name == NULL))
- {
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
- }
/* Branch based on section name, no complete string compare needed */
if (strncmp(sec_name,
DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION,
- config_sec_len) == 0)
- {
- if (filter_cfg_entries[index].key != NULL)
- {
+ config_sec_len) == 0) {
+ if (filter_cfg_entries[index].key != NULL) {
ret = dlt_config_file_get_value(config_file, sec_name,
filter_cfg_entries[index].key,
value);
- if ((ret != 0) && (filter_cfg_entries[index].is_opt == 0))
- {
+ if ((ret != 0) && (filter_cfg_entries[index].is_opt == 0)) {
dlt_vlog(LOG_WARNING,
- "Invalid configuration in section: %s -> %s : %s\n",
- sec_name, filter_cfg_entries[index].key, value);
+ "Invalid configuration in section: %s -> %s : %s\n",
+ sec_name, filter_cfg_entries[index].key, value);
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
}
- if ((ret != 0) && (filter_cfg_entries[index].is_opt == 1))
- {
+ if ((ret != 0) && (filter_cfg_entries[index].is_opt == 1)) {
dlt_vlog(LOG_DEBUG, "Optional parameter %s not specified\n",
- filter_cfg_entries[index].key);
+ filter_cfg_entries[index].key);
return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE;
}
}
- else
- {
+ else {
return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE;
}
}
@@ -1405,20 +1277,17 @@ DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file,
DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION,
storage_sec_len) == 0)
{
- if (filter_nonverbose_storage_entries[index].key != NULL)
- {
+ if (filter_nonverbose_storage_entries[index].key != NULL) {
if (dlt_config_file_get_value(config_file, sec_name,
- filter_nonverbose_storage_entries[index].key, value) != 0)
- {
+ filter_nonverbose_storage_entries[index].key, value) != 0) {
dlt_vlog(LOG_WARNING,
- "Invalid configuration in section: %s -> %s : %s\n",
- sec_name, filter_nonverbose_storage_entries[index].key,
- value);
+ "Invalid configuration in section: %s -> %s : %s\n",
+ sec_name, filter_nonverbose_storage_entries[index].key,
+ value);
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
}
}
- else
- {
+ else {
return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE;
}
}
@@ -1426,25 +1295,21 @@ DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file,
DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION,
control_sec_len) == 0))
{
- if (filter_nonverbose_control_entries[index].key != NULL)
- {
+ if (filter_nonverbose_control_entries[index].key != NULL) {
if (dlt_config_file_get_value(config_file, sec_name,
- filter_nonverbose_control_entries[index].key, value) != 0)
- {
+ filter_nonverbose_control_entries[index].key, value) != 0) {
dlt_vlog(LOG_WARNING,
- "Invalid configuration in section: %s -> %s : %s\n",
- sec_name, filter_nonverbose_control_entries[index].key,
- value);
+ "Invalid configuration in section: %s -> %s : %s\n",
+ sec_name, filter_nonverbose_control_entries[index].key,
+ value);
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
}
}
- else
- {
+ else {
return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE;
}
}
- else
- {
+ else {
dlt_log(LOG_ERR, "Error: Section name not valid \n");
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
}
@@ -1462,8 +1327,8 @@ DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage *handle,
dlt_logstorage_filter_set_strategy(tmp_data, tmp_data->sync);
ret = dlt_logstorage_prepare_table(handle, tmp_data);
- if (ret != 0)
- {
+
+ if (ret != 0) {
dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n",
__func__);
ret = DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR;
@@ -1472,23 +1337,21 @@ DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage *handle,
return ret;
}
/*Return :
- DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR - On filter properties or value is not valid
- DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR - On error while storing in hash table
+ * DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR - On filter properties or value is not valid
+ * DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR - On error while storing in hash table
*/
DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle,
- DltConfigFile *config_file,
- char *sec_name)
+ DltConfigFile *config_file,
+ char *sec_name)
{
DltLogStorageFilterConfig tmp_data;
- char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN + 1] = {'\0'};
+ char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN + 1] = { '\0' };
int i = 0;
int ret = 0;
if ((handle == NULL) || (config_file == NULL) || (sec_name == NULL))
- {
return DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR;
- }
memset(&tmp_data, 0, sizeof(DltLogStorageFilterConfig));
tmp_data.apids = NULL;
@@ -1501,60 +1364,52 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle,
tmp_data.log = NULL;
tmp_data.cache = NULL;
- for (i = 0 ; i < DLT_LOGSTORAGE_FILTER_CONF_COUNT ; i++)
- {
+ for (i = 0; i < DLT_LOGSTORAGE_FILTER_CONF_COUNT; i++) {
ret = dlt_logstorage_get_filter_value(config_file, sec_name, i, value);
+
if (ret == DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR)
- {
return ret;
- }
if (ret == DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE)
- {
continue;
- }
/* check value and store temporary */
ret = dlt_logstorage_check_param(&tmp_data, i, value);
- if (ret != 0)
- {
- if (tmp_data.apids != NULL)
- {
+
+ if (ret != 0) {
+ if (tmp_data.apids != NULL) {
free(tmp_data.apids);
tmp_data.apids = NULL;
}
- if (tmp_data.ctids != NULL)
- {
+ if (tmp_data.ctids != NULL) {
free(tmp_data.ctids);
tmp_data.ctids = NULL;
}
- if (tmp_data.file_name != NULL)
- {
+ if (tmp_data.file_name != NULL) {
free(tmp_data.file_name);
tmp_data.file_name = NULL;
}
- if (tmp_data.ecuid != NULL)
- {
+ if (tmp_data.ecuid != NULL) {
free(tmp_data.ecuid);
tmp_data.ecuid = NULL;
}
-
+
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
}
}
+
/* filter configuration is valid */
ret = dlt_logstorage_setup_table(handle, &tmp_data);
- if (ret != 0)
- {
+
+ if (ret != 0) {
dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n",
__func__);
ret = DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR;
}
- else /* move to next free filter configuration, if no error occurred */
- {
+ else { /* move to next free filter configuration, if no error occurred */
handle->num_configs += 1;
/* free tmp_data */
@@ -1576,7 +1431,7 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle,
*
*/
DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle,
- char *config_file_name)
+ char *config_file_name)
{
DltConfigFile *config = NULL;
int sec = 0;
@@ -1586,43 +1441,38 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle,
* filter configuration is valid and stored */
int valid = -1;
- if (config_file_name == NULL)
- {
+ if (config_file_name == NULL) {
dlt_vlog(LOG_ERR, "%s unexpected parameter received\n", __func__);
return -1;
}
config = dlt_config_file_init(config_file_name);
- if (config == NULL)
- {
+ if (config == NULL) {
dlt_log(LOG_CRIT, "Failed to open filter configuration file\n");
return -1;
}
dlt_config_file_get_num_sections(config, &num_sec);
- for (sec = 0 ; sec < num_sec ; sec++)
- {
+ for (sec = 0; sec < num_sec; sec++) {
char sec_name[DLT_CONFIG_FILE_ENTRY_MAX_LEN + 1];
- if (dlt_config_file_get_section_name(config, sec, sec_name) == -1)
- {
+ if (dlt_config_file_get_section_name(config, sec, sec_name) == -1) {
dlt_log(LOG_CRIT, "Failed to read section name\n");
dlt_config_file_release(config);
return -1;
}
- if (strstr(sec_name, GENERAL_BASE_NAME) != NULL)
- {
- dlt_log(LOG_CRIT, "General configuration not supported \n");
- continue;
+ if (strstr(sec_name, GENERAL_BASE_NAME) != NULL) {
+ dlt_log(LOG_CRIT, "General configuration not supported \n");
+ continue;
}
else if (dlt_logstorage_validate_filter_name(sec_name) == 0)
{
ret = dlt_daemon_offline_setup_filter_properties(handle, config, sec_name);
- if (ret == DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR)
- {
+
+ if (ret == DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR) {
break;
}
else if (ret == DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR)
@@ -1635,17 +1485,11 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle,
continue;
}
else
- {
- /* Filter properties read and stored successfuly */
- if (valid != 1)
- {
- valid = 0;
- }
-
- }
+ /* Filter properties read and stored successfuly */
+ if (valid != 1)
+ valid = 0;
}
- else /* unknown section */
- {
+ else { /* unknown section */
dlt_vlog(LOG_WARNING, "Unknown section: %s", sec_name);
}
}
@@ -1671,22 +1515,19 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle,
*/
DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle)
{
- char config_file_name[PATH_MAX + 1] = {'\0'};
+ char config_file_name[PATH_MAX + 1] = { '\0' };
int ret = 0;
/* Check if handle is NULL or already initialized or already configured */
if ((handle == NULL) ||
(handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED))
- {
return -1;
- }
/* Check if this device config was already setup */
- if (handle->config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
- {
+ if (handle->config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) {
dlt_vlog(LOG_ERR,
- "%s: Device already configured. Send disconnect first.\n",
- __func__);
+ "%s: Device already configured. Send disconnect first.\n",
+ __func__);
return -1;
}
@@ -1694,16 +1535,15 @@ DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle)
PATH_MAX,
"%s/%s",
handle->device_mount_point,
- DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME) < 0)
- {
+ DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME) < 0) {
dlt_log(LOG_ERR,
"Creating configuration file path string failed\n");
return -1;
}
ret = dlt_logstorage_store_filters(handle, config_file_name);
- if (ret == 1)
- {
+
+ if (ret == 1) {
handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
return 1;
}
@@ -1730,14 +1570,12 @@ DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle)
*/
int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point)
{
- if ((handle == NULL) || (mount_point == NULL))
- {
+ if ((handle == NULL) || (mount_point == NULL)) {
dlt_log(LOG_ERR, "Handle error \n");
return -1;
}
- if (handle->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
- {
+ if (handle->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) {
dlt_log(LOG_WARNING,
"Device already connected. Send disconnect, connect request\n");
@@ -1769,15 +1607,11 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point)
int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason)
{
if (handle == NULL)
- {
return -1;
- }
/* If configuration loading was done, free it */
if (handle->config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
- {
dlt_logstorage_free(handle, reason);
- }
/* Reset all device status */
memset(handle->device_mount_point, '\0', sizeof(char) * DLT_MOUNT_PATH_MAX);
@@ -1810,15 +1644,12 @@ int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key)
(key == NULL) ||
(handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ||
(handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE))
- {
return -1;
- }
config = (DltLogStorageFilterConfig *)
dlt_logstorage_list_find(key, &(handle->config_list));
- if (config == NULL)
- {
+ if (config == NULL) {
dlt_vlog(LOG_WARNING, "Configuration for key [%s] not found!\n", key);
return -1;
}
@@ -1847,7 +1678,8 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
char *ecuid)
{
DltLogStorageFilterConfig *ptr_config = NULL;
- char key[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = {{'\0'}, {'\0'}, {'\0'}};
+ char key[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] =
+ { { '\0' }, { '\0' }, { '\0' } };
int i = 0;
int apid_len = 0;
int ctid_len = 0;
@@ -1859,55 +1691,49 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
(handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ||
(handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) ||
(ecuid == NULL))
- {
return 0;
- }
/* Prepare possible keys with
* Possible combinations are
* ecu::
- ecu:apid:ctid
- :apid:ctid
- ecu::ctid
- ecu:apid:
- ::ctid
- :apid: */
+ * ecu:apid:ctid
+ * :apid:ctid
+ * ecu::ctid
+ * ecu:apid:
+ * ::ctid
+ * :apid: */
ecuid_len = strlen(ecuid);
+
if (ecuid_len > DLT_ID_SIZE)
- {
ecuid_len = DLT_ID_SIZE;
- }
- if ((apid == NULL) && (ctid == NULL))
- {
+ if ((apid == NULL) && (ctid == NULL)) {
/* ecu:: */
strncpy(key[0], ecuid, ecuid_len);
strncat(key[0], ":", 1);
strncat(key[0], ":", 1);
- ptr_config = (DltLogStorageFilterConfig *) dlt_logstorage_list_find(
- key[0], &(handle->config_list));
+ ptr_config = (DltLogStorageFilterConfig *)dlt_logstorage_list_find(
+ key[0], &(handle->config_list));
- if (ptr_config != NULL)
- {
+ if (ptr_config != NULL) {
config[num] = ptr_config;
num += 1;
}
+
return num;
}
apid_len = strlen(apid);
+
if (apid_len > DLT_ID_SIZE)
- {
apid_len = DLT_ID_SIZE;
- }
ctid_len = strlen(ctid);
+
if (ctid_len > DLT_ID_SIZE)
- {
ctid_len = DLT_ID_SIZE;
- }
/* :apid: */
strncpy(key[0], ":", 1);
@@ -1950,13 +1776,11 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
strncat(key[6], ":", 1);
/* Search the list three times with keys as -apid: , :ctid and apid:ctid */
- for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++)
- {
+ for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++) {
ptr_config = (DltLogStorageFilterConfig *)
dlt_logstorage_list_find(key[i], &(handle->config_list));
- if (ptr_config != NULL)
- {
+ if (ptr_config != NULL) {
config[num] = ptr_config;
num += 1;
}
@@ -1983,50 +1807,40 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
* @return number of found configurations
*/
DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle,
- DltLogStorageFilterConfig **config,
- char *apid,
- char *ctid,
- char *ecuid,
- int log_level)
+ DltLogStorageFilterConfig **config,
+ char *apid,
+ char *ctid,
+ char *ecuid,
+ int log_level)
{
int i = 0;
int num = 0;
if ((handle == NULL) || (config == NULL) || (ecuid == NULL))
- {
return -1;
- }
/* filter on names: find DltLogStorageFilterConfig structures */
num = dlt_logstorage_get_config(handle, config, apid, ctid, ecuid);
- if (num == 0)
- {
+ if (num == 0) {
dlt_log(LOG_DEBUG, "No valid filter configuration found\n");
return 0;
}
- for (i = 0 ; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS ; i++)
- {
+ for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++) {
if (config[i] == NULL)
- {
continue;
- }
/* filter on log level */
- if (log_level > config[i]->log_level)
- {
+ if (log_level > config[i]->log_level) {
config[i] = NULL;
continue;
}
/* filter on ECU id only if EcuID is set */
- if (config[i]->ecuid != NULL)
- {
+ if (config[i]->ecuid != NULL) {
if (strncmp(ecuid, config[i]->ecuid, DLT_ID_SIZE) != 0)
- {
config[i] = NULL;
- }
}
}
@@ -2056,7 +1870,7 @@ int dlt_logstorage_write(DltLogStorage *handle,
unsigned char *data3,
int size3)
{
- DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = {0};
+ DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = { 0 };
int i = 0;
int ret = 0;
int num = 0;
@@ -2075,63 +1889,52 @@ int dlt_logstorage_write(DltLogStorage *handle,
(data1 == NULL) || (data2 == NULL) || (data3 == NULL) ||
(handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ||
(handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE))
- {
return 0;
- }
/* Calculate real length of DltStandardHeaderExtra */
standardHeader = (DltStandardHeader *)data2;
if (!DLT_IS_HTYP_WEID(standardHeader->htyp))
- {
standardHeaderExtraLen -= DLT_ID_SIZE;
- }
if (!DLT_IS_HTYP_WSID(standardHeader->htyp))
- {
standardHeaderExtraLen -= DLT_SIZE_WSID;
- }
if (!DLT_IS_HTYP_WTMS(standardHeader->htyp))
- {
standardHeaderExtraLen -= DLT_SIZE_WTMS;
- }
- extraHeader = (DltStandardHeaderExtra *) (data2
- + sizeof(DltStandardHeader));
+ extraHeader = (DltStandardHeaderExtra *)(data2
+ + sizeof(DltStandardHeader));
- if (DLT_IS_HTYP_UEH(standardHeader->htyp))
- {
+ if (DLT_IS_HTYP_UEH(standardHeader->htyp)) {
header_len = sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + standardHeaderExtraLen;
+
/* check if size2 is big enough to contain expected DLT message header */
- if ((unsigned int)size2 < header_len)
- {
+ if ((unsigned int)size2 < header_len) {
dlt_log(LOG_ERR, "DLT message header is too small\n");
return 0;
}
- extendedHeader = (DltExtendedHeader *) (data2
- + sizeof(DltStandardHeader) + standardHeaderExtraLen);
+ extendedHeader = (DltExtendedHeader *)(data2
+ + sizeof(DltStandardHeader) + standardHeaderExtraLen);
log_level = DLT_GET_MSIN_MTIN(extendedHeader->msin);
/* check if log message need to be stored in a certain device based on
* filter configuration */
num = dlt_logstorage_filter(handle, config, extendedHeader->apid,
- extendedHeader->ctid, extraHeader->ecu, log_level);
+ extendedHeader->ctid, extraHeader->ecu, log_level);
- if (num == 0 || num == -1)
- {
+ if ((num == 0) || (num == -1)) {
dlt_log(LOG_DEBUG, "No valid filter configuration found!\n");
return 0;
}
}
- else
- {
+ else {
header_len = sizeof(DltStandardHeader) + standardHeaderExtraLen;
+
/* check if size2 is big enough to contain expected DLT message header */
- if ((unsigned int)size2 < header_len)
- {
+ if ((unsigned int)size2 < header_len) {
dlt_log(LOG_ERR, "DLT message header is too small (without extended header)\n");
return 0;
}
@@ -2141,29 +1944,23 @@ int dlt_logstorage_write(DltLogStorage *handle,
/* check if log message need to be stored in a certain device based on
* filter configuration */
num = dlt_logstorage_filter(handle, config, NULL,
- NULL, extraHeader->ecu, log_level);
+ NULL, extraHeader->ecu, log_level);
- if (num == 0 || num == -1)
- {
+ if ((num == 0) || (num == -1)) {
dlt_log(LOG_DEBUG, "No valid filter configuration found!\n");
return 0;
}
}
/* store log message in every found filter */
- for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++)
- {
+ for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++) {
if (config[i] == NULL)
- {
continue;
- }
/* If file name is not present, the filter is non verbose control filter
* hence skip storing */
if (config[i]->file_name == NULL)
- {
continue;
- }
/* prepare log file (create and/or open)*/
ret = config[i]->dlt_logstorage_prepare(config[i],
@@ -2171,8 +1968,7 @@ int dlt_logstorage_write(DltLogStorage *handle,
handle->device_mount_point,
size1 + size2 + size3);
- if (ret == 0) /* log data (write) */
- {
+ if (ret == 0) { /* log data (write) */
ret = config[i]->dlt_logstorage_write(config[i],
data1,
size1,
@@ -2181,8 +1977,7 @@ int dlt_logstorage_write(DltLogStorage *handle,
data3,
size3);
- if (ret == 0)
- {
+ if (ret == 0) {
/* flush to be sure log is stored on device */
ret = config[i]->dlt_logstorage_sync(config[i],
uconfig,
@@ -2190,27 +1985,21 @@ int dlt_logstorage_write(DltLogStorage *handle,
DLT_LOGSTORAGE_SYNC_ON_MSG);
if (ret != 0)
- {
dlt_log(LOG_ERR,
"dlt_logstorage_write: Unable to sync.\n");
- }
}
- else
- {
+ else {
handle->write_errors += 1;
if (handle->write_errors >=
DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS)
- {
err = -1;
- }
dlt_log(LOG_ERR,
"dlt_logstorage_write: Unable to write.\n");
}
}
- else
- {
+ else {
dlt_log(LOG_ERR,
"dlt_logstorage_write: Unable to prepare.\n");
}
@@ -2232,26 +2021,21 @@ int dlt_logstorage_sync_caches(DltLogStorage *handle)
DltLogStorageFilterList **tmp = NULL;
if (handle == NULL)
- {
return -1;
- }
tmp = &(handle->config_list);
- while (*(tmp) != NULL)
- {
- if ((*tmp)->data != NULL)
- {
+ while (*(tmp) != NULL) {
+ if ((*tmp)->data != NULL) {
if ((*tmp)->data->dlt_logstorage_sync((*tmp)->data,
&handle->uconfig,
handle->device_mount_point,
DLT_LOGSTORAGE_SYNC_ON_DEMAND) != 0)
- {
dlt_vlog(LOG_ERR,
- "%s: Sync failed. Continue with next cache.\n",
- __func__);
- }
+ "%s: Sync failed. Continue with next cache.\n",
+ __func__);
}
+
tmp = &(*tmp)->next;
}
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h
index 5020042..c2160b5 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage.h
@@ -113,7 +113,7 @@
#define DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE (1 << 4) /* sync on after specific size */
#define DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE (1 << 5) /* sync on file size reached */
-#define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S) &(s))
+#define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S)&(s))
/* logstorage max cache */
unsigned int g_logstorage_cache_max;
@@ -206,7 +206,7 @@ typedef struct
unsigned int connection_type; /* Type of connection */
unsigned int config_status; /* Status of configuration */
int write_errors; /* number of write errors */
-}DltLogStorage;
+} DltLogStorage;
typedef struct {
char *key; /* The configuration key */
@@ -250,7 +250,7 @@ typedef enum {
* @return 0 on success, -1 on error
*/
int dlt_logstorage_device_connected(DltLogStorage *handle,
- char *mount_point);
+ char *mount_point);
/**
* dlt_logstorage_device_disconnected
@@ -261,7 +261,7 @@ int dlt_logstorage_device_connected(DltLogStorage *handle,
* @return 0 on success, -1 on error
*/
int dlt_logstorage_device_disconnected(DltLogStorage *handle,
- int reason);
+ int reason);
/**
* dlt_logstorage_get_config
*
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
index 46f0f9e..1d31f46 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
@@ -57,39 +57,33 @@ void dlt_logstorage_log_file_name(char *log_file_name,
int idx)
{
if ((log_file_name == NULL) || (file_config == NULL))
- {
return;
- }
- char file_index[10] = {'\0'};
+ char file_index[10] = { '\0' };
- // create log file name
+ /* create log file name */
memset(log_file_name, 0, DLT_MOUNT_PATH_MAX * sizeof(char));
strcat(log_file_name, name);
strncat(log_file_name, &file_config->logfile_delimiter, 1);
snprintf(file_index, 10, "%d", idx);
- if (file_config->logfile_maxcounter != UINT_MAX)
- {
+ if (file_config->logfile_maxcounter != UINT_MAX) {
/* Setup 0's to be appended in file index until max index len*/
unsigned int digit_idx = 0;
unsigned int i = 0;
snprintf(file_index, 10, "%d", idx);
digit_idx = strlen(file_index);
- for (i = 0 ; i < (file_config->logfile_counteridxlen - digit_idx) ; i++)
- {
+ for (i = 0; i < (file_config->logfile_counteridxlen - digit_idx); i++)
strcat(log_file_name, "0");
- }
}
strcat(log_file_name, file_index);
/* Add time stamp if user has configured */
- if (file_config->logfile_timestamp)
- {
- char stamp[DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1] = {0};
+ if (file_config->logfile_timestamp) {
+ char stamp[DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1] = { 0 };
time_t t = time(NULL);
struct tm *tm_info = localtime(&t);
sprintf(stamp,
@@ -120,12 +114,9 @@ void dlt_logstorage_sort_file_name(DltLogStorageFileList **head)
int done = 0;
if ((head == NULL) || (*head == NULL) || ((*head)->next == NULL))
- {
return;
- }
- while (!done)
- {
+ while (!done) {
/* "source" of the pointer to the current node in the list struct */
DltLogStorageFileList **pv = head;
DltLogStorageFileList *nd = *head; /* local iterator pointer */
@@ -133,10 +124,8 @@ void dlt_logstorage_sort_file_name(DltLogStorageFileList **head)
done = 1;
- while (nx)
- {
- if (nd->idx > nx->idx)
- {
+ while (nx) {
+ if (nd->idx > nx->idx) {
nd->next = nx->next;
nx->next = nd;
*pv = nx;
@@ -168,16 +157,11 @@ void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head)
DltLogStorageFileList *n = NULL;
if ((head == NULL) || (*head == NULL) || ((*head)->next == NULL))
- {
return;
- }
- for (n = *head ; n != NULL ; n = n->next)
- {
- if (n && n_prev)
- {
- if ((n->idx - n_prev->idx) != 1)
- {
+ for (n = *head; n != NULL; n = n->next) {
+ if (n && n_prev) {
+ if ((n->idx - n_prev->idx) != 1) {
wrap_post = n;
wrap_pre = n_prev;
}
@@ -188,8 +172,7 @@ void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head)
tail = n_prev;
- if (wrap_post && wrap_pre)
- {
+ if (wrap_post && wrap_pre) {
wrap_pre->next = NULL;
tail->next = *head;
*head = wrap_post;
@@ -215,15 +198,12 @@ unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_co
unsigned int fileindex_len = 0;
if ((file_config == NULL) || (file == NULL))
- {
return -1;
- }
/* Calculate actual file name length */
filename = strchr(file, file_config->logfile_delimiter);
- if (filename == NULL)
- {
+ if (filename == NULL) {
dlt_vlog(LOG_ERR, "Cannot extract filename from %s\n", file);
return -1;
}
@@ -231,36 +211,32 @@ unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_co
filename_len = strlen(file) - strlen(filename);
/* index is retrived from file name */
- if (file_config->logfile_timestamp)
- {
+ if (file_config->logfile_timestamp) {
fileindex_len = strlen(file) -
(DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN +
filename_len + 1);
- idx = (int) strtol(&file[strlen(file) -
- (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
- fileindex_len +
- DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN)],
- &endptr,
- 10);
+ idx = (int)strtol(&file[strlen(file) -
+ (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
+ fileindex_len +
+ DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN)],
+ &endptr,
+ 10);
}
- else
- {
+ else {
fileindex_len = strlen(file) -
(DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
filename_len + 1);
- idx = (int) strtol(&file[strlen(file) -
- (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN
- + fileindex_len)], &endptr, 10);
+ idx = (int)strtol(&file[strlen(file) -
+ (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN
+ + fileindex_len)], &endptr, 10);
}
if ((endptr == file) || (idx == 0))
- {
dlt_log(LOG_ERR,
"Unable to calculate index from log file name. Reset to 001.\n");
- }
return idx;
}
@@ -283,46 +259,39 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
int i = 0;
int cnt = 0;
int ret = 0;
- struct dirent **files = {0};
+ struct dirent **files = { 0 };
unsigned int current_idx = 0;
if ((config == NULL) ||
(file_config == NULL) ||
(path == NULL) ||
(config->file_name == NULL))
- {
return -1;
- }
cnt = scandir(path, &files, 0, alphasort);
- if (cnt < 0)
- {
+ if (cnt < 0) {
dlt_log(LOG_ERR,
"dlt_logstorage_storage_dir_info: Failed to scan directory\n");
return -1;
}
- for (i = 0 ; i < cnt ; i++)
- {
+ for (i = 0; i < cnt; i++) {
int len = 0;
len = strlen(config->file_name);
if ((strncmp(files[i]->d_name,
config->file_name,
len) == 0) &&
- (files[i]->d_name[len] == file_config->logfile_delimiter))
- {
+ (files[i]->d_name[len] == file_config->logfile_delimiter)) {
DltLogStorageFileList **tmp = NULL;
current_idx = dlt_logstorage_get_idx_of_log_file(file_config,
files[i]->d_name);
- if (config->records == NULL)
- {
+ if (config->records == NULL) {
config->records = malloc(sizeof(DltLogStorageFileList));
- if (config->records == NULL)
- {
+ if (config->records == NULL) {
ret = -1;
dlt_log(LOG_ERR,
"Memory allocation failed\n");
@@ -331,19 +300,15 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
tmp = &config->records;
}
- else
- {
+ else {
tmp = &config->records;
while (*(tmp) != NULL)
- {
tmp = &(*tmp)->next;
- }
*tmp = malloc(sizeof(DltLogStorageFileList));
- if (*tmp == NULL)
- {
+ if (*tmp == NULL) {
ret = -1;
dlt_log(LOG_ERR,
"Memory allocation failed\n");
@@ -357,17 +322,14 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
}
}
- if (ret == 0)
- {
+ if (ret == 0) {
dlt_logstorage_sort_file_name(&config->records);
dlt_logstorage_rearrange_file_name(&config->records);
}
/* free scandir result */
- for (i = 0 ; i < cnt ; i++)
- {
+ for (i = 0; i < cnt; i++)
free(files[i]);
- }
free(files);
@@ -394,21 +356,18 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
int msg_size)
{
int ret = 0;
- char absolute_file_path[DLT_MOUNT_PATH_MAX + DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN + 1] = {'\0'};
- char storage_path[DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN + 1] = {'\0'};
+ char absolute_file_path[DLT_MOUNT_PATH_MAX + DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN + 1] = { '\0' };
+ char storage_path[DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN + 1] = { '\0' };
unsigned int num_log_files = 0;
struct stat s;
DltLogStorageFileList **tmp = NULL;
DltLogStorageFileList **newest = NULL;
- char file_name[DLT_MOUNT_PATH_MAX + 1] = {'\0'};
+ char file_name[DLT_MOUNT_PATH_MAX + 1] = { '\0' };
if (config == NULL)
- {
return -1;
- }
- if (strlen(dev_path) > DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN)
- {
+ if (strlen(dev_path) > DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN) {
dlt_vlog(LOG_ERR, "device path '%s' is too long to store\n", dev_path);
return -1;
}
@@ -416,33 +375,26 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
snprintf(storage_path, DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN, "%s/", dev_path);
/* check if there are already files stored */
- if (config->records == NULL)
- {
+ if (config->records == NULL) {
if (dlt_logstorage_storage_dir_info(file_config, storage_path, config)
!= 0)
- {
return -1;
- }
}
/* obtain locations of newest, current file names, file count */
tmp = &config->records;
- while (*(tmp) != NULL)
- {
+ while (*(tmp) != NULL) {
num_log_files += 1;
if ((*tmp)->next == NULL)
- {
newest = tmp;
- }
tmp = &(*tmp)->next;
}
/* need new file*/
- if (num_log_files == 0)
- {
+ if (num_log_files == 0) {
dlt_logstorage_log_file_name(file_name,
file_config,
config->file_name,
@@ -456,8 +408,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
/* Add file to file list */
*tmp = malloc(sizeof(DltLogStorageFileList));
- if (*tmp == NULL)
- {
+ if (*tmp == NULL) {
dlt_log(LOG_ERR,
"Memory allocation for file name failed\n");
return -1;
@@ -467,20 +418,17 @@ 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);
ret = stat(absolute_file_path, &s);
/* if size is enough, open it */
- if ((ret == 0) && (s.st_size + msg_size < (int)config->file_size))
- {
+ if ((ret == 0) && (s.st_size + msg_size < (int)config->file_size)) {
config->log = fopen(absolute_file_path, "a+");
}
- 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 */
@@ -491,9 +439,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
/* wrap around if max index is reached or an error occurred
* while calculating index from file name */
if ((idx > file_config->logfile_maxcounter) || (idx == 0))
- {
idx = 1;
- }
dlt_logstorage_log_file_name(file_name,
file_config,
@@ -511,8 +457,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
/* Add file to file list */
*tmp = malloc(sizeof(DltLogStorageFileList));
- if (*tmp == NULL)
- {
+ if (*tmp == NULL) {
dlt_log(LOG_ERR,
"Memory allocation for file name failed\n");
return -1;
@@ -525,8 +470,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
num_log_files += 1;
/* check if number of log files exceeds configured max value */
- if (num_log_files > config->num_files)
- {
+ if (num_log_files > config->num_files) {
/* delete oldest */
DltLogStorageFileList **head = &config->records;
DltLogStorageFileList *n = *head;
@@ -544,8 +488,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
}
}
- if (config->log == NULL)
- {
+ if (config->log == NULL) {
dlt_log(LOG_ERR,
"dlt_logstorage_create_log_file: Unable to open log file.\n");
return -1;
@@ -569,19 +512,18 @@ DLT_STATIC int dlt_logstorage_find_dlt_header(void *ptr,
unsigned int cnt)
{
int index = 0;
- char substring[] = {'D', 'L', 'T', 0x01};
- while(cnt > 0)
- {
- if (*((char *)(ptr + offset + index)) == 'D')
- {
- if (strncmp(ptr + offset + index , substring, 4) == 0)
- {
+ char substring[] = { 'D', 'L', 'T', 0x01 };
+
+ while (cnt > 0) {
+ if (*((char *)(ptr + offset + index)) == 'D') {
+ if (strncmp(ptr + offset + index, substring, 4) == 0)
return index;
- }
}
+
cnt--;
index++;
}
+
return -1;
}
@@ -597,27 +539,19 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config
int ret)
{
if (config == NULL)
- {
dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__);
- }
- if (ret <= 0)
- {
+
+ if (ret <= 0) {
if (ferror(config->log) != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to write cache into log file\n", __func__);
- }
}
- else
- {
+ else {
/* force sync */
if (fflush(config->log) != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__);
- }
+
if (fsync(fileno(config->log)) != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to sync log file\n", __func__);
- }
}
}
@@ -633,10 +567,10 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config
* @return 0 on success, -1 on error
*/
DLT_STATIC DltReturnValue dlt_logstorage_sync_create_new_file(
- DltLogStorageFilterConfig *config,
- DltLogStorageUserConfig *file_config,
- char *dev_path,
- unsigned int remain_file_size)
+ DltLogStorageFilterConfig *config,
+ DltLogStorageUserConfig *file_config,
+ char *dev_path,
+ unsigned int remain_file_size)
{
int index = 0;
int ret;
@@ -644,94 +578,88 @@ DLT_STATIC DltReturnValue dlt_logstorage_sync_create_new_file(
unsigned int count = 0;
DltLogStorageCacheFooter *footer = NULL;
- if (config == NULL || file_config == NULL || dev_path == NULL)
- {
+ if ((config == NULL) || (file_config == NULL) || (dev_path == NULL)) {
dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__);
return DLT_RETURN_WRONG_PARAMETER;
}
+
footer = (DltLogStorageCacheFooter *)(config->cache +
config->file_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_vlog(LOG_ERR, "%s: Cannot retrieve cache information\n", __func__);
return DLT_RETURN_WRONG_PARAMETER;
}
/* sync capable data to file */
- if (footer->offset >= footer->last_sync_offset)
- {
+ if (footer->offset >= footer->last_sync_offset) {
count = config->file_size - footer->offset;
+
if (count > remain_file_size)
- {
count = remain_file_size;
- }
- index = dlt_logstorage_find_dlt_header(config->cache,footer->offset,count);
+
+ index = dlt_logstorage_find_dlt_header(config->cache, footer->offset, count);
cache_offset = footer->offset;
}
- else
- {
+ else {
count = config->file_size - footer->last_sync_offset;
+
if (count > remain_file_size)
- {
count = remain_file_size;
- }
+
index = dlt_logstorage_find_dlt_header(config->cache,
footer->last_sync_offset,
count);
cache_offset = footer->last_sync_offset;
}
- if (index >= 0)
- {
+
+ if (index >= 0) {
ret = fwrite(config->cache + cache_offset + index, count - index, 1, config->log);
dlt_logstorage_check_write_ret(config, ret);
config->current_write_file_offset += count - index;
}
+
if (footer->last_sync_offset == 0)
- {
footer->last_sync_offset = footer->offset + count;
- }
else
- {
footer->last_sync_offset += count;
- }
+
config->total_write_count -= count;
/* sync data to current file in case of file is not full */
- if (config->current_write_file_offset < config->file_size)
- {
+ if (config->current_write_file_offset < config->file_size) {
count = config->file_size - config->current_write_file_offset;
- if (footer->last_sync_offset < config->file_size)
- {
+ if (footer->last_sync_offset < config->file_size) {
ret = fwrite(config->cache + footer->last_sync_offset, count, 1, config->log);
dlt_logstorage_check_write_ret(config, ret);
footer->last_sync_offset += count;
}
/* sync remaining amount of file from start of cache */
- else
- {
+ else {
config->sync_from_start = 1;
+
if (count > footer->offset)
- {
count = footer->offset;
- }
+
ret = fwrite(config->cache, count, 1, config->log);
dlt_logstorage_check_write_ret(config, ret);
footer->last_sync_offset = count;
}
+
config->total_write_count -= count;
}
config->current_write_file_offset = 0;
fclose(config->log);
config->log = NULL;
+
/* get always a new file */
if (dlt_logstorage_prepare_on_msg(config,
file_config,
dev_path,
- config->file_size) != 0)
- {
+ config->file_size) != 0) {
dlt_vlog(LOG_ERR,
"%s: failed to prepare log file for file_size\n", __func__);
return DLT_RETURN_ERROR;
@@ -751,33 +679,32 @@ DLT_STATIC DltReturnValue dlt_logstorage_sync_create_new_file(
* @return 0 on success, -1 on error
*/
DLT_STATIC DltReturnValue dlt_logstorage_sync_to_file(
- DltLogStorageFilterConfig *config,
- DltLogStorageUserConfig *file_config,
- char *dev_path)
+ DltLogStorageFilterConfig *config,
+ DltLogStorageUserConfig *file_config,
+ char *dev_path)
{
int ret = 0;
unsigned int remain_file_size = 0;
unsigned int count = 0;
DltLogStorageCacheFooter *footer = NULL;
- if (config == NULL || file_config == NULL || dev_path == NULL)
- {
+ if ((config == NULL) || (file_config == NULL) || (dev_path == NULL)) {
dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__);
return DLT_RETURN_WRONG_PARAMETER;
}
+
footer = (DltLogStorageCacheFooter *)(config->cache + config->file_size);
- if (footer == NULL)
- {
+ if (footer == NULL) {
dlt_vlog(LOG_ERR, "%s: Cannot retrieve cache information\n", __func__);
return DLT_RETURN_WRONG_PARAMETER;
- };
+ }
+
count = footer->offset - footer->last_sync_offset;
remain_file_size = config->file_size - config->current_write_file_offset;
/* sync data to file if required sync data exceeds remaining file size */
- if (count > remain_file_size)
- {
+ if (count > remain_file_size) {
ret = fwrite(config->cache + footer->last_sync_offset, remain_file_size, 1, config->log);
dlt_logstorage_check_write_ret(config, ret);
config->current_write_file_offset += remain_file_size;
@@ -787,17 +714,18 @@ DLT_STATIC DltReturnValue dlt_logstorage_sync_to_file(
config->current_write_file_offset = 0;
fclose(config->log);
config->log = NULL;
+
/* get always a new file */
if (dlt_logstorage_prepare_on_msg(config,
file_config,
dev_path,
- config->file_size) != 0)
- {
+ config->file_size) != 0) {
dlt_vlog(LOG_ERR,
"%s: failed to prepare log file for file_size\n", __func__);
return DLT_RETURN_ERROR;
}
}
+
ret = fwrite(config->cache + footer->last_sync_offset, count, 1, config->log);
dlt_logstorage_check_write_ret(config, ret);
config->current_write_file_offset += count;
@@ -817,35 +745,34 @@ DLT_STATIC DltReturnValue dlt_logstorage_sync_to_file(
* @return 0 on success, -1 on error
*/
DLT_STATIC DltReturnValue dlt_logstorage_sync_capable_data_to_file(
- DltLogStorageFilterConfig *config,
- int index_status)
+ DltLogStorageFilterConfig *config,
+ int index_status)
{
int ret = 0;
int index = 0;
unsigned int count = 0;
DltLogStorageCacheFooter *footer = NULL;
- if (config == NULL)
- {
+ if (config == NULL) {
dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__);
return DLT_RETURN_WRONG_PARAMETER;
}
footer = (DltLogStorageCacheFooter *)(config->cache + config->file_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_vlog(LOG_ERR, "%s: Cannot retrieve cache information\n", __func__);
return DLT_RETURN_WRONG_PARAMETER;
- };
+ }
+
count = config->file_size - footer->last_sync_offset;
+
if (index_status == 1)
- {
index = dlt_logstorage_find_dlt_header(config->cache,
footer->last_sync_offset,
count);
- }
- if (count > 0 && index >=0)
- {
+
+ if ((count > 0) && (index >= 0)) {
ret = fwrite(config->cache + footer->last_sync_offset + index,
count - index,
1,
@@ -853,6 +780,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_sync_capable_data_to_file(
dlt_logstorage_check_write_ret(config, ret);
config->current_write_file_offset += count - index;
}
+
config->total_write_count -= count;
footer->last_sync_offset = 0;
@@ -880,26 +808,20 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config,
struct stat s;
if ((config == NULL) || (file_config == NULL) || (dev_path == NULL))
- {
return -1;
- }
- if (config->log == NULL) /* open a new log file */
- {
+ if (config->log == NULL) { /* open a new log file */
ret = dlt_logstorage_open_log_file(config,
file_config,
dev_path,
log_msg_size);
}
- else /* already open, check size and create a new file if needed */
- {
+ else { /* already open, check size and create a new file if needed */
ret = fstat(fileno(config->log), &s);
- if (ret == 0)
- {
+ if (ret == 0) {
/* check if adding new data do not exceed max file size */
- if (s.st_size + log_msg_size >= (int)config->file_size)
- {
+ if (s.st_size + log_msg_size >= (int)config->file_size) {
fclose(config->log);
config->log = NULL;
ret = dlt_logstorage_open_log_file(config,
@@ -907,13 +829,11 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config,
dev_path,
log_msg_size);
}
- else /*everything is prepared */
- {
+ else { /*everything is prepared */
ret = 0;
}
}
- else
- {
+ else {
dlt_log(LOG_ERR,
"dlt_logstorage_prepare_log_file: stat() failed.\n");
ret = -1;
@@ -948,30 +868,22 @@ int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config,
int ret;
if ((config == NULL) || (data1 == NULL) || (data2 == NULL) || (data3 == NULL))
- {
return -1;
- }
ret = fwrite(data1, 1, size1, config->log);
if (ret != size1)
- {
dlt_log(LOG_WARNING, "Wrote less data than specified\n");
- }
ret = fwrite(data2, 1, size2, config->log);
if (ret != size2)
- {
dlt_log(LOG_WARNING, "Wrote less data than specified\n");
- }
ret = fwrite(data3, 1, size3, config->log);
if (ret != size3)
- {
dlt_log(LOG_WARNING, "Wrote less data than specified\n");
- }
return ferror(config->log);
}
@@ -998,18 +910,13 @@ int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config,
dev_path = dev_path;
if (config == NULL)
- {
return -1;
- }
- if (status == DLT_LOGSTORAGE_SYNC_ON_MSG) /* sync on every message */
- {
+ if (status == DLT_LOGSTORAGE_SYNC_ON_MSG) { /* sync on every message */
ret = fflush(config->log);
if (ret != 0)
- {
dlt_log(LOG_ERR, "fflush failed\n");
- }
}
return 0;
@@ -1034,9 +941,7 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config,
int log_msg_size)
{
if ((config == NULL) || (file_config == NULL) || (dev_path == NULL))
- {
return -1;
- }
/* Combinations allowed: on Daemon_Exit with on Demand,File_Size with Daemon_Exit
* File_Size with on Demand, Specific_Size with Daemon_Exit,Specific_Size with on Demand
@@ -1044,8 +949,7 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config,
*/
/* check for combinations of specific_size and file_size strategy */
if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) &&
- (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)) > 0)
- {
+ ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)) > 0)) {
dlt_log(LOG_WARNING, "wrong combination of sync strategies \n");
return -1;
}
@@ -1053,46 +957,37 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config,
log_msg_size = log_msg_size; /* satisfy compiler */
/* create file to sync cache into later */
- if (config->log == NULL)
- {
+ if (config->log == NULL) {
if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) &&
- (config->specific_size > config->file_size))
- {
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) &&
+ (config->specific_size > config->file_size)) {
dlt_log(LOG_ERR,
"Cannot prepare log file for ON_DAEMON_SPECIFIC_SIZE sync\n");
return -1;
}
else
- {
- /* get always a new file */
- if (dlt_logstorage_prepare_on_msg(config,
- file_config,
- dev_path,
- config->file_size) != 0)
- {
- dlt_log(LOG_ERR,
- "Cannot prepare log file for ON_DAEMON_EXIT sync\n");
- return -1;
- }
+ /* get always a new file */
+ if (dlt_logstorage_prepare_on_msg(config,
+ file_config,
+ dev_path,
+ config->file_size) != 0) {
+ dlt_log(LOG_ERR,
+ "Cannot prepare log file for ON_DAEMON_EXIT sync\n");
+ return -1;
}
}
-
- if (config->cache == NULL)
- {
+ if (config->cache == NULL) {
/* check for sync_specific_size strategy */
if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
- {
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) {
/* check total logstorage cache size */
if ((g_logstorage_cache_size +
config->specific_size +
sizeof(DltLogStorageCacheFooter)) >
- g_logstorage_cache_max)
- {
+ g_logstorage_cache_max) {
dlt_log(LOG_ERR, "Max size of Logstorage Cache already used.");
return -1;
}
@@ -1104,17 +999,15 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config,
/* update current used cache size */
g_logstorage_cache_size = config->specific_size +
- sizeof(DltLogStorageCacheFooter);
+ sizeof(DltLogStorageCacheFooter);
}
- else /* other cache strategies */
- {
+ else { /* other cache strategies */
/* check total logstorage cache size */
if ((g_logstorage_cache_size +
config->file_size +
sizeof(DltLogStorageCacheFooter)) >
- g_logstorage_cache_max)
- {
+ g_logstorage_cache_max) {
dlt_log(LOG_ERR, "Max size of Logstorage Cache already used.");
return -1;
}
@@ -1126,14 +1019,12 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config,
/* update current used cache size */
g_logstorage_cache_size = config->file_size +
- sizeof(DltLogStorageCacheFooter);
+ sizeof(DltLogStorageCacheFooter);
}
if (config->cache == NULL)
- {
dlt_log(LOG_CRIT,
"Cannot allocate memory for filter ring buffer\n");
- }
}
return 0;
@@ -1171,105 +1062,97 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config,
if ((config == NULL) || (data1 == NULL) || (size1 < 0) || (data2 == NULL) ||
(size2 < 0) || (data3 == NULL) || (size3 < 0) || (config->cache == NULL))
- {
return -1;
- }
if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
- {
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) {
footer = (DltLogStorageCacheFooter *)(config->cache +
config->specific_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_log(LOG_ERR, "Cannot retrieve cache footer. Address is NULL\n");
return -1;
}
+
msg_size = size1 + size2 + size3;
remain_cache_size = config->specific_size - footer->offset;
}
- else
- {
+ else {
footer = (DltLogStorageCacheFooter *)(config->cache +
config->file_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_log(LOG_ERR, "Cannot retrieve cache footer. Address is NULL\n");
return -1;
}
+
msg_size = size1 + size2 + size3;
remain_cache_size = config->file_size - footer->offset;
}
- if (msg_size < remain_cache_size) /* add at current position */
- {
+ if (msg_size < remain_cache_size) { /* add at current position */
curr_write_addr = (void *)(config->cache + footer->offset);
footer->offset += msg_size;
}
else if (msg_size > remain_cache_size)
{
if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
- {
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) {
/*check for message size exceeds cache size for specific_size strategy */
- if ((unsigned int) msg_size > config->specific_size)
- {
+ if ((unsigned int)msg_size > config->specific_size) {
dlt_log(LOG_WARNING, "Message is larger than cache. Discard.\n");
- return -1 ;
+ return -1;
}
}
- else if ((unsigned int) msg_size > config->file_size)
+ else if ((unsigned int)msg_size > config->file_size)
{
dlt_log(LOG_WARNING, "Message is larger than cache. Discard.\n");
return -1;
}
- /*sync to file for specific_size or file_size */
- if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) > 0)
- {
- ret = config->dlt_logstorage_sync(config,
- uconfig,
- dev_path,
- DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE);
- if (ret != 0)
- {
- dlt_log(LOG_ERR,"dlt_logstorage_sync: Unable to sync.\n");
- return -1;
- }
- }
- else if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
- {
-
- ret = config->dlt_logstorage_sync(config,
- uconfig,
- dev_path,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE);
- if (ret != 0)
- {
- dlt_log(LOG_ERR,"dlt_logstorage_sync: Unable to sync.\n");
- return -1;
- }
- }
- else if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_DEMAND) > 0)
- {
- config->pre_cache_sync = config->cur_cache_sync;
- config->cur_cache_sync = 0;
- if (config->pre_cache_sync == 0)
- {
- footer->last_sync_offset = 0;
- }
- }
+ /*sync to file for specific_size or file_size */
+ if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
+ DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) > 0) {
+ ret = config->dlt_logstorage_sync(config,
+ uconfig,
+ dev_path,
+ DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE);
+
+ if (ret != 0) {
+ dlt_log(LOG_ERR, "dlt_logstorage_sync: Unable to sync.\n");
+ return -1;
+ }
+ }
+ else if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
+ {
+
+ ret = config->dlt_logstorage_sync(config,
+ uconfig,
+ dev_path,
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE);
+
+ if (ret != 0) {
+ dlt_log(LOG_ERR, "dlt_logstorage_sync: Unable to sync.\n");
+ return -1;
+ }
+ }
+ else if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
+ DLT_LOGSTORAGE_SYNC_ON_DEMAND) > 0)
+ {
+ config->pre_cache_sync = config->cur_cache_sync;
+ config->cur_cache_sync = 0;
+
+ if (config->pre_cache_sync == 0)
+ footer->last_sync_offset = 0;
+ }
/* start writing from beginning */
curr_write_addr = config->cache;
footer->offset = msg_size;
footer->wrap_around_cnt += 1;
}
- else /* message just fits into cache */
- {
+ else { /* message just fits into cache */
curr_write_addr = (void *)(config->cache + footer->offset);
footer->wrap_around_cnt += 1;
}
@@ -1307,15 +1190,11 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
DltLogStorageCacheFooter *footer = NULL;
if (config == NULL)
- {
return -1;
- }
/* sync only, if given strategy is set */
- if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, status) > 0)
- {
- if ((config->log == NULL) || (config->cache == NULL))
- {
+ if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, status) > 0) {
+ if ((config->log == NULL) || (config->cache == NULL)) {
dlt_log(LOG_ERR,
"Cannot copy cache to file. One of both is NULL\n");
return -1;
@@ -1324,17 +1203,16 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
/* sync cache data to file for specific_size strategies */
if ((status == DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE)
- || ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
- && (status == DLT_LOGSTORAGE_SYNC_ON_DEMAND))
- || ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
- && (status == DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT)))
- {
+ || ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
+ && (status == DLT_LOGSTORAGE_SYNC_ON_DEMAND))
+ || ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
+ DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
+ && (status == DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT))) {
footer = (DltLogStorageCacheFooter *)(config->cache +
config->specific_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_log(LOG_ERR, "Cannot retrieve cache information\n");
return -1;
}
@@ -1347,16 +1225,11 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
remain_file_size = config->file_size - config->current_write_file_offset;
if (status == DLT_LOGSTORAGE_SYNC_ON_DEMAND)
- {
footer->last_sync_offset = footer->offset;
- }
else
- {
footer->last_sync_offset = 0;
- }
- if (remain_file_size < config->specific_size)
- {
+ if (remain_file_size < config->specific_size) {
config->current_write_file_offset = 0;
/* clean ring buffer and reset footer information */
memset(config->cache,
@@ -1368,20 +1241,20 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
fclose(config->log);
config->log = NULL;
- }
+ }
}
/* sync cache data to file for file size strategies*/
else if ((status == DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) ||
(status == DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT) ||
((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync,
- DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) > 0)
- && (status == DLT_LOGSTORAGE_SYNC_ON_DEMAND)))
+ DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) > 0)
+ && (status == DLT_LOGSTORAGE_SYNC_ON_DEMAND)))
{
footer = (DltLogStorageCacheFooter *)(config->cache +
config->file_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_log(LOG_ERR, "Cannot retrieve cache information\n");
return -1;
}
@@ -1394,13 +1267,12 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
footer->last_sync_offset = footer->offset;
if ((status != DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT)
- && (status != DLT_LOGSTORAGE_SYNC_ON_DEMAND))
- {
+ && (status != DLT_LOGSTORAGE_SYNC_ON_DEMAND)) {
config->current_write_file_offset = 0;
/* clean ring buffer and reset footer information */
memset(config->cache,
- 0,
- config->file_size + sizeof(DltLogStorageCacheFooter));
+ 0,
+ config->file_size + sizeof(DltLogStorageCacheFooter));
/* close the file, a new one will be created when prepare is
* called again */
@@ -1413,81 +1285,70 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
else if (status == DLT_LOGSTORAGE_SYNC_ON_DEMAND)
{
config->sync_from_start = 0;
- if ((file_config == NULL) || (dev_path == NULL))
- {
+
+ if ((file_config == NULL) || (dev_path == NULL)) {
dlt_log(LOG_ERR, "Cannot retrieve user configuration or mount point\n");
return -1;
}
+
footer = (DltLogStorageCacheFooter *)(config->cache +
config->file_size);
- if (footer == NULL)
- {
+
+ if (footer == NULL) {
dlt_log(LOG_ERR, "Cannot retrieve cache information\n");
return -1;
}
+
/* check for wrap around is 0 or cache is synced at least once
* in every wrap around */
- if ((footer->wrap_around_cnt < 1) || (config->cur_cache_sync == 1))
- {
+ if ((footer->wrap_around_cnt < 1) || (config->cur_cache_sync == 1)) {
ret = dlt_logstorage_sync_to_file(config,
file_config,
dev_path);
+
if (ret != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to sync data to file \n", __func__);
- }
}
- else
- {
+ else {
remain_file_size = config->file_size - config->current_write_file_offset;
/* check for total bytes of data need to sync */
- if (footer->offset >= footer->last_sync_offset )
- {
+ if (footer->offset >= footer->last_sync_offset)
config->total_write_count = config->file_size;
- }
else
- {
config->total_write_count = config->file_size - footer->last_sync_offset + footer->offset;
- }
/* sync data to file if required sync data exceeds remaining file size */
- if (config->total_write_count >= remain_file_size)
- {
+ if (config->total_write_count >= remain_file_size) {
ret = dlt_logstorage_sync_create_new_file(config,
file_config,
dev_path,
remain_file_size);
+
if (ret != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to sync and open new file\n", __func__);
- }
/* sync remaining end of cache data to new file*/
- if (config->sync_from_start == 0)
- {
+ if (config->sync_from_start == 0) {
ret = dlt_logstorage_sync_capable_data_to_file(config, 0);
+
if (ret != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to sync capable data to file\n", __func__);
- }
}
}
/* sync data to file if required sync data less than remaining file size */
- else
- {
+ else {
ret = dlt_logstorage_sync_capable_data_to_file(config, 1);
+
if (ret != 0)
- {
dlt_vlog(LOG_ERR, "%s: failed to sync capable data\n", __func__);
- }
}
+
/* sync data to file from almost the begin of cache
* if still data needs to sync */
- if (config->total_write_count > 0)
- {
+ if (config->total_write_count > 0) {
count = footer->offset - footer->last_sync_offset;
ret = fwrite(config->cache + footer->last_sync_offset,
count,
@@ -1498,6 +1359,7 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
footer->last_sync_offset += count;
}
+
config->cur_cache_sync = 1;
}
}