diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index f3aa277b9..70d9f1ebf 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -134,7 +134,7 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon, int i = 0; if ((daemon == NULL) || (ecu == NULL)) { - dlt_vlog(LOG_ERR, "%s: Wrong parameters", __func__); + dlt_vlog(LOG_ERR, "%s: Wrong parameters\n", __func__); return (DltDaemonRegisteredUsers *)NULL; } @@ -253,7 +253,7 @@ DltReturnValue dlt_daemon_find_preconfigured_trace_load_settings( *settings = NULL; if ((daemon == NULL) || (apid == NULL)) { - dlt_vlog(LOG_ERR, "%s: Wrong parameters", __func__); + dlt_vlog(LOG_ERR, "%s: Wrong parameters\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -477,7 +477,7 @@ int dlt_daemon_init_user_information(DltDaemon *daemon, daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers)); if (daemon->user_list == NULL) { - dlt_log(LOG_ERR, "Allocating memory for user information"); + dlt_log(LOG_ERR, "Allocating memory for user information\n"); return DLT_RETURN_ERROR; } @@ -491,7 +491,7 @@ int dlt_daemon_init_user_information(DltDaemon *daemon, daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers)); if (daemon->user_list == NULL) { - dlt_log(LOG_ERR, "Allocating memory for user information"); + dlt_log(LOG_ERR, "Allocating memory for user information\n"); return DLT_RETURN_ERROR; } @@ -1684,12 +1684,12 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (context == NULL)) { - dlt_vlog(LOG_ERR, "NULL parameter in %s", __func__); + dlt_vlog(LOG_ERR, "NULL parameter in %s\n", __func__); return -1; } if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_LEVEL) < DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, "Failed to set userheader in %s", __func__); + dlt_vlog(LOG_ERR, "Failed to set userheader in %s\n", __func__); return -1; } @@ -1721,7 +1721,7 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, &(usercontext), sizeof(DltUserControlMsgLogLevel)); if (ret < DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, "Failed to send data to application in %s: %s", + dlt_vlog(LOG_ERR, "Failed to send data to application in %s: %s\n", __func__, errno != 0 ? strerror(errno) : "Unknown error"); diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 4dfe0bd16..698f01ae3 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -761,7 +761,7 @@ DltReturnValue dlt_init_common(void) } /* Binary semaphore for threads */ - if ((pthread_attr_init(&dlt_mutex_attr) != 0) || + if ((pthread_mutexattr_init(&dlt_mutex_attr) != 0) || (pthread_mutexattr_settype(&dlt_mutex_attr, PTHREAD_MUTEX_ERRORCHECK) != 0) || (pthread_mutex_init(&dlt_mutex, &dlt_mutex_attr) != 0)) { dlt_user_init_state = INIT_UNITIALIZED; diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c index e705c3ef2..23cbf826b 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c @@ -601,7 +601,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, } config->working_file_name = strdup((*newest)->name); } - strncat(absolute_file_path, config->working_file_name, strlen(config->working_file_name)); + strcat(absolute_file_path, config->working_file_name); dlt_vlog(LOG_DEBUG, "%s: Number of log files-newest file-wrap_id [%u]-[%s]-[%u]\n", @@ -707,31 +707,33 @@ 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 (!(config->num_files == 1 && file_config->logfile_optional_counter)) { - /* delete oldest */ - DltLogStorageFileList **head = &config->records; - DltLogStorageFileList *n = *head; - memset(absolute_file_path, - 0, - sizeof(absolute_file_path) / sizeof(char)); - strcat(absolute_file_path, storage_path); - strncat(absolute_file_path, (*head)->name, strlen((*head)->name)); - dlt_vlog(LOG_DEBUG, - "%s: Remove '%s' (num_log_files: %d, config->num_files:%d, file_name:%s)\n", - __func__, absolute_file_path, num_log_files, - config->num_files, config->file_name); - if (remove(absolute_file_path) != 0) - dlt_log(LOG_ERR, "Could not remove file\n"); - - free((*head)->name); - (*head)->name = NULL; - *head = n->next; - n->next = NULL; - free(n); + while (num_log_files > config->num_files) { + if (config->num_files == 1 && file_config->logfile_optional_counter) { + break; } - } + /* delete oldest */ + DltLogStorageFileList **head = &config->records; + DltLogStorageFileList *n = *head; + memset(absolute_file_path, + 0, + sizeof(absolute_file_path) / sizeof(char)); + strcat(absolute_file_path, storage_path); + strcat(absolute_file_path, (*head)->name); + dlt_vlog(LOG_DEBUG, + "%s: Remove '%s' (num_log_files: %d, config->num_files:%d, file_name:%s)\n", + __func__, absolute_file_path, num_log_files, + config->num_files, config->file_name); + if (remove(absolute_file_path) != 0) + dlt_log(LOG_ERR, "Could not remove file\n"); + + free((*head)->name); + (*head)->name = NULL; + *head = n->next; + n->next = NULL; + free(n); + num_log_files--; + } } } @@ -1107,18 +1109,9 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, /* Sync only if on_msg */ if ((config->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) || (config->sync == DLT_LOGSTORAGE_SYNC_UNSET)) { - if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) { - if (fsync(fileno(config->gzlog)) != 0) { - if (errno != ENOSYS) { - dlt_vlog(LOG_ERR, "%s: failed to sync gzip log file\n", __func__); - } - } - } - else { - if (fsync(fileno(config->log)) != 0) { - if (errno != ENOSYS) { - dlt_vlog(LOG_ERR, "%s: failed to sync log file\n", __func__); - } + if (fsync(config->fd) != 0) { + if (errno != ENOSYS) { + dlt_vlog(LOG_ERR, "%s: failed to sync log file\n", __func__); } } }