summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon/dlt-daemon.c22
-rw-r--r--src/daemon/dlt.conf2
-rw-r--r--src/shared/dlt_common.c10
3 files changed, 28 insertions, 6 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) {
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf
index 7e19817..777aa82 100644
--- a/src/daemon/dlt.conf
+++ b/src/daemon/dlt.conf
@@ -46,6 +46,8 @@ LoggingMode = 0
LoggingLevel = 6
# The logging filename if internal logging mode is log to file (Default: /tmp/dlt.log)
+# If access to the file is not possible, the daemon will fall back to syslog
+# if WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK is set as compile flag
LoggingFilename = /tmp/dlt.log
# Timeout on send to client (sec)
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);
}