Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file deletion when rotating and some bugfixes #718

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/daemon/dlt_daemon_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 29 additions & 36 deletions src/offlinelogstorage/dlt_offline_logstorage_behavior.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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--;
}
}
}

Expand Down Expand Up @@ -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__);
}
}
}
Expand Down
Loading