summaryrefslogtreecommitdiff
path: root/src/daemon/dlt-daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/dlt-daemon.c')
-rw-r--r--src/daemon/dlt-daemon.c113
1 files changed, 88 insertions, 25 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 74f4049..e56381b 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -46,6 +46,8 @@
#endif
#include <sys/stat.h>
#include <sys/time.h>
+#include <libgen.h>
+
#if defined(linux) && defined(__NR_statx)
# include <linux/stat.h>
#endif
@@ -338,7 +340,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineTraceDirectory[0] = 0;
daemon_local->flags.offlineTraceFileSize = 1000000;
daemon_local->flags.offlineTraceMaxSize = 4000000;
- daemon_local->flags.offlineTraceFilenameTimestampBased = 1;
+ daemon_local->flags.offlineTraceFilenameTimestampBased = true;
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
@@ -356,6 +358,9 @@ int option_file_parser(DltDaemonLocal *daemon_local)
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, daemon_local->flags.loggingFilename);
}
+ daemon_local->flags.enableLoggingFileLimit = false;
+ daemon_local->flags.loggingFileSize = 250000;
+ daemon_local->flags.loggingFileMaxSize = 1000000;
daemon_local->timeoutOnSend = 4;
daemon_local->RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE;
@@ -514,7 +519,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
else if (strcmp(token, "LoggingMode") == 0)
{
- daemon_local->flags.loggingMode = atoi(value);
+ daemon_local->flags.loggingMode = (DltLoggingMode)atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "LoggingLevel") == 0)
@@ -530,6 +535,18 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.loggingFilename[sizeof(daemon_local->flags.loggingFilename) - 1] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
+ else if (strcmp(token, "EnableLoggingFileLimit") == 0)
+ {
+ daemon_local->flags.enableLoggingFileLimit = (bool)atoi(value);
+ }
+ else if (strcmp(token, "LoggingFileSize") == 0)
+ {
+ daemon_local->flags.loggingFileSize = atoi(value);
+ }
+ else if (strcmp(token, "LoggingFileMaxSize") == 0)
+ {
+ daemon_local->flags.loggingFileMaxSize = atoi(value);
+ }
else if (strcmp(token, "TimeOutOnSend") == 0)
{
daemon_local->timeoutOnSend = atoi(value);
@@ -578,7 +595,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
}
else if (strcmp(token, "OfflineTraceFileNameTimestampBased") == 0)
{
- daemon_local->flags.offlineTraceFilenameTimestampBased = atoi(value);
+ daemon_local->flags.offlineTraceFilenameTimestampBased = (bool)atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendECUSoftwareVersion") == 0)
@@ -940,7 +957,28 @@ 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_multiple_logfiles_support(daemon_local.flags.loggingMode,
+ daemon_local.flags.enableLoggingFileLimit,
+ daemon_local.flags.loggingFileSize,
+ daemon_local.flags.loggingFileMaxSize);
+
+ 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 +993,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) {
@@ -991,7 +1029,7 @@ int main(int argc, char *argv[])
dlt_log(LOG_ERR, "Could not load runtime config\n");
return -1;
}
-
+
/*
* Load dlt-runtime.cfg if available.
* This must be loaded before offline setup
@@ -1045,7 +1083,7 @@ int main(int argc, char *argv[])
/* initiate gateway */
if (daemon_local.flags.gatewayMode == 1) {
if (dlt_gateway_init(&daemon_local, daemon_local.flags.vflag) == -1) {
- dlt_log(LOG_CRIT, "Fail to create gateway\n");
+ dlt_log(LOG_CRIT, "Failed to create gateway\n");
return -1;
}
@@ -1108,6 +1146,8 @@ int main(int argc, char *argv[])
dlt_log(LOG_NOTICE, "Leaving DLT daemon\n");
+ dlt_log_free();
+
return 0;
} /* main() */
@@ -1150,11 +1190,6 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
if (daemon_local->flags.dflag)
dlt_daemon_daemonize(daemon_local->flags.vflag);
- /* Re-Initialize internal logging facility after fork */
- dlt_log_set_filename(daemon_local->flags.loggingFilename);
- dlt_log_set_level(daemon_local->flags.loggingLevel);
- dlt_log_init(daemon_local->flags.loggingMode);
-
/* initialise structure to use DLT file */
ret = dlt_file_init(&(daemon_local->file), daemon_local->flags.vflag);
@@ -1200,11 +1235,14 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
/* init offline trace */
if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) &&
daemon_local->flags.offlineTraceDirectory[0]) {
- if (dlt_offline_trace_init(&(daemon_local->offlineTrace),
- daemon_local->flags.offlineTraceDirectory,
- daemon_local->flags.offlineTraceFileSize,
- daemon_local->flags.offlineTraceMaxSize,
- daemon_local->flags.offlineTraceFilenameTimestampBased) == -1) {
+ if (multiple_files_buffer_init(&(daemon_local->offlineTrace),
+ daemon_local->flags.offlineTraceDirectory,
+ daemon_local->flags.offlineTraceFileSize,
+ daemon_local->flags.offlineTraceMaxSize,
+ daemon_local->flags.offlineTraceFilenameTimestampBased,
+ false,
+ DLT_OFFLINETRACE_FILENAME_BASE,
+ DLT_OFFLINETRACE_FILENAME_EXT) == -1) {
dlt_log(LOG_ERR, "Could not initialize offline trace\n");
return -1;
}
@@ -1621,6 +1659,7 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
}
}
else {
+ bool any_open = false;
while (head != NULL) { /* open socket for each IP in the bindAddress list */
if (dlt_daemon_socket_open(&fd, daemon_local->flags.port, head->ip) == DLT_RETURN_OK) {
@@ -1629,17 +1668,22 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
fd,
POLLIN,
DLT_CONNECTION_CLIENT_CONNECT)) {
- dlt_log(LOG_ERR, "Could not initialize main socket.\n");
- return DLT_RETURN_ERROR;
+ dlt_vlog(LOG_ERR, "Could not create connection, for binding %s\n", head->ip);
+ } else {
+ any_open = true;
}
}
else {
- dlt_log(LOG_ERR, "Could not initialize main socket.\n");
- return DLT_RETURN_ERROR;
+ dlt_vlog(LOG_ERR, "Could not open main socket, for binding %s\n", head->ip);
}
head = head->next;
}
+
+ if (!any_open) {
+ dlt_vlog(LOG_ERR, "Failed create main socket for any configured binding\n");
+ return DLT_RETURN_ERROR;
+ }
}
#ifdef UDP_CONNECTION_SUPPORT
@@ -1762,7 +1806,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i
/* free shared memory */
if (daemon_local->flags.offlineTraceDirectory[0])
- dlt_offline_trace_free(&(daemon_local->offlineTrace));
+ multiple_files_buffer_free(&(daemon_local->offlineTrace));
/* Ignore result */
dlt_file_free(&(daemon_local->file), daemon_local->flags.vflag);
@@ -2133,6 +2177,8 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon,
if (dlt_daemon_send_ringbuffer_to_client(daemon, daemon_local, verbose) == -1) {
dlt_log(LOG_WARNING, "Can't send contents of ringbuffer to clients\n");
+ close(in_sock);
+ in_sock = -1;
return -1;
}
@@ -3177,8 +3223,10 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon,
return DLT_DAEMON_ERROR_UNKNOWN;
}
- ret = dlt_daemon_client_send_message_to_all_client(daemon,
- daemon_local, verbose);
+ /* discard non-allowed levels if enforcement is on */
+ bool keep_message = enforce_context_ll_and_ts_keep_message(daemon_local);
+ if (keep_message)
+ dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose);
if (DLT_DAEMON_ERROR_OK != ret)
dlt_log(LOG_ERR, "failed to send message to client.\n");
@@ -3205,7 +3253,10 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon,
return DLT_DAEMON_ERROR_UNKNOWN;
}
- dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose);
+ /* discard non-allowed levels if enforcement is on */
+ bool keep_message = enforce_context_ll_and_ts_keep_message(daemon_local);
+ if (keep_message)
+ dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose);
/* keep not read data in buffer */
size = (int) (daemon_local->msg.headersize +
@@ -3225,6 +3276,18 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon,
return DLT_DAEMON_ERROR_OK;
}
+bool enforce_context_ll_and_ts_keep_message(DltDaemonLocal *daemon_local) {
+ if (daemon_local->flags.enforceContextLLAndTS &&
+ daemon_local->msg.extendedheader) {
+ const int mtin = DLT_GET_MSIN_MTIN(daemon_local->msg.extendedheader->msin);
+ if (mtin > daemon_local->flags.contextLogLevel) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
DltReceiver *rec,