summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorAlexander Mohr <alexander.m.mohr@mercedes-benz.com>2022-10-05 10:32:15 +0200
committerGitHub <noreply@github.com>2022-10-05 10:32:15 +0200
commit5b80a4c92c9aa9ef45ce1da599b401ba631a86ed (patch)
treea8fa737aa20b222808a643516857cd9c5e2d23ac /src/shared
parent34471d85fca14a5ec359d2d06a8d7018cb23beb2 (diff)
downloadDLT-daemon-5b80a4c92c9aa9ef45ce1da599b401ba631a86ed.tar.gz
internal-logging: Fix issues with file logging (#378)
This commit fixes the following issues if access to the internal log file is not possible (logging_mode = DLT_LOG_TO_FILE) * dlt_log_free tried to call fclose on a nullptr Added a nullcheck for this * Access to log file might be denied but access to logs is still wanted Add a new CMake option WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK If this is set to ON and the logging moe is set to file, the dlt-daemon will fall back to syslog if opening the internal log file failed Signed-off-by: Alexander Mohr <alexander.m.mohr@mercedes-benz.com>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dlt_common.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index adda5db..57455fa 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -1814,11 +1814,11 @@ void dlt_print_with_attributes(bool state)
print_with_attributes = state;
}
-void dlt_log_init(int mode)
+DltReturnValue dlt_log_init(int mode)
{
if ((mode < DLT_LOG_TO_CONSOLE) || (mode > DLT_LOG_DROPPED)) {
dlt_vlog(LOG_WARNING, "Wrong parameter for mode: %d\n", mode);
- return;
+ return DLT_RETURN_WRONG_PARAMETER;
}
logging_mode = mode;
@@ -1829,14 +1829,16 @@ void dlt_log_init(int mode)
if (logging_handle == NULL) {
dlt_user_printf("Internal log file %s cannot be opened!\n", logging_filename);
- return;
+ return DLT_RETURN_ERROR;
}
}
+
+ return DLT_RETURN_OK;
}
void dlt_log_free(void)
{
- if (logging_mode == DLT_LOG_TO_FILE)
+ if (logging_mode == DLT_LOG_TO_FILE && logging_handle)
fclose(logging_handle);
}