summaryrefslogtreecommitdiff
path: root/src/daemon/dlt-daemon.c
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/daemon/dlt-daemon.c
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/daemon/dlt-daemon.c')
-rw-r--r--src/daemon/dlt-daemon.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 35fb024..2c9ff6a 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -940,7 +940,25 @@ int main(int argc, char *argv[])
/* Initialize internal logging facility */
dlt_log_set_filename(daemon_local.flags.loggingFilename);
dlt_log_set_level(daemon_local.flags.loggingLevel);
- dlt_log_init(daemon_local.flags.loggingMode);
+ DltReturnValue log_init_result =
+ dlt_log_init(daemon_local.flags.loggingMode);
+
+ if (log_init_result != DLT_RETURN_OK) {
+ fprintf(stderr, "Failed to init internal logging\n");
+
+#if WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK
+ if (daemon_local.flags.loggingMode == DLT_LOG_TO_FILE) {
+ fprintf(stderr, "Falling back to syslog mode\n");
+
+ daemon_local.flags.loggingMode = DLT_LOG_TO_SYSLOG;
+ log_init_result = dlt_log_init(daemon_local.flags.loggingMode);
+ if (log_init_result != DLT_RETURN_OK) {
+ fprintf(stderr, "Failed to setup syslog logging, internal logs will "
+ "not be available\n");
+ }
+ }
+#endif
+ }
/* Print version information */
dlt_get_version(version, DLT_DAEMON_TEXTBUFSIZE);
@@ -955,7 +973,7 @@ int main(int argc, char *argv[])
if (dlt_mkdir_recursive(dltFifoBaseDir) != 0) {
dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", dltFifoBaseDir);
return -1;
- }
+ }
#else
if (dlt_mkdir_recursive(DLT_USER_IPC_PATH) != 0) {