diff options
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/daemon/dlt-daemon.c | 52 | ||||
-rw-r--r-- | src/daemon/dlt-daemon.h | 11 | ||||
-rw-r--r-- | src/daemon/dlt.conf | 9 |
4 files changed, 59 insertions, 14 deletions
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt index f7aaa26..9916bb4 100644 --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -32,6 +32,7 @@ set(dlt_daemon_SRCS ${PROJECT_SOURCE_DIR}/src/lib/dlt_client.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_common.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_config_file_parser.c + ${PROJECT_SOURCE_DIR}/src/shared/dlt_multiple_files.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_offline_trace.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_protocol.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_user_shared.c diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index c8a8506..ee0f772 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) @@ -941,7 +958,10 @@ int main(int argc, char *argv[]) dlt_log_set_filename(daemon_local.flags.loggingFilename); dlt_log_set_level(daemon_local.flags.loggingLevel); DltReturnValue log_init_result = - dlt_log_init(daemon_local.flags.loggingMode); + 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"); @@ -1126,6 +1146,8 @@ int main(int argc, char *argv[]) dlt_log(LOG_NOTICE, "Leaving DLT daemon\n"); + dlt_log_free(); + return 0; } /* main() */ @@ -1171,7 +1193,12 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in /* 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); + // 'free' dlt logging and corresponding file handle before re-initializing + dlt_log_free(); + dlt_log_init_multiple_logfiles_support(daemon_local->flags.loggingMode, + daemon_local->flags.enableLoggingFileLimit, + daemon_local->flags.loggingFileSize, + daemon_local->flags.loggingFileMaxSize); /* initialise structure to use DLT file */ ret = dlt_file_init(&(daemon_local->file), daemon_local->flags.vflag); @@ -1218,11 +1245,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; } @@ -1786,7 +1816,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); diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 071562f..cc879cb 100644 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -69,6 +69,7 @@ #include <limits.h> /* for NAME_MAX */ #include <sys/time.h> +#include <stdarg.h> #include "dlt_daemon_common.h" #include "dlt_user_shared.h" @@ -103,10 +104,13 @@ typedef struct char offlineTraceDirectory[DLT_DAEMON_FLAG_MAX]; /**< (String: Directory) Store DLT messages to local directory (Default: /etc/dlt.conf) */ int offlineTraceFileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */ int offlineTraceMaxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */ - int offlineTraceFilenameTimestampBased; /**< (int) timestamp based or index based (Default: 1 Timestamp based) */ - int loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */ + bool offlineTraceFilenameTimestampBased; /**< (Boolean) timestamp based or index based (Default: true=Timestamp based) */ + DltLoggingMode loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */ int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */ char loggingFilename[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */ + bool enableLoggingFileLimit; /**< (Boolean) Indicate whether size of logging file(s) is limited (Default: false) */ + int loggingFileSize; /**< (int) Maximum size in bytes of one logging file (Default: 250000) */ + int loggingFileMaxSize; /**< (int) Maximum size in bytes of all logging files (Default: 1000000) */ int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */ char pathToECUSoftwareVersion[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The file from which to read the ECU version from. */ int sendTimezone; /**< (Boolean) Send Timezone perdiodically */ @@ -154,7 +158,8 @@ typedef struct DltShm dlt_shm; /**< Shared memory handling */ unsigned char *recv_buf_shm; /**< buffer for receive message from shm */ #endif - DltOfflineTrace offlineTrace; /**< Offline trace handling */ + MultipleFilesRingBuffer offlineTrace; /**< Offline trace handling */ + MultipleFilesRingBuffer dltLogging; /**< Dlt logging handling */ int timeoutOnSend; unsigned long RingbufferMinSize; unsigned long RingbufferMaxSize; diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf index 777aa82..11a5057 100644 --- a/src/daemon/dlt.conf +++ b/src/daemon/dlt.conf @@ -50,6 +50,15 @@ LoggingLevel = 6 # if WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK is set as compile flag LoggingFilename = /tmp/dlt.log +# Indicate whether size of logging file(s) is limited (Default: 0) +EnableLoggingFileLimit = 0 + +# Maximum size in bytes of one logging file (Default: 250000) +# LoggingFileSize = 250000 + +# Maximum size in bytes of all logging files (Default: 1000000) +# LoggingFileMaxSize = 1000000 + # Timeout on send to client (sec) TimeOutOnSend = 4 |