diff -Nru dlt-daemon-2.18.9/Android.bp dlt-daemon-2.18.4/Android.bp --- dlt-daemon-2.18.9/Android.bp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/Android.bp 1970-01-01 00:00:00.000000000 +0000 @@ -1,202 +0,0 @@ -/** - * Copyright (C) 2019 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. - * - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -cc_defaults { - name: "dlt_defaults", - vendor: true, - - local_include_dirs: [ - "include/dlt", - ], - - generated_headers: ["dlt_version_header", - "dlt_user_header"], - - cflags: [ - "-DDLT_DAEMON_USE_UNIX_SOCKET_IPC", - "-DDLT_LIB_USE_UNIX_SOCKET_IPC", - "-DCONFIGURATION_FILES_DIR=\"/vendor/etc\"", - "-DDLT_USER_IPC_PATH=\"/dev/socket\"", - ] + [ - "-Wno-unused-parameter", - "-W", - "-Wall", - ], -} - -// Generate dlt_version.h without Cmake -genrule { - name: "dlt_version_header", - tool_files: ["util/create_dlt_version_h.py"], - srcs: [ - "CMakeLists.txt", - "cmake/dlt_version.h.cmake", - ], - cmd: "$(location util/create_dlt_version_h.py) $(in) $(out)", - out: ["dlt_version.h"], -} - -// Generate dlt_user.h without Cmake -genrule { - name: "dlt_user_header", - tool_files: ["util/create_dlt_user_h.py"], - srcs: [ - "include/dlt/dlt_user.h.in", - ], - cmd: "$(location util/create_dlt_user_h.py) $(in) $(out)", - out: ["dlt_user.h"], -} - -prebuilt_etc { - name: "dlt-daemon-configuration", - vendor: true, - src: "src/daemon/dlt.conf", - filename_from_src: true, -} - -cc_binary { - - name: "dlt-daemon", - defaults: ["dlt_defaults"], - - init_rc: [ - "src/daemon/dlt-daemon.rc", - ], - - local_include_dirs: [ - "src/daemon", - "src/gateway", - "src/lib", - "src/shared", - "src/offlinelogstorage", - ], - - srcs: [ - "src/daemon/dlt-daemon.c", - "src/daemon/dlt_daemon_client.c", - "src/daemon/dlt_daemon_common.c", - "src/daemon/dlt_daemon_connection.c", - "src/daemon/dlt_daemon_event_handler.c", - "src/daemon/dlt_daemon_offline_logstorage.c", - "src/daemon/dlt_daemon_serial.c", - "src/daemon/dlt_daemon_socket.c", - "src/daemon/dlt_daemon_unix_socket.c", - "src/gateway/dlt_gateway.c", - "src/lib/dlt_client.c", - "src/shared/dlt_common.c", - "src/shared/dlt_config_file_parser.c", - "src/shared/dlt_multiple_files.c", - "src/shared/dlt_offline_trace.c", - "src/shared/dlt_protocol.c", - "src/shared/dlt_user_shared.c", - "src/offlinelogstorage/dlt_offline_logstorage.c", - "src/offlinelogstorage/dlt_offline_logstorage_behavior.c", - ], - - shared_libs: [ - "libc", - "libutils", - "libcutils", - ], - - required: ["dlt-daemon-configuration"], -} - -cc_library_shared { - name: "libdlt", - defaults: ["dlt_defaults"], - - local_include_dirs: [ - "src/lib", - "src/shared", - ], - - export_include_dirs: [ - "include/dlt", - ], - - export_generated_headers: [ - "dlt_version_header", - "dlt_user_header" - ], - - srcs: [ - "src/lib/dlt_client.c", - "src/lib/dlt_env_ll.c", - "src/lib/dlt_filetransfer.c", - "src/lib/dlt_user.c", - "src/shared/dlt_common.c", - "src/shared/dlt_multiple_files.c", - "src/shared/dlt_protocol.c", - "src/shared/dlt_user_shared.c", - ], -} - -cc_binary { - - name: "dlt-example-user", - defaults: ["dlt_defaults"], - - srcs: [ - "src/examples/dlt-example-user.c", - ], - - shared_libs: [ - "libc", - "libdlt", - ], -} - -cc_binary { - - name: "dlt-receive", - defaults: ["dlt_defaults"], - - srcs: [ - "src/console/dlt-receive.c", - ], - - shared_libs: [ - "libc", - "libdlt", - ], -} - -cc_binary { - - name: "dlt-logd-converter", - defaults: ["dlt_defaults"], - - srcs: [ - "src/android/dlt-logd-converter.cpp", - ], - init_rc: [ - "src/android/dlt-logd-converter.rc", - ], - - cflags: [ - "-Wextra", - "-Wpedantic", - "-std=c++14", - ], - shared_libs: [ - "libdlt", - "liblog", - ], -} - -// vim: ft=python - diff -Nru dlt-daemon-2.18.9/AUTHORS dlt-daemon-2.18.4/AUTHORS --- dlt-daemon-2.18.9/AUTHORS 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/AUTHORS 2019-09-03 08:28:13.000000000 +0000 @@ -14,4 +14,3 @@ Mohammed AL Dardoun Lassi Marttala Simon Brandner -Copyright (c) 2019 MBition GmbH, Andreas Seidl diff -Nru dlt-daemon-2.18.9/automotive-dlt-config.cmake.in dlt-daemon-2.18.4/automotive-dlt-config.cmake.in --- dlt-daemon-2.18.9/automotive-dlt-config.cmake.in 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/automotive-dlt-config.cmake.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -####### -# SPDX license identifier: MPL-2.0 -# -# Copyright (C) 2021, Martin Willers -# -# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -####### - -# Config file for the Genivi::dlt package. - -# This file exports the Genivi::dlt CMake target which should be passed to the -# target_link_libraries command. -# -# In addition, the following variable is defined: -# @PROJECT_NAME@_FOUND - TRUE if headers and library were found - -include(CMakeFindDependencyMacro) - -find_dependency(Threads) - -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") - -check_required_components(@PROJECT_NAME@) diff -Nru dlt-daemon-2.18.9/automotive-dlt-c++.pc.in dlt-daemon-2.18.4/automotive-dlt-c++.pc.in --- dlt-daemon-2.18.9/automotive-dlt-c++.pc.in 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/automotive-dlt-c++.pc.in 2019-09-03 08:28:13.000000000 +0000 @@ -3,6 +3,6 @@ Name: DLT C++ Description: Diagnostic Log and Trace C++ extensions -Version: @PROJECT_VERSION@ +Version: @DLTCPP_VERSION@ Requires: automotive-dlt Cflags: -std=gnu++0x diff -Nru dlt-daemon-2.18.9/automotive-dlt.pc.in dlt-daemon-2.18.4/automotive-dlt.pc.in --- dlt-daemon-2.18.9/automotive-dlt.pc.in 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/automotive-dlt.pc.in 2019-09-03 08:28:13.000000000 +0000 @@ -20,8 +20,8 @@ Name: DLT Description: Diagnostic Log and Trace -Version: @PROJECT_VERSION@ +Version: @DLT_VERSION@ Requires: -Libs: -L${libdir} -L${libdir}/static -ldlt -lrt -lpthread @ZLIB_LIBRARY@ -Cflags: -I${includedir}/dlt -I${includedir} -DDLT_@PROJECT_VERSION_MAJOR@_@PROJECT_VERSION_MINOR@ +Libs: -L${libdir} -ldlt -lrt -lpthread @ZLIB_LIBRARY@ +Cflags: -I${includedir}/dlt -DDLT_@DLT_MAJOR_VERSION@_@DLT_MINOR_VERSION@ diff -Nru dlt-daemon-2.18.9/automotive-dlt.spec.in dlt-daemon-2.18.4/automotive-dlt.spec.in --- dlt-daemon-2.18.9/automotive-dlt.spec.in 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/automotive-dlt.spec.in 2019-09-03 08:28:13.000000000 +0000 @@ -14,7 +14,7 @@ ####### Name: @PROJECT_NAME@ -Version: @PROJECT_VERSION@ +Version: @DLT_VERSION@ Release: @GENIVI_RPM_RELEASE@ Summary: %{name} - Diagnostic Log and Trace Group: System Environment/Base @@ -108,8 +108,8 @@ /etc/dlt.conf /usr/share/dlt-filetransfer/dlt-test-filetransfer-file /usr/share/dlt-filetransfer/dlt-test-filetransfer-image.png -%{_libdir}/libdlt.so.@PROJECT_VERSION_MAJOR@ -%{_libdir}/libdlt.so.@PROJECT_VERSION@ +%{_libdir}/libdlt.so.@DLT_MAJOR_VERSION@ +%{_libdir}/libdlt.so.@DLT_VERSION@ %{_libdir}/libdlt.so %{_bindir}/dlt-system %{_bindir}/dlt-convert diff -Nru dlt-daemon-2.18.9/.clang-format dlt-daemon-2.18.4/.clang-format --- dlt-daemon-2.18.9/.clang-format 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/.clang-format 1970-01-01 00:00:00.000000000 +0000 @@ -1,90 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: false -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: false -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: true - IndentBraces: false -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IndentCaseLabels: false -IndentWidth: 4 -IndentWrappedFunctionNames: false -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -ReflowComments: true -SortIncludes: true -SpaceAfterCStyleCast: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 4 -UseTab: Never -... - diff -Nru dlt-daemon-2.18.9/cmake/CMakeLists.txt dlt-daemon-2.18.4/cmake/CMakeLists.txt --- dlt-daemon-2.18.9/cmake/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/cmake/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -52,7 +52,6 @@ CHECK_INCLUDE_FILES( sys/uio.h HAVE_SYSUIO_H) CHECK_INCLUDE_FILES( termios.h HAVE_TERMIOS_H) CHECK_INCLUDE_FILES( unistd.h HAVE_UNISTD_H) -CHECK_INCLUDE_FILES( mqueue.h HAVE_MQUEUE_H) INCLUDE(CheckFunctionExists) @@ -73,29 +72,6 @@ CHECK_FUNCTION_EXISTS( strstr HAVE_FUNC_STRSTR) CHECK_FUNCTION_EXISTS( strtol HAVE_FUNC_STRTOL) -# Message queue -find_library(RT_LIBRARY rt) -if(RT_LIBRARY) - include(CheckLibraryExists) - CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_open mqueue.h HAVE_FUNC_MQOPEN) - CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_close mqueue.h HAVE_FUNC_MQCLOSE) - CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_unlink mqueue.h HAVE_FUNC_MQUNLINK) - CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_send mqueue.h HAVE_FUNC_MQSEND) - CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_receive mqueue.h HAVE_FUNC_MQRECEIVE) -else() - CHECK_FUNCTION_EXISTS( mq_open HAVE_FUNC_MQOPEN) - CHECK_FUNCTION_EXISTS( mq_close HAVE_FUNC_MQCLOSE) - CHECK_FUNCTION_EXISTS( mq_unlink HAVE_FUNC_MQUNLINK) - CHECK_FUNCTION_EXISTS( mq_send HAVE_FUNC_MQSEND) - CHECK_FUNCTION_EXISTS( mq_receive HAVE_FUNC_MQRECEIVE) -endif() - -if(CMAKE_THREAD_LIBS_INIT) - CHECK_LIBRARY_EXISTS(${CMAKE_THREAD_LIBS_INIT} pthread_setname_np pthread.h HAVE_FUNC_PTHREAD_SETNAME_NP) -else(CMAKE_THREAD_LIBS_INIT) - CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_FUNC_PTHREAD_SETNAME_NP) -endif(CMAKE_THREAD_LIBS_INIT) - if(WITH_CHECK_CONFIG_FILE) configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.cmake ${PROJECT_BINARY_DIR}/include/dlt/config.h) endif(WITH_CHECK_CONFIG_FILE) diff -Nru dlt-daemon-2.18.9/cmake/dlt_version.h.cmake dlt-daemon-2.18.4/cmake/dlt_version.h.cmake --- dlt-daemon-2.18.9/cmake/dlt_version.h.cmake 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/cmake/dlt_version.h.cmake 2019-09-03 08:28:13.000000000 +0000 @@ -18,10 +18,10 @@ #define __DLT_VERSION_H_ #define _DLT_PACKAGE_VERSION_STATE "@DLT_VERSION_STATE@" -#define _DLT_PACKAGE_VERSION "@PROJECT_VERSION@" -#define _DLT_PACKAGE_MAJOR_VERSION "@PROJECT_VERSION_MAJOR@" -#define _DLT_PACKAGE_MINOR_VERSION "@PROJECT_VERSION_MINOR@" -#define _DLT_PACKAGE_PATCH_LEVEL "@PROJECT_VERSION_PATCH@" +#define _DLT_PACKAGE_VERSION "@DLT_VERSION@" +#define _DLT_PACKAGE_MAJOR_VERSION "@DLT_MAJOR_VERSION@" +#define _DLT_PACKAGE_MINOR_VERSION "@DLT_MINOR_VERSION@" +#define _DLT_PACKAGE_PATCH_LEVEL "@DLT_PATCH_LEVEL@" #define _DLT_PACKAGE_REVISION "@DLT_REVISION@" #ifdef DLT_SYSTEMD_ENABLE diff -Nru dlt-daemon-2.18.9/CMakeLists.txt dlt-daemon-2.18.4/CMakeLists.txt --- dlt-daemon-2.18.9/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -13,15 +13,20 @@ # For further information see http://www.genivi.org/. ####### -cmake_minimum_required(VERSION 3.3) -project(automotive-dlt VERSION 2.18.8) +cmake_minimum_required(VERSION 2.8.5) +project(automotive-dlt) mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) include(GNUInstallDirs) # Set version parameters +set(DLT_MAJOR_VERSION 2) +set(DLT_MINOR_VERSION 18) +set(DLT_PATCH_LEVEL 4) +set(DLT_VERSION ${DLT_MAJOR_VERSION}.${DLT_MINOR_VERSION}.${DLT_PATCH_LEVEL}) set(DLT_VERSION_STATE STABLE) +set(DLT_REVISION "") execute_process(COMMAND git describe --tags WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE DLT_REVISION @@ -48,7 +53,6 @@ option(WITH_SYSTEMD "Set to ON to create unit files and systemd check on dlt-daemon startup" OFF) option(WITH_SYSTEMD_WATCHDOG "Set to ON to use the systemd watchdog in dlt-daemon" OFF) option(WITH_SYSTEMD_JOURNAL "Set to ON to use the systemd journal in dlt-system" OFF) -option(WITH_SYSTEMD_SOCKET_ACTIVATION "Set to ON to use systemd socket activation" OFF) option(WITH_DOC "Set to ON to build documentation target" OFF) option(WITH_MAN "Set to ON to build man pages" OFF) option(WITH_CHECK_CONFIG_FILE "Set to ON to create a configure file of CheckIncludeFiles and CheckFunctionExists" OFF) @@ -56,26 +60,13 @@ option(WITH_GPROF "Set -pg to compile flags" OFF) option(WITH_DLTTEST "Set to ON to build with modifications to test User-Daemon communication with corrupt messages" OFF) option(WITH_DLT_SHM_ENABLE "EXPERIMENTAL! Set to ON to use shared memory as IPC. EXPERIMENTAL!" OFF) -option(WITH_DLT_ADAPTOR "Set to ON to build src/adaptor binaries" OFF) -option(WITH_DLT_ADAPTOR_STDIN "Set to ON to build src/adaptor/stdin binaries" OFF) -option(WITH_DLT_ADAPTOR_UDP "Set to ON to build src/adaptor/udp binaries" OFF) +option(WITH_DLT_ADAPTOR "Set to ON to build src/adaptor binaries" OFF) option(WITH_DLT_CONSOLE "Set to ON to build src/console binaries" ON) -option(WITH_DLT_CONSOLE_WO_CTRL "Set to ON not to build control commands under src/console" OFF) -option(WITH_DLT_CONSOLE_WO_SBTM "Set to ON not to build dlt-sortbytimestamp under src/console" OFF) -option(WITH_DLT_CONSOLE_RECEIVE "Set to OFF to skip building dlt_receive" ON) -option(WITH_DLT_CONSOLE_CONVERT "Set to OFF to skip building dlt_convert" ON) -option(WITH_DLT_CONSOLE_CONTROL "Set to OFF to skip building dlt_control" ON) -option(WITH_DLT_CONSOLE_PASSIVE_NODE_CTRL "Set to OFF to skip building dlt_passive_node_ctrl" ON) - option(WITH_DLT_EXAMPLES "Set to ON to build src/examples binaries" ON) -option(WITH_DLT_FILETRANSFER "Set to ON to build dlt-system with filetransfer support" OFF) option(WITH_DLT_SYSTEM "Set to ON to build src/system binaries" OFF) option(WITH_DLT_DBUS "Set to ON to build src/dbus binaries" OFF) option(WITH_DLT_TESTS "Set to ON to build src/test binaries" ON) option(WITH_DLT_UNIT_TESTS "Set to ON to build gtest framework and tests/binaries" OFF) -option(WITH_DLT_QNX_SYSTEM "Set to ON to build QNX system binary dlt-qnx-system" OFF) -option(WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK "Set to ON to enable fallback to syslog if dlt logging to file fails" OFF) -option(WITH_DLT_NETWORK_TRACE "Set to ON to enable network trace (if message queue is supported)" ON) set(DLT_IPC "FIFO" CACHE STRING "UNIX_SOCKET,FIFO") set(DLT_USER "genivi" CACHE STRING "Set user for process not run as root") @@ -87,16 +78,7 @@ option(WITH_DLT_USE_IPv6 "Set to ON for IPv6 support" ON) option(WITH_DLT_KPI "Set to ON to build src/kpi binaries" OFF) option(WITH_DLT_FATAL_LOG_TRAP "Set to ON to enable DLT_LOG_FATAL trap(trigger segv inside dlt-user library)" OFF) -option(WITH_UDP_CONNECTION "Set to ON to enable dlt UDP multicast SUPPORT" OFF) -option(WITH_LIB_SHORT_VERSION "Set to ON to build library with only major number in version" OFF) -option(WITH_DLT_DISABLE_MACRO "Set to ON to build code without Macro interface support" OFF) -option(WITH_LEGACY_INCLUDE_PATH "Set to ON to add /dlt to include paths for the CMake config file, in addition to only " ON) -option(WITH_EXTENDED_FILTERING "Set to OFF to build without extended filtering. Using json filter files is only supported for Linux based system with json-c and QNX." OFF) - -option(WITH_DLT_DAEMON_VSOCK_IPC "Set to ON to enable VSOCK support in daemon" OFF) -option(WITH_DLT_LIB_VSOCK_IPC "Set to ON to enable VSOCK support in library (DLT_IPC is not used in library)" OFF) - -set(DLT_VSOCK_PORT "13490" CACHE STRING "VSOCK port number for logging traffic.") +option(WITH_UDP_CONNECTION "Set to ON to enable dlt UDP multicast SUPPORT" ON) # RPM settings set(GENIVI_RPM_RELEASE "1") # ${DLT_REVISION}") @@ -104,7 +86,7 @@ # Build, project and include settings find_package(Threads REQUIRED) -if(WITH_DLT_COREDUMPHANDLER OR WITH_DLT_FILETRANSFER) +if(WITH_DLT_SYSTEM) set(ZLIB_LIBRARY "-lz") find_package(ZLIB REQUIRED) else() @@ -118,8 +100,8 @@ include_directories( ${PROJECT_SOURCE_DIR} - ${PROJECT_BINARY_DIR}/include/dlt ${PROJECT_SOURCE_DIR}/include/dlt + ${PROJECT_BINARY_DIR}/include/dlt ${PROJECT_SOURCE_DIR}/src/shared ${PROJECT_SOURCE_DIR}/src/core_dump_handler ${PROJECT_SOURCE_DIR}/src/offlinelogstorage @@ -132,20 +114,8 @@ add_definitions(-D_GNU_SOURCE) -if(NOT DLT_IPC STREQUAL "UNIX_SOCKET" AND NOT DLT_IPC STREQUAL "FIFO") - message(FATAL_ERROR "${DLT_IPC} is not a valid value for DLT_IPC") -endif() -add_definitions(-DDLT_DAEMON_USE_${DLT_IPC}_IPC) -if(WITH_DLT_DAEMON_VSOCK_IPC) - add_definitions(-DDLT_DAEMON_VSOCK_IPC_ENABLE) -endif() -if(NOT WITH_DLT_LIB_VSOCK_IPC) - add_definitions(-DDLT_LIB_USE_${DLT_IPC}_IPC) -else() - add_definitions(-DDLT_LIB_USE_VSOCK_IPC) -endif() -if(WITH_DLT_DAEMON_VSOCK_IPC OR WITH_DLT_LIB_VSOCK_IPC) - add_definitions(-DDLT_VSOCK_PORT=${DLT_VSOCK_PORT}) +if(DLT_IPC STREQUAL "UNIX_SOCKET") + add_definitions(-DDLT_USE_UNIX_SOCKET_IPC) endif() if(NOT DLT_USER_IPC_PATH) @@ -169,13 +139,6 @@ add_definitions(-DDLT_USE_IPv6) endif() -if(WITH_DLT_QNX_SYSTEM AND NOT "${CMAKE_C_COMPILER}" MATCHES "nto-qnx|qcc") - message(FATAL_ERROR "Can only compile for QNX with a QNX compiler.") -endif() - -if (WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK) - add_definitions(-DWITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK) -endif() if(WITH_GPROF) add_compile_options(-pg) @@ -208,25 +171,17 @@ install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-c++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT devel) endif() -set(CONFIGURATION_FILES_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}) +if(CMAKE_INSTALL_PREFIX STREQUAL "/usr") + set(CONFIGURATION_FILES_DIR "/etc") +else() + set(CONFIGURATION_FILES_DIR "${CMAKE_INSTALL_PREFIX}/etc") +endif() + add_definitions(-DCONFIGURATION_FILES_DIR="${CONFIGURATION_FILES_DIR}") add_subdirectory(cmake) -if (WITH_DLT_NETWORK_TRACE) - # Message queue - if(HAVE_MQUEUE_H AND HAVE_FUNC_MQOPEN AND HAVE_FUNC_MQCLOSE AND - HAVE_FUNC_MQUNLINK AND HAVE_FUNC_MQSEND AND HAVE_FUNC_MQRECEIVE) - add_definitions(-DDLT_NETWORK_TRACE_ENABLE) - set(DLT_NETWORK_TRACE_ENABLE 1) - else() - message(STATUS "Disable network trace interface since message queue is not supported") - endif() -else() - message(STATUS "Network trace interface disabled") -endif() - -if(WITH_SYSTEMD OR WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD_JOURNAL OR WITH_SYSTEMD_SOCKET_ACTIVATION) +if(WITH_SYSTEMD OR WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD_JOURNAL) find_package(PkgConfig REQUIRED) execute_process(COMMAND pkg-config --modversion systemd OUTPUT_VARIABLE SYSTEMD_VERSION) string(REPLACE "\n" "" SYSTEMD_VERSION ${SYSTEMD_VERSION}) @@ -243,21 +198,12 @@ add_definitions(-DDLT_SYSTEMD_JOURNAL_ENABLE) endif() - if (WITH_SYSTEMD_SOCKET_ACTIVATION) - if(NOT DLT_IPC STREQUAL "UNIX_SOCKET") - message(FATAL_ERROR "WITH_SYSTEMD_SOCKET_ACTIVATION is only supported for UNIX_SOCKET") - endif() - add_definitions(-DDLT_SYSTEM_SOCKET_ACTIVATION_ENABLE) - endif() - set(systemd_SRCS ${PROJECT_SOURCE_DIR}/systemd/3rdparty/sd-daemon.c) set(SYSTEMD_UNITDIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system" CACHE PATH "Set directory to install systemd unit files") add_subdirectory(systemd) -else() - set(systemd_SRCS "") endif() if(WITH_DLT_LOGSTORAGE_CTRL_UDEV) @@ -268,42 +214,18 @@ add_definitions(-DDLT_FATAL_LOG_RESET_ENABLE) endif() -if(WITH_DLT_FILTER_BACKEND_PROP) - add_definitions(-DHAS_PROPRIETARY_FILTER_BACKEND) -endif() - -if(WITH_EXTENDED_FILTERING) - if(("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") OR ("${CMAKE_SYSTEM_NAME}" MATCHES "Android")) - find_package(PkgConfig REQUIRED) - pkg_check_modules(JSON REQUIRED json-c) - set(DLT_JSON_LIBRARY ${JSON_LIBRARIES}) - elseif("${CMAKE_SYSTEM_NAME}" MATCHES "QNX") - set(DLT_JSON_LIBRARY json) - else() - message(FATAL_ERROR "OS doesn't support extended filtering. Please build without cmake option '-DWITH_EXTENDED_FILTERING=OFF'") - endif() - add_definitions(-DEXTENDED_FILTERING) -else() - set(DLT_JSON_LIBRARY "") -endif() - add_subdirectory(doc) add_subdirectory(src) -add_subdirectory(include) +add_subdirectory(include/dlt) add_subdirectory(testscripts) -if (WITH_DLT_UNIT_TESTS) - find_package(GTest) - - if (NOT GTEST_FOUND) - add_subdirectory( gtest-1.7.0 ) - endif() - enable_testing() +if(WITH_DLT_UNIT_TESTS) + add_subdirectory( gtest-1.7.0 ) add_subdirectory(tests) endif() message(STATUS) message(STATUS "-------------------------------------------------------------------------------") -message(STATUS "Build for Version ${PROJECT_VERSION} build ${DLT_REVISION} version state ${DLT_VERSION_STATE}") +message(STATUS "Build for Version ${DLT_VERSION} build ${DLT_REVISION} version state ${DLT_VERSION_STATE}") message(STATUS "WITH_SYSTEMD = ${WITH_SYSTEMD}") message(STATUS "WITH_SYSTEMD_WATCHDOG = ${WITH_SYSTEMD_WATCHDOG}") message(STATUS "WITH_SYSTEMD_JOURNAL = ${WITH_SYSTEMD_JOURNAL}") @@ -311,13 +233,9 @@ message(STATUS "WITH_MAN = ${WITH_MAN}") message(STATUS "WITH_DLT_ADAPTOR = ${WITH_DLT_ADAPTOR}") -message(STATUS "WITH_DLT_ADAPTOR_UDP = ${WITH_DLT_ADAPTOR_UDP}") message(STATUS "WITH_DLT_CONSOLE = ${WITH_DLT_CONSOLE}") -message(STATUS "WITH_DLT_CONSOLE_WO_CTRL = ${WITH_DLT_CONSOLE_WO_CTRL}") -message(STATUS "WITH_DLT_CONSOLE_WO_SBTM = ${WITH_DLT_CONSOLE_WO_SBTM}") message(STATUS "WITH_DLT_EXAMPLES = ${WITH_DLT_EXAMPLES}") message(STATUS "WITH_DLT_SYSTEM = ${WITH_DLT_SYSTEM}") -message(STATUS "WITH_DLT_FILETRANSFER = ${WITH_DLT_FILETRANSFER}") message(STATUS "WITH_DLT_DBUS = ${WITH_DLT_DBUS}") message(STATUS "WITH_DLT_TESTS = ${WITH_DLT_TESTS}") message(STATUS "WITH_DLT_UNIT_TESTS = ${WITH_DLT_UNIT_TESTS}") @@ -345,17 +263,7 @@ message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}") message(STATUS "WITH_DLT_LOGSTORAGE_CTRL_UDEV = ${WITH_DLT_LOGSTORAGE_CTRL_UDEV}") message(STATUS "DLT_IPC = ${DLT_IPC}(Path: ${DLT_USER_IPC_PATH})") -message(STATUS "WITH_DLT_DAEMON_VSOCK_IPC = ${WITH_DLT_DAEMON_VSOCK_IPC}") -message(STATUS "WITH_DLT_LIB_VSOCK_IPC = ${WITH_DLT_LIB_VSOCK_IPC}") -message(STATUS "DLT_VSOCK_PORT = ${DLT_VSOCK_PORT}") message(STATUS "WITH_UDP_CONNECTION = ${WITH_UDP_CONNECTION}") -message(STATUS "WITH_DLT_QNX_SYSTEM = ${WITH_DLT_QNX_SYSTEM}") -message(STATUS "WITH_DLT_NETWORK_TRACE = ${WITH_DLT_NETWORK_TRACE}") -message(STATUS "WITH_LIB_SHORT_VERSION = ${WITH_LIB_SHORT_VERSION}") -message(STATUS "WITH_LEGACY_INCLUDE_PATH = ${WITH_LEGACY_INCLUDE_PATH}") -message(STATUS "WITH_EXTENDED_FILTERING = ${WITH_EXTENDED_FILTERING}") -message(STATUS "WITH_DLT_DISABLE_MACRO = ${WITH_DLT_DISABLE_MACRO}") -message(STATUS "WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK = ${WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK}" ) message(STATUS "Change a value with: cmake -D=") message(STATUS "-------------------------------------------------------------------------------") message(STATUS) diff -Nru dlt-daemon-2.18.9/debian/changelog dlt-daemon-2.18.4/debian/changelog --- dlt-daemon-2.18.9/debian/changelog 2023-04-28 09:26:31.000000000 +0000 +++ dlt-daemon-2.18.4/debian/changelog 2023-06-30 09:32:16.000000000 +0000 @@ -1,139 +1,9 @@ -dlt-daemon (2.18.9-1) unstable; urgency=medium +dlt-daemon (2.18.4-0.1~bpo16.04.1~ppa1) xenial; urgency=medium - * New upstream release. - * Fix watch file regex to take account of alpha releases - * Drop all patches, now fixed upstream - * Add two patches proposed upstream, 481.patch and 482.patch - to fix build failures with security build flags enabled and with different - cmake configurations + * Change backport to xenial. + - lower compat level to 10 - -- Gianfranco Costamagna Fri, 28 Apr 2023 11:26:31 +0200 - -dlt-daemon (2.18.8-6) unstable; urgency=medium - - * Switch from GENIVI to COVESA - - -- Gianfranco Costamagna Tue, 10 Jan 2023 15:36:58 +0100 - -dlt-daemon (2.18.8-5) unstable; urgency=medium - - * debian/patches/433.patch - - Add upstream-proposed patch to fix latomic underlinkage on riscv64 - * Upload to lunar with atomic fix on cmake - - -- Gianfranco Costamagna Tue, 10 Jan 2023 11:40:57 +0100 - -dlt-daemon (2.18.8-4) unstable; urgency=medium - - * Enable tests during build - * Enable extended filtering feature. - * Refresh patch 398 - * Add upstream patch to fix a test build failure - * Add R^3: no - - -- Gianfranco Costamagna Tue, 10 Jan 2023 10:41:43 +0100 - -dlt-daemon (2.18.8-3) unstable; urgency=medium - - * Fix dh_installinit call with compat level 13 - * Install some more tool and manpage, e.g. dlt-sortbytimestamp - * Also install cmake helper - * Install some missing manpages - * Override dh_install to avoid installing not needed files, avoiding - dh_missing failures with compat level 13 - - -- Gianfranco Costamagna Tue, 10 Jan 2023 07:20:45 +0100 - -dlt-daemon (2.18.8-2) unstable; urgency=medium - - * debian/patches/398.patch - - add upstream patch to fix a buffer overflow on 32 bit systems. - * Bump std-version to4.6.2 - * Bump compat level to 13 - - -- Gianfranco Costamagna Mon, 09 Jan 2023 15:07:11 +0100 - -dlt-daemon (2.18.8-1) unstable; urgency=low - - * New upstream release - * Dropped an upstreamed patch - - -- Aigars Mahinovs Mon, 14 Nov 2022 21:50:12 +0100 - -dlt-daemon (2.18.6-2.1) unstable; urgency=high - - * Non-maintainer upload. - * CVE-2022-31291: Double free in dlt_config_file_set_section(). - (Closes: #1014534) - - -- Adrian Bunk Thu, 18 Aug 2022 19:39:48 +0300 - -dlt-daemon (2.18.6-2) unstable; urgency=medium - - * Enable and run unit tests during build step: - - b-d on libgtest-dev - - patch cmake to run the system gtest version without rebuilding it - - -- Gianfranco Costamagna Tue, 06 Apr 2021 18:35:22 +0200 - -dlt-daemon (2.18.6-1) unstable; urgency=medium - - * Update to new release - * Drop all patches: upstream - - -- Gianfranco Costamagna Sat, 09 Jan 2021 14:18:44 +0100 - -dlt-daemon (2.18.5-0.4) unstable; urgency=medium - - * Team upload (add myself to uploaders list since I maintained it on the - last 1.5 years and 6 uploads, Aigars please let me know if this is ok for - you) - * debian/patches/33fbad18c814e13bd7ba2053525d8959fee437d1.patch: - * debian/patches/ef7ca2706aa2e877c1be62d73554c6c79996d69a.patch: - - cherry-pick two upstream commits to fix the ABI with the python-dlt one - (unbreaking python-dlt migration and build) - - -- Gianfranco Costamagna Wed, 02 Dec 2020 18:39:15 +0100 - -dlt-daemon (2.18.5-0.3) unstable; urgency=high - - * Non-maintainer upload - * debian/patches/275.patch: - - cherry-pick upstream fix for CVE-2020-29394 - (Closes: #976228) - - -- Gianfranco Costamagna Tue, 01 Dec 2020 21:57:59 +0100 - -dlt-daemon (2.18.5-0.2) unstable; urgency=medium - - * Non-maintainer upload - * Add backports of upstream PR #241 and #245 to properly fix - the gcc-10 build failure without regressions. - - -- Gianfranco Costamagna Sat, 29 Aug 2020 08:56:20 +0200 - -dlt-daemon (2.18.5-0.1) unstable; urgency=medium - - * Non-maintainer upload - * New upstream release. - * Drop debian/patches/170.patch: upstream - * debian/patches/238.patch: - - upstream proposed patch to fix gcc-10 build failures (Closes: #957140) - * enable UDP_CONNECTION and DLT_FILETRANSFER - - -- Gianfranco Costamagna Fri, 31 Jul 2020 14:09:08 +0200 - -dlt-daemon (2.18.4-0.2) unstable; urgency=medium - - [ Martyn Welch ] - * Non-maintainer upload - * Move systemd unit files into associated packages - Closes: #944253 - - [ Gianfranco Costamagna ] - * Replace dbus-glib with correct libdbus-1-dev (Closes: #955836) - - -- Martyn Welch Fri, 20 Mar 2020 16:37:12 +0000 + -- Gianfranco Costamagna Fri, 30 Jun 2023 11:32:16 +0200 dlt-daemon (2.18.4-0.1) unstable; urgency=medium diff -Nru dlt-daemon-2.18.9/debian/compat dlt-daemon-2.18.4/debian/compat --- dlt-daemon-2.18.9/debian/compat 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/debian/compat 2023-06-30 09:32:16.000000000 +0000 @@ -0,0 +1 @@ +10 diff -Nru dlt-daemon-2.18.9/debian/control dlt-daemon-2.18.4/debian/control --- dlt-daemon-2.18.9/debian/control 2023-01-10 14:36:13.000000000 +0000 +++ dlt-daemon-2.18.4/debian/control 2023-06-30 09:32:16.000000000 +0000 @@ -1,12 +1,12 @@ Source: dlt-daemon Priority: optional Maintainer: Aigars Mahinovs -Uploaders: Gianfranco Costamagna -Build-Depends: debhelper-compat (= 13), cmake, zlib1g-dev, libdbus-1-dev, doxygen, libgtest-dev, libsystemd-dev, pandoc, systemd, libsystemd-dev, libjson-c-dev -Standards-Version: 4.6.2 +Build-Depends: debhelper (>= 10), cmake, zlib1g-dev, libdbus-glib-1-dev, doxygen, libsystemd-dev, pandoc, systemd +Standards-Version: 4.4.0 Section: libs -Rules-Requires-Root: no -Homepage: https://github.com/COVESA/dlt-daemon +Homepage: https://at.projects.genivi.org/wiki/display/PROJ/Diagnostic+Log+and+Trace +#Vcs-Git: https://anonscm.debian.org/git/collab-maint/dlt-daemon.git +#Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/dlt-daemon.git Package: libdlt-dev Section: libdevel @@ -16,7 +16,7 @@ Description: Diagnostic Log and Trace (DLT) library (development) This component provides a log and trace interface, based on the standardised protocol specified in the AUTOSAR standard 4.0 DLT. This software can be used - by COVESA components and other applications as logging facility. + by GENIVI components and other applications as logging facility. . DLT library is used by apps that need to log to a DLT daemon directly and by apps that want to read logs from DLT daemon. This package provides development @@ -29,7 +29,7 @@ Description: Diagnostic Log and Trace (DLT) library This component provides a log and trace interface, based on the standardised protocol specified in the AUTOSAR standard 4.0 DLT. This software can be used - by COVESA components and other applications as logging facility. + by GENIVI components and other applications as logging facility. . DLT library is used by apps that need to log to a DLT daemon directly and by apps that want to read logs from DLT daemon. @@ -42,9 +42,9 @@ Description: Diagnostic Log and Trace logging daemon This component provides a log and trace interface, based on the standardised protocol specified in the AUTOSAR standard 4.0 DLT. This software can be used - by COVESA components and other applications as logging facility. + by GENIVI components and other applications as logging facility. . - The DLT daemon is the central component in COVESA, which gathers all logs and + The DLT daemon is the central component in GENIVI, which gathers all logs and traces from the DLT user applications. The logs and traces can optionally be directly written to a file in the ECU. The DLT daemon forwards all logs and traces to a connected DLT client. The DLT client can send control @@ -60,7 +60,7 @@ Description: Diagnostic Log and Trace (DLT) (documentation) This component provides a log and trace interface, based on the standardised protocol specified in the AUTOSAR standard 4.0 DLT. This software can be used - by COVESA components and other applications as logging facility. + by GENIVI components and other applications as logging facility. . This package includes tools to connect to and experiment with DLT daemon. Most usefully this includes 'dlt-receive' to connect to a (remote) DLT server @@ -75,6 +75,6 @@ Description: Diagnostic Log and Trace (DLT) (documentation) This component provides a log and trace interface, based on the standardised protocol specified in the AUTOSAR standard 4.0 DLT. This software can be used - by COVESA components and other applications as logging facility. + by GENIVI components and other applications as logging facility. . This package includes example apps and test tools for DLT server. diff -Nru dlt-daemon-2.18.9/debian/copyright dlt-daemon-2.18.4/debian/copyright --- dlt-daemon-2.18.9/debian/copyright 2023-01-10 14:36:41.000000000 +0000 +++ dlt-daemon-2.18.4/debian/copyright 2018-07-23 12:32:38.000000000 +0000 @@ -1,7 +1,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: COVESA dlt-daemon +Upstream-Name: GENIVI dlt-daemon Upstream-Contact: Christoph Lipka , Manikandan Chockalingam , Alexander Wenzel -Source: https://github.com/COVESA/dlt-daemon +Source: https://github.com/GENIVI/dlt-daemon Files: * Copyright: 2015 BMW AG diff -Nru dlt-daemon-2.18.9/debian/dlt-daemon.install dlt-daemon-2.18.4/debian/dlt-daemon.install --- dlt-daemon-2.18.9/debian/dlt-daemon.install 2023-04-28 09:26:31.000000000 +0000 +++ dlt-daemon-2.18.4/debian/dlt-daemon.install 2018-07-23 12:32:38.000000000 +0000 @@ -3,5 +3,6 @@ usr/bin/dlt-daemon usr/share/man/man1/dlt-daemon.* usr/share/man/man5/dlt.conf.* -usr/share/man/man5/dlt_gateway.conf.* -#usr/lib/systemd/system/dlt.socket +usr/lib/systemd/system/dlt-adaptor-udp.service /usr/share/doc/dlt-daemon/examples +usr/lib/systemd/system/dlt-example-user.service /usr/share/doc/dlt-daemon/examples +usr/lib/systemd/system/dlt-receive.service /usr/share/doc/dlt-daemon/examples diff -Nru dlt-daemon-2.18.9/debian/dlt-tools.install dlt-daemon-2.18.4/debian/dlt-tools.install --- dlt-daemon-2.18.9/debian/dlt-tools.install 2023-01-10 06:20:45.000000000 +0000 +++ dlt-daemon-2.18.4/debian/dlt-tools.install 2018-07-23 12:32:38.000000000 +0000 @@ -7,16 +7,10 @@ usr/bin/dlt-dbus usr/bin/dlt-kpi usr/bin/dlt-receive -usr/bin/dlt-sortbytimestamp usr/bin/dlt-system usr/bin/dlt-*-ctrl -usr/share/man/man1/dlt-adaptor* -usr/share/man/man1/dlt-control* usr/share/man/man1/dlt-convert* usr/share/man/man1/dlt-*-ctrl* usr/share/man/man1/dlt-receive* -usr/share/man/man1/dlt-sortbytimestamp* usr/share/man/man1/dlt-system* usr/share/man/man5/dlt-system* -usr/lib/systemd/system/dlt-adaptor-udp.service /usr/share/doc/dlt-tools/examples -usr/lib/systemd/system/dlt-receive.service /usr/share/doc/dlt-tools/examples diff -Nru dlt-daemon-2.18.9/debian/libdlt-dev.install dlt-daemon-2.18.4/debian/libdlt-dev.install --- dlt-daemon-2.18.9/debian/libdlt-dev.install 2023-01-10 06:20:45.000000000 +0000 +++ dlt-daemon-2.18.4/debian/libdlt-dev.install 2018-07-23 12:32:38.000000000 +0000 @@ -1,4 +1,3 @@ usr/include/* usr/lib/*/lib*.so -usr/lib/*/cmake/* usr/lib/*/pkgconfig/* diff -Nru dlt-daemon-2.18.9/debian/libdlt-examples.install dlt-daemon-2.18.4/debian/libdlt-examples.install --- dlt-daemon-2.18.9/debian/libdlt-examples.install 2021-01-09 13:18:42.000000000 +0000 +++ dlt-daemon-2.18.4/debian/libdlt-examples.install 2018-07-23 12:32:38.000000000 +0000 @@ -4,4 +4,3 @@ src/examples/* /usr/share/doc/libdlt-examples doc/*.txt /usr/share/doc/libdlt-examples doc/images/* /usr/share/doc/libdlt-examples -usr/lib/systemd/system/dlt-example-user.service /usr/share/doc/libdlt-examples/examples diff -Nru dlt-daemon-2.18.9/debian/patches/170.patch dlt-daemon-2.18.4/debian/patches/170.patch --- dlt-daemon-2.18.9/debian/patches/170.patch 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/debian/patches/170.patch 2019-09-19 11:31:17.000000000 +0000 @@ -0,0 +1,23 @@ +From 8e9d1c5f235a5b5d5db1ae3db3cc546a9796c2c8 Mon Sep 17 00:00:00 2001 +From: Gianfranco Costamagna +Date: Thu, 19 Sep 2019 13:52:36 +0200 +Subject: [PATCH] Update cmakelist, fix build due to copy-paste error + +dlt-control should generate a dlt-control manpage, not a dlt-system one +--- + doc/CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt +index 1aea68b..35f7213 100644 +--- a/doc/CMakeLists.txt ++++ b/doc/CMakeLists.txt +@@ -168,7 +168,7 @@ if(WITH_MAN) + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-daemon.1 > ${MAN_BUILD_DIR}/dlt-daemon.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-receive.1 > ${MAN_BUILD_DIR}/dlt-receive.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-system.1 > ${MAN_BUILD_DIR}/dlt-system.1.gz +- COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-control.1 > ${MAN_BUILD_DIR}/dlt-system.1.gz ++ COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-control.1 > ${MAN_BUILD_DIR}/dlt-control.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1 > ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1 > ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1 > ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1.gz diff -Nru dlt-daemon-2.18.9/debian/patches/481.patch dlt-daemon-2.18.4/debian/patches/481.patch --- dlt-daemon-2.18.9/debian/patches/481.patch 2023-04-28 09:26:31.000000000 +0000 +++ dlt-daemon-2.18.4/debian/patches/481.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -From 95476de802585629c6d89707a9247bbb0c70f6c9 Mon Sep 17 00:00:00 2001 -From: Gianfranco Costamagna -Date: Fri, 28 Apr 2023 22:39:57 +0200 -Subject: [PATCH] Update gtest_dlt_daemon_multiple_files_logging.cpp -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Fix build error due to dlt_vlog not having the correct format string with security build flags enabled - -[ 88%] Building CXX object tests/CMakeFiles/gtest_dlt_daemon_multiple_files_logging.dir/gtest_dlt_daemon_multiple_files_logging.cpp.o -cd dlt-daemon-2.18.9/obj-x86_64-linux-gnu/tests && /usr/bin/c++ -DCONFIGURATION_FILES_DIR=\"/etc\" -DDLT_DAEMON_USE_FIFO_IPC -DDLT_LIB_USE_FIFO_IPC -DDLT_NETWORK_TRACE_ENABLE -DDLT_SYSTEMD_ENABLE -DDLT_SYSTEMD_JOURNAL_ENABLE -DDLT_UNIT_TESTS -DDLT_USER_IPC_PATH=\"/tmp\" -DDLT_USE_IPv6 -DEXTENDED_FILTERING -D_GNU_SOURCE -Idlt-daemon-2.18.9 -Idlt-daemon-2.18.9/obj-x86_64-linux-gnu/include/dlt -Idlt-daemon-2.18.9/include/dlt -Idlt-daemon-2.18.9/src/shared -Idlt-daemon-2.18.9/src/core_dump_handler -Idlt-daemon-2.18.9/src/offlinelogstorage -Idlt-daemon-2.18.9/src/lib -Idlt-daemon-2.18.9/src/daemon -Idlt-daemon-2.18.9/src/console -Idlt-daemon-2.18.9/src/gateway -Idlt-daemon-2.18.9/systemd/3rdparty -g -O2 -ffile-prefix-map=dlt-daemon-2.18.9=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -isystem /include -std=gnu++0x -std=gnu++11 -Wall -Wextra -Wno-variadic-macros -Wno-strict-aliasing -DGTEST_HAS_PTHREAD=1 -MD -MT tests/CMakeFiles/gtest_dlt_daemon_multiple_files_logging.dir/gtest_dlt_daemon_multiple_files_logging.cpp.o -MF CMakeFiles/gtest_dlt_daemon_multiple_files_logging.dir/gtest_dlt_daemon_multiple_files_logging.cpp.o.d -o CMakeFiles/gtest_dlt_daemon_multiple_files_logging.dir/gtest_dlt_daemon_multiple_files_logging.cpp.o -c dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp -dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp: In member function ‘virtual void t_dlt_logging_multiple_files_append_reinit_normal_Test::TestBody()’: -dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp:106:13: error: format not a string literal and no format arguments [-Werror=format-security] - 106 | dlt_vlog(LOG_INFO, log1); - | ~~~~~~~~^~~~~~~~~~~~~~~~ -dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp:110:13: error: format not a string literal and no format arguments [-Werror=format-security] - 110 | dlt_vlog(LOG_INFO, log2); - | ~~~~~~~~^~~~~~~~~~~~~~~~ -In file included from /usr/include/string.h:535, - from /usr/include/gtest/internal/gtest-port.h:264, - from /usr/include/gtest/internal/gtest-internal.h:40, - from /usr/include/gtest/gtest.h:62, - from dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp:27: -In function ‘strncpy’, ---- - tests/gtest_dlt_daemon_multiple_files_logging.cpp | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/tests/gtest_dlt_daemon_multiple_files_logging.cpp b/tests/gtest_dlt_daemon_multiple_files_logging.cpp -index 2da512e1..05b58f2c 100644 ---- a/tests/gtest_dlt_daemon_multiple_files_logging.cpp -+++ b/tests/gtest_dlt_daemon_multiple_files_logging.cpp -@@ -103,11 +103,11 @@ TEST(t_dlt_logging_multiple_files_append_reinit, normal) - const char* log2 = "TWO\n"; - - configure(path, file_name, true, file_size, max_file_size); -- dlt_vlog(LOG_INFO, log1); -+ dlt_vlog(LOG_INFO, "%s", log1); - EXPECT_NO_THROW(dlt_log_free()); - - configure(path, file_name, true, file_size, max_file_size); -- dlt_vlog(LOG_INFO, log2); -+ dlt_vlog(LOG_INFO, "%s", log2); - EXPECT_NO_THROW(dlt_log_free()); - verify_in_one_file(path, file_name, log1, log2); - } diff -Nru dlt-daemon-2.18.9/debian/patches/482.patch dlt-daemon-2.18.4/debian/patches/482.patch --- dlt-daemon-2.18.9/debian/patches/482.patch 2023-04-28 09:26:31.000000000 +0000 +++ dlt-daemon-2.18.4/debian/patches/482.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,38 +0,0 @@ -From b38761831670e980a58acb33d611f65255d678ac Mon Sep 17 00:00:00 2001 -From: Gianfranco Costamagna -Date: Fri, 28 Apr 2023 22:46:36 +0200 -Subject: [PATCH] Update CMakeLists.txt - -Link systemd libraries, to avoid underlinking of tests with --DWITH_SYSTEMD_SOCKET_ACTIVATION=ON - -[ 82%] Linking CXX executable gtest_dlt_daemon_gateway -cd dlt-daemon-2.18.9/obj-x86_64-linux-gnu/tests && /usr/bin/cmake -E cmake_link_script CMakeFiles/gtest_dlt_daemon_gateway.dir/link.txt --verbose=1 -/usr/bin/c++ -g -O2 -ffile-prefix-map=dlt-daemon-2.18.9=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -isystem /include -std=gnu++0x -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -rdynamic CMakeFiles/gtest_dlt_daemon_gateway.dir/gtest_dlt_daemon_gateway.cpp.o CMakeFiles/gtest_dlt_daemon_gateway.dir/__/systemd/3rdparty/sd-daemon.c.o -o gtest_dlt_daemon_gateway -Wl,-rpath,dlt-daemon-2.18.9/obj-x86_64-linux-gnu/src/daemon ../src/daemon/libdlt_daemon.so /usr/lib/x86_64-linux-gnu/libgtest.a /usr/lib/x86_64-linux-gnu/libgtest_main.a -lrt /usr/lib/x86_64-linux-gnu/libgtest.a -/usr/bin/ld: ../src/daemon/libdlt_daemon.so: undefined reference to `sd_listen_fds_with_names' ---- - tests/CMakeLists.txt | 10 +++++++++- - 1 file changed, 9 insertions(+), 1 deletion(-) - -diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt -index 579d7308..3155ca9a 100644 ---- a/tests/CMakeLists.txt -+++ b/tests/CMakeLists.txt -@@ -21,8 +21,16 @@ else() - set(LIBRARIES socket) - endif() - -+if(WITH_SYSTEMD_JOURNAL) -+ if(SYSTEMD_VERSION LESS 209) -+ set(SYSTEMD_LIBS systemd-journal systemd-id128) -+ else(SYSTEMD_VERSION LESS 209) -+ set(SYSTEMD_LIBS systemd) -+ endif(SYSTEMD_VERSION LESS 209) -+endif(WITH_SYSTEMD_JOURNAL) -+ - set(DLT_LIBRARIES dlt ${GTEST_LIBS} ${LIBRARIES}) --set(DLT_DAEMON_LIBRARIES dlt_daemon ${GTEST_LIBS} ${LIBRARIES}) -+set(DLT_DAEMON_LIBRARIES dlt_daemon ${GTEST_LIBS} ${LIBRARIES} ${SYSTEMD_LIBS}) - set(DLT_CONTROL_LIBRARIES dlt dlt_control_common_lib ${GTEST_LIBS}) - - #Receiver used for QTs. add_test() is not required diff -Nru dlt-daemon-2.18.9/debian/patches/series dlt-daemon-2.18.4/debian/patches/series --- dlt-daemon-2.18.9/debian/patches/series 2023-04-28 09:26:31.000000000 +0000 +++ dlt-daemon-2.18.4/debian/patches/series 2019-09-19 11:31:17.000000000 +0000 @@ -1,2 +1 @@ -481.patch -482.patch +170.patch diff -Nru dlt-daemon-2.18.9/debian/rules dlt-daemon-2.18.4/debian/rules --- dlt-daemon-2.18.9/debian/rules 2023-04-28 09:26:31.000000000 +0000 +++ dlt-daemon-2.18.4/debian/rules 2019-09-19 11:31:17.000000000 +0000 @@ -2,6 +2,7 @@ # See debhelper(7) (uncomment to enable) # output every command that modifies files on the build system. export DH_VERBOSE = 1 +export LIBS="pthread" # see FEATURE AREAS in dpkg-buildflags(1) #export DEB_BUILD_MAINT_OPTIONS = hardening=+all @@ -18,24 +19,13 @@ override_dh_auto_configure: - # keep disabled for now? -DDLT_IPC=UNIX_SOCKET -DWITH_SYSTEMD_SOCKET_ACTIVATION=ON - dh_auto_configure -- \ - -DWITH_SYSTEMD=ON -DWITH_SYSTEMD_JOURNAL=ON -DWITH_MAN=ON -DWITH_DLT_ADAPTOR=ON \ - -DWITH_DLT_DBUS=ON -DWITH_DLT_SYSTEM=ON -DWITH_DLT_KPI=ON -DWITH_DLT_FILETRANSFER=ON -DWITH_UDP_CONNECTION=ON \ - -DWITH_DLT_UNIT_TESTS=ON -DWITH_EXTENDED_FILTERING=ON -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) - - -override_dh_auto_install: - dh_auto_install - # we use the Debian version for the services files - rm debian/tmp/usr/lib/systemd/system/dlt-dbus.service debian/tmp/usr/lib/systemd/system/dlt-system.service debian/tmp/usr/lib/systemd/system/dlt.service - # they are used only for testing, and they mention /usr/local/ in source code, so they can't work anyway - rm debian/tmp/usr/share/dlt-filetransfer/dlt-test-filetransfer-file debian/tmp/usr/share/dlt-filetransfer/dlt-test-filetransfer-image.png + dh_auto_configure -- -DWITH_SYSTEMD=ON -DWITH_SYSTEMD_JOURNAL=ON -DWITH_MAN=ON -DWITH_DLT_ADAPTOR=ON \ + -DWITH_DLT_DBUS=ON -DWITH_DLT_SYSTEM=ON -DWITH_DLT_KPI=ON -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) override_dh_installinit: dh_installinit -pdlt-tools --name=dlt-tools-system -n dh_installinit -pdlt-tools --name=dlt-tools-dbus -n - dh_installinit -n + dh_installinit --remaining -n override_dh_clean: dh_clean diff -Nru dlt-daemon-2.18.9/debian/watch dlt-daemon-2.18.4/debian/watch --- dlt-daemon-2.18.9/debian/watch 2023-01-10 14:35:26.000000000 +0000 +++ dlt-daemon-2.18.4/debian/watch 2018-07-23 12:32:38.000000000 +0000 @@ -1,4 +1,4 @@ version=4 opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/dlt-daemon-$1\.tar\.gz/ \ - https://github.com/COVESA/dlt-daemon/tags .*/v?(\d\S*)\.tar\.gz + https://github.com/GENIVI/dlt-daemon/tags .*/v?(\d\S*)\.tar\.gz diff -Nru dlt-daemon-2.18.9/doc/CMakeLists.txt dlt-daemon-2.18.4/doc/CMakeLists.txt --- dlt-daemon-2.18.9/doc/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -25,32 +25,22 @@ MESSAGE(FATAL_ERROR "Could not find pandoc for man page generation.") endif(NOT PANDOC_TOOL) - FIND_PROGRAM(SED_TOOL - NAMES sed - PATHS /bin - /usr/bin - /usr/local/bin) - - if(NOT SED_TOOL) - MESSAGE(FATAL_ERROR "Could not find sed for html generation.") - endif(NOT SED_TOOL) - - file(GLOB MD_FILES "${PROJECT_SOURCE_DIR}/doc/*.md") - - add_custom_target(generate_doc ALL) - add_custom_command(TARGET generate_doc PRE_BUILD - COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${PROJECT_SOURCE_DIR}/README.md -o ${PROJECT_BINARY_DIR}/README.html - COMMAND ${SED_TOOL} -i 's|\.md|\.html|g' ${PROJECT_BINARY_DIR}/README.html) - foreach(FILE ${MD_FILES}) - get_filename_component(FILENAME ${FILE} NAME) - string(REPLACE ".md" ".html" HTML_FILE ${FILENAME}) - add_custom_command(TARGET generate_doc PRE_BUILD - COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${FILE} -o ${PROJECT_BINARY_DIR}/doc/${HTML_FILE} - COMMAND ${SED_TOOL} -i 's|\.md|\.html|g' ${PROJECT_BINARY_DIR}/doc/${HTML_FILE}) - endforeach() + set(MAN_SRC_DIR ${CMAKE_SOURCE_DIR}) + set(MAN_BUILD_DIR ${CMAKE_BINARY_DIR}) + + add_custom_target(generate_doc ALL + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/README.md -o ${MAN_BUILD_DIR}/README.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_for_developers.md -o ${MAN_BUILD_DIR}/doc/dlt_for_developers.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_glossary.md -o ${MAN_BUILD_DIR}/doc/dlt_glossary.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_offline_logstorage.md -o ${MAN_BUILD_DIR}/doc/dlt_offline_logstorage.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_multinode.md -o ${MAN_BUILD_DIR}/doc/dlt_multinode.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_extended_network_trace.md -o ${MAN_BUILD_DIR}/doc/dlt_extended_network_trace.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_filetransfer.md -o ${MAN_BUILD_DIR}/doc/dlt_filetransfer.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_kpi.md -o ${MAN_BUILD_DIR}/doc/dlt_kpi.html + COMMAND ${PANDOC_TOOL} -s -f markdown -t html5 ${MAN_SRC_DIR}/doc/dlt_cdh.md -o ${MAN_BUILD_DIR}/doc/dlt_cdh.html) # Doxygen - find_package(Doxygen REQUIRED) + find_package(Doxygen) configure_file(${PROJECT_SOURCE_DIR}/doc/doxygen.cfg.cmake ${PROJECT_BINARY_DIR}/doc/doxygen.cfg @ONLY) @@ -72,8 +62,17 @@ add_custom_target (doc-manuals ALL COMMAND mkdir -p ${PROJECT_BINARY_DIR}/doc/manuals COMMAND mkdir -p ${PROJECT_BINARY_DIR}/doc/manuals/images - COMMAND cp -r ${PROJECT_SOURCE_DIR}/doc/images/* ${PROJECT_BINARY_DIR}/doc/manuals/images - COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_design_specification.html ${PROJECT_SOURCE_DIR}/doc/dlt_design_specification.md + COMMAND cp ${PROJECT_SOURCE_DIR}/doc/images/* ${PROJECT_BINARY_DIR}/doc/manuals/images + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/README.html ${PROJECT_SOURCE_DIR}/README.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_glossary.html ${CMAKE_SOURCE_DIR}/doc/dlt_glossary.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_for_developers.html ${CMAKE_SOURCE_DIR}/doc/dlt_for_developers.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_offline_logstorage.html ${CMAKE_SOURCE_DIR}/doc/dlt_offline_logstorage.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_multinode.html ${CMAKE_SOURCE_DIR}/doc/dlt_multinode.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_extended_network_trace.html ${CMAKE_SOURCE_DIR}/doc/dlt_extended_network_trace.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_filetransfer.html ${CMAKE_SOURCE_DIR}/doc/dlt_filetransfer.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_kpi.html ${CMAKE_SOURCE_DIR}/doc/dlt_kpi.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_cdh.html ${CMAKE_SOURCE_DIR}/doc/dlt_cdh.md + COMMAND ${ASCIIDOC_TOOL} -a TOC1 -o ${PROJECT_BINARY_DIR}/doc/manuals/dlt_design_specification.html ${PROJECT_SOURCE_DIR}/doc/dlt_design_specification.txt WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/doc ) @@ -104,56 +103,109 @@ set(MAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(MAN_BUILD_DIR ${PROJECT_BINARY_DIR}/doc) - file(GLOB MD_SRC "${MAN_SRC_DIR}/*.[1-8].md") - - set(MAN_BUILD_SRC "") - foreach(FILE ${MD_SRC}) - get_filename_component(FILENAME ${FILE} NAME) - string(REPLACE ".md" "" MAN_FILENAME ${FILENAME}) - list(APPEND MAN_BUILD_SRC ${MAN_BUILD_DIR}/${MAN_FILENAME}) - endforeach() - - set(MAN_BUILD_GZ "") - foreach(FILE ${MAN_BUILD_SRC}) - list(APPEND MAN_BUILD_GZ "${FILE}.gz") - endforeach() - - add_custom_target(generate_man ALL) - - set(CNT "0") - list(LENGTH MD_SRC NUMBER_OF_MAN_PAGES) - while(CNT LESS ${NUMBER_OF_MAN_PAGES}) - list(GET MD_SRC ${CNT} SRC_MD_FILE) - list(GET MAN_BUILD_SRC ${CNT} BUILD_MAN_FILE) - list(GET MAN_BUILD_GZ ${CNT} BUILD_MAN_GZ_FILE) - - add_custom_command(TARGET generate_man PRE_BUILD - COMMAND ${PANDOC_TOOL} -s -t man ${SRC_MD_FILE} -o ${BUILD_MAN_FILE} - COMMAND ${GZIP_TOOL} -c ${BUILD_MAN_FILE} > ${BUILD_MAN_GZ_FILE}) - - MATH(EXPR CNT "${CNT}+1") - endwhile() + set(MD_SRC + ${MAN_SRC_DIR}/dlt.conf.5.md + ${MAN_SRC_DIR}/dlt-system.conf.5.md + ${MAN_SRC_DIR}/dlt-convert.1.md + ${MAN_SRC_DIR}/dlt-sortbytimestamp.1.md + ${MAN_SRC_DIR}/dlt-daemon.1.md + ${MAN_SRC_DIR}/dlt-receive.1.md + ${MAN_SRC_DIR}/dlt-system.1.md + ${MAN_SRC_DIR}/dlt-control.1.md + ${MAN_SRC_DIR}/dlt-logstorage-ctrl.1.md + ${MAN_SRC_DIR}/dlt-passive-node-ctrl.1.md + ${MAN_SRC_DIR}/dlt-adaptor-stdin.1.md + ${MAN_SRC_DIR}/dlt-adaptor-udp.1.md) + + set(MAN_SRC + ${MAN_SRC_DIR}/dlt.conf.5 + ${MAN_SRC_DIR}/dlt-system.conf.5 + ${MAN_SRC_DIR}/dlt-convert.1 + ${MAN_SRC_DIR}/dlt-sortbytimestamp.1 + ${MAN_SRC_DIR}/dlt-daemon.1 + ${MAN_SRC_DIR}/dlt-receive.1 + ${MAN_SRC_DIR}/dlt-system.1 + ${MAN_SRC_DIR}/dlt-control.1 + ${MAN_SRC_DIR}/dlt-logstorage-ctrl.1 + ${MAN_SRC_DIR}/dlt-passive-node-ctrl.1 + ${MAN_SRC_DIR}/dlt-adaptor-stdin.1 + ${MAN_SRC_DIR}/dlt-adaptor-udp.1) + + set(MAN_BUILD_SRC + ${MAN_BUILD_DIR}/dlt.conf.5 + ${MAN_BUILD_DIR}/dlt-system.conf.5 + ${MAN_BUILD_DIR}/dlt-convert.1 + ${MAN_BUILD_DIR}/dlt-sortbytimestamp.1 + ${MAN_BUILD_DIR}/dlt-daemon.1 + ${MAN_BUILD_DIR}/dlt-receive.1 + ${MAN_BUILD_DIR}/dlt-system.1 + ${MAN_BUILD_DIR}/dlt-control.1 + ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1 + ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1 + ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1 + ${MAN_BUILD_DIR}/dlt-adaptor-udp.1) + + set(MAN_BUILD_GZ + ${MAN_BUILD_DIR}/dlt.conf.5.gz + ${MAN_BUILD_DIR}/dlt-system.conf.5.gz + ${MAN_BUILD_DIR}/dlt-convert.1.gz + ${MAN_BUILD_DIR}/dlt-sortbytimestamp.1.gz + ${MAN_BUILD_DIR}/dlt-daemon.1.gz + ${MAN_BUILD_DIR}/dlt-receive.1.gz + ${MAN_BUILD_DIR}/dlt-system.1.gz + ${MAN_BUILD_DIR}/dlt-control.1.gz + ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1.gz + ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1.gz + ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1.gz + ${MAN_BUILD_DIR}/dlt-adaptor-udp.1.gz) + + add_custom_target(generate_man ALL + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt.conf.5.md -o ${MAN_BUILD_DIR}/dlt.conf.5 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-system.conf.5.md -o ${MAN_BUILD_DIR}/dlt-system.conf.5 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-convert.1.md -o ${MAN_BUILD_DIR}/dlt-convert.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-sortbytimestamp.1.md -o ${MAN_BUILD_DIR}/dlt-sortbytimestamp.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-daemon.1.md -o ${MAN_BUILD_DIR}/dlt-daemon.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-receive.1.md -o ${MAN_BUILD_DIR}/dlt-receive.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-system.1.md -o ${MAN_BUILD_DIR}/dlt-system.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-control.1.md -o ${MAN_BUILD_DIR}/dlt-control.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-logstorage-ctrl.1.md -o ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-passive-node-ctrl.1.md -o ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-adaptor-stdin.1.md -o ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1 + COMMAND ${PANDOC_TOOL} -s -t man ${MAN_SRC_DIR}/dlt-adaptor-udp.1.md -o ${MAN_BUILD_DIR}/dlt-adaptor-udp.1 + + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt.conf.5 > ${MAN_BUILD_DIR}/dlt.conf.5.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-system.conf.5 > ${MAN_BUILD_DIR}/dlt-system.conf.5.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-convert.1 > ${MAN_BUILD_DIR}/dlt-convert.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-sortbytimestamp.1 > ${MAN_BUILD_DIR}/dlt-sortbytimestamp.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-daemon.1 > ${MAN_BUILD_DIR}/dlt-daemon.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-receive.1 > ${MAN_BUILD_DIR}/dlt-receive.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-system.1 > ${MAN_BUILD_DIR}/dlt-system.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-control.1 > ${MAN_BUILD_DIR}/dlt-system.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1 > ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1 > ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1 > ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1.gz + COMMAND ${GZIP_TOOL} -c ${MAN_BUILD_DIR}/dlt-adaptor-udp.1 > ${MAN_BUILD_DIR}/dlt-adaptor-udp.1.gz) # If user has not set the base dir for man pages, use a default location set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man) - set(MAN5_GZ_FILES "") - set(MAN1_GZ_FILES "") - foreach(FILE ${MAN_BUILD_GZ}) - if(${FILE} MATCHES "(\.1\.gz)$") - list(APPEND MAN1_GZ_FILES ${FILE}) - elseif(${FILE} MATCHES "(\.5\.gz)$") - list(APPEND MAN5_GZ_FILES ${FILE}) - endif() - endforeach() - install(FILES - ${MAN5_GZ_FILES} + ${MAN_BUILD_DIR}/dlt.conf.5.gz + ${MAN_BUILD_DIR}/dlt-system.conf.5.gz DESTINATION ${MAN_INSTALL_DIR}/man5 ) install(FILES - ${MAN1_GZ_FILES} + ${MAN_BUILD_DIR}/dlt-convert.1.gz + ${MAN_BUILD_DIR}/dlt-sortbytimestamp.1.gz + ${MAN_BUILD_DIR}/dlt-daemon.1.gz + ${MAN_BUILD_DIR}/dlt-receive.1.gz + ${MAN_BUILD_DIR}/dlt-system.1.gz + ${MAN_BUILD_DIR}/dlt-control.1.gz + ${MAN_BUILD_DIR}/dlt-logstorage-ctrl.1.gz + ${MAN_BUILD_DIR}/dlt-passive-node-ctrl.1.gz + ${MAN_BUILD_DIR}/dlt-adaptor-stdin.1.gz + ${MAN_BUILD_DIR}/dlt-adaptor-udp.1.gz DESTINATION ${MAN_INSTALL_DIR}/man1 ) -endif(WITH_MAN) \ No newline at end of file +endif(WITH_MAN) diff -Nru dlt-daemon-2.18.9/doc/dlt-adaptor-stdin.1.md dlt-daemon-2.18.4/doc/dlt-adaptor-stdin.1.md --- dlt-daemon-2.18.9/doc/dlt-adaptor-stdin.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-adaptor-stdin.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -26,6 +26,10 @@ : To flush the buffered logs while unregistering app +-s + +: Set socket to Blocking mode if unix socket is used + -t : Set timeout when sending messages at exit, in ms (default: 10000 = 10sec) diff -Nru dlt-daemon-2.18.9/doc/dlt_build_options.md dlt-daemon-2.18.4/doc/dlt_build_options.md --- dlt-daemon-2.18.9/doc/dlt_build_options.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_build_options.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ -# DLT Build Options - -DLT is highly configurable. It allows you to choose between certain technologies -or implementations and to turn on or off certain features. This way, you can -adjust it to your needs and keep the build process as simple as possible. - -In order to change these options, you can modify these values with cmake, do the -appropriate changes in CmakeList.txt or via the commandline for cmake - -Change a value with: cmake -D\=\, E.g. - -```bash -cmake .. -DWITH_SYSTEMD=ON -DWITH_SYSTEMD_JOURNAL=ON -DCMAKE_INSTALL_PREFIX=/usr -``` - -## General Options - -Option | Value | Comment -:--- | :--- | :--- -BUILD\_SHARED\_LIBS | ON | Set to OFF to build static libraries -DLT\_IPC |"FIFO" | Set to either "UNIX\_SOCKET" or "FIFO" -WITH\_DLT\_USE\_IPv6 | ON | Set to ON for IPv6 support -WITH\_DLT\_EXAMPLES | ON | Set to ON to build src/examples binaries -DLT\_USER | genivi | Set user for process not run as root -WITH\_CHECK\_CONFIG\_FILE | OFF | Set to ON to create a configure file of CheckIncludeFiles and CheckFunctionExists -CMAKE\_INSTALL\_PREFIX | /usr/local -CMAKE\_BUILD\_TYPE | RelWithDebInfo -WITH\_UDP\_CONNECTION | OFF | Set to ON to enable dlt UDP multicast SUPPORT -WITH\_DLT\_DAEMON\_VSOCK\_IPC | OFF | Set to ON for VSOCK support in daemon. -WITH\_DLT\_LIB\_VSOCK\_IPC | OFF | Set to ON for VSOCK support in libdlt (DLT\_IPC is overridden in libdlt). -DLT\_VSOCK\_PORT | 13490 | Port to use for VSOCK communication. -WITH\_LEGACY\_INCLUDE\_PATH | ON | Set to ON to add /dlt to include paths for the CMake config file, in addition to only - -## Command Line Tool Options - - Option | Value | Comment - :--- | :--- | :--- -WITH\_DLT\_ADAPTOR | OFF | Set to ON to build src/adaptor binaries -WITH\_DLT\_CONSOLE | ON | Set to ON to build src/console binaries -WITH\_DLT\_SYSTEM | OFF | Set to ON to build src/system binaries -WITH\_DLT\_LOGSTORAGE\_CTRL\_UDEV | OFF | PROTOTYPE! Set to ON to build -WITH\_DLT\_KPI | OFF | Set to ON to build src/kpi binaries -WITH\_EXTENDED\_FILTERING | OFF | Set to OFF to build without extended filtering. Using json filter files is only supported for Linux based system with json-c and QNX. - -## Linux OS Integration Options - - Option | Value | Comment - :--- | :--- | :--- -WITH\_SYSTEMD | OFF | Set to ON to run CMakeLists.txt in systemd -WITH\_SYSTEMD\_WATCHDOG | OFF | Set to ON to use the systemd watchdog in dlt-daemon -WITH\_SYSTEMD\_JOURNAL | OFF | Set to ON to use the systemd journal in dlt-system -WITH\_DLT\_DBUS | OFF | Set to ON to build src/dbus binaries - -## QNX OS Integration Options - -Option | Value | Comment -:--- | :--- | :--- -WITH\_DLT\_QNX\_SYSTEM | OFF | Set to ON to build QNX system binary dlt-qnx-system - -## Documentation Options - -Option | Value | Comment - :--- | :--- | :--- -WITH\_DOC | OFF | Set to ON to build API documentation -WITH\_MAN | OFF | Set to ON to build man pages - -## Test Options - -Option | Value | Comment -:--- | :--- | :--- -WITH\_TESTSCRIPTS | OFF | Set to ON to run CMakeLists.txt in test scripts -WITH\_DLT\_TESTS | ON | Set to ON to build src/test binaries -WITH\_DLTTEST | OFF | Set to ON to build with modifications to test User-Daemon communication with corrupt messages -WITH\_DLT\_UNIT\_TESTS | OFF | Set to ON to build unit test binaries -WITH\_GPROF | OFF | Set \-pg to compile flag - -## Experimental Features Options (Dragons ahead!) - -Option | Value | Comment -:--- | :--- | :--- -WITH\_DLT\_SHM\_ENABLE | OFF | Set to ON to enable shared memory as IPC -WITH\_DLT\_CXX11\_EXT | OFF | Set to ON to build C++11 extensions -WITH\_DLT\_COREDUMPHANDLER | OFF | Set to ON to build src/core\_dump\_handler binaries. diff -Nru dlt-daemon-2.18.9/doc/dlt.conf.5.md dlt-daemon-2.18.4/doc/dlt.conf.5.md --- dlt-daemon-2.18.9/doc/dlt.conf.5.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt.conf.5.md 2019-09-03 08:28:13.000000000 +0000 @@ -63,7 +63,7 @@ ## LoggingMode -The logging console for internal logging of dlt-daemon. 0 = log to stdout, 1 = log to syslog, 2 = log to file (see LoggingFilename), 3 = log to stderr +The logging console for internal logging of dlt-daemon. 0 = log to stdout, 1 = log to syslog, 2 = log to file (see LoggingFilename) Default: 0 @@ -79,26 +79,6 @@ Default: /tmp/dlt.log -## EnableLoggingFileLimit - -Only relevant for logging in file (LoggingMode = 2). -If EnableLoggingFileLimit is set to 0, the daemon logs to one logging file without any size limit. -If EnableLoggingFileLimit is set to 1, the daemon considers the size limits configured by LoggingFileSize and LoggingFileMaxSize. If the limits are configured accordingly, multiple log files are used. - - Default: 0 - -## LoggingFileSize - -Only considered for logging in file (LoggingMode = 2) and EnableLoggingFileLimit = 1. Maximum size in bytes of one logging file. - - Default: 250000 - -## LoggingFileMaxSize - -Only considered for logging in file (LoggingMode = 2) and EnableLoggingFileLimit = 1. Maximum size in bytes of all logging files. - - Default: 1000000 - ## TimeOutOnSend Socket timeout in seconds for sending to clients. @@ -123,13 +103,6 @@ Default: 500000 -## Daemon FIFOSize - -The size of Daemon FIFO (MinSize: depend on pagesize of system, MaxSize: please check `/proc/sys/fs/pipe-max-size`) -This is only supported for Linux. - - Default: 65536 - ## ContextLogLevel Initial log-level that is sent when an application registers. DLT_LOG_OFF = 0, DLT_LOG_FATAL = 1, DLT_LOG_ERROR = 2, DLT_LOG_WARN = 3, DLT_LOG_INFO = 4, DLT_LOG_DEBUG = 5, DLT_LOG_VERBOSE = 6 @@ -147,12 +120,6 @@ Force log level and trace status of contexts to not exceed "ContextLogLevel" and "ContextTraceStatus". If set to 1 (ON) whenever a context registers or changes the log-level it has to be lower or equal to ContextLogLevel. Default: 0 - -## InjectionMode - -If set to 0, the injection mode (see [here](./dlt_for_developers.md#DLT-Injection-Messages)) is disabled. - - Default: 1 # GATEWAY CONFIGURATION diff -Nru dlt-daemon-2.18.9/doc/dlt-control.1.md dlt-daemon-2.18.4/doc/dlt-control.1.md --- dlt-daemon-2.18.9/doc/dlt-control.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-control.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -6,7 +6,7 @@ # SYNOPSIS -**dlt-control** \[**-v**\] \[**-h**\] \[**-S**\] \[**-R**\] \[**-y**\] \[**-b** baudrate\] \[**-e** ecuid\] \[**-a** id\] \[**-c** id\] \[**-s** id\] \[**-m** message\] \[**-x** message\] \[**-t** milliseconds\] \[**-l** level\] \[**-r** tracestatus\] \[**-d** loglevel\] \[**-f** tracestatus\] \[**-i** enable\] \[**-o**\] \[**-g**\] \[**-j**\] \[**-u**\] \[**-p** port\] hostname/serial\_device\_name +**dlt-control** \[**-v**\] \[**-h**\] \[**-S**\] \[**-R**\] \[**-y**\] \[**-b** baudrate\] \[**-e** ecuid\] \[**-a** id\] \[**-c** id\] \[**-s** id\] \[**-m** message\] \[**-x** message\] \[**-t** milliseconds\] \[**-l** level\] \[**-r** tracestatus\] \[**-d** loglevel\] \[**-f** tracestatus\] \[**-i** enable\] \[**-o**\] \[**-g**\] \[**-j**\] \[**-u**\] hostname/serial\_device\_name # DESCRIPTION @@ -126,10 +126,6 @@ -u : unix port --p - -: Port for TCP communication (Default: 3490). - # EXAMPLES Change log level of application "APP1" to DEBUG with unix port diff -Nru dlt-daemon-2.18.9/doc/dlt-convert.1.md dlt-daemon-2.18.4/doc/dlt-convert.1.md --- dlt-daemon-2.18.9/doc/dlt-convert.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-convert.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -6,7 +6,7 @@ # SYNOPSIS -**dlt-convert** \[**-h**\] \[**-a**\] \[**-x**\] \[**-m**\] \[**-s**\] \[**-t**\] \[**-o** filename\] \[**-v**\] \[**-c**\] \[**-f** filterfile\] \[**-b** number\] \[**-e** number\] \[**-w**\] file1 \[file2\] \[file3\] +**dlt-convert** \[**-h**\] \[**-a**\] \[**-x**\] \[**-m**\] \[**-s**\] \[**-o** filename\] \[**-v**\] \[**-c**\] \[**-f** filterfile\] \[**-b** number\] \[**-e** number\] \[**-w**\] file1 \[file2\] \[file3\] # DESCRIPTION @@ -63,10 +63,6 @@ : Follow dlt file while file is increasing. --t - -: Handling the compressed input files (tar.gz). - # EXAMPLES Convert DLT file into ASCII: @@ -75,12 +71,9 @@ Cut a specific range, e.g. from message 1 to message 3 from a file called log.dlt and store the result to a file called newlog.dlt: **dlt-convert -b 1 -e 3 -o newlog.dlt log.dlt** -Paste two dlt files log1.dlt and log2.dlt to a new file called newlog.dlt: +Paste two dlt files log1.dlt and log2.dlt to a new file called newlog.dlt:: **dlt-convert -o newlog.dlt log1.dlt log2.dlt** -Handle the compressed input files and join inputs into a new file called newlog.dlt: - **dlt-convert -t -o newlog.dlt log1.dlt compressed_log2.tar.gz** - # EXIT STATUS Non zero is returned in case of failure. diff -Nru dlt-daemon-2.18.9/doc/dlt_demo_setup.md dlt-daemon-2.18.4/doc/dlt_demo_setup.md --- dlt-daemon-2.18.9/doc/dlt_demo_setup.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_demo_setup.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,88 +0,0 @@ -# DLT Demo Setup -Back to [README.md](../README.md) - -In this document you will run an instance of -dlt-daemon. It silently waits to collect and buffer log messages that are -produced by one or multiple DLT users. You will run one of those DLT users and -make it produce log messages that are sent to the daemon. Eventually, you launch -a client that collects and displays these messages. - -*Note: We assume that you installed DLT (i.e. executed the [two optional steps -after build](../README.md#build-and-install)). Otherwise you have to take care -of the executable paths and explicitly state the library path.* - -## Run the DLT Daemon -The DLT daemon is highly configurable but for this case the default settings are -okay. Don't be put off by warning messages: -```bash -$ dlt-daemon -[1886222.668006]~DLT~32290~NOTICE ~Starting DLT Daemon; DLT Package Version: 2.18.0 STABLE, Package Revision: v2.18.1, build on Dec 8 2020 11:11:51 --SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM - -[1886222.668651]~DLT~32290~INFO ~FIFO size: 65536 -[1886222.668764]~DLT~32290~INFO ~Activate connection type: 5 -[1886222.668897]~DLT~32290~INFO ~dlt_daemon_socket_open: Socket created -[1886222.669047]~DLT~32290~INFO ~dlt_daemon_socket_open: Listening on ip 0.0.0.0 and port: 3490 -[1886222.669159]~DLT~32290~INFO ~dlt_daemon_socket_open: Socket send queue size: 16384 -[1886222.669355]~DLT~32290~INFO ~Activate connection type: 1 -[1886222.669509]~DLT~32290~INFO ~Activate connection type: 9 -[1886222.669644]~DLT~32290~INFO ~Ringbuffer configuration: 500000/10000000/500000 -[1886222.669924]~DLT~32290~NOTICE ~Failed to open ECU Software version file. -[1886222.670034]~DLT~32290~INFO ~Activate connection type: 6 -[1886222.670188]~DLT~32290~INFO ~Switched to buffer state for socket connections. -[1886222.670365]~DLT~32290~WARNING ~dlt_daemon_applications_load: cannot open file /tmp/dlt-runtime-application.cfg: No such file or directory -``` -The daemon opened a named pipe from which it is ready to read and buffer log -messages. It also accepts connections on TCP port 3490 by clients to collect -the messages. - -## Produce Log Messages -A simulated ECU - a DLT user - will now use the DLT library to create log -messages and send them through the named pipe for the daemon to collect. Open a -second terminal and run -```bash -$ dlt-example-user -n 5 -l 3 "This is my first log message" -Send 0 This is my first log message -Log level changed of context TEST, LogLevel=4, TraceState=0 -Log level changed of context TS1, LogLevel=4, TraceState=0 -Log level changed of context TS2, LogLevel=4, TraceState=0 -Send 1 This is my first log message -Client disconnected! -Send 2 This is my first log message -Send 3 This is my first log message -Send 4 This is my first log message -``` -This will send 5 (```-n 5```) identical log messages of Log-Level -WARNING ```(-l 3)``` containing a string payload. - -## Read logs -The DLT daemon now has the messages in its buffer and will keep them there until -they are fetched. A mighty tool for receiving and processing log messages is the -[DLT-Viewer](https://github.com/GENIVI/dlt-viewer), which also provides a -graphical UI. For now, a simple command line client is absolutely sufficient: -```bash -$ dlt-receive -a localhost -2020/04/30 12:27:14.976731 17134987 000 ECU1 DA1- DC1- control response N 1 [service(3842), ok, 02 00 00 00 00] -2020/04/30 12:27:14.976779 17067139 000 ECU1 DA1- DC1- control response N 1 [service(3842), ok, 01 00 00 00 00] -2020/04/30 12:27:14.976787 17067139 004 ECU1 DLTD INTM log info V 1 [Client connection #7 closed. Total Clients : 0] -2020/04/30 12:27:14.976794 17104625 005 ECU1 DLTD INTM log info V 1 [ApplicationID 'LOG' registered for PID 5241, Description=Test Application for Logging] -2020/04/30 12:27:14.976802 17104625 000 ECU1 DA1- DC1- control response N 1 [get_log_info, 07, 01 00 4c 4f 47 00 01 00 54 45 53 54 ff ff 18 00 54 65 73 74 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 4c 6f 67 67 69 6e 67 1c 00 54 65 73 74 20 41 70 70 6c 69 63 61 74 69 6f 6e 20 66 6f 72 20 4c 6f 67 67 69 6e 67 72 65 6d 6f] -2020/04/30 12:27:14.976823 17104625 000 ECU1 DA1- DC1- control response N 1 [get_log_info, 07, 01 00 4c 4f 47 00 01 00 54 53 31 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 31 20 66 6f 72 20 69 6e 6a 65 63 74 69 6f 6e 1c 00 54 65 73 74 20 41 70 70 6c 69 63 61 74 69 6f 6e 20 66 6f 72 20 4c 6f 67 67 69 6e 67 72 65 6d 6f] -2020/04/30 12:27:14.976844 17104625 000 ECU1 DA1- DC1- control response N 1 [get_log_info, 07, 01 00 4c 4f 47 00 01 00 54 53 32 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 32 20 66 6f 72 20 69 6e 6a 65 63 74 69 6f 6e 1c 00 54 65 73 74 20 41 70 70 6c 69 63 61 74 69 6f 6e 20 66 6f 72 20 4c 6f 67 67 69 6e 67 72 65 6d 6f] -2020/04/30 12:27:14.976866 17104588 000 ECU1 LOG- TEST log warn V 2 [0 This is my first log message] -2020/04/30 12:27:14.976872 17109592 001 ECU1 LOG- TEST log warn V 2 [1 This is my first log message] -2020/04/30 12:27:14.976880 17114599 002 ECU1 LOG- TEST log warn V 2 [2 This is my first log message] -2020/04/30 12:27:14.976884 17119607 003 ECU1 LOG- TEST log warn V 2 [3 This is my first log message] -2020/04/30 12:27:14.976889 17124611 004 ECU1 LOG- TEST log warn V 2 [4 This is my first log message] -2020/04/30 12:27:14.976894 17134988 006 ECU1 DLTD INTM log info V 1 [New client connection #8 established, Total Clients : 1] -2020/04/30 12:27:15.442016 17139641 000 ECU1 DA1- DC1- control response N 1 [service(3841), ok, 4c 4f 47 00 54 45 53 54 72 65 6d 6f] -2020/04/30 12:27:15.442044 17139642 007 ECU1 DLTD INTM log info V 1 [Unregistered ApID 'LOG'] -``` -The client connects to the default port 3490 of localhost to collect all -messages and interprets the payload as ASCII text (```-a```). You can see lots -of additional messages. These are control messages to control the flow between -client and daemon. You will learn about them later. For now, you have set up a -basic example have seen DLT in action. - -You can now experiment with this setup. What happens if you start the DLT user -first and (while the DLT user is still running) the daemon? \ No newline at end of file diff -Nru dlt-daemon-2.18.9/doc/dlt_design_specification.md dlt-daemon-2.18.4/doc/dlt_design_specification.md --- dlt-daemon-2.18.9/doc/dlt_design_specification.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_design_specification.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,837 +0,0 @@ -*** -SPDX license identifier: MPL-2.0 - -Copyright (C) 2011-2015, BMW AG - -This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - -This Source Code Form is subject to the terms of the -Mozilla Public License (MPL), v. 2.0. -If a copy of the MPL was not distributed with this file, -You can obtain one at http://mozilla.org/MPL/2.0/ - -For further information see http://www.genivi.org/ -*** - -# DLT Design Specification -Alexander Wenzel -0.0.1, 2012/10/10: Initial version - -Luong Hong Duy Khanh -0.0.2, 2020/04/10: Update and convert to markdown format - -![genivilogo](images/genivilogo.png "GENIVI") - -## Purpose -This document specifies the usage of the DLT daemon v2 and also the internal -functionality of the DLT daemon v2. The DLT daemon v2 is a complete rework of -the DLT daemon v1, which is part of the GENIVI 1.0 release. - -The DLT daemon component is based on the -[AUTOSAR 4.0 standard DLT](https://www.autosar.org/fileadmin/user_upload/standards/classic/4-0/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf) -(the current latest version is -[R19-11](https://www.autosar.org/fileadmin/user_upload/standards/classic/19-11/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf)). - -## Overview - -![dlt_overview](images/dlt_overview.png "DLT OVERVIEW") - -The DLT daemon is the central component in GENIVI, where logs and traces are -gathered from the DLT user and different applications, stored optionally -temporarily or permanently in a file in the ECU. The DLT daemon forwards all -logs and traces to a connected DLT client application, which can run directly -on the GENIVI system or more likely on an external tester device. - -The DLT client can send control messages to the daemon, e.g. to set individual -log levels of applications and contexts or get the list of applications and -contexts registered in the DLT daemon. - -In DLT, a log message contains debug information like state changes or value -changes and a trace message contains information, which has passed via the -Virtual Function Bus (VFB). - -## Architecture - -### DLT daemon - -The DLT daemon is the central component between the DLT clients and one or more -applications using the DLT user library. - -#### Overview -The DLT daemon is a standalone application which is running as the center of -management and this is implemented as a single-thread process. The DLT daemon -communicates with the DLT clients over TCP/IP connections or over a serial line -with the applications using the DLT user library over named pipes (FIFOs), -UNIX sockets or VSOCK sockets based on compile time configuration. - -The message format is specified in the DLT AUTOSAR Standard. More details -concerning the exchanged user messages and their content can be found in -[chapter 6](https://www.autosar.org/fileadmin/user_upload/standards/adaptive/19-11/AUTOSAR_SWS_LogAndTrace.pdf#page=10). - - -The main time, the DLT daemon executes the main loop, in which file and socket -descriptors are watched (via poll()). If a message is received, the DLT daemon -reacts. - -Here is a rough schematic, how the DLT daemon is structured: - -![dlt_architecture](images/dlt_architecture.png "DLT ARCHITECTURE") - - -#### Initialization -During initialization of the DLT daemon, the following steps occur: - -- Option handling. -- Option file parsed. The most important configuration files is dlt.conf -- Initialization of logging facility for the DLT daemon application. The DLT -daemon application by itself prints to screen, if not in daemon mode. In daemon -mode, it uses the syslog daemon for log messages of the DLT daemon application. -- Then the daemon enters initialization phase 1: - - Enter daemon mode, if started as daemon - - Initialize output of messages to the local file - - Parse filter file, if specified; then set filters for file storage - - Setup signal handler - - Open DLT output file, if specified -- After phase 1, the daemon initializes the connection handling: - - Delete, create and open its own named FIFO /tmp/dlt or UNIX_SOCKET - - If VSOCK support is enabled in the daemon, open, bind and listen to VSOCK - socket for incoming application connections. - - Open, bind and listen to TCP socket for incoming connections - - Setup and open serial device, if specified -- Then the daemon enters initialization phase 2: - - Initialize daemon data structures - - Initialize ring buffer for client connection - - Check if a runtime configuration exists, if yes load all stored application - and context ids, as well as all log levels and trace statuses. Store this - information to a local array. - - Prepare the main loop - - Initialize receiver objects for socket and serial connection - - Initialize binary semaphore - - Create and start thread(s) for timing messages, sending of these messages is - disabled at default. -- After phase 2: - - Initialize the offline logstorage, if the directory path is specified. - - Prepare timer for system watchdog, if specified. - - Prepare timer to check incoming events. - - Prepare timer to send ECU version, if specified. - - Initialize the gateway mode, if specified, then prepare the timer for gateway. -- Now, the initialization is finished, and the DLT daemon enters the main loop. - -#### Main loop -In the main loop, the following things occur: - -- Wait for event(s) on the incoming named pipe or socket, the TCP connections -(the one connection for new connections, and all TCP connections from clients), -and possibly on the serial device, via poll() call. -- Distinguish from which socket/file descriptor the connection came, and handle them: - - Event from TCP server socket (New DLT client to DLT daemon): - - Create a new TCP connection - - If the newly created connection is the first TCP connection, send all log - messages already stored in ring buffer to DLT client. - - Event from incoming named pipe (FIFO) or UNIX socket and, if enabled, VSOCK - socket (from DLT user library to DLT daemon): - - Use dlt receiver to read data - - As long as there are DLT messages available in received data, the handle - user messages type can be found at src/shared/dlt_user_shared_cfg.h - - Move rest of data in front of buffer for next read attempt - - Event from serial device (DLT client to DLT daemon via serial device) - - Use other dlt receiver to read data - - As long as there are DLT messages available in received data: - - Check for DLT message type control request, and if yes process the request - - Move rest of data in front of buffer for next read attempt - - Event from TCP socket (DLT client to DLT daemon via TCP connection) - - Use other dlt receiver to read data, and check for lost connection - - As long as there are DLT messages available in received data: - - Check for DLT message type control request, and if yes process the request - - Move rest of data in front of buffer for next read attempt - -How the received user messages and control messages are handled, is described -in the Appendix. - -#### Clean up -Before exiting from DLT daemon, the following cleanup procedures occur: - -- Local cleanup - - Destroy the connection list - - Free the used memory by the organising structure of file - - Uninitialise the offline trace - - Free the used memory by the organising structure of file - - Delete existing named pipes (FIFOs) or UNIX_SOCKET - - Cleanup dlt logstorage -- Close UDP connection, if specified -- De-initialize the gateway, if specified. All internal data will be freed -- De-Initialise the dlt daemon structure - - Clear all contexts in internal context management of specific ecu - - Clear all applications in internal application management of specific ecu - - Release and free memory used by dynamic ringbuffer - -Now, the cleanup is finished, and the DLT daemon is terminated. -### DLT user library - -#### Overview -The DLT user library is linked to each application that wants to use DLT. It -encapsulates the communication with the DLT daemon and provides two interfaces: -the DLT user macro interface and the DLT user functional interface. All macros -from the DLT user macro interface are mapped to functions in the DLT user -functional interface. The DLT user library has one additional thread, called -housekeeper thread, responsible for receiving and sending messages from/to -the DLT daemon. - -The DLT user library can be written/read from multiple threads (the threads of -applications which are using DLT APIs, and DLT housekeeper thread which will -send log messages to the daemon). To prevent the concurrent access to the DLT -buffer, parts of functions accessible by the user interface are protected by a -semaphore as well as parts of the function which is called within the thread. - -#### Initialization -During initialization, the following things are done: - -- Setup internal structure including Application ID and Description (textual) -of application -- Get value from environment variable "DLT_LOCAL_PRINT_MODE". This variable can -be used to control the local printing mode of the DLT user library. If enabled -(either via "AUTOMATIC" or via "FORCE_ON"), all messages, which are prepared to -be sent to the DLT daemon will also be print out locally (as ASCII string). If -the environment variable is set, this value overrides the local print mode which -can be set with the API function dlt_enable_local_print() or with dlt_disable_local_print() -from within the application using the DLT user library. The following values -are allowed: - - "AUTOMATIC": Local printing is enabled, if NO DLT daemon is running. - - "FORCE_ON": Local printing is always enabled. - - "FORCE_OFF": Local printing is always disabled. -- Clear internal context array (dynamically growing in step size -DLT_USER_CONTEXT_ALLOC_SIZE, typically 500). The internal context array is NOT -be kept sorted, as the DLT daemon stores for each registered context the offset -position within this array, and sends this offset position for faster access of -a context within this internal context array. The internal context array -contains one entry for each context: - - Context ID - - Log level for this context - - Trace status for this context - - Initialize table (dynamically growing in step-size 1) with function pointers - for callback functions used for injection messages - - Description (textual) of context -- Initialize ringbuffer for local storage of not sent messages -- Setup signal handler and atexit handler -- Ignore all pipe signals -- Create and open own named pipe (with the name /tmp/dlt, where is the -process id of the application using the DLT user library) or UNIX/VSOCK socket IPC -to the DLT daemon -- Open local file for storage, if specified -- Initialize receiver object -- Start housekeeper thread for receiving messages - -#### De-Initialization -During de-initialization, the following things are done: - -- De-register application (and all contexts belonging to this application) from -DLT daemon -- Stop housekeeper thread -- Close and remove own named pipe to the DLT daemon, if FIFO is used -- Close and remove Unix socket if socket IPC is used -- De-Initialize receiver object -- De-Initialize ringbuffer - -#### Register application and context -During register of the application, the following things occur: - -- Auto-initialize DLT user library, if necessary -- Store application id to internal structure -- Store application description to internal structure -- Send message DLT_REGISTER_APPLICATION to DLT daemon - -During register of a context of the application, the following things occur: - -- Auto-initialize DLT user library, if necessary -- Check, if context was already registered, if not, dynamically increment if -required, the context array in step size DLT_USER_CONTEXT_ALLOC_SIZE, -typically 500. Then store one entry for the new context to internal context array. -- Send message DLT_REGISTER_CONTEXT to DLT daemon - -#### Unregister context and application - -During unregister of context, the following things occur: - -- Delete context from internal structures -- Send message DLT_UNREGISTER_CONTEXT to DLT daemon - -During unregister of application, the following things occur: - -- Delete application from internal structures -- Send message DLT_UNREGISTER_APPLICATION to DLT daemon - -#### Handling of messages received from DLT daemon - -During housekeeper thread within the DLT user library checks for newly received -messages from the DLT daemon, and handles them in the following way: - -- **DLT_USER_MESSAGE_LOG_LEVEL** - - Store received log level and trace status for the received context to the - context array. -- **DLT_USER_MESSAGE_INJECTION** - - Check all registered callbacks for this context: - - Compare service id of registered callback with received service id, if - they matches: - - Call registered callback function. - -#### Overflow handling - -If the named pipe/socket of the DLT daemon is full, an overflow flag is set and -the message stored in a ring buffer. The next time, a message could be sent to -the DLT daemon, an overflow message is sent first, then the contents of the ring -buffer. If sending of this message was possible, the overflow flag is reset. - -#### Send log message - -During sending of a log message, the following things occur: - -- Auto-initialize DLT user library, if necessary -- Initialize DLT log structure -- Store log level of log message in DLT log structure -- Check if log level is smaller than or equal than the stored log level of the -context, under which the message should be sent. If yes continue, else don't -send this log message. This is a kind of filtering on the DLT user library side. -- In non-verbose mode, insert message id -- Add values (int, string, raw, …) to DLT log structure: - - Set argument type (only in verbose mode) - - Copy content of argument to message - - Set length information of argument - - Set number of arguments and total length of message -- Create new message with the help of the DLT log structure and handle this message: - - Initialize new message - - Add headers (standard header, extended header, storage header, ...) to this - message - - If logging to a file is enabled, write the log message to file - - Print message locally, if requested by environment variable - - Check if connection to DLT daemon was lost and try to reattach to daemon. - - Check for overflow flag and try to send overflow message. - - Try to send message to DLT daemon, and check for return values. This can be: - - data could not be written - - handle not open or pipe/socket error - - other error condition - - no error, all right - - If sending failed, put this message in the ring buffer for later sending. - - Handle these error conditions. - -#### Send network trace message - -During sending of a network trace message, the following things occur: - -- Auto-initialize DLT user library, if necessary -- Check for trace status of network trace message to be sent. -- If Trace status equals on: - - Initialize DLT log structure - - Set trace status in DLT log structure to network trace type of message - - Copy length of network message header to DLT log structure - - Copy data of network message header to DLT log structure - - Copy length of network trace payload to DLT log structure - - Copy data of network trace payload to DLT log structure - - Create new message with the help of the DLT log structure and handle this message - -#### Register callback function for injection message - -During registration of a callback function for an injection message, then following -steps are executed: - - - Check if the environment variable DLT\_DISABLE\_INJECTION\_MSG\_AT\_USER is set. - - If yes: - - libdlt will ignore all data/messages from dlt-daemon, including: - loglevel change, custom injection messages ... - - If no (default): - - libdlt will handle all data/messages from dlt-daemon as normal. - - For the specified context, check if service id is already in the table of the - registered callbacks (this table is dynamically growing in steps of one entry). - - If yes: - - Stored service id is set to service id to be registered - - Stored callback function pointer is set to callback function pointer to - be registered - - If no: - - Increase the number of callbacks for this context - - Store service id in callback table - - Store function pointer in callback table - -#### Android: Thread termination - -On Android, `pthread_cancel` is not available in bionic. So current -implementation uses *SIGUSR1* and `pthread_kill` to terminate housekeeper -thread. Due to this, application which is linked to DLT library should not -define *SIGUSR1*. - -### Communication between DLT daemon and DLT user library - -The communication mechanism (IPC) used between DLT daemon and DLT user library -are named pipes (FIFOs), UNIX sockets or VSOCK sockets, based on compile time -configuration). - -During the startup of the DLT daemon, the DLT daemon creates and opens the IPC -(FIFOs or UNIX_SOCKET) on the configured path called /tmp/dlt. If a DLT user -application using the DLT user library wants to send log messages to the DLT -daemon, this IPC is used. - -During the startup of the DLT user application using the DLT user library, it -creates and opens the same IPC type of DLT daemon. If the DLT daemon wants to -send the control messages to the DLT user application, this IPC is used. - -- When the FIFOs IPC is used, a named pipe called /tmp/dltpipes/dlt, where - is the process id of the DLT user application. Each DLT user application -creates its own named pipe to communicate with the DLT daemon. -- When the UNIX_SOCKETS IPC is used, the DLT user application just needs to -connect to the opened socket port of DLT daemon. All DLT user applications -use the same UNIX_SOCKETS port to communicate with the DLT daemon. - -The exchanged messages are described in the -[chapter 7.1](https://www.autosar.org/fileadmin/user_upload/standards/adaptive/19-11/AUTOSAR_SWS_LogAndTrace.pdf#page=12). - -In a system with a single process tree where PIDs are unique, the FIFOs IPC shall -work well. - -In a system with the multiple nested process trees, each process tree -maintains an entirely isolated set of processes. Because of that, PIDs are not -unique anymore and a DLT User application running in the parent PID namespace -might have the same PID as another DLT User application running in the child -PID namespace. Since a DLT User application creates its own FIFO based on its -PID (getpid()), the DLT Daemon has to deal with multiple applications registering -itself with the same PID, which is impossible. To solve this problem, the -UNIX_SOCKETS based communication is used. The UNIX_SOCKETS IPC is also supported -in the Non-linux platforms (eg: QNX). - -If the daemon is built with VSOCK socket support, it can also receive log -messages from processes running in virtual machines. The communication mechanism -between the daemon and the DLT user library on the host is still FIFOs or UNIX -sockets. But the DLT user library for the system running in the virtual machine -can be built to use VSOCK sockets for sending log messages to the daemon. See -"man vsock" for more information about VSOCK sockets. This is an alternative to -using a [multinode](dlt_multinode.md) setup for receiving DLT log messages from -processes in a virtualized environment. No passive daemon(s) are required and it -works without having a network configured between the guest and the host. - -### Place of message creation - -The following table shows, where the certain types of DLT messages are created. -The message types are described in more detail in the AUTOSAR Specification for -Diagnostic Log and Trace. - -| Type of message | DLT client | DLT daemon | DLT library | -| ---------------- | :--------: | :--------: | :---------: | -| Control request | X | X | | -| Control response | | X | -| Log message | | | X | -| Trace message | | | X | - -This table shows, that: - -- DLT messages of message type control request are created in the DLT client, -and then sent to the DLT daemon. -- DLT messages of message type control response (to a control request) are -created in the DLT daemon, and then sent to the DLT client. -- DLT messages of type log and of type trace are created in the DLT user library, -then passed (via the named pipe of the DLT daemon) to the DLT daemon, which -forwards them to the connected DLT clients. - -### Message flow -The following figure shows the overall flow of messages. - -![dlt_message_flow](images/dlt_message_flow.png "DLT MESSAGE FLOW") - - -## Appendix - -### Messages exchanged between DLT daemon and DLT user library - -There are several user messages (each has its own message identifier -DLT_USER_MESSAGE_*) which will are exchanged between DLT daemon and DLT user -library, and will be described in the following sub-chapters. - -From DLT user library to DLT daemon: - -- **DLT_USER_MESSAGE_REGISTER_APPLICATION** -- **DLT_USER_MESSAGE_UNREGISTER_APPLICATION** -- **DLT_USER_MESSAGE_REGISTER_CONTEXT** -- **DLT_USER_MESSAGE_UNREGISTER_CONTEXT** -- **DLT_USER_MESSAGE_LOG** -- **DLT_USER_MESSAGE_OVERFLOW** -- **DLT_USER_MESSAGE_APP_LL_TS** - -From DLT daemon to DLT user library: - -- **DLT_USER_MESSAGE_LOG_LEVEL** -- **DLT_USER_MESSAGE_INJECTION** - -Each of the following messages has a message header with the following information: - -- Pattern: DUH0x01 -- Message identifier - -#### User Message: Register Application - -This message is sent by the DLT user library once per application to register the -application to the DLT daemon. -It contains the following information: - -- The application id of the application to be registered -- The process id of the process using the DLT user library. This information is -required, if the DLT daemon wants to send something to the DLT user library. -- The length of the following description. -- The application description. - -#### User Message: Unregister Application - -This message is sent by the DLT user library once per application to unregister -the application from the DLT daemon. -It contains the following information: - -- The application id of the application to be unregistered -- The process id of the process using the DLT user library. - -#### User Message: Register Context - -This message is sent by the DLT user library once for each context which should -be registered to the DLT daemon. -It contains the following information: - -- The application id of the application to be registered -- The context id of the application to be registered -- Each created context is stored with its associated information in a dynamically -growing array in the DLT user library. The index in this array is sent. -- The process id of the process using the DLT user library. This information is -required, if the DLT daemon wants to send something to the DLT user library. -- The initial log level of the context -- The initial trace status of the context -- The length of the following description. -- The context description. - -#### User Message: Unregister Context - -This message is sent by the DLT user library once for each context which should -be unregistered from the DLT daemon. -It contains the following information: - -- The application id of the application to be unregistered -- The context id of the application to be unregistered -- The process id of the process using the DLT user library. - -#### User Message: Log - -This is the standard log/trace message send by the DLT user library to the DLT daemon. -It contains the following information: - -- A standard DLT message header as specified in the AUTOSAR R4.0 DLT standard. -- An extended DLT message header as specified in the AUTOSAR R4.0 DLT standard. -- The payload of the DLT message - -#### User Message: Overflow - -This message is sent from the DLT user library to the DLT daemon, if there was -an overflow during writing to the DLT daemon named pipe or socket IPC. -It contains no further information. - -#### User Message: Application Log Level and Trace Status - -This message is sent from the DLT user library to the DLT daemon, when the -overall Log Level and Trace Status for the whole DLT application should be set -from within the DLT application. -It contains the following information: - -- The application id -- The Log Level to be set for the whole application -- The Trace Status to be set for the whole application - -#### User Message: Log Level - -If the log level or trace status is changed, or initialized, this message is -sent from the DLT daemon to the DLT user library to store the current log level -and trace status for filtering in the DLT user library. - -It contains the following information: - -- The new set log level -- New set trace status. -- Each created context is stored with its associated information in a dynamically -growing array in the DLT user library. The index in this array is sent. - -#### User Message: Injection - -This message is sent from the DLT daemon to the DLT user library, if an injection -message was received by the DLT daemon from a DLT client. Via the context, the -appropriate application and its named pipe can be identified. The injection -message is then passed to this named pipe. - -It contains the following information: - -- Each created context is stored with its associated information in a dynamically -growing array in the DLT user library. The index in this array is sent. -- Service ID of the injection message -- Length of the following injection message -- The contents of the injection message - -### DLT daemon: User message handling - -Following things occur for the received DLT user messages: - -- **DLT_USER_MESSAGE_REGISTER_APPLICATION** - - Add all information about application to a local application array - (dynamically growing in a predefined step size (DLT_DAEMON_APPL_ALLOC_SIZE, - typically 500)). The array is always being kept sorted (via qsort()). Finding - entries in this array is done by a binary search (via bsearch()). - - Open named pipe (or Unix socket IPC if specified) to DLT application using - the DLT user library with process id . The name of the pipe (or Unix - socket IPC) is /tmp/dlt -- **DLT_USER_MESSAGE_UNREGISTER_APPLICATION** - - Remove all information about this application from local application array, - and remove all information of all contexts belonging to this application from - local context array. The arrays are always being kept sorted, without empty - entries in between. Dynamically shrinking of this array is NOT implemented. -- **DLT_USER_MESSAGE_REGISTER_CONTEXT** - - Add all information about context to local context array (dynamically growing - in a predefined step size (DLT_DAEMON_CONTEXT_ALLOC_SIZE, typically 1000)). - The array is always being kept sorted (via qsort()). Finding entries in this - array is done by a binary search (via bsearch()). - - Send log level and trace status to DLT user library for this context. - Therefore, the DLT_USER_MESSAGE_LOG_LEVEL is used. -- **DLT_USER_MESSAGE_UNREGISTER_CONTEXT** - - Remove all information about this context from local context array. The array - is always being kept sorted, without empty entries in between. Dynamically - shrinking of this array is NOT implemented. -- **DLT_USER_MESSAGE_OVERFLOW** - - Set internal flag for overflow. - - Create and send DLT control message response overflow to all connected TCP - connections, and optionally to serial device, if connected. If the message - was sent, reset the internal flag for overflow. -- **DLT_USER_MESSAGE_LOG** - - Overwrite ECU id, if requested - - Set storage header - - Check for filters of message, if no filter is set, or filter is matching: - - Possibly display message as specified in the options. - - Whole message display in hex - - Whole message display in ASCII - - Show message headers only - - Store message to output file - - Set serial header in front of message, if specified. - - Create and try to send DLT message to all DLT clients connected via TCP - connection, and optionally via serial device. - - If the message could not be sent, store the message to a local ring buffer. - The ring buffer internally uses a variable length for the buffered elements, - and therefore uses the memory available for the buffer the best way possible. - If the buffer is full, the oldest messages are silently discarded, until - there is enough space for the message to be stored in the ring buffer. -- **DLT_USER_MESSAGE_APP_LL_TS** - - For all contexts belonging to the specified application: - - Set specified log level - - Set specified trace status - - Send specified log level and trace status to DLT client library - -### DLT daemon: Control message handling - -If the DLT daemon receives a control message request from a DLT client, it handles -it in the following way. First the service id of the message is detected, and -if it is no injection message, the following things occur: - -- DLT_SERVICE_ID_SET_LOG_LEVEL - - Check if received log level is other then already set log level. If yes: - - Store new log level to local array. - - Send new log level to DLT user library for this context. Therefore, the - DLT_USER_MESSAGE_LOG_LEVEL is used. Note that the DLT would take the log - level of Logstorage as the highest priority. So even if log level is changed - from client, it will be overwritten by Logstorage definition. - - Send DLT control response to DLT client, with status of operation. -- DLT_SERVICE_ID_SET_TRACE_STATUS - - Check if received trace status is other then already set trace status. If yes: - - Store new trace status to local array. - - Send new trace status to DLT user library for this context. Therefore, the - DLT_USER_MESSAGE_LOG_LEVEL is used. - - Send DLT control response to DLT client, with status of operation. -- DLT_SERVICE_ID_GET_LOG_INFO - - Create answer message for DLT control response. All kinds of requests are supported: - - Application/Context: - - All applications and all contexts - - One application and all of its contexts - - One application with one context. - - Request type (as specified in the AUTOSAR DLT Standard, 1 and 2 are not specified): - - 3: Application ID, Context ID - - 4: Application ID, Context ID, Log Level - - 5: Application ID, Context ID, Trace Status - - 6: Application ID, Context ID, Log Level, Trace Status - - 7: Application ID, Context ID, Log Level, Trace Status, Description - - Answer is of the corresponding type 3-7, or of type 8 (no matching context - ids found), or of type 2 (error). - - Send DLT control response answer to DLT client. -- DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL - - Send DLT control response with default log level to DLT client. -- DLT_SERVICE_ID_STORE_CONFIG - - Store configuration files with currently registered application ids and - context ids as well as currently set log levels and trace statuses to - configuration files. If these files exists, they will be read in when the DLT - daemon is started next time. - - Send DLT control response to DLT client. -- DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT - - Delete the stored configuration files, if they exists. - - Set default log level and trace status to initial values, and inform all - applications using the default log level and trace status about the new defaults. - - Send DLT control response to DLT client. -- DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_SET_VERBOSE_MODE - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_SET_MESSAGE_FILTERING - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_SET_TIMING_PACKETS - - Set flag to start/stop sending of timing messages in thread. - - Send DLT control response to DLT client. -- DLT_SERVICE_ID_GET_LOCAL_TIME - - Send DLT control response with local time to DLT client. -- DLT_SERVICE_ID_USE_ECU_ID - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_USE_SESSION_ID - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_USE_TIMESTAMP - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_USE_EXTENDED_HEADER - - Send DLT control response "Not supported" to DLT client -- DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL - - Check if received default log level is other than already stored default - log level. If yes: - - Store new default log level to internal structure. - - Send a DLT_USER_MESSAGE_LOG_LEVEL to all DLT clients containing the new - default log level, which uses a context which is set to default log level. - - Send DLT control response to DLT client, with status of operation. -- DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS - - Check if received default trace status is other than already stored default - trace status. If yes: - - Store new default trace status to internal structure. - - Send a DLT_USER_MESSAGE_LOG_LEVEL to all DLT clients containing the new - default trace status, which uses a context which is set to default trace status. - - Send DLT control response to DLT client, with status of operation. -- DLT_SERVICE_ID_GET_SOFTWARE_VERSION - - Send DLT control response containing a software version string to DLT Client. - - The software version string contains: - - the package version of the package dltv2, e.g. "2.0.0" - - the package status of the package dltv2, e.g. "alpha, beta, final" - - the overall subversion revision number for the package dltv2, e.g. "2300" -- DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW - - Try to send DLT control response containing the status of the internal flag - for overflow. If the message could be send, reset the internal flag for overflow. - -For handling of the injection message, the following steps occur: - -- Create new user message DLT_USER_MESSAGE_INJECTION from received DLT control -request message, and send this user message to the DLT application using the -DLT user library. - -### Mapping to files - -Here is a description, how the whole project is structured and which files exists. -The following table shows a top level view of the available Git repositories: - -| Directory | Description | -| --------- | ----------- | -| dlt | DLT Daemon and Library implementation; command line utilities, examples and test programs | -| dlt_viewer | DLT Client GUI (DLT Viewer): QT based implementation | - -As this document has the focus on the DLT Daemon and the DLT user library, only -the "dlt" directory is introduced in more detail: - -| Directory | Description | -| --------- | ----------- | -| doc | Documentation | -| include | Include files, installed on target | -| src | Source Code | -| src/shared | Shared source code (between DLT daemon and DLT user library) | -| src/adaptor | Adaptors to DLT daemon:dlt-adaptor-stdin (for connection over stdin) dlt-adaptor-udp (for connection over UDP) | -| src/console | Console utilities: logstorage, dlt-control, dlt-convert, dlt-passive-node-ctrl, dlt-receive, and dlt-sortbytimestamp | -| src/daemon | DLT Daemon | -| src/examples | Examples for usage of the DLT user library:dlt-example-user (Macro IF) anddlt-example-user-func (Function IF) andwintestclient (MS Windows based test client) | -| src/lib | DLT library functions | -| src/tests | Test programs:dlt-test-client and dlt-test-user for automatic tests, dlt-test-stress for stress tests, dlt-test-internal for internal tests | -| testscripts | Several supporting scripts | - -The DLT daemon implementation uses the following files, besides DLT functions from files from the shared directory: - -| File | Description | -| --------- | ----------- | -| dlt-daemon.c | DLT daemon implementation | -| dlt-daemon.h | Header file for dlt-daemon.c | -| dlt-daemon_cfg.h | Compile time configuration for DLT daemon, Part1 | -| dlt_daemon_common.c | Supporting functions for a DLT daemon implementation | -| dlt_daemon_common.h | Header file for dlt_daemon_common.c | -| dlt_daemon_common_cfg.h | Compile time configuration for DLT daemon, Part2 | - -The DLT user library contains the following files: - -| File | Description | -| --------- | ----------- | -| dlt_user.c | Implementation of functions, available via the DLT user library interface. | -| dlt_user_cfg.h | Compile time configuration for dlt_user.c | -| dlt_client.c | Functions required for DLT Client implementations | -| dlt_client_cfg.h | Compile time configuration for dlt_client.c | - -The shared directory contains the following files: - -| File | Description | -| --------- | ----------- | -| dlt_common.c | Common helper functions, such as: Print functions for DLT messages, Functions for handling DLT Ids, Filter functions, DLT message handling functions, Functions for handling DLT files, DLT receiver functions, Log handling, Ringbuffer functions, Setting and checking of storage header | -| dlt_common_cfg.h | Compile time configuration for dlt_common.c | -| dlt_user_shared.c | Shared functions, required by the DLT daemon and the DLT user library, such as: Setting and checking the user header, Sending DLT messages over named pipes (FIFOs) or UNIX/VSOCK sockets | -| dlt_user_shared.h | Header file for dlt_user_shared.c | -| dlt_user_shared_cfg.h | Compile time configuration for dlt_user_shared.c | - -The public available include directory contains the following header files: - -| File | Description | -| --------- | ----------- | -| dlt.h | Overall include file, includes dlt_common.h and dlt_user.h | -| dlt_common.h | Include file for dlt_common.c | -| dlt_user.h | Include file for dlt_user.c, contains the "User API" functions | -| dlt_user_macros.h | Include file for dlt_user.c, contains the "User API" macros | -| dlt_client.h | Include file for dlt_client.c | -| dlt_protocol.h | DLT protocol specfic definitions and macros | -| dlt_types.h | Definition of types, must be adapted to the target architecture and compiler toolchain. | - -### Description of used structures in implementation - -The following important structures are used in the DLT Daemon and DLT User Library: - -| Structure | Description | -| --------- | ----------- | -| DltDaemonFlags | Flags and values, set over command line during start-up of DLT daemon | -| DltDaemonLocal | Global variables of the DLT Daemon, grouped together in a struct | -| DltDaemon | Parameters of the DLT daemon | -| DltDaemonApplication | Parameters of an application, used within DLT daemon | -| DltDaemonContext | Parameters of a context, used within DLT daemon | -| DltUserControlMsg... | User control messages | -| DltContext | Each context is represented with this structure | -| DltContextData | Temorary used structure for constructing a log message | -| DltUserInjectionCallback | One entry in dynamic callback table for callback function | -| dlt_ll_ts_type | Table managing all contexts (and loglevels and trce statuses) within DLT user library, contains dynamicly growing array with "DltUserInjectionCallback" entries | -| DltUser | Parameters for DLT user library application, contains dynamically growing array with "dlt_ll_ts_type" entries | -| DltStorageHeader | Storage header | -| DltStandardHeader | Structure for standard header of a DLT message | -| DltStandardHeaderExtra | Structure for standard header extra fields of a DLT message | -| DltExtendedHeader | Structure for extended header of a DLT message | -| DltService... | Structures for control messages (requests and responses) | -| DltFilter | Structure to store filter parameters | -| DltMessage | Structure to organize a DLT message, includes pointers to DltStorageHeader, DltStandardHeader, DltStandardHeaderExtra, and DltExtendedHeader, data of message is stored within a private buffer within this structure | -| DltFile | Structure to organize access to a DLT File | -| DltReceiver | Structure to organize the receiving of data | -| DltRingbuffer | Structure to organize a ring buffer | - -#### Implementation specifics - -- The following preconditions were given prior to implementation: - - C-only implementation for the DLT daemon and the DLT user library - - Implementation of common functions, which can be used in a command line - utility as well as in a Graphical UI - - Implementation of C+\+ like classes in C, see dlt_common.c and dlt_common.h -- The current implementation of the DLT daemon and DLT user library is tested -with gcc under Ubuntu 16.04 on Intel HW; Android and QNX on IMX, RCAR, Qualcomm -ARM target boards. -- It is assumed that packed structs are always stored in memory in the order -specified within the packed struct. -- The implementation is multithread safe. -- Initialize DLT application and contexts, then forking and using the forked -process, will lead to unclear behavior (or in the worst case to a crash), as the -forked process uses another process id as the parent process. Instead, initialize -the DLT application and contexts in the forked process. -- Calling of DLT logging and tracing functions within a callback function for -injections are not supported, and will lead to an unclear behavior. \ No newline at end of file diff -Nru dlt-daemon-2.18.9/doc/dlt_design_specification.txt dlt-daemon-2.18.4/doc/dlt_design_specification.txt --- dlt-daemon-2.18.9/doc/dlt_design_specification.txt 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_design_specification.txt 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,644 @@ +//// +# SPDX license identifier: MPL-2.0 +# +# Copyright (C) 2011-2015, BMW AG +# +# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. +# +# This Source Code Form is subject to the terms of the +# Mozilla Public License (MPL), v. 2.0. +# If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# For further information see http://www.genivi.org/. +//// + +DLT Design Specification +======================== +Alexander Wenzel +0.0.1, 2012/10/10: Initial version + +image::images/genivilogo.png[width=128] + +*This document is not up to date* + +== Purpose +This document specifies the usage of the DLT daemon v2 and also the internal functionality of the DLT daemon v2. The DLT daemon v2 is a complete rework of the DLT daemon v1, which is part of the GENIVI 1.0 release. +The DLT daemon is the central place where logs and traces are gathered from different applications, stored temporarily or permanently and transferred to a DLT client application, which can run directly on the GENIVI system or more likely on a external tester device. +The DLT client component is described in an extra document. +The DLT daemon component is based on the AUTOSAR 4.0 standard DLT. + +== Overview + +.DLT Architecture +image::images/dlt_overview.png[] + +The DLT daemon is the central component in GENIVI, which gathers all logs and traces from the DLT user applications. The logs and traces are stored optionally directly in a file in the ECU. The DLT daemon forwards all logs and traces to a connected DLT client. +The DLT client can send control messages to the daemon, e.g. to set individual log levels of applications and contexts or get the list of applications and contexts registered in the DLT daemon. + +== Architecture + +=== DLT daemon +The DLT daemon is the central component between the DLT clients and one or more applications using the DLT user library. + +==== Overview +The DLT daemon communicates with the DLT clients over TCP/IP connections or over a serial line (the message format is specified in the DLT AUTOSAR Standard), with the applications using the DLT user library over named pipes (FIFOs) or UNIX_SOCKET based on compile time configuration. More details concerning the exchanged user messages and their content can be found in chapter chapter 6.3. +The main time, the DLT daemon executes a main loop, in which file and socket descriptors are watched (via poll()). If a message is received, the DLT daemon reacts. Additionally, a thread is implemented, which if enabled sends each second a keep-alive message to all connected DLT clients. +Here is a rough schematic, how the DLT daemon is structured: + +.DLT Overview +image::images/dlt_architecture.png[] + +==== Initialization +During initialization of the DLT daemon, the following steps occur: + +* Option handling +* Initialization of logging facility for the DLT daemon application. The DLT daemon application by itself prints to screen, if not in daemon mode. In daemon mode, it uses the syslog daemon for log messages of the DLT daemon application. +* Then the daemon enters initialization phase 1: +** Enter daemon mode, if started as daemon +** Initialize output of messages to local file +** Parse filter file, if specified; then set filters for file storage +** Setup signal handler +** Open DLT output file, if specified +* After phase 1, the daemon initializes the connection handling: +** Delete, create and open its own named FIFO /tmp/dlt or UNIX_SOCKET +** Open, bind and listen to TCP socket for incoming connections +** Setup and open serial device, if specified +* Then the daemon enters initialization phase 2: +** Initialize daemon data structures +** Initialize ring buffer for client connection +** Check if a runtime configuration exists, if yes load all stored application and context ids, as well as all log levels and trace statuses. Store this information to a local array. +** Prepare main loop +** Initialize receiver objects for socket and serial connection +** Initialize binary semaphore +** Create and start thread for timing messages, sending of these messages is disabled at default. +* Now, the initialization is finished, and the DLT daemon enters the main loop. + +==== Main loop +In the main loop, the following things occur: + +* Wait for event on the incoming named pipe or socket, the TCP connections (the one connection for new connections, and all TCP connections from clients), and possibly on the serial device, via poll() call. +* Distinguish from which socket/file descriptor the connection came, and handle them: +** Event from TCP server socket (New DLT client to DLT daemon): +*** Create new TCP connection +*** If the newly created connection is the first TCP connection, send all log messages already stored in ring buffer to DLT client. +** Event from incoming named pipe or unix socket(DLT user library to DLT daemon): +*** Use dlt receiver to read data +*** As long as there are DLT messages available in received data: +**** Handle user message: +***** DLT_USER_MESSAGE_REGISTER_APPLICATION +***** DLT_USER_MESSAGE_UNREGISTER_APPLICATION +***** DLT_USER_MESSAGE_REGISTER_CONTEXT +***** DLT_USER_MESSAGE_UNREGISTER_CONTEXT +***** DLT_USER_MESSAGE_OVERFLOW +***** DLT_USER_MESSAGE_LOG +***** DLT_USER_MESSAGE_APP_LL_TS +*** Move rest of data in front of buffer for next read attempt +** Event from serial device (DLT client to DLT daemon via serial device) +*** Use other dlt receiver to read data +*** As long as there are DLT messages available in received data: +**** Check for DLT message type control request, and if yes process the request +*** Move rest of data in front of buffer for next read attempt +** Event from TCP socket (DLT client to DLT daemon via TCP connection) +*** Use other dlt receiver to read data, and check for lost connection +*** As long as there are DLT messages available in received data: +**** Check for DLT message type control request, and if yes process the request +*** Move rest of data in front of buffer for next read attempt + +How the received user messages and control messages are handled, is described in the Appendix. + +=== DLT user library + +==== Overview +The DLT user library is linked to each application which wants to use DLT. It encapsulates the communication with the DLT daemon, and provides two interfaces: the DLT user macro interface and the DLT user functional interface. All macros from the DLT user macro interface are mapped to functions in the DLT user functional interface. The DLT user library has one additional thread, responsible for receiving messages from the DLT daemon. Parts of functions accessible by the user interface are protected by a semaphore, as well as parts of the function which is called within the thread. + +==== Initialization +During initialization, the following things are done: + +* Setup internal structure including Application ID and Description (textual) of application +* Get value from environment variable "DLT_LOCAL_PRINT_MODE". This variable can be used to control the local printing mode of the DLT user library. If enabled (either via "AUTOMATIC" or via "FORCE_ON"), all messages, which are prepared to be sent to the DLT daemon will also be print out locally (as ASCII string). If the environment variable is set, this value overrides the local print mode which can be set with the API function dlt_enable_local_print() or with dlt_disable_local_print() from within the application using the DLT user library. The following values are allowed: +*** "AUTOMATIC": Local printing is enabled, if NO DLT daemon is running. +*** "FORCE_ON": Local printing is always enabled. +*** "FORCE_OFF": Local printing is always disabled. +* Clear internal context array (dynamically growing in step size DLT_USER_CONTEXT_ALLOC_SIZE, typically 500). The internal context array is NOT be kept sorted, as the DLT daemon stores for each registered context the offset position within this array, and sends this offset position for faster access of a context within this internal context array). The internal context array contains one entry for each context: +** Context ID +** Log level for this context +** Trace status for this context +** Initialize table (dynamically growing in step-size 1) with function pointers for callback functions used for injection messages +** Description (textual) of context +* Initialize ringbuffer for local storage of not sent messages +* Setup signal handler and atexit handler +* Ignore all pipe signals +* Create and open own named pipe with the name /tmp/dlt, where is the process id of the application using the DLT user library. +* Open named pipe to the DLT daemon +* Open local file for storage, if specified +* Initialize receiver object +* Start receiver thread + +==== De-Initialization +During de-initialization, the following things are done: + +* De-register application (and all contexts belonging to this application) from DLT daemon +* Stop receiver thread +* Close and remove own named pipe +* Close named pipe to the DLT daemon +* De-Initialize receiver object +* De-Initialize ringbuffer + +==== Register application and context +During register of the application, the following things occur: + +* Auto-initialize DLT user library, if necessary +* Store application id to internal structure +* Store application description to internal structure +* Send message DLT_REGISTER_APPLICATION to DLT daemon + +During register of a context of the application, the following things occur: + +* Auto-initialize DLT user library, if necessary +* Check, if context was already registered, if not , dynamically increment if required, the context array in step size DLT_USER_CONTEXT_ALLOC_SIZE, typically 500. Then store one entry for the new context to internal context array. +* Send message DLT_REGISTER_CONTEXT to DLT daemon + +==== Unregister context and application + +During unregister of context, the following things occur: + +* Delete context from internal structures +* Send message DLT_UNREGISTER_CONTEXT to DLT daemon + +During unregister of application, the following things occur: + +* Delete application from internal structures +* Send message DLT_UNREGISTER_APPLICATION to DLT daemon + +==== Handling of messages received from DLT daemon + +During receiver thread within the DLT user library checks for newly received messages from the DLT daemon, and handles them in the following way: + +* DLT_USER_MESSAGE_LOG_LEVEL +** Store received log level and trace status for the received context to the context array +* DLT_USER_MESSAGE_INJECTION +** Check all registered callbacks for this context: +*** Compare service id of registered callback with received service id, if they matches: +**** Call registered callback function. + +==== Overflow handling + +If the named pipe/socket of the DLT daemon is full, an overflow flag is set and the message stored in a ring buffer. The next time, a message could be send to the DLT daemon, an overflow message is send first, then the contents of the ring buffer. If sending of this message was possible, the overflow flag is reset. + +==== Send log message + +During sending of a log message, the following things occur: + +* Auto-initialize DLT user library, if necessary +* Initialize DLT log structure +* Store log level of log message in DLT log structure +* Check if log level is smaller than or equal than the stored log level of the context, under which the message should be sent. If yes continue, else don't send this log message. This is a kind of filtering on the DLT user library side. +* In non-verbose mode, insert message id +* Add values (int, string, raw, …) to DLT log structure: +** Set argument type (only in verbose mode) +** Copy content of argument to message +** Set length information of argument +** Set number of arguments and total length of message +* Create new message with the help of the DLT log structure and handle this message: +** Initialize new message +** Add headers (standard header, extended header, storage header, ...) to this message +** If logging to a file is enabled, write the log message to file. Finished sending log. +** Print message locally, if requested by environment variable +** Check if connection to DLT daemon was lost and try to reattach to daemon. +** Check for overflow flag and try to send overflow message. +** Try to send message to DLT daemon, and check for return values. This can be: +*** data could not be written +*** handle not open or pipe/socket error +*** other error condition +*** no error, all right +** If sending failed, put this message in the ring buffer for later sending. +** Handle this error conditions. + +==== Send network trace message + +During sending of a network trace message, the following things occur: + +* Auto-initialize DLT user library, if necessary +* Check for trace status of network trace message to be send. +* If Trace status equals on: +** Initialize DLT log structure +** Set trace status in DLT log structure to network trace type of message +** Copy length of network message header to DLT log structure +** Copy data of network message header to DLT log structure +** Copy length of network trace payload to DLT log structure +** Copy data of network trace payload to DLT log structure +** Create new message with the help of the DLT log structure and handle this message + +==== Register callback function for injection message + +During registration of a callback function for a injection message, the following steps are executed: + +** For the specified context, check if service id is already in the table of the registered callbacks (this table is dynamically growing in steps of one entry). +*** If yes: +**** Stored service id is set to service id to be registered +**** Stored callback function pointer is set to callback function pointer to be registered +*** If no: +**** Increase nr of callbacks for this context +**** Store service id in callback table +**** Store function pointer in callback table + +=== Communication between DLT daemon and DLT user library + +The communication mechanism(IPC) used between DLT daemon and DLT user library are named pipes (FIFOs) or UNIX_SOCKETS (based on compile time configuration). +During startup of the DLT daemon, the DLT daemon creates and opens the IPC on configured path. If a DLT user application using the DLT user library wants to send something to the DLT daemon this IPC is used. +During startup of the DLT user application using the DLT user library, it creates and opens the same IPC (a named pipe called /tmp/dlt, where is the process id of the DLT user application or an UNIX_SOCKET). If the DLT daemon wants to send something to the DLT user application, this IPC is used. +The exchanged messages are described in the chapter 7.1. + +=== Place of message creation + +The following table shows, where the DLT messages are created. The message types are described in more detail in the AUTOSAR Specification for Diagnostic Log and Trace. + +[options="header"] +|============================================================================================== +| Type of message | DLT client | DLT daemon | DLT library +| Control request | X | X | +| Control response | | X | +| Log message | | | X +| Trace message | | | X +|============================================================================================== + +* "Get log info" request only, if enabled with \-r option in DLT daemon during start-up +* "File generation" means, that the DLT client creates a file for testing purposes, containing multiple DLT messages. This functionality is only in the "old" DLT viewer (WX widget-based implementation) available. + +This table shows, that: + +** DLT messages of message type control request (e.g. "Get Log Info"-Request) are created in the DLT client, and then sent to the DLT daemon. +** DLT messages of message type control response (to a control request) are created in the DLT daemon, and then sent to the DLT client. +** DLT messages of type log and of type trace are created in the DLT user library, then passed (via the named pipe of the DLT daemon) to the DLT daemon , which forwards them to the connected DLT clients. + +=== Message flow + +The following figure shows the overall flow of messages. + +.DLT Message flow +image::images/dlt_message_flow.png[] + + +== Appendix + +=== Messages exchanged between DLT daemon and DLT user library + +There are several user messages (each has its own message identifier DLT_USER_MESSAGE_*) which will are exchanged between DLT daemon and DLT user library, and will be described in the following sub-chapters. + +From DLT user library to DLT daemon: + +* DLT_USER_MESSAGE_REGISTER_APPLICATION +* DLT_USER_MESSAGE_UNREGISTER_APPLICATION +* DLT_USER_MESSAGE_REGISTER_CONTEXT +* DLT_USER_MESSAGE_UNREGISTER_CONTEXT +* DLT_USER_MESSAGE_LOG +* DLT_USER_MESSAGE_OVERFLOW +* DLT_USER_MESSAGE_APP_LL_TS + +From DLT daemon to DLT user library: + +* DLT_USER_MESSAGE_LOG_LEVEL +* DLT_USER_MESSAGE_INJECTION + +Each of the following messages has a message header with the following information: + +* Pattern: DUH0x01 +* Message identifier + +==== User Message: Register Application + +This message is send by the DLT user library once per application to register the application to the DLT daemon. +It contains the following information: + +* The application id of the application to be registered +* The process id of the process using the DLT user library. This information is required, if the DLT daemon wants to send something to the DLT user library. +* The length of the following description. +* The application description. + +==== User Message: Unregister Application + +This message is send by the DLT user library once per application to unregister the application from the DLT daemon. +It contains the following information: + +* The application id of the application to be unregistered +* The process id of the process using the DLT user library. + +==== User Message: Register Context + +This message is send by the DLT user library once for each context which should be registered to the DLT daemon. +It contains the following information: + +* The application id of the application to be registered +* The context id of the application to be registered +* Each created context is stored with its associated information in a dynamically growing array in the DLT user library. The index in this array is send. +* The process id of the process using the DLT user library. This information is required, if the DLT daemon wants to send something to the DLT user library. +* The initial log level of the context +* The initial trace status of the context +* The length of the following description. +* The context description. + +==== User Message: Unregister Context + +This message is send by the DLT user library once for each context which should be unregistered from the DLT daemon. +It contains the following information: + +* The application id of the application to be unregistered +* The context id of the application to be unregistered +* The process id of the process using the DLT user library. + +==== User Message: Log + +This is the standard log/trace message send by the DLT user library to the DLT daemon. +It contains the following information: + +* A standard DLT message header as specified in the AUTOSAR R4.0 DLT standard. +* An extended DLT message header as specified in the AUTOSAR R4.0 DLT standard. +* The payload of the DLT message + +==== User Message: Overflow + +This message is send from the DLT user library to the DLT daemon, if there was an overflow during writing to the DLT daemon named pipe. +It contains no further information. + +==== User Message: Application Log Level and Trace Status + +This message is send from the DLT user library to the DLT daemon, when the overall Log Level and Trace Status for the whole DLT application should be set from within the DLT application. +It contains the following information: + +* The application id +* The Log Level to be set for the whole application +* The Trace Status to be set for the whole application + +==== User Message: Log Level + +If the log level or trace status is changed, or initialized, this message is send from the DLT daemon to the DLT user library to store the current log level and trace status for filtering in the DLT user library. + +It contains the following information: + +* The new set log level +* New set trace status. +* Each created context is stored with its associated information in a dynamically growing array in the DLT user library. The index in this array is send. + +==== User Message: Injection + +This message is send from the DLT daemon to the DLT user library, if an injection message was received by the DLT daemon from a DLT client. Via the context, the appropriate application and its named pipe can be identified. The injection message is then passed to this named pipe. + +It contains the following information: + +* Each created context is stored with its associated information in a dynamically growing array in the DLT user library. The index in this array is send. +* Service ID of the injection message +* Length of the following injection message +* The contents of the injection message + +=== DLT daemon: User message handling + +Following things occur for the received DLT user messages: + +* DLT_USER_MESSAGE_REGISTER_APPLICATION +** Add all information about application to a local application array (dynamically growing in a predefined step size (DLT_DAEMON_APPL_ALLOC_SIZE, typically 500)). The array is always being kept sorted (via qsort()). Finding entries in this array is done by a binary search (via bsearch()). +** Open named pipe to DLT application using the DLT user library with process id . The name of the pipe is /tmp/dlt +* DLT_USER_MESSAGE_UNREGISTER_APPLICATION +** Remove all information about this application from local application array, and remove all information of all contexts belonging to this application from local context array. The arrays are always being kept sorted, without empty entries in between. Dynamically shrinking of this array is NOT implemented. +* DLT_USER_MESSAGE_REGISTER_CONTEXT +** Add all information about context to local context array (dynamically growing in a predefined step size (DLT_DAEMON_CONTEXT_ALLOC_SIZE, typically 1000)). The array is always being kept sorted (via qsort()). Finding entries in this array is done by a binary search (via bsearch()). +** Send log level and trace status to DLT user library for this context. Therefore, the DLT_USER_MESSAGE_LOG_LEVEL is used. +** Create and send DLT control message response "get log info" for this application and context to all connected DLT clients, if requested (-r option during startup of DLT daemon). +* DLT_USER_MESSAGE_UNREGISTER_CONTEXT +** Remove all information about this context from local context array. The array is always being kept sorted, without empty entries in between. Dynamically shrinking of this array is NOT implemented. +* DLT_USER_MESSAGE_OVERFLOW +** Set internal flag for overflow. +** Create and send DLT control message response overflow to all connected TCP connections, and optionally to serial device, if connected. If the message was sent, reset the internal flag for overflow. +* DLT_USER_MESSAGE_LOG +** Overwrite ECU id, if requested +** Set storage header +** Check for filters of message, if no filter is set, or filter is matching: +*** Possibly display message as specified in the options. +**** Whole message display in hex +**** Whole message display in ASCII +**** Show message headers only +*** Store message to output file +*** Set serial header in front of message, if specified. +*** Create and try to send DLT message to all DLT clients connected via TCP connection, and optionally via serial device. +*** If the message could not be sent, store the message to a local ring buffer. The ring buffer internally uses a variable length for the buffered elements, and therefore uses the memory available for the buffer the best way possible. If the buffer is full, the oldest messages are silently discarded, until there is enough space for the message to be stored in the ring buffer. +* DLT_USER_MESSAGE_APP_LL_TS +** For all contexts belonging to the specified application: +*** Set specified log level +*** Set specified trace status +*** Send specified log level and trace status to DLT client library + +=== DLT daemon: Control message handling + +If the DLT daemon receives a control message request from a DLT client, it handles it in the following way. First the service id of the message is detected, and if it is no injection message, the following things occur: + +* DLT_SERVICE_ID_SET_LOG_LEVEL +** Check if received log level is other then already set log level. If yes: +*** Store new log level to local array. +*** Send new log level to DLT user library for this context. Therefore, the DLT_USER_MESSAGE_LOG_LEVEL is used. +** Send DLT control response to DLT client, with status of operation. +* DLT_SERVICE_ID_SET_TRACE_STATUS +** Check if received trace status is other then already set trace status. If yes: +*** Store new trace status to local array. +*** Send new trace status to DLT user library for this context. Therefore, the DLT_USER_MESSAGE_LOG_LEVEL is used. +** Send DLT control response to DLT client, with status of operation. +* DLT_SERVICE_ID_GET_LOG_INFO +** Create answer message for DLT control response. All kinds of requests are supported: +*** Application/Context: +**** All applications and all contexts +**** One application and all of its contexts +**** One application with one context. +*** Request type (as specified in the AUTOSAR DLT Standard, 1 and 2 are not specified): +**** 3: Application ID, Context ID +**** 4: Application ID, Context ID, Log Level +**** 5: Application ID, Context ID, Trace Status +**** 6: Application ID, Context ID, Log Level, Trace Status +**** 7: Application ID, Context ID, Log Level, Trace Status, Description +** Answer is of the corresponding type 3-7, or of type 8 (no matching context ids found), or of type 2 (error). +** Send DLT control response answer to DLT client. +* DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL +** Send DLT control response with default log level to DLT client. +* DLT_SERVICE_ID_STORE_CONFIG +** Store configuration files with currently registered application ids and context ids as well as currently set log levels and trace statuses to configuration files. If these files exists, they will be read in when the DLT daemon is started next time. +** Send DLT control response to DLT client. +* DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT +** Delete the stored configuration files, if they exists. +** Set default log level and trace status to initial values, and inform all applications using the default log level and trace status about the new defaults. +** Send DLT control response to DLT client. +* DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_SET_VERBOSE_MODE +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_SET_MESSAGE_FILTERING +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_SET_TIMING_PACKETS +** Set flag to start/stop sending of timing messages in thread. +** Send DLT control response to DLT client. +* DLT_SERVICE_ID_GET_LOCAL_TIME +** Send DLT control response with local time to DLT client. +* DLT_SERVICE_ID_USE_ECU_ID +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_USE_SESSION_ID +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_USE_TIMESTAMP +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_USE_EXTENDED_HEADER +** Send DLT control response "Not supported" to DLT client +* DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL +** Check if received default log level is other than already stored default log level. If yes: +*** Store new default log level to internal structure. +*** Send a DLT_USER_MESSAGE_LOG_LEVEL to all DLT clients containing the new default log level, which uses a context which is set to default log level. +** Send DLT control response to DLT client, with status of operation. +* DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS +** Check if received default trace status is other than already stored default trace status. If yes: +*** Store new default trace status to internal structure. +*** Send a DLT_USER_MESSAGE_LOG_LEVEL to all DLT clients containing the new default trace status, which uses a context which is set to default trace status. +** Send DLT control response to DLT client, with status of operation. +* DLT_SERVICE_ID_GET_SOFTWARE_VERSION +** Send DLT control response containing a software version string to DLT Client. +** The software version string contains: +*** the package version of the package dltv2, e.g. "2.0.0" +*** the package status of the package dltv2, e.g. "alpha, beta, final" +*** the overall subversion revision number for the package dltv2, e.g. "2300" +* DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW +** Try to send DLT control response containing the status of the internal flag for overflow. If the message could be send, reset the internal flag for overflow. + +For handling of the injection message, the following steps occur: + +* Create new user message DLT_USER_MESSAGE_INJECTION from received DLT control request message, and send this user message to the DLT application using the DLT user library. + +=== Mapping to files + +Here is a description, how the whole project is structured and which files exists. +The following table shows a top level view of the available Git repositories: + +[options="header"] +|============================================================================================== +| Directory | Description +| dlt | DLT Daemon and Library implementation; command line utilities, examples and test programs +| dlt_viewer | DLT Client GUI (DLT Viewer): QT based implementation +|============================================================================================== + +As this document has the focus on the DLT Daemon and the DLT user library, only the "dlt" directory is introduced in more detail: + +[options="header"] +|============================================================================================== +| Directory | Description +| doc | Documentation +| include | Include files, installed on target +| package | Packaging support files +| src | Source Code +| src/shared | Shared source code (between DLT daemon and DLT user library) +| src/adaptor | Adaptors to DLT daemon:dlt-adaptor-stdin (for connection over stdin) dlt-adaptor-udp (for connection over UDP) +| src/console | Console utilities: dlt-receive, dlt-convert, and dlt-sortbytimestamp +| src/daemon | DLT Daemon +| src/example | Examples for usage of the DLT user library:dlt-example-user (Macro IF) anddlt-example-user-func (Function IF) andwintestclient (MS Windows based test client) +| src/lib | DLT library functions +| src/tests | Test programs:dlt-test-client and dlt-test-user for automatic tests, dlt-test-stress for stress tests, dlt-test-internal for internal tests +| src/winclientlib | MS Windows implementation of a client library +| testscripts | Several supporting scripts +|============================================================================================== + +The DLT daemon implementation uses the following files, besides DLT functions from files from the shared directory: + +[options="header"] +|============================================================================================== +| File | Description +| dlt-daemon.c | DLT daemon implementation +| dlt-daemon.h | Header file for dlt-daemon.c +| dlt-daemon_cfg.h | Compile time configuration for DLT daemon, Part1 +| dlt_daemon_common.c | Supporting functions for a DLT daemon implementation +| dlt_daemon_common.h | Header file for dlt_daemon_common.c +| dlt_daemon_common_cfg.h | Compile time configuration for DLT daemon, Part2 +|============================================================================================== + +The DLT user library contains the following files: + +[options="header"] +|============================================================================================== +| File | Description +| dlt_user.c | Implementation of functions, available via the DLT user library interface. +| dlt_user_cfg.h | Compile time configuration for dlt_user.c +| dlt_client.c | Functions required for DLT Client implementations +| dlt_client_cfg.h | Compile time configuration for dlt_client.c +|============================================================================================== + +The shared directory contains the following files: + +[options="header"] +|============================================================================================== +| File | Description +| dlt_common.c | Common helper functions, such as: +- Print functions for DLT messages +- Functions for handling DLT Ids +- Filter functions +- DLT message handling functions +- Functions for handling DLT files +- DLT receiver functions +- Log handling +- Ringbuffer functions +- Setting and checking of storage header +| dlt_common_cfg.h | Compile time configuration for dlt_common.c +| dlt_user_shared.c | Shared functions, required by the DLT daemon and the DLT user library, such as: +- Setting and checking the user header +- Sending DLT messages over named pipes (FIFOs) +| dlt_user_shared.h | Header file for dlt_user_shared.c +| dlt_user_shared_cfg.h | Compile time configuration for dlt_user_shared.c +|============================================================================================== + +The public available include directory contains the following header files: + +|============================================================================================== +| File | Description +| dlt.h | Overall include file, includes dlt_common.h and dlt_user.h +| dlt_common.h | Include file for dlt_common.c +| dlt_user.h | Include file for dlt_user.c, contains the "User API" functions +| dlt_user_macros.h | Include file for dlt_user.c, contains the "User API" macros +| dlt_client.h | Include file for dlt_client.c +| dlt_protocol.h | DLT protocol specfic definitions and macros +| dlt_types.h | Definition of types, must be adapted to the target architecture and compiler toolchain. +|============================================================================================== + +=== Description of used structures in implementation + +The following important structures are used in the DLT Daemon and DLT User Library: + +[options="header"] +|============================================================================================== +| Structure | Description +| DltDaemonFlags | Flags and values, set over command line during start-up of DLT daemon +| DltDaemonLocal | Global variables of the DLT Daemon, grouped together in a struct +| DltDaemon | Parameters of the DLT daemon +| DltDaemonApplication | Parameters of an application, used within DLT daemon +| DltDaemonContext | Parameters of a context, used within DLT daemon +| DltUserControlMsg... | User control messages +| DltContext | Each context is represented with this structure +| DltContextData | Temorary used structure for constructing a log message +| DltUserInjectionCallback | One entry in dynamic callback table for callback function +| dlt_ll_ts_type | Table managing all contexts (and loglevels and trce statuses) within DLT user library, contains dynamicly growing array with "DltUserInjectionCallback" entries +| DltUser | Parameters for DLT user library application, contains dynamically growing array with "dlt_ll_ts_type" entries +| DltStorageHeader | Storage header +| DltStandardHeader | Structure for standard header of a DLT message | +| DltStandardHeaderExtra | Structure for standard header extra fields of a DLT message +| DltExtendedHeader | Structure for extended header of a DLT message +| DltService... | Structures for control messages (requests and responses) +| DltFilter | Structure to store filter parameters +| DltMessage | Structure to organize a DLT message, includes pointers to DltStorageHeader, DltStandardHeader, DltStandardHeaderExtra, and DltExtendedHeader, data of message is stored within a private buffer within this structure +| DltFile | Structure to organize access to a DLT File +| DltReceiver | Structure to organize the receiving of data +| DltRingbuffer | Structure to organize a ring buffer +|============================================================================================== + +==== Implementation specifics + +* The following preconditions were given prior to implementation: +** C-only implementation for the DLT daemon and the DLT user library +** Implementation of common functions, which can be used in a command line utility as well as in an Graphical UI +** Implementation of C+\+ like classes in C, see dlt_common.c and dlt_common.h +* The current implementation of the DLT daemon and DLT user library is only tested with gcc under Ubuntu 16.04 on Intel HW. +* It is assumed that packed structs are always stored in memory in the order specified within the packed struct. +* The implementation is multithread safe. +* Initialize DLT application and contexts, then forking and using the forked process, will lead to unclear behavior (or in worst case to a crash), as the forked process uses another process id as the parent process. Instead, initialize the DLT application and contexts in the forked process. +* Calling of DLT logging and tracing functions within a callback function for injections is not supported, and will lead to an unclear behavior. + diff -Nru dlt-daemon-2.18.9/doc/dlt_example_user.md dlt-daemon-2.18.4/doc/dlt_example_user.md --- dlt-daemon-2.18.9/doc/dlt_example_user.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_example_user.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,114 +0,0 @@ -% DLT-EXAMPLE-USER(1) - -# NAME - -**dlt-example-user** - Console based application for sending a custom dlt message - -# SYNOPSIS - -**dlt-example-user** \[**-h**\] \[**-g**\] \[**-a**\] \[**-k**\] \[**-d** delay\] \[**-f** filename\] \[**-S** filesize\] \[**-n** count\] \[**-m** mode\] \[**-l** level\] \[**-A** appID\] \[**-C** contextID\] \[**-t** timeout\] \[**-s** size\] message - -# DESCRIPTION - -Sends the given message as DLT messages to DLT daemon or prints the raw DLT messages into a local file. - -## OPTIONS - --h - -: Display a short help text. - --g - -: Switch to non-verbose mode (Default: verbose mode). - --a - -: Enable local printing of DLT messages (Default: disabled). - --k - -: Send marker message. - --d - -: Milliseconds to wait between sending messages (Default: 500). - --f - -: Use local log file instead of sending to daemon. - --S - -: Set maximum size of local log file (Default: UINT\_MAX). - --n - -: Number of messages to be generated (Default: 10). - --m - -: Set log mode 0=off, 1=external, 2=internal, 3=both. - --l - -: Set log level, level=-1..6 (Default: 3). - --A - -: Set app ID for send message (Default: LOG). - --C - -: Set context ID for send message (Default: TEST). - --t - -: Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec). - --r - -: Send raw data with specified size instead of string. - - -# EXAMPLES - -Send "HelloWorld" with default settings (10 times, every 0.5 seconds) as DLT message to dlt-daemon:: - - dlt-example-user HelloWorld - -Set app ID to `APP1`, context Id to `TEST` and log level to `error` for send message:: - - dlt-example-user -l 2 -A APP1 -C TEST HelloWorld - -Send 100 DLT messages every second:: - - dlt-example-user -n 100 -d 1000 HelloWorld - -Send "HelloWorld" can log to local file with maximum size 1000 bytes:: - - dlt-example-user -f helloworld.dlt -S 1000 HelloWorld - -# EXIT STATUS - -Non zero is returned in case of failure. - -# Notes - -The default descriptions for application and context registration are used irrespective of the IDs that could be set. App will always register with "Test Application for Logging" and context with "Test Context for Logging". - -# AUTHOR - -Darian Biastoch (dbiastoch@de.adit-jv.com) - -# COPYRIGHT - -Copyright (C) 2020 ADIT GmbH. License MPL-2.0: Mozilla Public License version 2.0 . - -# BUGS - -See Github issue: - -# SEE ALSO - -**dlt-daemon(1)** diff -Nru dlt-daemon-2.18.9/doc/dlt_extended_network_trace.md dlt-daemon-2.18.4/doc/dlt_extended_network_trace.md --- dlt-daemon-2.18.9/doc/dlt_extended_network_trace.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_extended_network_trace.md 2019-09-03 08:28:13.000000000 +0000 @@ -5,13 +5,7 @@ ## Introduction The extended network trace allows the user to send or truncate network trace -messages that are larger than the normal maximum size of a DLT message. This -interface will be enabled if following calls are supported on the target: -- mq\_open -- mq\_close -- mq\_unlink -- mq\_send -- mq\_receive +messages that are larger than the normal maximum size of a DLT message. ## Protocol diff -Nru dlt-daemon-2.18.9/doc/dlt_for_developers.md dlt-daemon-2.18.4/doc/dlt_for_developers.md --- dlt-daemon-2.18.9/doc/dlt_for_developers.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_for_developers.md 2019-09-03 08:28:13.000000000 +0000 @@ -3,13 +3,14 @@ Back to [README.md](../README.md) Table of Contents -1. [DLT Example Application](#DLT-Example-Application) -2. [General Rules for Logging](#General-Rules-for-Logging) -3. [The use of Log Levels](#The-use-of-Log-Levels) -4. [DLT Library Runtime Configuration](#DLT-Library-Runtime-Configuration) -5. [DLT API Usage](#DLT-API-Usage) -6. [DLT injection messages](#DLT-Injection-Messages) -7. [Log level changed callback](#Log-level-changed-callback) +1. [Summary](#Summary) +2. [Example Application](#DLT-Example-Application) +3. [General Rules for Logging](#General-Rules-for-Logging) +4. [The use of Log Levels](#The-use-of-Log-Levels) +5. [DLT Library Runtime Configuration](#DLT-Library-Runtime-Configuration) +6. [DLT API Usage](#DLT-API-Usage) +7. [DLT injection messages](#DLT-Injection-Messages) +8. [Log level changed callback](#Log-level-changed-callback) ## DLT Example Application @@ -61,66 +62,14 @@ application have to be unregistered. ### DLT with cmake - -To use DLT with CMake, the recommended way is to use the CMake Config file -that is being generated as part of installation. - -You can thus: -``` -find_package(automotive-dlt REQUIRED) -... -target_link_libraries(myapp PRIVATE Genivi::dlt) -``` -which lets your project automatically gain all necessary compile and link flags -needed by libdlt, including the include directories. - -The generated CMake Config file follows "Modern CMake" convention and only -exports an IMPORTED CMake target; it does not set any variables, except for the -`automotive-dlt_FOUND` variable that can be used to treat DLT as an optional -dependency. - -The generated CMake config file (which is implicitly being used when you call -`find_package(automotive-dlt)`) by default only adds the top-level directory -to the compiler's header search path; this requires that users' #include -directives are written in the regular form e.g. ``. If you want -to be able to use the legacy form `` as well (as is always allowed by -the pkg-config module for backwards compatibility reasons), you can configure -DLT with the CMake option `-DWITH_LEGACY_INCLUDE_PATH=On` in order to -achieve that. - -### DLT with pkg-config - -Alternatively to the CMake integration detailed above, it is also possible -to use DLT via pkg-config. This can also be done with CMake's PkgConfig -module as well. - -#### PkgConfig usage with "Modern CMake" - -Here, you let the PkgConfig module create targets as well; the target's name -is however determined by the PkgConfig module: - -``` -find_package(PkgConfig) -pkg_check_modules(DLT REQUIRED IMPORTED_TARGET automotive-dlt) -``` - -As per "Modern CMake", there are again no variables to be added, but only -a CMake target to be added to the link libraries: - -``` -target_link_libraries(myapp PRIVATE PkgConfig::DLT) -``` - -#### PkgConfig usage with "Legacy CMake" (<3.0) - -Here, you let the PkgConfig module only create variables, but not targets: +To use DLT with cmake, the following lines are the important ones: ``` find_package(PkgConfig) pkg_check_modules(DLT REQUIRED automotive-dlt) ``` -to INCLUDE\_DIRECTORIES (or, since CMake 2.8.11, TARGET\_INCLUDE\_DIRECTORIES), add +to INCLUDE\_DIRECTORIES, add ``` ${DLT_INCLUDE_DIRS} @@ -129,28 +78,9 @@ and to TARGET\_LINK\_LIBRARIES: ``` -${DLT_LINK_LIBRARIES} (preferred, for CMake >= 3.12) -${DLT_LIBRARIES} (otherwise) -``` - -The contents of `${DLT_LIBRARIES}` do not include the library's path -(e.g. `-L/path/to/lib`), so if the library resides in a location that is not -on the linker's default search path, you'll either have to add that path -to LINK\_DIRECTORIES: -``` -link_directories(${DLT_LIBRARY_DIRS}) -``` -or, alternatively, not use `${DLT_LIBRARIES}`, but `${DLT_LDFLAGS}` instead, -which combines `${DLT_LIBRARIES}` and `${DLT_LIBRARY_DIRS}`: -``` -target_link_libraries(myapp ${DLT_LDFLAGS}) +${DLT_LIBRARIES} ``` -### Limitation - -On Android, definition of `SIGUSR1` in DLT application shall be avoided since -DLT library blocks `SIGUSR1` to terminate housekeeper thread at exit. - ## General Rules for Logging ### Be Smart @@ -158,9 +88,9 @@ Before implementing logging in code one should take a second to think about a concept first. Often strategic places in the software can be used as a central place for logging. Such places are often interfaces to other SW components. Use -the solution with the smallest impact. Avoid logging the "good cases" but log +the solution with the smallest impact. Avoid logging the “good cases” but log e.g. in your error handling sections – you will need error handling anyway. In -case an error occurred more logs don't matter as long as your regular code +case an error occurred more logs don’t matter as long as your regular code produces little logs. Keep in mind that tracing comes with a price tag – you are working in an embedded environment where CPU, memory and Bandwidth are sparse. @@ -183,7 +113,7 @@ data, especially when log messages are processed by scripts. Such scripts often use regular expressions – make the job easier! -For example don't write log entries like this: +For example don’t write log entries like this: > Total frames: 1000 > @@ -201,8 +131,8 @@ ### Do not use ASCII-art -Information should be "on your fingertips". Logging is a tool to ease crushing -bugs, not to win a computer art contest. → Don't use ASCII Art! +Information should be “on your fingertips”. Logging is a tool to ease crushing +bugs, not to win a computer art contest. → Don’t use ASCII Art! ### Do not create charts using ASCII @@ -226,8 +156,7 @@ Good example: ``` -int index = 0; -for(; index export DLT\_INITIAL\_LOG\_LEVEL="EXA1:CON1:5;EXA1:CON2:6" - -If the log level of all applications and contexts shall be initialized, then: - -> export DLT\_INITIAL\_LOG\_LEVEL="::2" - -If the log level for all contexts of application "EXA1" shall be initialized, then: - -> export DLT\_INITIAL\_LOG\_LEVEL="EXA1::2" - -If the log level of context "CON1" shall be initialized, then: - -> export DLT\_INITIAL\_LOG\_LEVEL=":CON1:2" - -In case only the log level of context "CON1" of application "EXA1" shall be -initialized, and other contexts will be ignored, then: - -> export DLT\_INITIAL\_LOG\_LEVEL="::0;EXA1:CON1:2" - -2. If DLT\_INITIAL\_LOG\_LEVEL variable is not exported in the environment, -log level for it each context can be changed in the config file (/etc/dlt.conf). - -Default log level will be 4 (DLT\_LOG\_INFO) - -> ContextLogLevel = 4 - -3. DLT user can use dlt\_register\_context\_ll\_ts() api to initialize log -level for each context. - -Example: -> //Register new context to daemon, with initial log level is DLT\_LOG\_VERBOSE -> -> dlt\_register\_context\_ll\_ts(&con\_exa1, "CON", "First context", DLT\_LOG\_VERBOSE, DLT\_TRACE\_STATUS\_OFF); - -The priority of context log level would be as follows: -- Priority 1: Using dlt\_register\_context\_ll\_ts() api -- Priority 2: Using environment variable DLT\_INITIAL\_LOG\_LEVEL -- Priority 3: Setting in config file dlt.conf +> export DLT\_INITIAL\_LOG\_LEVEL=”EXA1:CON1:5;EXA1:CON2:6” ### Local print mode @@ -502,25 +393,6 @@ immediately after registering. Typically this is not a problem, but may arise especially with simple examples. -### Get application ID - -To get the application ID value, requested to allocate a char array at least -4 byte length and input to the function call. - -The application ID will be stored in this input char array. - -#### MACRO - -``` -DLT_GET_APPID(appid); -``` - -#### Function - -``` -dlt_get_appid(appid); -``` - ### Define and register all logging contexts As many contexts as needed can be defined. These contexts can be declared as @@ -591,14 +463,9 @@ ### Logging command -DLT provides functions that allow for flexible construction of messages -with an arbitrary number of arguments. Both Verbose and Non-Verbose -messages are supported, with different APIs. Sending a message using -these functions require multiple function calls, for starting message -construction, adding the arguments, and sending off the message. - -The following table shows an example of all 4 types for logging -using a constant string and an integer. +DLT provides functions and macros for logging, whereas the interface for +Verbose and Non-Verbose differs. The following table shows an example of all 4 +types for logging using a constant string and an integer. #### Verbose vs. Non-Verbose API @@ -642,180 +509,32 @@ } ``` -#### Statefulness of Verbose/Non-Verbose - -The library uses a global state that applies to all logging commands being used. -If the library is in global "Verbose" mode, both the "Verbose" and the "Non-Verbose" -API calls shown above will always result in Verbose messages being sent. - -However, if the library is in global "Non-Verbose" mode, it is possible to send -both Verbose and Non-Verbose messages in a single session; all "Verbose" APIs will -send Verbose messages, and all "Non-Verbose" APIs will send Non-Verbose messages. - -It does not make sense to send a Non-Verbose message via a Verbose API, as there -is then no sensible message ID, which is however mandatory when sending -Non-Verbose messages. - -#### Switching Verbose and Non-Verbose - -To switch Verbose/Non-Verbose mode (Verbose mode is default), the following -APIs are available: - -##### MACRO +Drawback of that solution is that the developer has to decide during +development if Verbose or Non-Verbose mode shall be used and the code most +likely ends up as written in the dlt-example-user application: ``` -DLT_VERBOSE_MODE(); -DLT_NONVERBOSE_MODE(); -``` - -##### Function - -``` -dlt_verbose_mode(); -dlt_nonverbose_mode(); -``` - -#### String arguments - -For string arguments, you can choose between ASCII and UTF-8 encoding. This -encoding is written into the argument header, so that the receiver knows what to -expect when parsing the message. - -In addition, you can also choose between null-terminated strings and (potentially) -non-null-terminated ones. -The latter often arise in C++ code when using classes such as std::string\_view, -which does not provide an accessor method that returns a null-terminated C-string. -Copying data out of a std::string\_view thus requires to copy only the desired -number of characters. - -For instance, using Verbose mode: - -``` -std::string_view line = "Name: Ford Prefect"; -std::string_view key = line.substr(0, 4); -std::string_view value = line.substr(6); - -if (dlt_user_log_write_start_id(&ctx, &ctxdata, DLT_LOG_INFO, 42) > 0) { - dlt_user_log_write_constant_utf8_string(&myctxdata, "key"); - dlt_user_log_write_sized_utf8_string(&myctxdata, key.data(), key.size()); - dlt_user_log_write_constant_utf8_string(&myctxdata, "value"); - dlt_user_log_write_sized_utf8_string(&myctxdata, value.data(), value.size()); - dlt_user_log_write_finish(&myctxdata); -} -``` - -#### Using custom timestamps - -The timestamp that is transmitted in the header of a DLT message is usually generated automatically by the library itself right before the message is sent. If you wish to change this, e.g. because you want to indicate when an event occured, rather than when the according message was assembled, you can supply a custom timestamp. Compared to the example above, two macros are defined for convenience: - -``` -uint32_t timestamp = 1234567; /* uptime in 0.1 milliseconds */ if (gflag) { /* Non-verbose mode */ - DLT_LOG_ID_TS(ctx, DLT_LOG_INFO, 42, timestamp, - DLT_INT(num), DLT_STRING(text)); + DLT_LOG_ID(ctx, DLT_LOG_INFO, 42 /* unique msg ID */, DLT_INT(num), + DLT_STRING(text)); } else { /* Verbose mode */ - DLT_LOG_TS(ctx, DLT_LOG_INFO, timestamp, - DLT_INT(num), DLT_STRING(text)); -} -``` - -If you wish to (or have to) use the function interface, you need to set the flag to make use of the user-supplied timestamp manually after calling dlt_user_log_write_start(): - - -``` -if (dlt_user_log_write_start(&ctx, &ctxdata, DLT_LOG_INFO) > 0) { - ctxdata.use_timestamp = DLT_USER_TIMESTAMP; - ctxdata.user_timestamp = (uint32_t) 1234567; - dlt_user_log_write_string(&myctxdata, "ID: "); - dlt_user_log_write_uint32(&myctxdata, 123); - dlt_user_log_write_finish(&myctxdata); + DLT_LOG(ctx, DLT_LOG_INFO, DLT_INT(num), DLT_STRING(text)); } ``` -#### Send log message with given buffer - -DLT applications can prepare a log message buffer by themselves instead -of calling logging parameters. There are two benefits; the applications -can reduce API calls to DLT library as much as possible so that the -APIs won't block the application's sequence, and dynamic allocation can -be avoided in DLT library during runtime. - -The applications should prepare following values in order to use this -functionality: - -- *char buffer[DLT_USER_BUF_MAX_SIZE]*: Buffer which contains one log message payload -- *size_t size*: Buffer size -- *int32_t args_num*: Number of arguments - -One argument in the buffer consists of following: -| Length(byte) | Description | -|----------------|--------------| -| 4 | Type Info | -| x | Data Payload | +##### Switching Verbose and Non-Verbose -DLT Applications need to simulate what are done in logging parameters to -store data to the buffer (type info given to the buffer, etc.), -otherwise the behavior is undefined. - -Also important note here is that the functionality works properly only -with these function combination: - -- *Start logging*: dlt\_user\_log\_write\_start\_w\_given\_buffer -- *Finish logging*: dlt\_user\_log\_write\_finish\_w\_given\_buffer - -Since the function does not allocate memory dynamically, it could lead -to segmentation fault or memory leak with different APIs. It is mandatory -to check if dlt_user_is_logLevel_enabled is returning DLT_RETURN_TRUE before -calling dlt_user_log_write_start_w_given_buffer (see below code example). - -##### Macro - -No macro interface is available as of now. - -##### Function - -``` -/* Example: Prepare one log message with uint16 */ -char buffer[DLT_USER_BUF_MAX_SIZE] = {0}; -size_t size = 0; -int32_t args_num = 0; - -uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; -memcpy(buffer + size, &(type_info), sizeof(uint32_t)); -size += sizeof(uint32_t); - -uint16_t data = 1234; -memcpy(buffer + size, &data, sizeof(uint16_t)); -size += sizeof(uint16_t); - -args_num++; - -/* Give the buffer to DLT library */ -if (dlt_user_is_logLevel_enabled(&ctx,DLT_LOG_INFO) == DLT_RETURN_TRUE) -{ - if (dlt_user_log_write_start_w_given_buffer(&ctx, &ctxdata, DLT_LOG_INFO, buffersize, args_num) > 0) - { - dlt_user_log_write_finish_w_given_buffer(&ctxdata); - } -} -``` - -#### Attributes - -In verbose mode, log message arguments can contain attributes. A "name" attribute -describes the purpose or semantics of an argument, and a "unit" attribute -describes its unit (if applicable - not all argument data types support having -a "unit" attribute). +To switch Verbose/Non-Verbose mode (Verbose mode is default), the following +APIs are available: ``` -dlt_user_log_write_float64_attr(&myctxdata, 4.2, "speed", "m/s"); +DLT_VERBOSE_MODE(); +DLT_NONVERBOSE_MODE(); ``` -In non-verbose mode, these attributes are not added to the message. - ### Logging parameters The following parameter types can be used. Multiple parameters can be added to @@ -825,45 +544,22 @@ Type | Description --- | --- DLT\_STRING(TEXT) | String -DLT\_STRING\_ATTR(TEXT,NAME) | String (with attribute) -DLT\_SIZED\_STRING(TEXT,LENGTH) | String with known length -DLT\_SIZED\_STRING\_ATTR(TEXT,LENGTH,NAME) | String with known length (with attribute) -DLT\_CSTRING(TEXT) | Constant string (not sent in non-verbose mode) -DLT\_CSTRING\_ATTR(TEXT,NAME) | Constant string (with attribute; not sent in non-verbose mode) -DLT\_SIZED\_CSTRING(TEXT,LENGTH) | Constant string with known length (not sent in non-verbose mode) -DLT\_SIZED\_CSTRING\_ATTR(TEXT,LENGTH,NAME) | Constant string with known length (with attribute; not sent in non-verbose mode) -DLT\_UTF8(TEXT) | Utf8-encoded string -DLT\_UTF8\_ATTR(TEXT,NAME) | Utf8-encoded string (with attribute) -DLT\_SIZED\_UTF8(TEXT,LENGTH) | Utf8-encoded string with known length -DLT\_SIZED\_UTF8\_ATTR(TEXT,LENGTH,NAME) | Utf8-encoded string with known length (with attribute) +DLT\_CSTRING(TEXT) | Constant String (not send in non-verbose mode) +DLT\_UTF8 | Utf8-encoded string DLT\_RAW(BUF,LENGTH) | Raw buffer -DLT\_RAW\_ATTR(BUF,LENGTH,NAME) | Raw buffer (with attribute) DLT\_INT(VAR) | Integer variable, dependent on platform -DLT\_INT\_ATTR(VAR,NAME,UNIT) | Integer variable, dependent on platform (with attributes) DLT\_INT8(VAR) |Integer 8 Bit variable -DLT\_INT8\_ATTR(VAR,NAME,UNIT) |Integer 8 Bit variable (with attributes) DLT\_INT16(VAR) | Integer 16 Bit variable -DLT\_INT16\_ATTR(VAR,NAME,UNIT) | Integer 16 Bit variable (with attributes) DLT\_INT32(VAR) | Integer 32 Bit variable -DLT\_INT32\_ATTR(VAR,NAME,UNIT) | Integer 32 Bit variable (with attributes) DLT\_INT64(VAR) | Integer 64 bit variable -DLT\_INT64\_ATTR(VAR,NAME,UNIT) | Integer 64 bit variable (with attributes) DLT\_UINT(VAR) | Unsigned integer variable -DLT\_UINT\_ATTR(VAR,NAME,UNIT) | Unsigned integer variable (with attributes) DLT\_UINT8(VAR) | Unsigned 8 Bit integer variable -DLT\_UINT8\_ATTR(VAR,NAME,UNIT) | Unsigned 8 Bit integer variable (with attributes) DLT\_UINT16(VAR) |Unsigned 16 Bit integer variable -DLT\_UINT16\_ATTR(VAR,NAME,UNIT) |Unsigned 16 Bit integer variable (with attributes) DLT\_UINT32(VAR) | Unsigned 32 Bit integer variable -DLT\_UINT32\_ATTR(VAR,NAME,UNIT) | Unsigned 32 Bit integer variable (with attributes) DLT\_UINT64(VAR) | Unsigned 64 bit integer variable -DLT\_UINT64\_ATTR(VAR,NAME,UNIT) | Unsigned 64 bit integer variable (with attributes) DLT\_BOOL(VAR) | Boolean variable -DLT\_BOOL\_ATTR(VAR,NAME) | Boolean variable (with attribute) DLT\_FLOAT32(VAR) | Float 32 Bit variable -DLT\_FLOAT32\_ATTR(VAR,NAME,UNIT) | Float 32 Bit variable (with attributes) DLT\_FLOAT64(VAR) | Float 64 Bit variable -DLT\_FLOAT64\_ATTR(VAR,NAME,UNIT) | Float 64 Bit variable (with attributes) DLT\_HEX8(UINT\_VAR) | 8 Bit hex value DLT\_HEX16(UINT\_VAR) | 16 Bit hex value DLT\_HEX32(UINT\_VAR) | 32 Bit hex value @@ -884,9 +580,6 @@ DLT_TRACE_NETWORK(mycontext, DLT_NW_TRACE_CAN, headerlen, header, payloadlen, payload); ``` -Note that when DLT_NETWORK_TRACE_ENABLE is disabled, the mqueue.h will not be -included. - ### DLT C++ Extension The DLT C++ extension was added to DLT in version 2.13. This approach solves @@ -976,7 +669,7 @@ ``` From DLT Viewer, an injection message can be sent by right-clicking the -corresponding context in the project view ("Send injection"). A dialog will pop +corresponding context in the project view (“Send injection”). A dialog will pop up to specify the injection data as shown below. ![alt text](images/dlt-viewer-send-injection-dialog.png "DLT Viewer Send Injection Callback") @@ -989,19 +682,3 @@ ``` DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(CONTEXT, CALLBACK) ``` -## Disable injection messages - -An environment variable named `DLT_DISABLE_INJECTION_MSG_AT_USER` could be used in case -dlt application wants to ignore all data/messages from dlt-daemon completely. - -To use: - -``` -export DLT_DISABLE_INJECTION_MSG_AT_USER=1 -``` - -To clear: - -``` -unset DLT_DISABLE_INJECTION_MSG_AT_USER -``` diff -Nru dlt-daemon-2.18.9/doc/dlt_gateway.conf.5.md dlt-daemon-2.18.4/doc/dlt_gateway.conf.5.md --- dlt-daemon-2.18.9/doc/dlt_gateway.conf.5.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_gateway.conf.5.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,119 +0,0 @@ -% DLT_GATEWAY.CONF(5) - -# NAME - -**dlt_gateway.conf** - DLT configuration file for gateway - -# DESCRIPTION - -The configuration file dlt_gateway.conf allows to configure the different runtime behaviour of gateway in Multinode feature. - -The configuration file is written in an INI file format and contains information about different connected passive nodes. - -If Multinode feature is enabled, dlt-daemon loads by default the configuration file /etc/dlt_gateway.conf. - -An alternative configuration file can be loaded by changing `GatewayConfigFile` in dlt.conf(5). - -# GENERAL SECTION - -### Interval - -Time interval for reconnection to passive Node in second. - - Default: 1 - -# PASSIVENODE SECTION - -Each passive node’s connection parameters are specified in a unique numbered separate section - -([PassiveNode{1,2, …N}]). - - Example: [PassiveNode1] - -### IPaddress - -Because TCP is the only supported communication channel, - -the IPaddress and Port of the Passive DLT Daemon has to be specified. - -IP Address of passive node. Mandatory - -### Port - -TCP port. Default 3490 is used if no port is specified. - - Default: 3490 - -### EcuID - -ECU identifier of passive node. Mandatory. - -### Connect - -With the Connect property it is possible to specify when the Gateway DLT Daemon -shall connect to the passive node. - - Default: OnStartUp - - The following values are allowed: - - OnStartup The Gateway DLT Daemon tries to connect to the Passive DLT Daemon - immediately after the Gateway DLT Daemon is started. - OnDemand The Gateway DLT Daemon tries to connect to the Passive DLT Daemon - when it receives a connection request. - -### Timeout - -Stop connecting to passive node, if not successful after 10 retries. - -After of retries, the connection to passive Node is marked as DISABLED. - -It means there is no any retry anymore. - -Set to 0 for endless retry. - - Default: 10 - -### SendControl - -Send following control messages after connection is established. Optional. - - Default: disabled - -Supported Control messages: - - DLT_SERVICE_ID_GET_LOG_INFO 0x03 - DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL 0x04 - DLT_SERVICE_ID_GET_SOFTWARE_VERSION 0x13 - -### SendSerialHeader - -Send Serial Header with control messages. Value in dlt.conf(5) is used as default if not specified. - - Default: disabled - -### SendPeriodicControl - -Send following control messages periodically. - - Default: disabled - -Format: - - control:interval[in seconds] - -# AUTHOR - -Thanh Bui Nguyen Quoc (thanh.buinguyenquoc (at) vn (dot) bosch (dot) vn) - -# COPYRIGHT - -Copyright (C) 2020 Advanced Driver Information Technology, Bosch and DENSO. License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - -# BUGS - -See Github issue: - -# SEE ALSO - -**dlt.conf(5)**, **dlt-daemon(1)** diff -Nru dlt-daemon-2.18.9/doc/dlt_glossary.md dlt-daemon-2.18.4/doc/dlt_glossary.md --- dlt-daemon-2.18.9/doc/dlt_glossary.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_glossary.md 2019-09-03 08:28:13.000000000 +0000 @@ -10,8 +10,6 @@ Context ID | This is a user defined ID to group log and trace messages produced by an application. Each Application ID can own several Context IDs and the Context IDs shall be unique within an Application ID. The identification of the source of a log and trace message is done with a pair of Application ID and Context ID. It is composed by four 8 bit ASCII characters. Control Message | A control message is send by a connected client application (e.g. Log Viewer) to the DLT Daemon that includes an action request. E.g. change the Log level of a certain application). DLT Daemon | The DLT Daemon is the central component which receives all logs and traces from the DLT user applications. The DLT Daemon forwards all logs and traces to a connected DLT client (e.g. Log Viewer) or stores them optionally in a file on the target. -DLT Library | Provides applications (esp. DLT users) with an API to produce DLT messages and to handle DLT Control Messages accordingly. -DLT User | A DLT User is a type of application that produces log messages. It typically uses the DLT library to produce the messages and resembles an ECU. DLT Viewer | The DLT Viewer is the GENIVI Log Viewer implementation. It is a Qt-based desktop application able to run on Windows and Linux operating systems. Further information and source code can be found here: https://github.com/GENIVI/dlt-viewer Gateway DLT Daemon | In a Multi-Node system, the DLT Daemon running on the Node directly connected to a Log Viewer is called Gateway DLT Daemon (if configured as Gateway). It forwards log messages from Passive DLT Daemons to Log Viewers and command/control messages from Log Viewer(s) to Passive DLT Daemon(s). Injection Message | An injection message is a control message for a specific DLT application. diff -Nru dlt-daemon-2.18.9/doc/dlt-logstorage-ctrl.1.md dlt-daemon-2.18.4/doc/dlt-logstorage-ctrl.1.md --- dlt-daemon-2.18.9/doc/dlt-logstorage-ctrl.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-logstorage-ctrl.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -38,14 +38,6 @@ : Specify connection timeout. Default is: 10s. --S - -: Send message with serial header (Default: Without serial header) - --R - -: Enable resync serial header - # EXAMPLES Activate the offline logstorage device mounted on /mnt/dltlog diff -Nru dlt-daemon-2.18.9/doc/dlt_multinode.md dlt-daemon-2.18.4/doc/dlt_multinode.md --- dlt-daemon-2.18.9/doc/dlt_multinode.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_multinode.md 2019-09-03 08:28:13.000000000 +0000 @@ -38,14 +38,10 @@ ### Gateway Configuration File -The MultiNode configuration file has to be loaded by the Gateway DLT Daemon during startup. - -Example: +The MultiNode configuration file has to be loaded by the Gateway DLT Daemon +during startup. ``` -[General] -Interval=1 - [PassiveNode1] ; IP Address. (Mandatory) IPaddress = 192.168.2.32 @@ -55,8 +51,7 @@ EcuID = ECU2 ; Connection to passive node only on demand. Default ‘OnStartup’ if not specified Connect = OnDemand -; Stop connecting to passive node, if not successful after 10 retries. -; Set to 0 for endless retry. +; timeout in seconds Timeout = 10 ; Send following control messages after connection is established SendControl=0x03, 0x13 @@ -65,7 +60,27 @@ SendSerialHeader=1 ``` -For more details, please refer to [dlt_gateway.conf.5.md](dlt_gateway.conf.5.md) +The configuration file is written in an INI file format and contains information +about different connected passive nodes. Each passive node’s connection +parameters are specified in a unique numbered separate section +([PassiveNode{1,2, …N}]). Because TCP is the only supported communication +channel, the IPaddress and Port of the Passive DLT Daemon has to be specified. + +With the Connect property it is possible to specify when the Gateway DLT Daemon +shall connect to the passive node. The following values are allowed: +- OnStartup - The Gateway DLT Daemon tries to connect to the Passive DLT Daemon + immediately after the Gateway DLT Daemon is started. +- OnDemand - The Gateway DLT Daemon tries to connect to the Passive DLT Daemon + when it receives a connection request. + +The Timeout property specifies the time after which the Gateway DLT Daemon stops +connecting attempts to a Passive DLT Daemon. If the connection is not +established within the specified time, the Gateway DLT Daemon gives up +connecting attempts and writes an error messages to its internal log. The +following control messages are supported to be send to a passive node +automatically after connection is established: +- 0x03: Get Log Info +- 0x13: Get Software Version ## Using DLT MultiNode @@ -79,7 +94,5 @@ -n passive Node identifier (e.g. ECU2) -s Show passive node(s) connection status -t Specify connection timeout (Default: 10s) - -S Send message with serial header (Default: Without serial header) - -R Enable resync serial header -v Set verbose flag (Default:0) ``` diff -Nru dlt-daemon-2.18.9/doc/dlt_offline_logstorage.md dlt-daemon-2.18.4/doc/dlt_offline_logstorage.md --- dlt-daemon-2.18.9/doc/dlt_offline_logstorage.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt_offline_logstorage.md 2019-09-03 08:28:13.000000000 +0000 @@ -79,10 +79,7 @@ The Parameter "SyncBehavior","EcuID" and "SpecificSize" are optional - all others are mandatory. -If both of the parameter "LogAppName" and "ContextName" are set to wildcard or -not present in the configuration file, "EcuID" must be specified. - -A typical configuration file may look like: +An configuration file might look like: ``` [FILTER1] @@ -115,44 +112,6 @@ EcuID=ECU1 ``` -In case of Non-Verbose mode, following filters should be used. - -``` -[NON-VERBOSE-STORAGE-FILTER] # filter configuration name for a Non-Verbose passive node -EcuID= # Specify ECU identifier -File= # Base name of the created files that containing the logs, e.g. "example". For further file naming scheme configurations see man dlt.conf -FileSize= # Maximum file size in bytes -NOFiles= # Number of created files before oldest is deleted and a new one is created - -[NON-VERBOSE-LOGLEVEL-CTRL] # filter configuration name to control log level of Non-Verbose applications -LogAppName= # Name of application (wildcard allowed) -ContextName= # Name of context (wildcard allowed) -LogLevel= # Define log level, e.g. DLT_LOG_INFO or DLT_LOG_FATAL -EcuID= # Specify ECU identifier -``` - -A typical configuration file may look like: - -``` -[NON-VERBOSE-STORAGE-FILTER1] -EcuID=PASV -File=scc -FileSize=50000 -NOFiles=5 - -[NON-VERBOSE-LOGLEVEL-CTRL1] -LogAppName=LOG -ContextName=TEST -LogLevel=DLT_LOG_DEBUG -EcuID=PASV - -[NON-VERBOSE-LOGLEVEL-CTRL2] -LogAppName=.* -ContextName=.* -LogLevel=DLT_LOG_WARN -EcuID=PASV -``` - ## Usage DLT Offline Logstorage @@ -198,8 +157,6 @@ -p Mount point path -s Sync Logstorage cache -t Specify connection timeout (Default: 10s) - -S Send message with serial header (Default: Without serial header) - -R Enable resync serial header -v Set verbose flag (Default:0) ``` @@ -272,27 +229,3 @@ Note : 1. Combinations (not allowed: combinations with ON_MSG,combination of ON\_FILE\_SIZE with ON\_SPECIFIC\_SIZE) 2. If on\_demand sync strategy alone is specified, it is advised to concatenate the log files in sequential order before viewing it on viewer. -3. In case multiple FILTERs use the same `File` value, it is recommened that the following settings must also have same values: `NOFiles`, `FileSize` and `SpecificSize` - -## Maintain Logstorage Log Level Implementation - -The log level setting of each user context in the logstorage FILTER will be -treated as the highest priority. Other clients (e.g: dlt-control, dlt-viewer) -can update the user context's log level to a lower level but can not update -to a higher level. In case the clients need to update the user context's log -level to a higher level, the new macro ```MaintainLogstorageLogLevel``` is -implemented in the ```[General]``` session to allow changing user context's -log level to any level or maintain the log level of logstorage configuration. - -A typical configuration file may look like: - - ``` - [General] - MaintainLogstorageLogLevel=OFF - ``` - -By setting ```MaintainLogstorageLogLevel=OFF``` or ```MaintainLogstorageLogLevel=0```, -the clients are able to update any log level to user contexts. - -By setting ```MaintainLogstorageLogLevel=ON``` or ```MaintainLogstorageLogLevel=1``` -or not set, the logstorage will maintain its log level as the highest priority. diff -Nru dlt-daemon-2.18.9/doc/dlt-passive-node-ctrl.1.md dlt-daemon-2.18.4/doc/dlt-passive-node-ctrl.1.md --- dlt-daemon-2.18.9/doc/dlt-passive-node-ctrl.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-passive-node-ctrl.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -34,14 +34,6 @@ : Specify connection timeout (Default: 10s) --S - -: Send message with serial header (Default: Without serial header) - --R - -: Enable resync serial header - -v : Set verbose flag (Default:0) diff -Nru dlt-daemon-2.18.9/doc/dlt-qnx-system.md dlt-daemon-2.18.4/doc/dlt-qnx-system.md --- dlt-daemon-2.18.9/doc/dlt-qnx-system.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-qnx-system.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,102 +0,0 @@ -# dlt-qnx-system - -QNX specific logging features of dlt are managed by the ```dlt-qnx-system``` process. -It currently contains the message forwarder from slogger2 to DLT. - -The application listens to the system logs on QNX (slogger2) and sends them to -DLT. The prerequisite is that dlt-daemon is already started and running. -dlt-qnx-system loads by default the configuration file ```/etc/dlt-qnx-system.conf```. - -> In order to catch all logs via slog2, the syslog needs to forward to slogger2 in [syslog.conf](http://www.qnx.com/developers/docs/7.0.0/index.html#com.qnx.doc.neutrino.utilities/topic/s/syslog.conf.html). - -To change the log level, use application ID and context ID set in configuration -file. ```DLT_INITIAL_LOG_LEVEL``` can be set on startup phase, or control -message can be sent from DLT client (e.g. dlt-control, DLT Viewer) at runtime. -Refer to [dlt_for_developers.md](dlt_for_developers.md) for more detail. - - -## Usage - -```bash -dlt-qnx-system [-h] [-d] [-c FILENAME] -``` - --h - -: Display a short help text. - --d - -: Daemonize. Detach from Terminal and run in background. - --c - -: Load an alternative configuration file. By default the configuration file - */etc/dlt-qnx-system.conf* is loaded. - - -Non zero is returned in case of failure. - - -## Configuration - -By default, the configuration is loaded from */etc/dlt-qnx-system.conf*. It -contains a few basic options: - -- *ApplicationId*: this QNX system log forwarder will have this application ID - and appear on DLT client. Default value is *QSYM*. -- *ApplicationContextID*: the context ID of the above application to appear on - DLT client. Default value is *QSYC*. -- *QnxSlogger2Enable*: when the value is 1 (by default), the QNX slogger2 - adapter which sends slogger2 to DLT will be started. Otherwise if the value - if 0, it won't be started. -- *QnxSlogger2ContextId*: this will set the context ID of the QNX slogger2 - adapter. Default value is *QSLA*. -- *QnxSlogger2UseOriginalTimestamp*: when the value is 1 (by default), slogger2 - event timestamps will be used as DLT timestamps. - - - -## Slogger2 adapter - -The slogger2 adapter that can be enabled in dlt-qnx-system attaches to slogger2 and converts the messages to dlt messages. - - -### Log level mapping - -As the severity levels on QNX system log are different from DLT Log Level, the below table shows how they're converted from the former to the latter. - - -| QNX System Log Level | DLT Log Level | -|----------------------|--------------------| -| SLOG2\_SHUTDOWN | DLT\_LOG\_FATAL | -| SLOG2\_CRITICAL | DLT\_LOG\_FATAL | -| SLOG2\_ERROR | DLT\_LOG\_ERROR | -| SLOG2\_WARNING | DLT\_LOG\_WARN | -| SLOG2\_NOTICE | DLT\_LOG\_INFO | -| SLOG2\_INFO | DLT\_LOG\_INFO | -| SLOG2\_DEBUG1 | DLT\_LOG\_DEBUG | -| SLOG2\_DEBUG2 | DLT\_LOG\_VERBOSE | - - -### Context Mapping - -The json file dlt-slog2ctxt.json can be used to map slogger names to dlt-contexts. - -#### Example - -Here is an example that sets a mapping from the "dumper" process to the DLT Context "DUMP", and the QNX Hypervisor to "QVM". -The description field is in the registration with libdlt. - -```python -{ - "DUMP": { - "name": "dumper", - "description": "Writes core dump files to disk" - }, - "SYSL": { - "name": "syslogd", - "description": "" - } -} -``` diff -Nru dlt-daemon-2.18.9/doc/dlt-receive.1.md dlt-daemon-2.18.4/doc/dlt-receive.1.md --- dlt-daemon-2.18.9/doc/dlt-receive.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-receive.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -6,7 +6,7 @@ # SYNOPSIS -**dlt-receive** \[**-h**\] \[**-a**\] \[**-x**\] \[**-m**\] \[**-s**\] \[**-o** filename\] \[**-c** limit\] \[**-v**\] \[**-y**\] \[**-b** baudrate\] \[**-e** ecuid\] \[**-f** filterfile\] \[**-j** filterfile\] \[**-p** port\] hostname/serial_device_name +**dlt-receive** \[**-h**\] \[**-a**\] \[**-x**\] \[**-m**\] \[**-s**\] \[**-o** filename\] \[**-c** limit\] \[**-v**\] \[**-y**\] \[**-b** baudrate\] \[**-e** ecuid\] \[**-f** filterfile\] hostname/serial_device_name # DESCRIPTION @@ -46,14 +46,6 @@ : Verbose mode. --S - -: Send message with serial header (Default: Without serial header) - --R - -: Enable resync serial header - -y : Serial device mode. @@ -68,15 +60,8 @@ -f -: Enable filtering of messages. Takes a space separated filter file (see [Space separated filter file](#Space-separated-filter-file)). +: Enable filtering of messages. --j - -: Enable extended filtering of messages. Takes a json filter file ([Json filter file](#Json-filter-file)). - --p - -: Port for UDP and TCP communication (Default: 3490). # EXAMPLES Print received message headers received from a dlt-daemon running on localhost:: @@ -91,41 +76,6 @@ Store incoming messages in file(s) and restrict file sizes to 1 megabyte. If limit is reached, log.dlt will be renamed into log.0.dlt, log.1.dlt, ... No files will be overwritten in this mode:: **dlt-receive -o log.dlt -c 1M localhost** -## Space separated filter file -File that defines multiple filters. Can be used as argument for `-f` option. With this it's only possible to filter messages depending on their Application ID and/or Context ID. The syntax is: first AppID and optional a CtxID behind it, with a space in between. Each line defines a filter and the maximum number of filters is 30. - -Example: -``` -DLTD INTM -DLT INT -TEST -``` - -## Json filter file -Only available, when builded with cmake option `WITH_EXTENDED_FILTERING`. - -File that defines multiple filters. Can be used as argument for `-j` option. With this it's also possible to filter messages depending on their Application ID, Context ID, log level and payload size. The following example shows the syntax. Names of the filters can be customized, but not more than 15 characters long. The maximum number of filters is also 30. - -Example: -``` -{ -"filter1": { - "AppId": "LOG", - "ContextId": "TEST", - "LogLevel": "3" - }, -"filter2": { - "AppId": "app", - "LogLevel": "4" - }, -"filter3": { - "AppId": "app2", - "ContextId": "con2", - "PayloadMin": "20", - "PayloadMax": "50" - } -} -``` # EXIT STATUS Non zero is returned in case of failure. diff -Nru dlt-daemon-2.18.9/doc/dlt-sortbytimestamp.1.md dlt-daemon-2.18.4/doc/dlt-sortbytimestamp.1.md --- dlt-daemon-2.18.9/doc/dlt-sortbytimestamp.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-sortbytimestamp.1.md 2019-09-03 08:28:13.000000000 +0000 @@ -2,7 +2,7 @@ # NAME -**dlt-sortbytimestamp** - Re-order DLT Logging files according to message creation time and timestamp. +**dlt-sortbytimestamp** - Re-order DLT Logging files according to message creation time # SYNOPSIS @@ -12,11 +12,13 @@ By default messages in DLT files are ordered according to the time the logger received them. This can unhelpful when tracing a sequence of events on a busy multi-threaded/multi-core system, because thread pre-emption combined with multiple processes attempting to log messages simultaneously means that the order in which the messages are received may vary significantly from the order in which they were created. -*dlt-sortbytimestamp* is able to re-order a DLT input file's messages according both their creation time and timestamp, and writes them to an output DLT file. +*dlt-sortbytimestamp* re-orders a DLT input file's messages according their creation timestamp, and writes them to an output DLT file. -# NOTE +# IMPORTANT NOTE -Use the \*-b\* and/or \*-e\* options to specify a range of messages within a single reboot cycle and all will be well. +Message timestamps are recorded relative to boot time. DLT files can contain messages from more than one reboot cycle. Because timestamping is reset to zero at each boot, simply running *dlt-sortbytimestamp* against a multi-boot-cycle DLT input file will produce a tangled mess. + +Use the *-b* and/or *-e* options to specify a range of messages within a single reboot cycle and all will be well. Hint: use *dlt-viewer* to ascertain the endpoints of the range in question. diff -Nru dlt-daemon-2.18.9/doc/dlt-system.conf.5.md dlt-daemon-2.18.4/doc/dlt-system.conf.5.md --- dlt-daemon-2.18.9/doc/dlt-system.conf.5.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/dlt-system.conf.5.md 2019-09-03 08:28:13.000000000 +0000 @@ -36,7 +36,7 @@ ## SyslogEnable -If this option is set to 1, the syslog adapter feature is enabled. SyslogPort needs to be configured too if Syslog is enabled. +If this option is set to 1, the syslog adapter feature is enabled. Default: 0 @@ -48,7 +48,7 @@ ## SyslogPort -This value defines the UDP port opened for receiving log messages from syslog. Configuration for syslog to forward log to this port is necessary. Adding this config `` *.* @localhost:47111 `` in config file of syslog (usually in /etc/rsyslog.d/50-default.conf) and restart the syslog service by command "sudo systemctl restart rsyslog.service". +This value defines the UDP port opened for receiving log messages from syslog. Default: 47111 @@ -114,6 +114,12 @@ Default: 0 +## FiletransferTimeDelay + +Time in seconds to wait between deletion of transferred file and start of next file transfer. + + Default: 10 + ## FiletransferTimeoutBetweenLogs Time in seconds to wait between two file transfer logs of a single file to DLT. Binary files /tmp/tmpd42071rz/3t7x5JdZTJ/dlt-daemon-2.18.9/doc/images/dlt_architecture.png and /tmp/tmpd42071rz/EkLYkosTTH/dlt-daemon-2.18.4/doc/images/dlt_architecture.png differ Binary files /tmp/tmpd42071rz/3t7x5JdZTJ/dlt-daemon-2.18.9/doc/images/dlt_overview.png and /tmp/tmpd42071rz/EkLYkosTTH/dlt-daemon-2.18.4/doc/images/dlt_overview.png differ diff -Nru dlt-daemon-2.18.9/doc/test/dlt-test-qnx-slogger.1.md dlt-daemon-2.18.4/doc/test/dlt-test-qnx-slogger.1.md --- dlt-daemon-2.18.9/doc/test/dlt-test-qnx-slogger.1.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/doc/test/dlt-test-qnx-slogger.1.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -% DLT-TEST-QNX-SLOGGER(1) - -# NAME - -**dlt-test-qnx-slogger** - Console based test application for sending messages -to QNX slogger - -# SYNOPSIS - -**dlt-test-qnx-slogger** \[**-h**\] \[**-n** count\] \[**-d** delay\] \[**-l** length\] - - -# DESCRIPTION - -The binary writes specific amount of messages to slogger2. This can be used to -test `dlt-qnx-system` ([dlt-qnx-system.md](dlt_qnx_system.md)). - -## OPTIONS - --h - -: Display a short help text. - --n - -: Number of messages to be generated (Default: 10). - --d - -: Milliseconds to wait between sending messages (Default: 500). - --l - -: Messages length (Default: 100 bytes). - -# Examples - -Send 100 messages every 1 second: - - dlt-test-qnx-slogger -n 100 -d 1000 - -# EXIT STATUS - -Non zero value is returned in case of failure. - -# AUTHOR - -Saya Sugiura (ssugiura@jp.adit-jv.com) - -# COPYRIGHT - -Copyright (C) 2021 ADIT GmbH. License MPL-2.0: Mozilla Public License version 2.0 . - -# BUGS - -See Github issue: - -# SEE ALSO - -**dlt-qnx-system.md(1)** diff -Nru dlt-daemon-2.18.9/.github/workflows/cmake-ctest.yml dlt-daemon-2.18.4/.github/workflows/cmake-ctest.yml --- dlt-daemon-2.18.9/.github/workflows/cmake-ctest.yml 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/.github/workflows/cmake-ctest.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -name: CMake - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - WITH_DLT_UNIT_TESTS: ON - -jobs: - build: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. - # You can convert this to a matrix build if you need cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_DLT_UNIT_TESTS=${{env.WITH_DLT_UNIT_TESTS}} - - - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} diff -Nru dlt-daemon-2.18.9/.github/workflows/codeql-analysis.yml dlt-daemon-2.18.4/.github/workflows/codeql-analysis.yml --- dlt-daemon-2.18.9/.github/workflows/codeql-analysis.yml 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/.github/workflows/codeql-analysis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -name: "CodeQL" - -on: - push: - branches: [master] - pull_request: - # The branches below must be a subset of the branches above - branches: [master] - schedule: - - cron: '0 9 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['cpp'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹ️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff -Nru dlt-daemon-2.18.9/.gitignore dlt-daemon-2.18.4/.gitignore --- dlt-daemon-2.18.9/.gitignore 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/.gitignore 2019-09-03 08:28:13.000000000 +0000 @@ -5,14 +5,8 @@ automotive-dlt.pc config.h include/dlt/dlt_version.h -include/dlt/dlt_user.h .project .cproject .settings .idea/ -*~ -*.o -*.out -*.swp cmake-build-debug/ -.vscode/ \ No newline at end of file diff -Nru dlt-daemon-2.18.9/include/CMakeLists.txt dlt-daemon-2.18.4/include/CMakeLists.txt --- dlt-daemon-2.18.9/include/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -13,6 +13,5 @@ # For further information see http://www.genivi.org/. ####### - -add_subdirectory( dlt ) +ADD_SUBDIRECTORY( dlt ) diff -Nru dlt-daemon-2.18.9/include/dlt/CMakeLists.txt dlt-daemon-2.18.4/include/dlt/CMakeLists.txt --- dlt-daemon-2.18.9/include/dlt/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -13,27 +13,16 @@ # For further information see http://www.genivi.org/. ####### -if(WITH_DLT_DISABLE_MACRO) - set(DLT_DISABLE_MACRO 1) -endif() - -configure_file(dlt_user.h.in dlt_user.h) - -set(HEADER_LIST dlt.h dlt_user_macros.h dlt_client.h dlt_protocol.h - dlt_common.h dlt_types.h dlt_shm.h dlt_offline_trace.h - dlt_filetransfer.h dlt_common_api.h dlt_multiple_files.h - ${CMAKE_CURRENT_BINARY_DIR}/dlt_version.h - ${CMAKE_CURRENT_BINARY_DIR}/dlt_user.h) - -if(WITH_DLT_DISABLE_MACRO) - list(REMOVE_ITEM HEADER_LIST dlt_user_macros.h) -endif() +install(FILES dlt.h dlt_user.h dlt_user_macros.h dlt_client.h dlt_protocol.h + dlt_common.h dlt_types.h dlt_shm.h dlt_offline_trace.h + dlt_filetransfer.h dlt_common_api.h + ${PROJECT_BINARY_DIR}/include/dlt/dlt_version.h + DESTINATION include/dlt + COMPONENT devel) if(WITH_DLT_CXX11_EXT) - list(APPEND HEADER_LIST dlt_cpp_extension.hpp) + install(FILES dlt_cpp_extension.hpp + DESTINATION include/dlt + COMPONENT devel) endif() -install(FILES ${HEADER_LIST} - DESTINATION include/dlt - COMPONENT devel) - diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_client.h dlt-daemon-2.18.4/include/dlt/dlt_client.h --- dlt-daemon-2.18.9/include/dlt/dlt_client.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_client.h 2019-09-03 08:28:13.000000000 +0000 @@ -75,31 +75,26 @@ # include "dlt_types.h" # include "dlt_common.h" -#include typedef enum { DLT_CLIENT_MODE_UNDEFINED = -1, DLT_CLIENT_MODE_TCP, DLT_CLIENT_MODE_SERIAL, - DLT_CLIENT_MODE_UNIX, - DLT_CLIENT_MODE_UDP_MULTICAST + DLT_CLIENT_MODE_UNIX } DltClientMode; typedef struct { DltReceiver receiver; /**< receiver pointer to dlt receiver structure */ int sock; /**< sock Connection handle/socket */ - char *servIP; /**< servIP IP adress/Hostname of interface */ - char *hostip; /**< hostip IP address of UDP host receiver interface */ + char *servIP; /**< servIP IP adress/Hostname of TCP/IP interface */ int port; /**< Port for TCP connections (optional) */ char *serialDevice; /**< serialDevice Devicename of serial device */ char *socketPath; /**< socketPath Unix socket path */ - char ecuid[4]; /**< ECUiD */ + char ecuid[4]; /**< ECUiD */ speed_t baudrate; /**< baudrate Baudrate of serial interface, as speed_t */ DltClientMode mode; /**< mode DltClientMode */ - int send_serial_header; /**< (Boolean) Send DLT messages with serial header */ - int resync_serial_header; /**< (Boolean) Resync to serial header on all connection */ } DltClient; # ifdef __cplusplus @@ -107,7 +102,6 @@ # endif void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data)); -void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void *data)); /** * Initialising dlt client structure with a specific port @@ -147,15 +141,6 @@ * @return Value from DltReturnValue enum */ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose); - -/** - * Send a message to the daemon through the socket. - * @param client pointer to dlt client structure. - * @param msg The message to be send in DLT format. - * @return Value from DltReturnValue enum. - */ -DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *msg); - /** * Send ancontrol message to the dlt daemon * @param client pointer to dlt client structure @@ -285,14 +270,6 @@ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate); /** - * Set mode within dlt client structure - * @param client pointer to dlt client structure - * @param mode DltClientMode - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode); - -/** * Set server ip * @param client pointer to dlt client structure * @param ipaddr pointer to command line argument @@ -301,14 +278,6 @@ int dlt_client_set_server_ip(DltClient *client, char *ipaddr); /** - * Set server UDP host receiver interface address - * @param client pointer to dlt client structure - * @param hostip pointer to multicast group address - * @return negative value if there was an error - */ -int dlt_client_set_host_if_address(DltClient *client, char *hostip); - -/** * Set serial device * @param client pointer to dlt client structure * @param serial_device pointer to command line argument diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_common.h dlt-daemon-2.18.4/include/dlt/dlt_common.h --- dlt-daemon-2.18.9/include/dlt/dlt_common.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_common.h 2019-09-03 08:28:13.000000000 +0000 @@ -75,10 +75,8 @@ # include # include -# include # ifdef __linux__ # include -# include # else # include # endif @@ -88,14 +86,6 @@ # include # endif -# if defined(__GNUC__) -# define PURE_FUNCTION __attribute__((pure)) -# define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, a, b))) -# else -# define PURE_FUNCTION /* nothing */ -# define PRINTF_FORMAT(a,b) /* nothing */ -# endif - # if !defined (__WIN32__) && !defined(_MSC_VER) # include # endif @@ -103,12 +93,14 @@ # include "dlt_types.h" # include "dlt_protocol.h" -# define DLT_PACKED __attribute__((aligned(1), packed)) +# if !defined (PACKED) +# define PACKED __attribute__((aligned(1), packed)) +# endif # if defined (__MSDOS__) || defined (_MSC_VER) /* set instead /Zp8 flag in Visual C++ configuration */ -# undef DLT_PACKED -# define DLT_PACKED +# undef PACKED +# define PACKED # endif /* @@ -191,13 +183,12 @@ # define LOG_DAEMON (3 << 3) # endif -typedef enum { +enum { DLT_LOG_TO_CONSOLE = 0, DLT_LOG_TO_SYSLOG = 1, DLT_LOG_TO_FILE = 2, - DLT_LOG_TO_STDERR = 3, - DLT_LOG_DROPPED = 4 -} DltLoggingMode; + DLT_LOG_DROPPED = 3 +}; /** * The standard TCP Port used for DLT daemon, can be overwritten via -p \ when starting dlt-daemon @@ -220,9 +211,6 @@ # define DLT_SIZE_WSID (sizeof(uint32_t)) # define DLT_SIZE_WTMS (sizeof(uint32_t)) -/* Size of buffer for text output */ -#define DLT_CONVERT_TEXTBUFSIZE 10024 - /** * Definitions for GET_LOG_INFO */ @@ -230,6 +218,17 @@ # define GET_LOG_INFO_LENGTH 13 # define SERVICE_OPT_LENGTH 3 +/* checks if received size is big enough for expected data */ +# define DLT_CHECK_RCV_DATA_SIZE(received, required) \ + ({ \ + int _ret = DLT_RETURN_OK; \ + if (((int)received - (int)required) < 0) { \ + dlt_vlog(LOG_WARNING, "%s: Received data not complete\n", __func__); \ + _ret = DLT_RETURN_ERROR; \ + } \ + _ret; \ + }) + /** * Get the size of extra header parameters, depends on htyp. */ @@ -242,9 +241,13 @@ # define __func__ __FUNCTION__ # endif -# define PRINT_FUNCTION_VERBOSE(_verbose) \ - if (_verbose) \ - dlt_vlog(LOG_INFO, "%s()\n", __func__) +# define PRINT_FUNCTION_VERBOSE(_verbose) \ + { \ + if (_verbose) \ + { \ + dlt_vlog(LOG_INFO, "%s()\n", __func__); \ + } \ + } # ifndef NULL # define NULL (char *)0 @@ -295,44 +298,37 @@ # define DLT_FILTER_MAX 30 /**< Maximum number of filters */ # define DLT_MSG_READ_VALUE(dst, src, length, type) \ - do { \ + { \ if ((length < 0) || ((length) < ((int32_t)sizeof(type)))) \ { length = -1; } \ else \ { dst = *((type *)src); src += sizeof(type); length -= sizeof(type); } \ - } while(0) + } # define DLT_MSG_READ_ID(dst, src, length) \ - do { \ + { \ if ((length < 0) || ((length) < DLT_ID_SIZE)) \ { length = -1; } \ else \ { memcpy(dst, src, DLT_ID_SIZE); src += DLT_ID_SIZE; length -= DLT_ID_SIZE; } \ - } while(0) + } -# define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \ - do { \ - if ((maxlength < 0) || (length <= 0) || (dstlength < length) || (maxlength < length)) \ - { \ - maxlength = -1; \ - } \ +# define DLT_MSG_READ_STRING(dst, src, maxlength, length) \ + { \ + if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) \ + { maxlength = -1; } \ else \ - { \ - memcpy(dst, src, length); \ - dlt_clean_string(dst, length); \ - dst[length] = 0; \ - src += length; \ - maxlength -= length; \ - } \ - } while(0) + { memcpy(dst, src, length); dlt_clean_string(dst, length); dst[length] = 0; \ + src += length; maxlength -= length; } \ + } # define DLT_MSG_READ_NULL(src, maxlength, length) \ - do { \ + { \ if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) \ { length = -1; } \ else \ { src += length; maxlength -= length; } \ - } while(0) + } # define DLT_HEADER_SHOW_NONE 0x0000 # define DLT_HEADER_SHOW_TIME 0x0001 @@ -408,7 +404,6 @@ typedef enum { DLT_RECEIVE_SOCKET, - DLT_RECEIVE_UDP_SOCKET, DLT_RECEIVE_FD } DltReceiverType; @@ -422,12 +417,10 @@ */ extern char dltSerialHeaderChar[DLT_ID_SIZE]; -#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC /** * The common base-path of the dlt-daemon-fifo and application-generated fifos */ extern char dltFifoBaseDir[DLT_PATH_MAX]; -#endif #ifdef DLT_SHM_ENABLE /** @@ -450,7 +443,7 @@ uint32_t seconds; /**< seconds since 1.1.1970 */ int32_t microseconds; /**< Microseconds */ char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */ -} DLT_PACKED DltStorageHeader; +} PACKED DltStorageHeader; /** * The structure of the DLT standard header. This header is used in each DLT message. @@ -460,7 +453,7 @@ uint8_t htyp; /**< This parameter contains several informations, see definitions below */ uint8_t mcnt; /**< The message counter is increased with each sent DLT message */ uint16_t len; /**< Length of the complete message, without storage header */ -} DLT_PACKED DltStandardHeader; +} PACKED DltStandardHeader; /** * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp. @@ -470,7 +463,7 @@ char ecu[DLT_ID_SIZE]; /**< ECU id */ uint32_t seid; /**< Session number */ uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */ -} DLT_PACKED DltStandardHeaderExtra; +} PACKED DltStandardHeaderExtra; /** * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter. @@ -481,7 +474,7 @@ uint8_t noar; /**< number of arguments */ char apid[DLT_ID_SIZE]; /**< application id */ char ctid[DLT_ID_SIZE]; /**< context id */ -} DLT_PACKED DltExtendedHeader; +} PACKED DltExtendedHeader; /** * The structure to organise the DLT messages. @@ -522,12 +515,12 @@ char apid[DLT_ID_SIZE]; /**< application id */ char ctid[DLT_ID_SIZE]; /**< context id */ char com[DLT_ID_SIZE]; /**< communication interface */ -} DLT_PACKED DltServiceGetLogInfoRequest; +} PACKED DltServiceGetLogInfoRequest; typedef struct { uint32_t service_id; /**< service ID */ -} DLT_PACKED DltServiceGetDefaultLogLevelRequest; +} PACKED DltServiceGetDefaultLogLevelRequest; /** * The structure of the DLT Service Get Log Info response. @@ -575,7 +568,7 @@ char ctid[DLT_ID_SIZE]; /**< context id */ uint8_t log_level; /**< log level to be set */ char com[DLT_ID_SIZE]; /**< communication interface */ -} DLT_PACKED DltServiceSetLogLevel; +} PACKED DltServiceSetLogLevel; /** * The structure of the DLT Service Set Default Log Level. @@ -585,7 +578,7 @@ uint32_t service_id; /**< service ID */ uint8_t log_level; /**< default log level to be set */ char com[DLT_ID_SIZE]; /**< communication interface */ -} DLT_PACKED DltServiceSetDefaultLogLevel; +} PACKED DltServiceSetDefaultLogLevel; /** * The structure of the DLT Service Set Verbose Mode @@ -594,7 +587,7 @@ { uint32_t service_id; /**< service ID */ uint8_t new_status; /**< new status to be set */ -} DLT_PACKED DltServiceSetVerboseMode; +} PACKED DltServiceSetVerboseMode; /** * The structure of the DLT Service Set Communication Interface Status @@ -604,7 +597,7 @@ uint32_t service_id; /**< service ID */ char com[DLT_ID_SIZE]; /**< communication interface */ uint8_t new_status; /**< new status to be set */ -} DLT_PACKED DltServiceSetCommunicationInterfaceStatus; +} PACKED DltServiceSetCommunicationInterfaceStatus; /** * The structure of the DLT Service Set Communication Maximum Bandwidth @@ -614,20 +607,20 @@ uint32_t service_id; /**< service ID */ char com[DLT_ID_SIZE]; /**< communication interface */ uint32_t max_bandwidth; /**< maximum bandwith */ -} DLT_PACKED DltServiceSetCommunicationMaximumBandwidth; +} PACKED DltServiceSetCommunicationMaximumBandwidth; typedef struct { uint32_t service_id; /**< service ID */ uint8_t status; /**< reponse status */ -} DLT_PACKED DltServiceResponse; +} PACKED DltServiceResponse; typedef struct { uint32_t service_id; /**< service ID */ uint8_t status; /**< reponse status */ uint8_t log_level; /**< log level */ -} DLT_PACKED DltServiceGetDefaultLogLevelResponse; +} PACKED DltServiceGetDefaultLogLevelResponse; typedef struct { @@ -635,20 +628,20 @@ uint8_t status; /**< reponse status */ uint8_t overflow; /**< overflow status */ uint32_t overflow_counter; /**< overflow counter */ -} DLT_PACKED DltServiceMessageBufferOverflowResponse; +} PACKED DltServiceMessageBufferOverflowResponse; typedef struct { uint32_t service_id; /**< service ID */ -} DLT_PACKED DltServiceGetSoftwareVersion; +} PACKED DltServiceGetSoftwareVersion; typedef struct { uint32_t service_id; /**< service ID */ uint8_t status; /**< reponse status */ uint32_t length; /**< length of following payload */ - char *payload; /**< payload */ -} DLT_PACKED DltServiceGetSoftwareVersionResponse; + /*char [] payload;*/ +} PACKED DltServiceGetSoftwareVersionResponse; /** * The structure of the DLT Service Unregister Context. @@ -660,7 +653,7 @@ char apid[DLT_ID_SIZE]; /**< application id */ char ctid[DLT_ID_SIZE]; /**< context id */ char comid[DLT_ID_SIZE]; /**< communication interface */ -} DLT_PACKED DltServiceUnregisterContext; +} PACKED DltServiceUnregisterContext; /** * The structure of the DLT Service Connection Info @@ -671,7 +664,7 @@ uint8_t status; /**< reponse status */ uint8_t state; /**< new state */ char comid[DLT_ID_SIZE]; /**< communication interface */ -} DLT_PACKED DltServiceConnectionInfo; +} PACKED DltServiceConnectionInfo; /** * The structure of the DLT Service Timezone @@ -682,7 +675,7 @@ uint8_t status; /**< reponse status */ int32_t timezone; /**< Timezone in seconds */ uint8_t isdst; /**< Is daylight saving time */ -} DLT_PACKED DltServiceTimezone; +} PACKED DltServiceTimezone; /** * The structure of the DLT Service Marker @@ -691,7 +684,7 @@ { uint32_t service_id; /**< service ID */ uint8_t status; /**< reponse status */ -} DLT_PACKED DltServiceMarker; +} PACKED DltServiceMarker; /*** * The structure of the DLT Service Offline Logstorage @@ -702,14 +695,31 @@ char mount_point[DLT_MOUNT_PATH_MAX]; /**< storage device mount point */ uint8_t connection_type; /**< connection status of the connected device connected/disconnected */ char comid[DLT_ID_SIZE]; /**< communication interface */ -} DLT_PACKED DltServiceOfflineLogstorage; +} PACKED DltServiceOfflineLogstorage; +/** + * The structure of DLT Service Get Filter Config + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< response status */ + char name[DLT_ENTRY_MAX]; /**< config name */ + uint32_t level; /**< filter level */ + uint32_t client_mask; /**< client mask */ + uint32_t ctrl_mask; /**< control message mask */ + char injections[DLT_ENTRY_MAX]; /**< list of injections */ +} PACKED DltServiceGetCurrentFilterInfo; + +/** + * The structure of DLT Service Passive Node Connect + */ typedef struct { uint32_t service_id; /**< service ID */ uint32_t connection_status; /**< connect/disconnect */ char node_id[DLT_ID_SIZE]; /**< passive node ID */ -} DLT_PACKED DltServicePassiveNodeConnect; +} PACKED DltServicePassiveNodeConnect; /** * The structure of DLT Service Passive Node Connection Status @@ -721,7 +731,7 @@ uint32_t num_connections; /**< number of connections */ uint8_t connection_status[DLT_ENTRY_MAX]; /**< list of connection status */ char node_id[DLT_ENTRY_MAX]; /**< list of passive node IDs */ -} DLT_PACKED DltServicePassiveNodeConnectionInfo; +} PACKED DltServicePassiveNodeConnectionInfo; /** * Structure to store filter parameters. @@ -732,9 +742,6 @@ { char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */ char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */ - int log_level[DLT_FILTER_MAX]; /**< log level */ - int32_t payload_max[DLT_FILTER_MAX]; /**< upper border for payload */ - int32_t payload_min[DLT_FILTER_MAX]; /**< lower border for payload */ int counter; /**< number of filters */ } DltFilter; @@ -752,8 +759,8 @@ int32_t counter; /**< number of messages in DLT file with filter */ int32_t counter_total; /**< number of messages in DLT file without filter */ int32_t position; /**< current index to message parsed in DLT file starting at 0 */ - uint64_t file_length; /**< length of the file */ - uint64_t file_position; /**< current position in the file */ + long file_length; /**< length of the file */ + long file_position; /**< current position in the file */ /* error counters */ int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */ @@ -781,15 +788,13 @@ char *buf; /**< pointer to position within receiver buffer */ char *backup_buf; /** pointer to the buffer with partial messages if any **/ int fd; /**< connection handle */ - DltReceiverType type; /**< type of connection handle */ int32_t buffersize; /**< size of receiver buffer */ - struct sockaddr_in addr; /**< socket address information */ } DltReceiver; typedef struct { unsigned char *shm; /* pointer to beginning of shared memory */ - unsigned int size; /* size of data area in shared memory */ + int size; /* size of data area in shared memory */ unsigned char *mem; /* pointer to data area in shared memory */ uint32_t min_size; /**< Minimum size of buffer */ @@ -870,17 +875,6 @@ DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, int size); /** - * Helper function to determine a bounded length of a string. - * This function returns zero if @a str is a null pointer, - * and it returns @a maxsize if the null character was not found in the first @a maxsize bytes of @a str. - * This is a re-implementation of C11's strnlen_s, which we cannot yet assume to be available. - * @param str pointer to string whose length is to be determined - * @param maxsize maximal considered length of @a str - * @return the bounded length of the string - */ -PURE_FUNCTION size_t dlt_strnlen_s(const char* str, size_t maxsize); - -/** * Helper function to print an id. * @param text pointer to ASCII string where to write the id * @param id four byte char array as used in DLT mesages as IDs. @@ -925,9 +919,9 @@ */ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose); /** - * Save filter in space separated list to text file. + * Save filter list to file. * @param filter pointer to structure of organising DLT filter - * @param filename filename to safe filters into + * @param filename filename to load filters from * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ @@ -937,40 +931,28 @@ * @param filter pointer to structure of organising DLT filter * @param apid application id to be found in filter list * @param ctid context id to be found in filter list - * @param log_level log level to be found in filter list - * @param payload_min minimum payload lenght to be found in filter list - * @param payload_max maximum payload lenght to be found in filter list * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error (or not found), else return index of filter */ -int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, int verbose); /** * Add new filter to filter list. * @param filter pointer to structure of organising DLT filter * @param apid application id to be added to filter list (must always be set). * @param ctid context id to be added to filter list. empty equals don't care. - * @param log_level log level to be added to filter list. 0 equals don't care. - * @param payload_min min lenght of payload to be added to filter list. 0 equals don't care. - * @param payload_max max lenght of payload to be added to filter list. INT32_MAX equals don't care. * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, int verbose); /** * Delete filter from filter list * @param filter pointer to structure of organising DLT filter * @param apid application id to be deleted from filter list * @param ctid context id to be deleted from filter list - * @param log_level log level to be deleted from filter list - * @param payload_min minimum payload lenght to be deleted from filter list - * @param payload_max maximum payload lenght to be deleted from filter list * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, int verbose); /** * Initialise the structure used to access a DLT message. @@ -996,7 +978,7 @@ * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_header(DltMessage *msg, char *text, size_t textlength, int verbose); +DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose); /** * Print Header into an ASCII string, selective. * @param msg pointer to structure of organising access to DLT messages @@ -1006,7 +988,7 @@ * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t textlength, int flags, int verbose); +DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, int textlength, int flags, int verbose); /** * Print Payload into an ASCII string. * @param msg pointer to structure of organising access to DLT messages @@ -1016,7 +998,7 @@ * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlength, int type, int verbose); +DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose); /** * Check if message is filtered or not. All filters are applied (logical OR). * @param msg pointer to structure of organising access to DLT messages @@ -1082,17 +1064,6 @@ */ DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose); /** - * This function reads DLT file and parse DLT message one by one. - * Each message will be written into new file. - * If a filter is set, the filter list is used. - * @param file pointer to structure of organizing access to DLT file - * @param filename file to contain parsed DLT messages. - * @param type 1 = payload as hex, 2 = payload as ASCII. - * @param verbose if set to true verbose information is printed out. - * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error - */ -DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, int type, int verbose); -/** * Find next message in the DLT file and parse them. * This function finds the next message in the DLT file. * If a filter is set, the filter list is used. @@ -1172,36 +1143,16 @@ * @param filename the filename */ void dlt_log_set_filename(const char *filename); -#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC -/** - * Set FIFO base direction - * @param pipe_dir the pipe direction - */ -void dlt_log_set_fifo_basedir(const char *pipe_dir); -#endif /** * Set internal logging level * @param level the level */ void dlt_log_set_level(int level); - -/** - * Set whether to print "name" and "unit" attributes in console output - * @param state true = with attributes, false = without attributes - */ -void dlt_print_with_attributes(bool state); - /** * Initialize (external) logging facility - * @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr + * @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file */ -DltReturnValue dlt_log_init(int mode); -/** - * Print with variable arguments to specified file descriptor by DLT_LOG_MODE environment variable (like fprintf) - * @param format format string for message - * @return negative value if there was an error or the total number of characters written is returned on success - */ -int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1, 2); +void dlt_log_init(int mode); /** * Log ASCII string with null-termination to (external) logging facility * @param prio priority (see syslog() call) @@ -1215,7 +1166,7 @@ * @param format format string for log message * @return negative value if there was an error */ -DltReturnValue dlt_vlog(int prio, const char *format, ...) PRINTF_FORMAT(2, 3); +DltReturnValue dlt_vlog(int prio, const char *format, ...); /** * Log size bytes with variable arguments to (external) logging facility (similar to snprintf) * @param prio priority (see syslog() call) @@ -1223,7 +1174,7 @@ * @param format format string for log message * @return negative value if there was an error */ -DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) PRINTF_FORMAT(3, 4); +DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...); /** * De-Initialize (external) logging facility */ @@ -1233,11 +1184,10 @@ * Initialising a dlt receiver structure * @param receiver pointer to dlt receiver structure * @param _fd handle to file/socket/fifo, fram which the data should be received - * @param type specify whether received data is from socket or file/fifo * @param _buffersize size of data buffer for storing the received data * @return negative value if there was an error */ -DltReturnValue dlt_receiver_init(DltReceiver *receiver, int _fd, DltReceiverType type, int _buffersize); +DltReturnValue dlt_receiver_init(DltReceiver *receiver, int _fd, int _buffersize); /** * De-Initialize a dlt receiver structure * @param receiver pointer to dlt receiver structure @@ -1248,23 +1198,23 @@ * Initialising a dlt receiver structure * @param receiver pointer to dlt receiver structure * @param fd handle to file/socket/fifo, fram which the data should be received - * @param type specify whether received data is from socket or file/fifo * @param buffer data buffer for storing the received data * @return negative value if there was an error and zero if success */ -DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, DltReceiverType type, char **buffer); +DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char **buffer); /** * De-Initialize a dlt receiver structure * @param receiver pointer to dlt receiver structure * @return negative value if there was an error and zero if success */ -DltReturnValue dlt_receiver_free_global_buffer(DltReceiver *receiver); +DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver); /** * Receive data from socket or file/fifo using the dlt receiver structure * @param receiver pointer to dlt receiver structure + * @param from_src specify whether received data is from socket or file/fifo * @return number of received bytes or negative value if there was an error */ -int dlt_receiver_receive(DltReceiver *receiver); +int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src); /** * Remove a specific size of bytes from the received data * @param receiver pointer to dlt receiver structure @@ -1306,13 +1256,6 @@ */ DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader); -/** - * Checks if received size is big enough for expected data - * @param received size - * @param required size - * @return negative value if required size is not sufficient - * */ -DltReturnValue dlt_check_rcv_data_size(int received, int required); /** * Initialise static ringbuffer with a size of size. @@ -1506,17 +1449,7 @@ /* */ /** - * Common part of initialisation. Evaluates the following environment variables - * and stores them in dlt_user struct: - * - DLT_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE - * - DLT_LOCAL_PRINT_MODE (AUTOMATIC: 0, FORCE_ON: 2, FORCE_OFF: 3) - * - DLT_INITIAL_LOG_LEVEL (e.g. APPx:CTXa:6;APPx:CTXb:5) - * - DLT_FORCE_BLOCKING - * - DLT_USER_BUFFER_MIN - * - DLT_USER_BUFFER_MAX - * - DLT_USER_BUFFER_STEP - * - DLT_LOG_MSG_BUF_LEN - * - DLT_DISABLE_INJECTION_MSG_AT_USER + * Common part of initialisation * @return negative value if there was an error */ DltReturnValue dlt_init_common(void); @@ -1594,14 +1527,14 @@ uint8_t **ptr, int32_t *datalength, char *text, - size_t textlength, + int textlength, int byteLength, int verbose); /** * Check environment variables. */ -void dlt_check_envvar(void); +void dlt_check_envvar(); /** * Parse the response text and identifying service id and its options. @@ -1631,28 +1564,15 @@ */ int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count); - /** - * Convert get log info from ASCII to string (with '\0' termination) - * - * @param rp char - * @param rp_count int - * @param wp char Array needs to be 1 byte larger than len to store '\0' - * @param len int - */ -void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int len); - - -/** - * Convert get log info from ASCII to ID (without '\0' termination) + * Convert get log info from ASCII to ID * * @param rp char * @param rp_count int * @param wp char * @param len int - * @return position of last read character in wp */ -int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len); +void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len); /** * Convert from hex ASCII to binary @@ -1662,64 +1582,13 @@ */ void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size); +# ifndef DLT_USE_UNIX_SOCKET_IPC /** - * Helper function to execute the execvp function in a new child process. - * @param filename file path to store the stdout of command (NULL if not required) - * @param command execution command followed by arguments with NULL-termination - * @return negative value if there was an error - */ -int dlt_execute_command(char *filename, char *command, ...); - -/** - * Return the extension of given file name. - * @param filename Only file names without prepended path allowed. - * @return pointer to extension - */ -char *get_filename_ext(const char *filename); - -/** - * Extract the base name of given file name (without the extension). - * @param abs_file_name Absolute path to file name. - * @param base_name Base name it is extracted to. - * @param base_name_length Base name length. - * @return indicating success + * Create the specified path, recursive if necessary + * behaves like calling mkdir -p \ on the console */ -bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len); - -/** - * Initialize (external) logging facility - * @param mode DltLoggingMode, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr - * @param enable_multiple_logfiles, true if multiple logfiles (incl. size limits) should be use - * @param logging_file_size, maximum size in bytes of one logging file - * @param logging_files_max_size, maximum size in bytes of all logging files - */ -DltReturnValue dlt_log_init_multiple_logfiles_support(DltLoggingMode mode, bool enable_multiple_logfiles, int logging_file_size, int logging_files_max_size); - -/** - * Initialize (external) logging facility for single logfile. - */ -DltReturnValue dlt_log_init_single_logfile(); - -/** - * Initialize (external) logging facility for multiple files logging. - */ -DltReturnValue dlt_log_init_multiple_logfiles(int logging_file_size, int logging_files_max_size); - -/** - * Logs into log files represented by the multiple files buffer. - * @param format First element in a specific format that will be logged. - * @param ... Further elements in a specific format that will be logged. - */ -void dlt_log_multiple_files_write(const char* format, ...); - -void dlt_log_free_single_logfile(); - -void dlt_log_free_multiple_logfiles(); - -/** - * Checks whether (internal) logging in multiple files is active. - */ -bool dlt_is_log_in_multiple_files_active(); +int dlt_mkdir_recursive(const char *dir); +# endif # ifdef __cplusplus } diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_filetransfer.h dlt-daemon-2.18.4/include/dlt/dlt_filetransfer.h --- dlt-daemon-2.18.9/include/dlt/dlt_filetransfer.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_filetransfer.h 2019-09-03 08:28:13.000000000 +0000 @@ -52,8 +52,6 @@ #define DLT_FILETRANSFER_ERROR_INFO_ABOUT -700 /* ! Error code for dlt_user_log_file_packagesCount */ #define DLT_FILETRANSFER_ERROR_PACKAGE_COUNT -800 -/* ! Error code for failed get serial number */ -#define DLT_FILETRANSFER_FILE_SERIAL_NUMBER -900 /* !Transfer the complete file as several dlt logs. */ diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_multiple_files.h dlt-daemon-2.18.4/include/dlt/dlt_multiple_files.h --- dlt-daemon-2.18.9/include/dlt/dlt_multiple_files.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_multiple_files.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,154 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2011-2015, BMW AG - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -/*! - * \author - * Oleg Tropmann - * Daniel Weber - * - * \copyright Copyright © 2022 Mercedes-Benz AG. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - * \file dlt_multiple_files.h - */ - - -#ifndef DLT_MULTIPLE_FILES_H -#define DLT_MULTIPLE_FILES_H - -#include - -#include "dlt_common.h" -#include "dlt_types.h" - -#define MULTIPLE_FILES_FILENAME_INDEX_DELIM "." -#define MULTIPLE_FILES_FILENAME_TIMESTAMP_DELIM "_" - -/** - * Represents a ring buffer of multiple files of identical file size. - * File names differ in timestamp or index (depending on chosen mode). - * This buffer is used, e.g. for dlt offline traces and the internal dlt logging (dlt.log) - */ -typedef struct -{ - char directory[NAME_MAX + 1];/**< (String) Store DLT messages to local directory */ - char filename[NAME_MAX + 1]; /**< (String) Filename of currently used log file */ - int fileSize; /**< (int) Maximum size in bytes of one file, e.g. for offline trace 1000000 as default */ - int maxSize; /**< (int) Maximum size of all files, e.g. for offline trace 4000000 as default */ - bool filenameTimestampBased; /**< (bool) is filename timestamp based? false = index based (Default: true) */ - char filenameBase[NAME_MAX + 1];/**< (String) Prefix of file name */ - char filenameExt[NAME_MAX + 1];/**< (String) Extension of file name */ - int ohandle; /**< (int) file handle to current output file */ -} MultipleFilesRingBuffer; - -/** - * Initialise the multiple files buffer. - * This function call opens the currently used log file. - * A check of the complete size of the files is done during startup. - * Old files are deleted, if there is not enough space left to create new file. - * This function must be called before using further multiple files functions. - * @param files_buffer pointer to MultipleFilesRingBuffer struct. - * @param directory directory where to store multiple files. - * @param file_size maximum size of one files. - * @param max_size maximum size of complete multiple files in bytes. - * @param filename_timestamp_based filename to be created on timestamp-based or index-based. - * @param append Indicates whether the current log files is used or a new file should be be created - * @param filename_base Base name. - * @param filename_ext File extension. - * @return negative value if there was an error. - */ -extern DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer, - const char *directory, - int file_size, - int max_size, - bool filename_timestamp_based, - bool append, - const char *filename_base, - const char *filename_ext); - -/** - * Uninitialise the multiple files buffer. - * This function call closes currently used log file. - * This function must be called after usage of multiple files. - * @param files_buffer pointer to MultipleFilesRingBuffer struct. - * @return negative value if there was an error. -*/ -extern DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer *files_buffer); - -/** - * Write data into multiple files. - * If the current used log file exceeds the max file size, new log file is created. - * A check of the complete size of the multiple files is done before new file is created. - * Old files are deleted, if there is not enough space left to create new file. - * @param files_buffer pointer to MultipleFilesRingBuffer struct. - * @param data pointer to first data block to be written, null if not used. - * @param size size in bytes of first data block to be written, 0 if not used. - * @return negative value if there was an error. - */ -extern DltReturnValue multiple_files_buffer_write(MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - int size); - -/** - * First the limits are verified. Then the oldest file is deleted and a new file is created on demand. - * @param files_buffer pointer to MultipleFilesRingBuffer struct. - * @param size size in bytes of data that will be written. - */ -void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer *files_buffer, - int size); - -/** - * Writes the given data to current file specified by corresponding file handle. - * @param files_buffer pointer to MultipleFilesRingBuffer struct. - * @param data pointer to data block to be written, null if not used. - * @param size size in bytes of given data block to be written, 0 if not used. - */ -DltReturnValue multiple_files_buffer_write_chunk(const MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - int size); - -/** - * Get size of currently used multiple files buffer. - * @return size in bytes. - */ -extern ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer *files_buffer); - -/** - * Provides info about the multiple files storage directory. - * @param path path of the storage directory - * @param file_name filename to search for - * @param newest pointer to store newest filename - * @param oldest pointer to store oldest filename - * @return num of files in the directory. - */ -unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char *file_name, - char *newest, char *oldest); - -/** - * Creates filename with index. - * @param files_buffer pointer to MultipleFilesRingBuffer struct. - * @param length the maximum length of the log_file_name. - * @param idx index to be used for file name creation. - */ -void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, size_t length, unsigned int idx); - -/** - * Generates index for log file name. - * @param file filename supplied to create index. - * @return the index to be used for log file name. - */ -unsigned int multiple_files_buffer_get_idx_of_log_file(char *file); - -#endif // DLT_MULTIPLE_FILES_H diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_offline_trace.h dlt-daemon-2.18.4/include/dlt/dlt_offline_trace.h --- dlt-daemon-2.18.9/include/dlt/dlt_offline_trace.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_offline_trace.h 2019-09-03 08:28:13.000000000 +0000 @@ -57,32 +57,109 @@ #include -#include "dlt_multiple_files.h" #include "dlt_types.h" #define DLT_OFFLINETRACE_FILENAME_BASE "dlt_offlinetrace" +#define DLT_OFFLINETRACE_FILENAME_DELI "." #define DLT_OFFLINETRACE_FILENAME_EXT ".dlt" +#define DLT_OFFLINETRACE_INDEX_MAX_SIZE 10 +#define DLT_OFFLINETRACE_FILENAME_TO_COMPARE "dlt_offlinetrace_" +/* "dlt_offlinetrace.4294967295.dlt" -> MAX 32byte include NULL terminate */ +#define DLT_OFFLINETRACE_FILENAME_MAX_SIZE (sizeof(DLT_OFFLINETRACE_FILENAME_BASE) + \ + sizeof(DLT_OFFLINETRACE_FILENAME_DELI) + \ + DLT_OFFLINETRACE_INDEX_MAX_SIZE + \ + sizeof(DLT_OFFLINETRACE_FILENAME_EXT) + 1) + +typedef struct +{ + char directory[NAME_MAX + 1];/**< (String) Store DLT messages to local directory */ + char filename[NAME_MAX + 1]; /**< (String) Filename of currently used log file */ + int fileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */ + int maxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */ + int filenameTimestampBased; /**< (int) timestamp based or index based (Default: 1 Timestamp based) */ + int ohandle; +} DltOfflineTrace; + +/** + * Initialise the offline trace + * This function call opens the currently used log file. + * A check of the complete size of the offline trace is done during startup. + * Old files are deleted, if there is not enough space left to create new file. + * This function must be called before using further offline trace functions. + * @param trace pointer to offline trace structure + * @param directory directory where to store offline trace files + * @param fileSize maximum size of one offline trace file. + * @param maxSize maximum size of complete offline trace in bytes. + *.@param filenameTimestampBased filename to be created on timestamp based or index based + * @return negative value if there was an error + */ +extern DltReturnValue dlt_offline_trace_init(DltOfflineTrace *trace, + const char *directory, + int fileSize, + int maxSize, + int filenameTimestampBased); /** - * Write data into offline traces. + * Uninitialise the offline trace + * This function call closes currently used log file. + * This function must be called after usage of offline trace + * @param buf pointer to offline trace structure + * @return negative value if there was an error + */ +extern DltReturnValue dlt_offline_trace_free(DltOfflineTrace *buf); + +/** + * Write data into offline trace * If the current used log file exceeds the max file size, new log file is created. - * A check of the complete size of the offline traces is done before new file is created. + * A check of the complete size of the offline trace is done before new file is created. * Old files are deleted, if there is not enough space left to create new file. - * @param trace pointer to MultipleFilesRingBuffer struct. - * @param data1 pointer to first data block to be written, null if not used. - * @param size1 size in bytes of first data block to be written, 0 if not used. - * @param data2 pointer to second data block to be written, null if not used. - * @param size2 size in bytes of second data block to be written, 0 if not used. - * @param data3 pointer to third data block to be written, null if not used. - * @param size3 size in bytes of third data block to be written, 0 if not used. - * @return negative value if there was an error. + * @param trace pointer to offline trace structure + * @param data1 pointer to first data block to be written, null if not used + * @param size1 size in bytes of first data block to be written, 0 if not used + * @param data2 pointer to second data block to be written, null if not used + * @param size2 size in bytes of second data block to be written, 0 if not used + * @param data3 pointer to third data block to be written, null if not used + * @param size3 size in bytes of third data block to be written, 0 if not used + * @return negative value if there was an error */ -extern DltReturnValue dlt_offline_trace_write(MultipleFilesRingBuffer *trace, - const unsigned char *data1, +extern DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace, + unsigned char *data1, int size1, - const unsigned char *data2, + unsigned char *data2, int size2, - const unsigned char *data3, + unsigned char *data3, int size3); +/** + * Get size of currently used offline trace buffer + * @return size in bytes + */ +extern unsigned long dlt_offline_trace_get_total_size(DltOfflineTrace *trace); + +/** + * Provides info about the offline logs storage directory + * @param path path of the storage directory + * @param file_name filename to search for + * @param newest pointer to store newest filename + * @param oldest pointer to store oldest filename + * @return num of files in the directory + */ +unsigned int dlt_offline_trace_storage_dir_info(char *path, char *file_name, char *newest, char *oldest); + +/** + * creates filename with index + * @param log_file_name file name created with index + * @param name filename base + * @param idx index to be used for file name creation + */ +void dlt_offline_trace_file_name(char *log_file_name, char *name, unsigned int idx); + +/** + * generates index for log file name + * @param file filename supplied to create index + * @return the index to be used for log file name + */ +unsigned int dlt_offline_trace_get_idx_of_log_file(char *file); + + #endif /* DLT_OFFLINE_TRACE_H */ diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_types.h dlt-daemon-2.18.4/include/dlt/dlt_types.h --- dlt-daemon-2.18.9/include/dlt/dlt_types.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_types.h 2019-09-03 08:28:13.000000000 +0000 @@ -83,7 +83,6 @@ */ typedef enum { - DLT_RETURN_FILESZERR = -8, DLT_RETURN_LOGGING_DISABLED = -7, DLT_RETURN_USER_BUFFER_FULL = -6, DLT_RETURN_WRONG_PARAMETER = -5, @@ -174,17 +173,10 @@ DLT_USER_MODE_MAX /**< maximum value, used for range check */ } DltUserLogMode; -/** - * Definition of Maintain Logstorage Loglevel modes - */ -#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF -1 -#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF 0 -#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON 1 - typedef float float32_t; typedef double float64_t; -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC /** * Definition Library connection state */ @@ -196,13 +188,4 @@ } DltUserConnectionState; #endif -/** - * Definition of timestamp types - */ -typedef enum -{ - DLT_AUTO_TIMESTAMP = 0, - DLT_USER_TIMESTAMP -} DltTimestampType; - #endif /* DLT_TYPES_H */ diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_user.h dlt-daemon-2.18.4/include/dlt/dlt_user.h --- dlt-daemon-2.18.9/include/dlt/dlt_user.h 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_user.h 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,889 @@ +/* + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2011-2015, BMW AG + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * For further information see http://www.genivi.org/. + */ + +/*! + * \author Alexander Wenzel + * + * \copyright Copyright © 2011-2015 BMW AG. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt_user.h + */ + +/******************************************************************************* +** ** +** SRC-MODULE: dlt_user.h ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision: 1670 $ + * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ + * $LastChangedBy$ + * Initials Date Comment + * aw 13.01.2010 initial + */ + +#ifndef DLT_USER_H +# define DLT_USER_H + +/** + * \defgroup userapi DLT User API + * \addtogroup userapi + \{ + */ +# include + +# if !defined (__WIN32__) +# include +# endif + +# include "dlt_types.h" +# include "dlt_user_macros.h" +# include "dlt_shm.h" + +# ifdef __cplusplus +extern "C" { +# endif + +# define DLT_USER_BUF_MAX_SIZE 1390 /**< maximum size of each user buffer, also used for injection buffer */ + +# define DLT_USER_RESENDBUF_MAX_SIZE (DLT_USER_BUF_MAX_SIZE + 100) /**< Size of resend buffer; Max DLT message size is 1390 bytes plus some extra header space */ + +/* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */ +#define DLT_SEM_LOCK() do{\ + while ((sem_wait(&dlt_mutex) == -1) && (errno == EINTR)) \ + continue; /* Restart if interrupted */ \ + } while(0) +#define DLT_SEM_FREE() { sem_post(&dlt_mutex); } + +/** + * This structure is used for every context used in an application. + */ +typedef struct +{ + char contextID[DLT_ID_SIZE]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ + int8_t *log_level_ptr; /**< pointer to the log level */ + int8_t *trace_status_ptr; /**< pointer to the trace status */ + uint8_t mcnt; /**< message counter */ +} DltContext; + +/** + * This structure is used for context data used in an application. + */ +typedef struct +{ + DltContext *handle; /**< pointer to DltContext */ + unsigned char *buffer; /**< buffer for building log message*/ + int32_t size; /**< payload size */ + int32_t log_level; /**< log level */ + int32_t trace_status; /**< trace status */ + int32_t args_num; /**< number of arguments for extended header*/ + char *context_description; /**< description of context */ +} DltContextData; + +typedef struct +{ + uint32_t service_id; + int (*injection_callback)(uint32_t service_id, void *data, uint32_t length); + int (*injection_callback_with_id)(uint32_t service_id, void *data, uint32_t length, void *priv_data); + void *data; +} DltUserInjectionCallback; + +typedef struct +{ + char contextID[DLT_ID_SIZE]; /**< Context ID */ + int8_t log_level; /**< Log level */ + int8_t trace_status; /**< Trace status */ + void (*log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status); +} DltUserLogLevelChangedCallback; + +/** + * This structure is used in a table managing all contexts and the corresponding log levels in an application. + */ +typedef struct +{ + char contextID[DLT_ID_SIZE]; /**< Context ID */ + int8_t log_level; /**< Log level */ + int8_t *log_level_ptr; /**< Ptr to the log level */ + int8_t trace_status; /**< Trace status */ + int8_t *trace_status_ptr; /**< Ptr to the trace status */ + char *context_description; /**< description of context */ + DltUserInjectionCallback *injection_table; /**< Table with pointer to injection functions and service ids */ + uint32_t nrcallbacks; + + /* Log Level changed callback */ + void (*log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status); + +} dlt_ll_ts_type; + +/** + * @brief holds initial log-level for given appId:ctxId pair + */ +typedef struct +{ + char appId[DLT_ID_SIZE]; + char ctxId[DLT_ID_SIZE]; + int8_t ll; +} dlt_env_ll_item; + + +/** + * @brief holds all initial log-levels given via environment variable DLT_INITIAL_LOG_LEVEL + */ +typedef struct +{ + dlt_env_ll_item *item; + size_t array_size; + size_t num_elem; +} dlt_env_ll_set; + + +/** + * This structure is used once for one application. + */ +typedef struct +{ + char ecuID[DLT_ID_SIZE]; /**< ECU ID */ + char appID[DLT_ID_SIZE]; /**< Application ID */ + int dlt_log_handle; /**< Handle to fifo of dlt daemon */ + int dlt_user_handle; /**< Handle to own fifo */ + mqd_t dlt_segmented_queue_read_handle; /**< Handle message queue */ + mqd_t dlt_segmented_queue_write_handle; /**< Handle message queue */ + pthread_t dlt_segmented_nwt_handle; /**< thread handle of segmented sending */ + + int8_t dlt_is_file; /**< Target of logging: 1 to file, 0 to daemon */ + + dlt_ll_ts_type *dlt_ll_ts; /** [MAX_DLT_LL_TS_ENTRIES]; < Internal management struct for all + * contexts */ + uint32_t dlt_ll_ts_max_num_entries; /**< Maximum number of contexts */ + + uint32_t dlt_ll_ts_num_entries; /**< Number of used contexts */ + + int8_t overflow; /**< Overflow marker, set to 1 on overflow, 0 otherwise */ + uint32_t overflow_counter; /**< Counts the number of lost messages */ + + char *application_description; /**< description of application */ + + DltReceiver receiver; /**< Receiver for internal user-defined messages from daemon */ + + int8_t verbose_mode; /**< Verbose mode enabled: 1 enabled, 0 disabled */ + int8_t use_extende_header_for_non_verbose; /**< Use extended header for non verbose: 1 enabled, 0 disabled */ + int8_t with_session_id; /**< Send always session id: 1 enabled, 0 disabled */ + int8_t with_timestamp; /**< Send always timestamp: 1 enabled, 0 disabled */ + int8_t with_ecu_id; /**< Send always ecu id: 1 enabled, 0 disabled */ + + int8_t enable_local_print; /**< Local printing of log messages: 1 enabled, 0 disabled */ + int8_t local_print_mode; /**< Local print mode, controlled by environment variable */ + + int8_t log_state; /**< Log state of external connection: + * 1 client connected, + * 0 not connected, + * -1 unknown */ + + DltBuffer startup_buffer; /**< Ring-buffer for buffering messages during startup and missing connection */ + /* Buffer used for resending, locked by DLT semaphore */ + uint8_t *resend_buffer; + + uint32_t timeout_at_exit_handler; /**< timeout used in dlt_user_atexit_blow_out_user_buffer, in 0.1 milliseconds */ + dlt_env_ll_set initial_ll_set; + +# ifdef DLT_SHM_ENABLE + DltShm dlt_shm; +# endif +# ifdef DLT_TEST_ENABLE + int corrupt_user_header; + int corrupt_message_size; + int16_t corrupt_message_size_size; +# endif +# ifdef DLT_USE_UNIX_SOCKET_IPC + DltUserConnectionState connection_state; +# endif + uint16_t log_buf_len; /**< length of message buffer, by default: DLT_USER_BUF_MAX_SIZE */ +} DltUser; + +typedef int (*dlt_injection_callback_id)(uint32_t, void *, uint32_t, void *); +typedef int (*dlt_injection_callback)(uint32_t, void *, uint32_t); + +/************************************************************************************************** +* The following API functions define a low level function interface for DLT +**************************************************************************************************/ + +/** + * Initialize the generation of a DLT log message (intended for usage in verbose mode) + * This function has to be called first, when an application wants to send a new log messages. + * Following functions like dlt_user_log_write_string and dlt_user_log_write_finish must only be called, + * when return value is bigger than zero. + * @param handle pointer to an object containing information about one special logging context + * @param log pointer to an object containing information about logging context data + * @param loglevel this is the current log level of the log message to be sent + * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is matching + */ +DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel); + +/** + * Initialize the generation of a DLT log message (intended for usage in non-verbose mode) + * This function has to be called first, when an application wants to send a new log messages. + * Following functions like dlt_user_log_write_string and dlt_user_log_write_finish must only be called, + * when return value is bigger than zero. + * @param handle pointer to an object containing information about one special logging context + * @param log pointer to an object containing information about logging context data + * @param loglevel this is the current log level of the log message to be sent + * @param messageid message id of message + * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is matching + */ +DltReturnValue dlt_user_log_write_start_id(DltContext *handle, + DltContextData *log, + DltLogLevelType loglevel, + uint32_t messageid); + +/** + * Finishing the generation of a DLT log message and sending it to the DLT daemon. + * This function has to be called after writing all the log attributes of a log message. + * @param log pointer to an object containing information about logging context data + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_finish(DltContextData *log); + +/** + * Write a boolean parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data boolean parameter written into log message (mapped to uint8) + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data); + +/** + * Write a float parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data float32_t parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data); + +/** + * Write a double parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data float64_t parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_float64(DltContextData *log, double data); + +/** + * Write a uint parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data unsigned int parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data); +DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data); +DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data); +DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data); +DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data); + +/** + * Write a uint parameter into a DLT log message. The output will be formatted as given by the parameter type. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data unsigned int parameter written into log message. + * @param type The formatting type of the string output. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type); +DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type); +DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type); +DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type); + +/** + * Write a pointer value architecture independent. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data void* parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data); + +/** + * Write a int parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data int parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_int(DltContextData *log, int data); +DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data); +DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data); +DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data); +DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data); +/** + * Write a null terminated ASCII string into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param text pointer to the parameter written into log message containing null termination. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text); + +/** + * Write a constant null terminated ASCII string into a DLT log message. + * In non verbose mode DLT parameter will not be send at all. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param text pointer to the parameter written into log message containing null termination. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_constant_string(DltContextData *log, const char *text); + +/** + * Write a null terminated UTF8 string into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param text pointer to the parameter written into log message containing null termination. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *text); + +/** + * Write a binary memory block into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data pointer to the parameter written into log message. + * @param length length in bytes of the parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length); + +/** + * Write a binary memory block into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data pointer to the parameter written into log message. + * @param length length in bytes of the parameter written into log message. + * @param type the format information. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type); + +/** + * Trace network message + * @param handle pointer to an object containing information about one special logging context + * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST) + * @param header_len length of network message header + * @param header pointer to network message header + * @param payload_len length of network message payload + * @param payload pointer to network message payload + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_trace_network(DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len, + void *payload); + +/** + * Trace network message, truncated if necessary. + * @param handle pointer to an object containing information about logging context + * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST) + * @param header_len length of network message header + * @param header pointer to network message header + * @param payload_len length of network message payload + * @param payload pointer to network message payload + * @param allow_truncate Set to > 0 to allow truncating of the message if it is too large. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len, + void *payload, + int allow_truncate); + +/** + * Trace network message in segmented asynchronous mode. + * The sending of the data is done in a separate thread. + * Please note that handle must exist for the lifetime of the application, because + * data chunks are sent asynchronously in undetermined future time. + * @param handle pointer to an object containing information about logging context + * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST) + * @param header_len length of network message header + * @param header pointer to network message header + * @param payload_len length of network message payload + * @param payload pointer to network message payload + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len, + void *payload); + +/************************************************************************************************** +* The following API functions define a high level function interface for DLT +**************************************************************************************************/ + +/** + * Initialize the user lib communication with daemon. + * This function has to be called first, before using any DLT user lib functions. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_init(); + +/** + * Initialize the user lib writing only to file. + * This function has to be called first, before using any DLT user lib functions. + * @param name name of an optional log file + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_init_file(const char *name); + +/** + * Terminate the user lib. + * This function has to be called when finishing using the DLT user lib. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_free(); + +/** + * Check the library version of DLT library. + * @param user_major_version the major version to be compared + * @param user_minor_version the minor version to be compared + * @return Value from DltReturnValue enum, DLT_RETURN_ERROR if there is a mismatch + */ +DltReturnValue dlt_check_library_version(const char *user_major_version, const char *user_minor_version); + +/** + * Register an application in the daemon. + * @param apid four byte long character array with the application id + * @param description long name of the application + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_app(const char *apid, const char *description); + +/** + * Unregister an application in the daemon. + * This function has to be called when finishing using an application. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_unregister_app(void); + +/** + * Unregister an application in the daemon and also flushes the buffered logs. + * This function has to be called when finishing using an application. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_unregister_app_flush_buffered_logs(void); + +/** + * Register a context in the daemon. + * This function has to be called before first usage of the context. + * @param handle pointer to an object containing information about one special logging context + * @param contextid four byte long character array with the context id + * @param description long name of the context + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char *description); + +/** + * Register a context in the daemon with pre-defined log level and pre-defined trace status. + * This function has to be called before first usage of the context. + * @param handle pointer to an object containing information about one special logging context + * @param contextid four byte long character array with the context id + * @param description long name of the context + * @param loglevel This is the log level to be pre-set for this context + * (DLT_LOG_DEFAULT is not allowed here) + * @param tracestatus This is the trace status to be pre-set for this context + * (DLT_TRACE_STATUS_DEFAULT is not allowed here) + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_context_ll_ts(DltContext *handle, + const char *contextid, + const char *description, + int loglevel, + int tracestatus); + +/** + * Register a context in the daemon with log level changed callback fn. + * This function is introduced to avoid missing of LL change callback during registration + * @param handle pointer to an object containing information about one special logging context + * @param contextid four byte long character array with the context id + * @param description long name of the context + * @param *dlt_log_level_changed_callback This is the fn which will be called when log level is changed + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_context_llccb(DltContext *handle, + const char *contextid, + const char *description, + void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], + uint8_t log_level, + uint8_t trace_status)); + +/** + * Unregister a context in the DLT daemon. + * This function has to be called when finishing using a context. + * @param handle pointer to an object containing information about one special logging context + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_unregister_context(DltContext *handle); + + +/** + * Set maximum timeout for re-sending at exit + * @param timeout_in_milliseconds maximum time to wait until giving up re-sending, default 10000 (equals to 10 seconds) + */ +int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds); + +/** + * Set the logging mode used by the daemon. + * The logging mode is stored persistantly by the daemon. + * @see DltUserLogMode + * @param mode the new logging mode used by the daemon: off, extern, internal, both. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_set_log_mode(DltUserLogMode mode); + +/** + * Get the state of the connected client to the daemon. + * The user application gets a message, when client is connected or disconnected. + * This value contains the last state. + * It needs some time until the application gets state from the daemon. + * Until then the state is "unknown state". + * @return -1 = unknown state, 0 = client not connected, 1 = client connected + */ +int dlt_get_log_state(); + +/** + * Register callback function called when injection message was received + * @param handle pointer to an object containing information about one special logging context + * @param service_id the service id to be waited for + * @param (*dlt_injection_callback) function pointer to callback function + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t service_id, + int (*dlt_injection_callback)(uint32_t service_id, + void *data, + uint32_t length)); + +/** + * Register callback function with private data called when injection message was received + * @param handle pointer to an object containing information about one special logging context + * @param service_id the service id to be waited for + * @param (*dlt_injection_callback) function pointer to callback function + * @param priv private data + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint32_t service_id, + int (*dlt_injection_callback)(uint32_t service_id, + void *data, + uint32_t length, + void *priv_data), void *priv); + +/** + * Register callback function called when log level of context was changed + * @param handle pointer to an object containing information about one special logging context + * @param (*dlt_log_level_changed_callback) function pointer to callback function + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, + void (*dlt_log_level_changed_callback)( + char context_id[DLT_ID_SIZE], + uint8_t log_level, + uint8_t trace_status)); + +/** + * Switch to verbose mode + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_verbose_mode(void); + +/** + * Check the version of dlt library with library version used of the application. + * @param user_major_version version number of application - see dlt_version.h + * @param user_minor_version version number of application - see dlt_version.h + * @return Value from DltReturnValue enum, DLT_RETURN_ERROR if there is a mismatch + */ +DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version); + +/** + * Switch to non-verbose mode + * + */ +DltReturnValue dlt_nonverbose_mode(void); + +/** + * Use extended header in non verbose mode. + * Enabled by default. + * @param use_extende_header_for_non_verbose Use extended header for non verbose mode if true + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extende_header_for_non_verbose); + +/** + * Send session id configuration. + * Enabled by default. + * @param with_session_id Send session id in each message if enabled + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_with_session_id(int8_t with_session_id); + +/** + * Send timestamp configuration. + * Enabled by default. + * @param with_timestamp Send timestamp id in each message if enabled + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_with_timestamp(int8_t with_timestamp); + +/** + * Send ecu id configuration. + * Enabled by default. + * @param with_ecu_id Send ecu id in each message if enabled + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id); + +/** + * Set maximum logged log level and trace status of application + * + * @param loglevel This is the log level to be set for the whole application + * @param tracestatus This is the trace status to be set for the whole application + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus); + + +/** + * @brief adjust log-level based on values given through environment + * + * Iterate over the set of items, and find the best match. + * For any item that matches, the one with the highest priority is selected and that + * log-level is returned. + * + * Priorities are determined as follows: + * - no apid, no ctid only ll given in item: use ll with prio 1 + * - no apid, ctid matches: use ll with prio 2 + * - no ctid, apid matches: use ll with prio 3 + * - apid, ctid matches: use ll with prio 4 + * + * @param ll_set + * @param apid + * @param ctid + * @param ll + * If no item matches or in case of error, the original log-level (\param ll) is returned + */ +int dlt_env_adjust_ll_from_env(dlt_env_ll_set const *const ll_set, + char const *const apid, + char const *const ctid, + int const ll); + +/** + * @brief extract log-level settings from given string + * + * Scan \param env for setttings like apid:ctid:log-level and store them + * in given \param ll_set + * + * @param env reference to a string to be parsed, after parsing env will point after the last parse character + * @param ll_set set of log-level extracted from given string + * + * @return 0 on success + * @return -1 on failure + */ +int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set); + +void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set); + +/** + * Enable local printing of messages + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_enable_local_print(void); + +/** + * Disable local printing of messages + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_disable_local_print(void); + +/** + * Write a null terminated ASCII string into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param text pointer to the ASCII string written into log message containing null termination. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text); + +/** + * Write a null terminated ASCII string and an integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param text pointer to the ASCII string written into log message containing null termination. + * @param data integer value written into the log message + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, const char *text, int data); + +/** + * Write a null terminated ASCII string and an unsigned integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param text pointer to the ASCII string written into log message containing null termination. + * @param data unsigned integer value written into the log message + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data); + +/** + * Write an integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param data integer value written into the log message + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int data); + +/** + * Write an unsigned integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param data unsigned integer value written into the log message + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsigned int data); + +/** + * Write an unsigned integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param data pointer to the parameter written into log message. + * @param length length in bytes of the parameter written into log message. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *data, uint16_t length); + +/** + * Write marker message to DLT. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_log_marker(); + +/** + * Get the total size and available size of the shared memory buffer between daemon and applications. + * This information is useful to control the flow control between applications and daemon. + * For example only 50% of the buffer should be used for file transfer. + * @param total_size total size of buffer in bytes + * @param used_size used size of buffer in bytes + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size); + +/** + * Try to resend log message in the user buffer. Stops if the dlt_uptime is bigger than + * dlt_uptime() + DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT. A pause between the resending + * attempts can be defined with DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP + * @return number of messages in the user buffer + */ +int dlt_user_atexit_blow_out_user_buffer(void); + +/** + * Try to resend log message in the user buffer. + * @return Value from DltReturnValue enum + */ +DltReturnValue dlt_user_log_resend_buffer(void); + +/** + * Checks the log level passed by the log function if enabled for that context or not. + * This function can be called by applications before generating their logs. + * Also called before writing new log messages. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is enabled + */ +static inline DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle, DltLogLevelType loglevel) +{ + if ((loglevel < DLT_LOG_DEFAULT) || (loglevel >= DLT_LOG_MAX)) + return DLT_RETURN_WRONG_PARAMETER; + + if ((handle == NULL) || (handle->log_level_ptr == NULL)) + return DLT_RETURN_WRONG_PARAMETER; + + if ((loglevel <= (DltLogLevelType)(*(handle->log_level_ptr))) && (loglevel != DLT_LOG_OFF)) + return DLT_RETURN_TRUE; + + return DLT_RETURN_LOGGING_DISABLED; +} + +# ifdef DLT_TEST_ENABLE +void dlt_user_test_corrupt_user_header(int enable); +void dlt_user_test_corrupt_message_size(int enable, int16_t size); +# endif /* DLT_TEST_ENABLE */ + +# ifdef __cplusplus +} +# endif + +/** + \} + */ + +#endif /* DLT_USER_H */ diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_user.h.in dlt-daemon-2.18.4/include/dlt/dlt_user.h.in --- dlt-daemon-2.18.9/include/dlt/dlt_user.h.in 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_user.h.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,1269 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2011-2015, BMW AG - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -/*! - * \author Alexander Wenzel - * - * \copyright Copyright © 2011-2015 BMW AG. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - * \file dlt_user.h - */ - -/******************************************************************************* -** ** -** SRC-MODULE: dlt_user.h ** -** ** -** TARGET : linux ** -** ** -** PROJECT : DLT ** -** ** -** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** -** Markus Klein ** -** ** -** PURPOSE : ** -** ** -** REMARKS : ** -** ** -** PLATFORM DEPENDANT [yes/no]: yes ** -** ** -** TO BE CHANGED BY USER [yes/no]: no ** -** ** -*******************************************************************************/ - -/******************************************************************************* -** Author Identity ** -******************************************************************************** -** ** -** Initials Name Company ** -** -------- ------------------------- ---------------------------------- ** -** aw Alexander Wenzel BMW ** -** mk Markus Klein Fraunhofer ESK ** -*******************************************************************************/ - -/******************************************************************************* -** Revision Control History ** -*******************************************************************************/ - -/* - * $LastChangedRevision: 1670 $ - * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ - * $LastChangedBy$ - * Initials Date Comment - * aw 13.01.2010 initial - */ - -#ifndef DLT_USER_H -# define DLT_USER_H - -/** - * \defgroup userapi DLT User API - * \addtogroup userapi - \{ - */ - -#ifndef DLT_NETWORK_TRACE_ENABLE -#cmakedefine DLT_NETWORK_TRACE_ENABLE -#endif - -#cmakedefine01 DLT_DISABLE_MACRO - -#ifdef DLT_NETWORK_TRACE_ENABLE -# include -#else -# include -# include -#endif - -# include - -# if !defined (__WIN32__) -# include -# endif - -# include "dlt_types.h" -# include "dlt_shm.h" -#if !DLT_DISABLE_MACRO -# include "dlt_user_macros.h" -#endif - -# ifdef __cplusplus -extern "C" { -# endif - -# define DLT_USER_BUF_MAX_SIZE 1390 /**< maximum size of each user buffer, also used for injection buffer */ - -# define DLT_USER_RESENDBUF_MAX_SIZE (DLT_USER_BUF_MAX_SIZE + 100) /**< Size of resend buffer; Max DLT message size is 1390 bytes plus some extra header space */ - -/* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */ -#define DLT_SEM_LOCK() do{\ - while ((sem_wait(&dlt_mutex) == -1) && (errno == EINTR)) \ - continue; /* Restart if interrupted */ \ - } while(0) -#define DLT_SEM_FREE() { sem_post(&dlt_mutex); } - -/** - * This structure is used for every context used in an application. - */ -typedef struct -{ - char contextID[DLT_ID_SIZE]; /**< context id */ - int32_t log_level_pos; /**< offset in user-application context field */ - int8_t *log_level_ptr; /**< pointer to the log level */ - int8_t *trace_status_ptr; /**< pointer to the trace status */ - uint8_t mcnt; /**< message counter */ -} DltContext; - -/** - * This structure is used for context data used in an application. - */ -typedef struct -{ - DltContext *handle; /**< pointer to DltContext */ - unsigned char *buffer; /**< buffer for building log message*/ - int32_t size; /**< payload size */ - int32_t log_level; /**< log level */ - int32_t trace_status; /**< trace status */ - int32_t args_num; /**< number of arguments for extended header*/ - char *context_description; /**< description of context */ - DltTimestampType use_timestamp; /**< whether to use user-supplied timestamps */ - uint32_t user_timestamp; /**< user-supplied timestamp to use */ - int8_t verbose_mode; /**< verbose mode: 1 enabled, 0 disabled */ -} DltContextData; - -typedef struct -{ - uint32_t service_id; - int (*injection_callback)(uint32_t service_id, void *data, uint32_t length); - int (*injection_callback_with_id)(uint32_t service_id, void *data, uint32_t length, void *priv_data); - void *data; -} DltUserInjectionCallback; - -typedef struct -{ - char contextID[DLT_ID_SIZE]; /**< Context ID */ - int8_t log_level; /**< Log level */ - int8_t trace_status; /**< Trace status */ - void (*log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status); -} DltUserLogLevelChangedCallback; - -/** - * This structure is used in a table managing all contexts and the corresponding log levels in an application. - */ -typedef struct -{ - char contextID[DLT_ID_SIZE]; /**< Context ID */ - int8_t log_level; /**< Log level */ - int8_t *log_level_ptr; /**< Ptr to the log level */ - int8_t trace_status; /**< Trace status */ - int8_t *trace_status_ptr; /**< Ptr to the trace status */ - char *context_description; /**< description of context */ - DltUserInjectionCallback *injection_table; /**< Table with pointer to injection functions and service ids */ - uint32_t nrcallbacks; - - /* Log Level changed callback */ - void (*log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status); - -} dlt_ll_ts_type; - -/** - * @brief holds initial log-level for given appId:ctxId pair - */ -typedef struct -{ - char appId[DLT_ID_SIZE]; - char ctxId[DLT_ID_SIZE]; - int8_t ll; -} dlt_env_ll_item; - - -/** - * @brief holds all initial log-levels given via environment variable DLT_INITIAL_LOG_LEVEL - */ -typedef struct -{ - dlt_env_ll_item *item; - size_t array_size; - size_t num_elem; -} dlt_env_ll_set; - - -/** - * This structure is used once for one application. - */ -typedef struct -{ - char ecuID[DLT_ID_SIZE]; /**< ECU ID */ - char appID[DLT_ID_SIZE]; /**< Application ID */ - int dlt_log_handle; /**< Handle to fifo of dlt daemon */ - int dlt_user_handle; /**< Handle to own fifo */ -#ifdef DLT_NETWORK_TRACE_ENABLE - mqd_t dlt_segmented_queue_read_handle; /**< Handle message queue */ - mqd_t dlt_segmented_queue_write_handle; /**< Handle message queue */ - pthread_t dlt_segmented_nwt_handle; /**< thread handle of segmented sending */ -#endif - int8_t dlt_is_file; /**< Target of logging: 1 to file, 0 to daemon */ - unsigned int filesize_max; /**< Maximum size of existing file in case dlt_is_file=1 */ - - dlt_ll_ts_type *dlt_ll_ts; /** [MAX_DLT_LL_TS_ENTRIES]; < Internal management struct for all - * contexts */ - uint32_t dlt_ll_ts_max_num_entries; /**< Maximum number of contexts */ - - uint32_t dlt_ll_ts_num_entries; /**< Number of used contexts */ - - int8_t overflow; /**< Overflow marker, set to 1 on overflow, 0 otherwise */ - uint32_t overflow_counter; /**< Counts the number of lost messages */ - - char *application_description; /**< description of application */ - - DltReceiver receiver; /**< Receiver for internal user-defined messages from daemon */ - - int8_t verbose_mode; /**< Verbose mode enabled: 1 enabled, 0 disabled */ - int8_t use_extended_header_for_non_verbose; /**< Use extended header for non verbose: 1 enabled, 0 disabled */ - int8_t with_session_id; /**< Send always session id: 1 enabled, 0 disabled */ - int8_t with_timestamp; /**< Send always timestamp: 1 enabled, 0 disabled */ - int8_t with_ecu_id; /**< Send always ecu id: 1 enabled, 0 disabled */ - - int8_t enable_local_print; /**< Local printing of log messages: 1 enabled, 0 disabled */ - int8_t local_print_mode; /**< Local print mode, controlled by environment variable */ - int8_t disable_injection_msg; /**< Injection msg availability: 1 disabled, 0 enabled (default) */ - - int8_t log_state; /**< Log state of external connection: - * 1 client connected, - * 0 not connected, - * -1 unknown */ - - DltBuffer startup_buffer; /**< Ring-buffer for buffering messages during startup and missing connection */ - /* Buffer used for resending, locked by DLT semaphore */ - uint8_t *resend_buffer; - - uint32_t timeout_at_exit_handler; /**< timeout used in dlt_user_atexit_blow_out_user_buffer, in 0.1 milliseconds */ - dlt_env_ll_set initial_ll_set; - -# ifdef DLT_SHM_ENABLE - DltShm dlt_shm; -# endif -# ifdef DLT_TEST_ENABLE - int corrupt_user_header; - int corrupt_message_size; - int16_t corrupt_message_size_size; -# endif -# if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC - DltUserConnectionState connection_state; -# endif - uint16_t log_buf_len; /**< length of message buffer, by default: DLT_USER_BUF_MAX_SIZE */ -} DltUser; - -typedef int (*dlt_injection_callback_id)(uint32_t, void *, uint32_t, void *); -typedef int (*dlt_injection_callback)(uint32_t, void *, uint32_t); - -/************************************************************************************************** -* The following API functions define a low level function interface for DLT -**************************************************************************************************/ - -/** - * Initialize the generation of a DLT log message (intended for usage in verbose mode) - * This function has to be called first, when an application wants to send a new log messages. - * Following functions like dlt_user_log_write_string and dlt_user_log_write_finish must only be called, - * when return value is bigger than zero. - * @param handle pointer to an object containing information about one special logging context - * @param log pointer to an object containing information about logging context data - * @param loglevel this is the current log level of the log message to be sent - * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is matching - */ -DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel); - -/** - * Initialize the generation of a DLT log message (intended for usage in non-verbose mode) - * This function has to be called first, when an application wants to send a new log messages. - * Following functions like dlt_user_log_write_string and dlt_user_log_write_finish must only be called, - * when return value is bigger than zero. - * @param handle pointer to an object containing information about one special logging context - * @param log pointer to an object containing information about logging context data - * @param loglevel this is the current log level of the log message to be sent - * @param messageid message id of message - * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is matching - */ -DltReturnValue dlt_user_log_write_start_id(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - uint32_t messageid); - -/** - * Initialize the generation of a DLT log message with given buffer from DLT application. - * This can be considered as replacement of dlt_user_log_write_start/dlt_user_log_write_start_id - * and other data functions like dlt_user_log_write_string. The fourth, fifth, and sixth arguments - * shall be prepared by DLT application; this function is only responsible for checking log - * level and setting the given values to context data. This function has to be called first, - * when an application is ready to send a new log message with given buffer. This function only - * works with combination of dlt_user_log_write_finish_w_given_buffer and the function must only be - * called, when return value is bigger than zero. The function only supports verbose mode as of now. - * @param handle pointer to an object containing information about one special logging context - * @param log pointer to an object containing information about logging context data - * @param loglevel this is the current log level of the log message to be sent - * @param buffer data with log message - * @param size buffer size - * @param args_num number of arguments in buffer - * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is matching - */ -DltReturnValue dlt_user_log_write_start_w_given_buffer(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - char *buffer, - size_t size, - int32_t args_num); - -/** - * Finishing the generation of a DLT log message and sending it to the DLT daemon. - * This function has to be called after writing all the log attributes of a log message. - * @param log pointer to an object containing information about logging context data - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_finish(DltContextData *log); - -/** - * Finishing the generation of a DLT log message and sending it to the DLT daemon without - * freeing log buffer. This function only works with combination of - * dlt_user_log_write_start_w_given_buffer. This function has to be called after writing all - * the log attributes of a log message. - * @param log pointer to an object containing information about logging context data - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_finish_w_given_buffer(DltContextData *log); - -/** - * Write a boolean parameter into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data boolean parameter written into log message (mapped to uint8) - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data); - -/** - * Write a boolean parameter with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param data boolean parameter written into log message (mapped to uint8) - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name); - -/** - * Write a float parameter into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data float32_t parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data); - -/** - * Write a double parameter into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data float64_t parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_float64(DltContextData *log, double data); - -/** - * Write a float parameter with attributes into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0 - * and no content to the message for that attribute. - * - * @param log pointer to an object containing information about logging context data - * @param data float32_t parameter written into log message - * @param name the "name" attribute (or NULL) - * @param unit the "unit" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit); - -/** - * Write a double parameter with attributes into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0 - * and no content to the message for that attribute. - * - * @param log pointer to an object containing information about logging context data - * @param data float64_t parameter written into log message - * @param name the "name" attribute (or NULL) - * @param unit the "unit" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_float64_attr(DltContextData *log, float64_t data, const char *name, const char *unit); - -/** - * Write a uint parameter into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data unsigned int parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data); -DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data); -DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data); -DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data); -DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data); - -/** - * Write a uint parameter with attributes into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0 - * and no content to the message for that attribute. - * - * @param log pointer to an object containing information about logging context data - * @param data unsigned int parameter written into log message - * @param name the "name" attribute (or NULL) - * @param unit the "unit" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit); - -/** - * Write a uint parameter into a DLT log message. The output will be formatted as given by the parameter type. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data unsigned int parameter written into log message. - * @param type The formatting type of the string output. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type); -DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type); -DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type); -DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type); - -/** - * Write a pointer value architecture independent. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data void* parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data); - -/** - * Write a int parameter into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data int parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_int(DltContextData *log, int data); -DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data); -DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data); -DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data); -DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data); - -/** - * Write an int parameter with attributes into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0 - * and no content to the message for that attribute. - * - * @param log pointer to an object containing information about logging context data - * @param data int parameter written into log message - * @param name the "name" attribute (or NULL) - * @param unit the "unit" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_int_attr(DltContextData *log, int data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_int8_attr(DltContextData *log, int8_t data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_int16_attr(DltContextData *log, int16_t data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_int32_attr(DltContextData *log, int32_t data, const char *name, const char *unit); -DltReturnValue dlt_user_log_write_int64_attr(DltContextData *log, int64_t data, const char *name, const char *unit); - -/** - * Write a null terminated ASCII string into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text); - -/** - * Write a potentially non-null-terminated ASCII string into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_string(DltContextData *log, const char *text, uint16_t length); - -/** - * Write a constant null terminated ASCII string into a DLT log message. - * In non verbose mode DLT parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_constant_string(DltContextData *log, const char *text); - -/** - * Write a constant, potentially non-null-terminated ASCII string into a DLT log message. - * In non verbose mode DLT parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_constant_string(DltContextData *log, const char *text, uint16_t length); - -/** - * Write a null terminated UTF8 string into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *text); - -/** - * Write a potentially non-null-terminated UTF8 string into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); - -/** - * Write a constant null terminated UTF8 string into a DLT log message. - * In non verbose mode DLT parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text); - -/** - * Write a constant, potentially non-null-terminated UTF8 string into a DLT log message. - * In non verbose mode DLT parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text, uint16_t length); - -/** - * Write a null-terminated ASCII string with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_string_attr(DltContextData *log, const char *text, const char *name); - -/** - * Write a potentially non-null-terminated ASCII string with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - -/** - * Write a constant, null-terminated ASCII string with "name" attribute into a DLT log message. - * In non-verbose mode, this parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name); - -/** - * Write a constant, potentially non-null-terminated ASCII string with "name" attribute into a DLT log message. - * In non-verbose mode, this parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - -/** - * Write a null-terminated UTF-8 string with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); - -/** - * Write a potentially non-null-terminated UTF-8 string with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - -/** - * Write a constant, null-terminated UTF8 string with "name" attribute into a DLT log message. - * In non-verbose mode, this parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message containing null termination - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); - -/** - * Write a constant, potentially non-null-terminated UTF8 string with "name" attribute into a DLT log message. - * In non-verbose mode, this parameter will not be sent at all. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param text pointer to the parameter written into log message - * @param length length in bytes of @a text (without any termination character) - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_sized_constant_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - -/** - * Write a binary memory block into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data pointer to the parameter written into log message. - * @param length length in bytes of the parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length); - -/** - * Write a binary memory block into a DLT log message. - * dlt_user_log_write_start has to be called before adding any attributes to the log message. - * Finish sending log message by calling dlt_user_log_write_finish. - * @param log pointer to an object containing information about logging context data - * @param data pointer to the parameter written into log message. - * @param length length in bytes of the parameter written into log message. - * @param type the format information. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type); - -/** - * Write a binary memory block with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param data pointer to the parameter written into log message. - * @param length length in bytes of the parameter written into log message - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_raw_attr(DltContextData *log, const void *data, uint16_t length, const char *name); - -/** - * Write a binary memory block with "name" attribute into a DLT log message. - * dlt_user_log_write_start has to be called before adding any parameters to the log message. - * Finish building a log message by calling dlt_user_log_write_finish. - * - * If @a name is NULL, this function will add an attribute field with length 0 - * and no content to the message. - * - * @param log pointer to an object containing information about logging context data - * @param data pointer to the parameter written into log message. - * @param length length in bytes of the parameter written into log message - * @param type the format information - * @param name the "name" attribute (or NULL) - * @return value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_write_raw_formatted_attr(DltContextData *log, const void *data, uint16_t length, DltFormatType type, const char *name); - -/** - * Trace network message - * @param handle pointer to an object containing information about one special logging context - * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST) - * @param header_len length of network message header - * @param header pointer to network message header - * @param payload_len length of network message payload - * @param payload pointer to network message payload - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_trace_network(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload); - -/** - * Trace network message, truncated if necessary. - * @param handle pointer to an object containing information about logging context - * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST) - * @param header_len length of network message header - * @param header pointer to network message header - * @param payload_len length of network message payload - * @param payload pointer to network message payload - * @param allow_truncate Set to > 0 to allow truncating of the message if it is too large. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload, - int allow_truncate); - -/** - * Trace network message in segmented asynchronous mode. - * The sending of the data is done in a separate thread. - * Please note that handle must exist for the lifetime of the application, because - * data chunks are sent asynchronously in undetermined future time. - * @param handle pointer to an object containing information about logging context - * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST) - * @param header_len length of network message header - * @param header pointer to network message header - * @param payload_len length of network message payload - * @param payload pointer to network message payload - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload); - -/************************************************************************************************** -* The following API functions define a high level function interface for DLT -**************************************************************************************************/ - -/** - * Initialize the user lib communication with daemon. - * This function has to be called first, before using any DLT user lib functions. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_init(); - -/** - * Initialize the user lib writing only to file. - * This function has to be called first, before using any DLT user lib functions. - * @param name name of an optional log file - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_init_file(const char *name); - -/** - * Set maximum file size if lib is configured to write only to file. - * This function has to be called after dlt_init_file(). - * @param filesize maximum file size - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_set_filesize_max(unsigned int filesize); - -/** - * Terminate the user lib. - * This function has to be called when finishing using the DLT user lib. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_free(); - -/** - * Check the library version of DLT library. - * @param user_major_version the major version to be compared - * @param user_minor_version the minor version to be compared - * @return Value from DltReturnValue enum, DLT_RETURN_ERROR if there is a mismatch - */ -DltReturnValue dlt_check_library_version(const char *user_major_version, const char *user_minor_version); - -/** - * Register an application in the daemon. - * @param apid four byte long character array with the application id - * @param description long name of the application - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_app(const char *apid, const char *description); - -/** - * Unregister an application in the daemon. - * This function has to be called when finishing using an application. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_unregister_app(void); - -/** - * Unregister an application in the daemon and also flushes the buffered logs. - * This function has to be called when finishing using an application. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_unregister_app_flush_buffered_logs(void); - -/** - * Get the application id - * @param four byte long character array to store the application id - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_get_appid(char *appid); - -/** - * Register a context in the daemon. - * This function has to be called before first usage of the context. - * @param handle pointer to an object containing information about one special logging context - * @param contextid four byte long character array with the context id - * @param description long name of the context - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char *description); - -/** - * Register a context in the daemon with pre-defined log level and pre-defined trace status. - * This function has to be called before first usage of the context. - * @param handle pointer to an object containing information about one special logging context - * @param contextid four byte long character array with the context id - * @param description long name of the context - * @param loglevel This is the log level to be pre-set for this context - * (DLT_LOG_DEFAULT is not allowed here) - * @param tracestatus This is the trace status to be pre-set for this context - * (DLT_TRACE_STATUS_DEFAULT is not allowed here) - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_context_ll_ts(DltContext *handle, - const char *contextid, - const char *description, - int loglevel, - int tracestatus); - -/** - * Register a context in the daemon with log level changed callback fn. - * This function is introduced to avoid missing of LL change callback during registration - * @param handle pointer to an object containing information about one special logging context - * @param contextid four byte long character array with the context id - * @param description long name of the context - * @param *dlt_log_level_changed_callback This is the fn which will be called when log level is changed - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_context_llccb(DltContext *handle, - const char *contextid, - const char *description, - void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], - uint8_t log_level, - uint8_t trace_status)); - -/** - * Unregister a context in the DLT daemon. - * This function has to be called when finishing using a context. - * @param handle pointer to an object containing information about one special logging context - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_unregister_context(DltContext *handle); - - -/** - * Set maximum timeout for re-sending at exit - * @param timeout_in_milliseconds maximum time to wait until giving up re-sending, default 10000 (equals to 10 seconds) - */ -int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds); - -/** - * Set the logging mode used by the daemon. - * The logging mode is stored persistantly by the daemon. - * @see DltUserLogMode - * @param mode the new logging mode used by the daemon: off, extern, internal, both. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_set_log_mode(DltUserLogMode mode); - -/** - * Get the state of the connected client to the daemon. - * The user application gets a message, when client is connected or disconnected. - * This value contains the last state. - * It needs some time until the application gets state from the daemon. - * Until then the state is "unknown state". - * @return -1 = unknown state, 0 = client not connected, 1 = client connected - */ -int dlt_get_log_state(); - -/** - * Register callback function called when injection message was received - * @param handle pointer to an object containing information about one special logging context - * @param service_id the service id to be waited for - * @param (*dlt_injection_callback) function pointer to callback function - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t service_id, - int (*dlt_injection_callback)(uint32_t service_id, - void *data, - uint32_t length)); - -/** - * Register callback function with private data called when injection message was received - * @param handle pointer to an object containing information about one special logging context - * @param service_id the service id to be waited for - * @param (*dlt_injection_callback) function pointer to callback function - * @param priv private data - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint32_t service_id, - int (*dlt_injection_callback)(uint32_t service_id, - void *data, - uint32_t length, - void *priv_data), void *priv); - -/** - * Register callback function called when log level of context was changed - * @param handle pointer to an object containing information about one special logging context - * @param (*dlt_log_level_changed_callback) function pointer to callback function - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, - void (*dlt_log_level_changed_callback)( - char context_id[DLT_ID_SIZE], - uint8_t log_level, - uint8_t trace_status)); - -/** - * Switch to verbose mode - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_verbose_mode(void); - -/** - * Check the version of dlt library with library version used of the application. - * @param user_major_version version number of application - see dlt_version.h - * @param user_minor_version version number of application - see dlt_version.h - * @return Value from DltReturnValue enum, DLT_RETURN_ERROR if there is a mismatch - */ -DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version); - -/** - * Switch to non-verbose mode - * - * This does not force all messages to be sent as Non-Verbose ones, as that does not make much sense. - * Instead, it +allows+ the sending of both Verbose and Non-Verbose messages, depending on which APIs - * are being called. - */ -DltReturnValue dlt_nonverbose_mode(void); - -/** - * Use extended header in non verbose mode. - * Enabled by default. - * @param use_extended_header_for_non_verbose Use extended header for non verbose mode if true - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extended_header_for_non_verbose); - -/** - * Send session id configuration. - * Enabled by default. - * @param with_session_id Send session id in each message if enabled - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_with_session_id(int8_t with_session_id); - -/** - * Send timestamp configuration. - * Enabled by default. - * @param with_timestamp Send timestamp id in each message if enabled - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_with_timestamp(int8_t with_timestamp); - -/** - * Send ecu id configuration. - * Enabled by default. - * @param with_ecu_id Send ecu id in each message if enabled - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id); - -/** - * Set maximum logged log level and trace status of application - * - * @param loglevel This is the log level to be set for the whole application - * @param tracestatus This is the trace status to be set for the whole application - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus); - - -/** - * @brief adjust log-level based on values given through environment - * - * Iterate over the set of items, and find the best match. - * For any item that matches, the one with the highest priority is selected and that - * log-level is returned. - * - * Priorities are determined as follows: - * - no apid, no ctid only ll given in item: use ll with prio 1 - * - no apid, ctid matches: use ll with prio 2 - * - no ctid, apid matches: use ll with prio 3 - * - apid, ctid matches: use ll with prio 4 - * - * @param ll_set - * @param apid - * @param ctid - * @param ll - * If no item matches or in case of error, the original log-level (\param ll) is returned - */ -int dlt_env_adjust_ll_from_env(dlt_env_ll_set const *const ll_set, - char const *const apid, - char const *const ctid, - int const ll); - -/** - * @brief extract log-level settings from given string - * - * Scan \param env for setttings like apid:ctid:log-level and store them - * in given \param ll_set - * - * @param env reference to a string to be parsed, after parsing env will point after the last parse character - * @param ll_set set of log-level extracted from given string - * - * @return 0 on success - * @return -1 on failure - */ -int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set); - -void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set); - -/** - * Enable local printing of messages - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_enable_local_print(void); - -/** - * Disable local printing of messages - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_disable_local_print(void); - -/** - * Write a null terminated ASCII string into a DLT log message. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @param text pointer to the ASCII string written into log message containing null termination. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text); - -/** - * Write a null terminated ASCII string and an integer value into a DLT log message. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @param text pointer to the ASCII string written into log message containing null termination. - * @param data integer value written into the log message - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, const char *text, int data); - -/** - * Write a null terminated ASCII string and an unsigned integer value into a DLT log message. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @param text pointer to the ASCII string written into log message containing null termination. - * @param data unsigned integer value written into the log message - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data); - -/** - * Write an integer value into a DLT log message. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @param data integer value written into the log message - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int data); - -/** - * Write an unsigned integer value into a DLT log message. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @param data unsigned integer value written into the log message - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsigned int data); - -/** - * Write an unsigned integer value into a DLT log message. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @param data pointer to the parameter written into log message. - * @param length length in bytes of the parameter written into log message. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *data, uint16_t length); - -/** - * Write marker message to DLT. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_log_marker(); - -/** - * Get the total size and available size of the shared memory buffer between daemon and applications. - * This information is useful to control the flow control between applications and daemon. - * For example only 50% of the buffer should be used for file transfer. - * @param total_size total size of buffer in bytes - * @param used_size used size of buffer in bytes - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size); - -/** - * Try to resend log message in the user buffer. Stops if the dlt_uptime is bigger than - * dlt_uptime() + DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT. A pause between the resending - * attempts can be defined with DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP - * @return number of messages in the user buffer - */ -int dlt_user_atexit_blow_out_user_buffer(void); - -/** - * Try to resend log message in the user buffer. - * @return Value from DltReturnValue enum - */ -DltReturnValue dlt_user_log_resend_buffer(void); - -/** - * Checks the log level passed by the log function if enabled for that context or not. - * This function can be called by applications before generating their logs. - * Also called before writing new log messages. - * @param handle pointer to an object containing information about one special logging context - * @param loglevel this is the current log level of the log message to be sent - * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is enabled - */ -static inline DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle, DltLogLevelType loglevel) -{ - if ((loglevel < DLT_LOG_DEFAULT) || (loglevel >= DLT_LOG_MAX)) - return DLT_RETURN_WRONG_PARAMETER; - - if ((handle == NULL) || (handle->log_level_ptr == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - if ((loglevel <= (DltLogLevelType)(*(handle->log_level_ptr))) && (loglevel != DLT_LOG_OFF)) - return DLT_RETURN_TRUE; - - return DLT_RETURN_LOGGING_DISABLED; -} - -# ifdef DLT_TEST_ENABLE -void dlt_user_test_corrupt_user_header(int enable); -void dlt_user_test_corrupt_message_size(int enable, int16_t size); -# endif /* DLT_TEST_ENABLE */ - -# ifdef __cplusplus -} -# endif - -/** - \} - */ - -#endif /* DLT_USER_H */ diff -Nru dlt-daemon-2.18.9/include/dlt/dlt_user_macros.h dlt-daemon-2.18.4/include/dlt/dlt_user_macros.h --- dlt-daemon-2.18.9/include/dlt/dlt_user_macros.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/include/dlt/dlt_user_macros.h 2019-09-03 08:28:13.000000000 +0000 @@ -69,7 +69,6 @@ #define DLT_USER_MACROS_H #include "dlt_version.h" -#include "dlt_types.h" /** * \defgroup userapi DLT User API @@ -126,13 +125,6 @@ (void)dlt_unregister_app_flush_buffered_logs(); } while (0) /** - * To Get application ID. - * @Param APPID character pointer of minimum 4 bytes - */ -#define DLT_GET_APPID(APPID) do{\ - dlt_get_appid(APPID);} while(0) - -/** * Register context (with default log level and default trace status) * @param CONTEXT object containing information about one special logging context * @param CONTEXTID context id with maximal four characters @@ -202,52 +194,23 @@ * Send log message with variable list of messages (intended for verbose mode) * @param CONTEXT object containing information about one special logging context * @param LOGLEVEL the log level of the log message - * @param ... variable list of arguments + * @param ARGS variable list of arguments * @note To avoid the MISRA warning "The comma operator has been used outside a for statement" - * use a semicolon instead of a comma to separate the __VA_ARGS__. + * use a semicolon instead of a comma to separate the ARGS. * Example: DLT_LOG(hContext, DLT_LOG_INFO, DLT_STRING("Hello world"); DLT_INT(123)); */ #ifdef _MSC_VER /* DLT_LOG is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG(CONTEXT, LOGLEVEL, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ - } while (0) -#endif - -/** - * Send log message with variable list of messages (intended for verbose mode) - * @param CONTEXT object containing information about one special logging context - * @param LOGLEVEL the log level of the log message - * @param TS timestamp to be used for log message - * @param ... variable list of arguments - * @note To avoid the MISRA warning "The comma operator has been used outside a for statement" - * use a semicolon instead of a comma to separate the __VA_ARGS__. - * Example: DLT_LOG_TS(hContext, DLT_LOG_INFO, timestamp, DLT_STRING("Hello world"); DLT_INT(123)); - */ -#ifdef _MSC_VER -/* DLT_LOG_TS is not supported by MS Visual C++ */ -/* use function interface instead */ -#else -# define DLT_LOG_TS(CONTEXT, LOGLEVEL, TS, ...) \ +# define DLT_LOG(CONTEXT, LOGLEVEL, ARGS ...) \ do { \ DltContextData log_local; \ int dlt_local; \ dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ if (dlt_local == DLT_RETURN_TRUE) \ { \ - __VA_ARGS__; \ - log_local.use_timestamp = DLT_USER_TIMESTAMP; \ - log_local.user_timestamp = (uint32_t) TS; \ + ARGS; \ (void)dlt_user_log_write_finish(&log_local); \ } \ } while (0) @@ -258,57 +221,25 @@ * @param CONTEXT object containing information about one special logging context * @param LOGLEVEL the log level of the log message * @param MSGID the message id of log message - * @param ... variable list of arguments + * @param ARGS variable list of arguments: * calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(), * DLT_INT(), DLT_UINT(), DLT_RAW() * @note To avoid the MISRA warning "The comma operator has been used outside a for statement" - * use a semicolon instead of a comma to separate the __VA_ARGS__. + * use a semicolon instead of a comma to separate the ARGS. * Example: DLT_LOG_ID(hContext, DLT_LOG_INFO, 0x1234, DLT_STRING("Hello world"); DLT_INT(123)); */ #ifdef _MSC_VER /* DLT_LOG_ID is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ - } while (0) -#endif - -/** - * Send log message with variable list of messages (intended for non-verbose mode) - * @param CONTEXT object containing information about one special logging context - * @param LOGLEVEL the log level of the log message - * @param MSGID the message id of log message - * @param TS timestamp to be used for log message - * @param ... variable list of arguments - * calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(), - * DLT_INT(), DLT_UINT(), DLT_RAW() - * @note To avoid the MISRA warning "The comma operator has been used outside a for statement" - * use a semicolon instead of a comma to separate the __VA_ARGS__. - * Example: DLT_LOG_ID_TS(hContext, DLT_LOG_INFO, 0x1234, timestamp, DLT_STRING("Hello world"); DLT_INT(123)); - */ -#ifdef _MSC_VER -/* DLT_LOG_ID_TS is not supported by MS Visual C++ */ -/* use function interface instead */ -#else -# define DLT_LOG_ID_TS(CONTEXT, LOGLEVEL, MSGID, TS, ...) \ +# define DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS ...) \ do { \ DltContextData log_local; \ int dlt_local; \ dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \ if (dlt_local == DLT_RETURN_TRUE) \ { \ - __VA_ARGS__; \ - log_local.use_timestamp = DLT_USER_TIMESTAMP; \ - log_local.user_timestamp = (uint32_t) TS; \ + ARGS; \ (void)dlt_user_log_write_finish(&log_local); \ } \ } while (0) @@ -322,17 +253,6 @@ (void)dlt_user_log_write_string(&log_local, TEXT) /** - * Add string parameter with given length to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT ASCII string - * @param LEN length in bytes to take from @a TEXT - */ -#define DLT_SIZED_STRING(TEXT, LEN) \ - (void)dlt_user_log_write_sized_string(&log_local, TEXT, LEN) - -/** * Add constant string parameter to the log messsage. * @param TEXT Constant ASCII string */ @@ -340,17 +260,6 @@ (void)dlt_user_log_write_constant_string(&log_local, TEXT) /** - * Add constant string parameter with given length to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT Constant ASCII string - * @param LEN length in bytes to take from @a TEXT - */ -#define DLT_SIZED_CSTRING(TEXT, LEN) \ - (void)dlt_user_log_write_sized_constant_string(&log_local, TEXT, LEN) - -/** * Add utf8-encoded string parameter to the log messsage. * @param TEXT UTF8-encoded string */ @@ -358,115 +267,6 @@ (void)dlt_user_log_write_utf8_string(&log_local, TEXT) /** - * Add utf8-encoded string parameter with given length to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT UTF8-encoded string - * @param LEN length in bytes to take from @a TEXT - */ -#define DLT_SIZED_UTF8(TEXT, LEN) \ - (void)dlt_user_log_write_sized_utf8_string(&log_local, TEXT, LEN) - -/** - * Add constant utf8-encoded string parameter to the log messsage. - * @param TEXT Constant UTF8-encoded string - */ -#define DLT_CUTF8(TEXT) \ - (void)dlt_user_log_write_constant_utf8_string(&log_local, TEXT) - -/** - * Add constant utf8-encoded string parameter with given length to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT Constant UTF8-encoded string - * @param LEN length in bytes to take from @a TEXT - */ -#define DLT_SIZED_CUTF8(TEXT, LEN) \ - (void)dlt_user_log_write_sized_constant_utf8_string(&log_local, TEXT, LEN) - -/** - * Add string parameter with "name" attribute to the log messsage. - * @param TEXT ASCII string - * @param NAME "name" attribute - */ -#define DLT_STRING_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_string_attr(&log_local, TEXT, NAME) - -/** - * Add string parameter with given length and "name" attribute to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT ASCII string - * @param LEN length in bytes to take from @a TEXT - * @param NAME "name" attribute - */ -#define DLT_SIZED_STRING_ATTR(TEXT, LEN, NAME) \ - (void)dlt_user_log_write_sized_string_attr(&log_local, TEXT, LEN, NAME) - -/** - * Add constant string parameter with "name" attribute to the log messsage. - * @param TEXT Constant ASCII string - * @param NAME "name" attribute - */ -#define DLT_CSTRING_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_constant_string_attr(&log_local, TEXT, NAME) - -/** - * Add constant string parameter with given length and "name" attribute to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT Constant ASCII string - * @param LEN length in bytes to take from @a TEXT - * @param NAME "name" attribute - */ -#define DLT_SIZED_CSTRING_ATTR(TEXT, LEN, NAME) \ - (void)dlt_user_log_write_sized_constant_string_attr(&log_local, TEXT, LEN, NAME) - -/** - * Add utf8-encoded string parameter with "name" attribute to the log messsage. - * @param TEXT UTF8-encoded string - * @param NAME "name" attribute - */ -#define DLT_UTF8_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_utf8_string_attr(&log_local, TEXT, NAME) - -/** - * Add utf8-encoded string parameter with given length and "name" attribute to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT UTF8-encoded string - * @param LEN length in bytes to take from @a TEXT - * @param NAME "name" attribute - */ -#define DLT_SIZED_UTF8_ATTR(TEXT, LEN, NAME) \ - (void)dlt_user_log_write_sized_utf8_string_attr(&log_local, TEXT, LEN, ATTR) - -/** - * Add constant utf8-encoded string parameter with "name" attribute to the log messsage. - * @param TEXT Constant UTF8-encoded string - * @param NAME "name" attribute - */ -#define DLT_CUTF8_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_constant_utf8_string_attr(&log_local, TEXT, NAME) - -/** - * Add constant utf8-encoded string parameter with given length and "name" attribute to the log messsage. - * The string in @a TEXT does not need to be null-terminated, but - * the copied string will be null-terminated at its destination - * in the message buffer. - * @param TEXT Constant UTF8-encoded string - * @param LEN length in bytes to take from @a TEXT - * @param NAME "name" attribute - */ -#define DLT_SIZED_CUTF8_ATTR(TEXT, LEN, NAME) \ - (void)dlt_user_log_write_sized_constant_utf8_string_attr(&log_local, TEXT, LEN, NAME) - -/** * Add boolean parameter to the log messsage. * @param BOOL_VAR Boolean value (mapped to uint8) */ @@ -474,14 +274,6 @@ (void)dlt_user_log_write_bool(&log_local, BOOL_VAR) /** - * Add boolean parameter with "name" attribute to the log messsage. - * @param BOOL_VAR Boolean value (mapped to uint8) - * @param NAME "name" attribute - */ -#define DLT_BOOL_ATTR(BOOL_VAR, NAME) \ - (void)dlt_user_log_write_bool_attr(&log_local, BOOL_VAR, NAME) - -/** * Add float32 parameter to the log messsage. * @param FLOAT32_VAR Float32 value (mapped to float) */ @@ -496,24 +288,6 @@ (void)dlt_user_log_write_float64(&log_local, FLOAT64_VAR) /** - * Add float32 parameter with attributes to the log messsage. - * @param FLOAT32_VAR Float32 value (mapped to float) - * @param NAME "name" attribute - * @param UNIT "unit" attribute - */ -#define DLT_FLOAT32_ATTR(FLOAT32_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_float32_attr(&log_local, FLOAT32_VAR, NAME, UNIT) - -/** - * Add float64 parameter with attributes to the log messsage. - * @param FLOAT64_VAR Float64 value (mapped to double) - * @param NAME "name" attribute - * @param UNIT "unit" attribute - */ -#define DLT_FLOAT64_ATTR(FLOAT64_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_float64_attr(&log_local, FLOAT64_VAR, NAME, UNIT) - -/** * Add integer parameter to the log messsage. * @param INT_VAR integer value */ @@ -533,27 +307,6 @@ (void)dlt_user_log_write_int64(&log_local, INT_VAR) /** - * Add integer parameter with attributes to the log messsage. - * @param INT_VAR integer value - * @param NAME "name" attribute - * @param UNIT "unit" attribute - */ -#define DLT_INT_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int_attr(&log_local, INT_VAR, NAME, UNIT) - -#define DLT_INT8_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int8_attr(&log_local, INT_VAR, NAME, UNIT) - -#define DLT_INT16_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int16_attr(&log_local, INT_VAR, NAME, UNIT) - -#define DLT_INT32_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int32_attr(&log_local, INT_VAR, NAME, UNIT) - -#define DLT_INT64_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int64_attr(&log_local, INT_VAR, NAME, UNIT) - -/** * Add unsigned integer parameter to the log messsage. * @param UINT_VAR unsigned integer value */ @@ -573,27 +326,6 @@ (void)dlt_user_log_write_uint64(&log_local, UINT_VAR) /** - * Add unsigned integer parameter with attributes to the log messsage. - * @param UINT_VAR unsigned integer value - * @param NAME "name" attribute - * @param UNIT "unit" attribute - */ -#define DLT_UINT_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint_attr(&log_local, UINT_VAR, NAME, UNIT) - -#define DLT_UINT8_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint8_attr(&log_local, UINT_VAR, NAME, UNIT) - -#define DLT_UINT16_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint16_attr(&log_local, UINT_VAR, NAME, UNIT) - -#define DLT_UINT32_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint32_attr(&log_local, UINT_VAR, NAME, UNIT) - -#define DLT_UINT64_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint64_attr(&log_local, UINT_VAR, NAME, UNIT) - -/** * Add binary memory block to the log messages. * @param BUF pointer to memory block * @param LEN length of memory block @@ -614,15 +346,6 @@ (void)dlt_user_log_write_uint16_formatted(&log_local, UINT_VAR, DLT_FORMAT_BIN16) /** - * Add binary memory block with "name" attribute to the log messages. - * @param BUF pointer to memory block - * @param LEN length of memory block - * @param NAME "name" attribute - */ -#define DLT_RAW_ATTR(BUF, LEN, NAME) \ - (void)dlt_user_log_write_raw_attr(&log_local, BUF, LEN, NAME) - -/** * Architecture independent macro to print pointers */ #define DLT_PTR(PTR_VAR) \ diff -Nru dlt-daemon-2.18.9/README.md dlt-daemon-2.18.4/README.md --- dlt-daemon-2.18.9/README.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/README.md 2019-09-03 08:28:13.000000000 +0000 @@ -1,62 +1,31 @@ # Diagnostic Log and Trace -Build and Test status: [![Build Status](https://github.com/COVESA/dlt-daemon/actions/workflows/cmake-ctest.yml/badge.svg)]( https://github.com/COVESA/dlt-daemon/actions/workflows/cmake-ctest.yml) +Build and Test status: [![build and test status](https://travis-ci.org/GENIVI/dlt-daemon.svg?branch=master)](https://travis-ci.org/GENIVI/dlt-daemon) Alerts: [![Total alerts](https://img.shields.io/lgtm/alerts/g/GENIVI/dlt-daemon.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/GENIVI/dlt-daemon/alerts/) Code quality: [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/GENIVI/dlt-daemon.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/GENIVI/dlt-daemon/context:cpp) -The Github Actions is now used for Build Status, former is Travis CI - -# Diagnostic Log and Trace - -Welcome to GENIVI Diagnostic Log and Trace (DLT). If you are familiar with DLT -and want to know what's new, check the [Release Notes](ReleaseNotes.md). - -**New to DLT? Great! Welcome aboard.** We prepared a brief [overview](#overview) -for you as well as some information on how to [get started](#get-started) -immediately. After you made yourself familiar with the basic mechanics of DLT, -you can [learn more](#learn-more) about advanced concepts and features. - ## Overview -GENIVI DLT provides a log and trace interface, based on the standardised -protocol specified in the -[AUTOSAR standard 4.0 DLT](https://www.autosar.org/fileadmin/user_upload/standards/classic/4-0/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf). -It is used by other GENIVI components but can serve as logging framework for -other applications without relation to GENIVI. - -The most important terms and parts are depicted in the following figure. Please -refer to [Glossary](doc/dlt_glossary.md) for a full overview over DLT-specific -terms. +This component provides a log and trace interface, based on the standardised +protocol specified in the AUTOSAR standard 4.0 DLT. This software can be used +by GENIVI components and other applications as logging framework. + +DLT basically consists of 3 components: + +- **DLT Library**: Enables DLT logging for DLT user applications and temporary + storage of log messages if daemon isn't available. +- **DLT Daemon**: Receiving log messages from DLT user applications and + temporary storage of log messages if client isn't available. Transmit log + messages to DLT Client and response to control messages. +- **DLT Client**: Receiving and storing log messages from DLT Daemon into one + single trace file and sending control message ![alt text](doc/images/dlt_overview.png "DLT Overview") -- A **DLT User** essentially is an application that serves its respective (not -DLT-related) purpose and produces DLT log messages. It utilizes the DLT library -to craft and transmit these messages. -- The **DLT Library** provides a convenient API to DLT Users (i.e. applications) -to create DLT log messages and hand them over to the DLT Daemon. If the latter -is not avilable, the library will cache the messages in a ring buffer so they -don't get lost immediately. -- The **DLT Daemon** is the DLT communication interface of an ECU. It collects -and buffers log messages from one or more DLT users running on the ECU and -provides them to DLT clients upon their request. The daemon also accepts control -messages from the clients to adjust the daemon's or the aplications' behaviour. -- A **DLT Client** receives and consumes the log messages from DLT Users by -fetching them from DLT Daemons. It may also issue control messages to control -the behaviour of a DLT Daemon or its connected DLT Users. A DLT client can even -transmit user-defined data to a DLT User through so-calles injection messages. - -This is only the simplest of all use cases that you will further pursue in the -[Get Started](#get-started) section. Once you want to [learn more](#learn-more), -you will find that the repository contains advanced features utilizing several -adaptors and console utilities as well as test applications. - -## Get Started -In this section, you can learn how to [build and install](#build-and-install) -DLT. Then you can choose to [run a DLT demo](#run-a-dlt-demo) setup or to start -by [developing your own DLT-featured application](#develop-your-own-dlt-featured-application). +Furthermore, the repository contains several adaptors, console utilities as well +as test applications. -### Build and install +## Build and install The following packages need to be installed in order to be able to build and install DLT daemon: @@ -64,51 +33,114 @@ - cmake - zlib - dbus -- json-c (only required for dlt-receives extended filtering) On Ubuntu those dependencies can be installed with the following command: -```bash -sudo apt-get install cmake zlib1g-dev libdbus-glib-1-dev -optional: sudo apt-get install libjson-c-dev # in case you want to use dlt-receives extended filtering -``` - -Then proceed to download DLT if you haven't already. We recommend cloning the -repository, but downloading and extracting a zip-archive is fine as well. -```bash -cd /path/to/workspace -git clone https://github.com/GENIVI/dlt-daemon.git -``` +`sudo apt-get install cmake zlib1g-dev libdbus-glib-1-dev` To build and install the DLT daemon, follow these steps: ```bash -cd /path/to/workspace/dlt-daemon mkdir build cd build cmake .. make optional: sudo make install -optional: sudo ldconfig # in case you executed make install +optional: sudo ldconfig +``` + +### Configuration + +#### General Options + +Option | Value | Comment +:--- | :--- | :--- +BUILD\_SHARED\_LIBS | ON | Set to OFF to build static libraries +DLT\_IPC |"FIFO" | Set to either "UNIX\_SOCKET" or "FIFO" +WITH\_DLT\_USE\_IPv6 | ON | Set to ON for IPv6 support +WITH\_DLT\_EXAMPLES | ON | Set to ON to build src/examples binaries +DLT\_USER | genivi | Set user for process not run as root +WITH\_CHECK\_CONFIG\_FILE | OFF | Set to ON to create a configure file of CheckIncludeFiles and CheckFunctionExists +CMAKE\_INSTALL\_PREFIX | /usr/local +CMAKE\_BUILD\_TYPE | RelWithDebInfo +WITH\_UDP\_CONNECTION | ON | Set to ON to enable dlt UDP multicast SUPPORT + +#### Command Line Tool Options + + Option | Value | Comment + :--- | :--- | :--- +WITH\_DLT\_ADAPTOR | OFF | Set to ON to build src/adaptor binaries +WITH\_DLT\_CONSOLE | ON | Set to ON to build src/console binaries +WITH\_DLT\_SYSTEM | OFF | Set to ON to build src/system binaries +WITH\_DLT\_LOGSTORAGE\_CTRL\_UDEV | OFF | PROTOTYPE! Set to ON to build +WITH\_DLT\_KPI | OFF | Set to ON to build src/kpi binaries + +#### Linux OS Integration Options + + Option | Value | Comment + :--- | :--- | :--- +WITH\_SYSTEMD | OFF | Set to ON to run CMakeLists.txt in systemd +WITH\_SYSTEMD\_WATCHDOG | OFF | Set to ON to use the systemd watchdog in dlt-daemon +WITH\_SYSTEMD\_JOURNAL | OFF | Set to ON to use the systemd journal in dlt-system +WITH\_DLT\_DBUS | OFF | Set to ON to build src/dbus binaries + +#### Documentation Options + +Option | Value | Comment + :--- | :--- | :--- +WITH\_DOC | OFF | Set to ON to build documentation target +WITH\_MAN | OFF | Set to OFF to skip building of man pages + +#### Test Options + +Option | Value | Comment +:--- | :--- | :--- +WITH\_TESTSCRIPTS | OFF | Set to ON to run CMakeLists.txt in test scripts +WITH\_DLT\_TESTS | ON | Set to ON to build src/test binaries +WITH\_DLTTEST | OFF | Set to ON to build with modifications to test User-Daemon communication with corrupt messages +WITH\_DLT\_UNIT\_TESTS | OFF | Set to ON to build unit test binaries +WITH\_GPROF | OFF | Set \-pg to compile flag + +#### Experimental Features Options + +Option | Value | Comment +:--- | :--- | :--- +WITH\_DLT\_SHM\_ENABLE | OFF | Set to OFF to use FIFO as IPC from user to daemon +WITH\_DLT\_CXX11\_EXT | OFF | Set to ON to build C++11 extensions +WITH\_DLT\_COREDUMPHANDLER | OFF | EXPERIMENTAL! Set to ON to build src/core\_dump\_handler binaries. EXPERIMENTAL + +In order to change these options, you can modify these values with cmake, do the +appropriate changes in CmakeList.txt or via the commandline for cmake + +Change a value with: cmake -D\=\, E.g. + +```bash +cmake .. -DWITH_SYSTEMD=ON -DWITH_SYSTEMD_JOURNAL=ON -DCMAKE_INSTALL_PREFIX=/usr ``` -CMake accepts a plethora of [build options](doc/dlt_build_options.md) to -configure the build to suit your needs. -### Run a DLT demo -In case you haven't had a look at the brief [overview](#overview), now would be -the perfect occasion to learn about the most important terms and to get an idea -where data is buffered. Then go on with our guide on [how to set up a DLT demo -setup](doc/dlt_demo_setup.md). - -### Develop your own DLT-featured application - -Now that you have seen DLT in action, you probably want to develop your own -applications using DLT. You will find everything you need in our ["DLT for -Application Developers" guide](doc/dlt_for_developers.md). - -A hint: If you want to read the API documentation, you have to build it locally -at the moment. The API documentation is generated with _doxygen_. To build it, -run cmake with the ```-DWITH_DOC=ON``` option, e.g.: +## Documentation + +Specific documentation can be found in the following files: + +- [ReleaseNotes](ReleaseNotes.md) +- [Glossary](doc/dlt_glossary.md) +- [For Developers](doc/dlt_for_developers.md) +- [Logstorage](doc/dlt_offline_logstorage.md) +- [MultiNode](doc/dlt_multinode.md) +- [Extended Network Trace](doc/dlt_extended_network_trace.md) +- [DLT Filetransfer](doc/dlt_filetransfer.md) +- [DLT KPI](doc/dlt_kpi.md) +- [DLT Core Dump Handler](/doc/dlt_cdh.md) + +All text based documentation will be replaced with by Markdown-based documentation for convinient access. + +Old documentation (not maintained - will be removed in future releases): + +- DLT Design Specification: doc/dlt\_design\_specification.txt + +### API Documentation + +The API documentation is generated with _doxygen_. ```bash mkdir build @@ -117,47 +149,25 @@ make doc ``` -### Build DLT debian package - -To build the DLT debian package for your own purpose, follow these steps: +### Manpages -```bash -dpkg-buildpackage -us -uc -``` +- [dlt-daemon(1)](doc/dlt-daemon.1.md) +- [dlt.conf(5)](doc/dlt.conf.5.md) +- [dlt-system(1)](doc/dlt-system.1.md) +- [dlt-system.conf(5)](doc/dlt-system.conf.5.md) +- [dlt-convert(1)](doc/dlt-convert.1.md) +- [dlt-sortbytimestamp(1)](doc/dlt-sortbytimestamp.1.md) +- [dlt-receive(1)](doc/dlt-receive.1.md) +- [dlt-control(1)](doc/dlt-control.1.md) +- [dlt-logstorage-ctrl(1)](doc/dlt-logstorage-ctrl.1.md) +- [dlt-passive-node-ctrl(1)](doc/dlt-passive-node-ctrl.1.md) +- [dlt-adaptor-stdin(1)](doc/dlt-adaptor-stdin.1.md) +- [dlt-adaptor-udp(1)](doc/dlt-adaptor-udp.1.md) -## Learn more -Once you got your feet wet with developing your first application, you might -want to learn more. Find out about DLT's [advanced topics](#advanced-topics), -learn how to [configure, control and interface](#configure-control-and-interface) -DLT or study its internals by checking out the [design -specifications](./doc/dlt_design_specification.md). - -### Advanced Topics -The GENIVI DLT implementation is capable of by far more than to "just" send log -message. You will get an overview of advanced features in this section. Follow -the links to learn more about the respective concept. - -| Document | Description | -|----|----| -| [Build Options](./doc/dlt_build_options.md) | The CMake build system provides a large amount of build options. They let you turn on or off certain features and provide alternative implementation details. | -| [LogStorage](doc/dlt_offline_logstorage.md) | The DLT Daemon as well as the DLT libary provide buffers for caching log data during absence of a consumer. However, some use cases require to write large amounts of log message e.g. to mass storages for long term storage or because no other means of exfiltrating the log data is available. | -| [MultiNode](doc/dlt_multinode.md) | A DLT Daemon can run as a gateway to connect multiple passive nodes. Each passive node has its owns DLT Applications and runs its own daemon. The gateway node connects to all of them, collects the logs and routes them to the DLT Client. | -| [Extended Network Trace](doc/dlt_extended_network_trace.md) | Normal DLT messages are limited in size. To overcome this limitation the feature network trace message allows the user to send or truncate messages which would not fit into a normal DLT message. | -| [DLT Filetransfer](doc/dlt_filetransfer.md) | Although not originally designed for this, files can be transmitted over DLT. A corresponding DLT Client (e.g. DLT Viewer) can receive and decode them accordingly. | -| [DLT KPI](doc/dlt_kpi.md) | Valueable status information about the monitored system can be read via DLT as well. The information under `/proc` of the target system is at your hands easily. | -| [DLT Core Dump Handler](/doc/dlt_cdh.md) | This tool collects and extracts debug information then utilize [DLT Filetransfer](doc/dlt_filetransfer.md) to transfer the information to client. | - -### Configure, Control and Interface - -There is still lots to discover about DLT. If you turn on the generation of -manpages with the cmake option ```-DWITH_MAN=ON``` you can learn how to -configure DLT to exactly suit your needs, how to control the behvaiour of -running instances and how to interface DLT with existing system through -provided adaptors. +The man pages are generated with *pandoc*. -The man pages are generated with *pandoc*, which also needs *asciidoc* as dependency. +If the man pages are changed the following command must be executed. -Build manpages (initally or because something changed) with e.g. ```bash mkdir build cd build @@ -165,24 +175,7 @@ make generate_man ``` -| Document | Description | -|----|----| -| *Configuration* || -|[dlt-daemon(1)](doc/dlt-daemon.1.md) | How to start DLT-Daemon | -|[dlt.conf(5)](doc/dlt.conf.5.md) | Configure the DLT framework to reflect your use case| -| *Control running instances of DLT*|| -|[dlt-receive(1)](doc/dlt-receive.1.md)| Receive DLT messages from daemon and print or store the log messages. | -|[dlt-control(1)](doc/dlt-control.1.md)| Send control messages to daemon. | -|[dlt-logstorage-ctrl(1)](doc/dlt-logstorage-ctrl.1.md)| Send a trigger to daemon to connect/disconnect certain logstorage device, or send a demand to sync data the internal buffer into logstorage file. | -|[dlt-passive-node-ctrl(1)](doc/dlt-passive-node-ctrl.1.md)| Send a trigger to daemon to connect/disconnect passive daemon. | -| *Interfacing DLT* || -|[dlt-system(1)](doc/dlt-system.1.md) | DLT-System provides a way to directly access system logs via DLT | -|[dlt-system.conf(5)](doc/dlt-system.conf.5.md) | Configure DLT-System | -|[dlt-adaptor-stdin(1)](doc/dlt-adaptor-stdin.1.md)| Adaptor for forwarding input from stdin to daemon. | -|[dlt-adaptor-udp(1)](doc/dlt-adaptor-udp.1.md)| Adaptor for forwarding received UDP messages to daemon. | -|[dlt-convert(1)](doc/dlt-convert.1.md)| Convert DLT files into human readable format. | -|[dlt-sortbytimestamp(1)](doc/dlt-sortbytimestamp.1.md)| Read log messages from DLT file, sort by timestamp, and store them again. | -|[dlt-qnx-system(1)](doc/dlt-qnx-system.md) | Access system logs in QNX with DLT | +The generated man pages overwrite the existing ones. ## Contribution @@ -190,28 +183,14 @@ work that makes it easier to handle later on. If you want to commit your changes, create a -[Pull Request](https://github.com/genivi/dlt-daemon/pulls) in Github. Please -make sure to follow the -[Rules for commit messages](https://at.projects.genivi.org/wiki/display/PROJ/Rules+for+Commit+Messages) +[Pull Request](https://github.com/genivi/dlt-daemon/pulls) in Github. ### Coding Rules -This project is now using clang-format as replacement of uncrustify. - -For convenience, any code changes will be harmonized before commit by hooks/pre-commit. +Before contributing code, run uncrustify to harmonize code style. -- Install clang-format - -- Install pre-commit script by: - - ```bash - cp scripts/pre-commit.sample .git/hooks/pre-commit - ``` - -- Configuration: .clang-format - -For reference to clang-format, you can check with: -[Configurator](https://zed0.co.uk/clang-format-configurator/) +Configuration: util/uncrustify.cfg +uncrustify version: 0.68\_f ## Known issues @@ -236,10 +215,13 @@ Full information on the license for the cityhash code is available in "COPYING" file in src/core\_dump\_handler/cityhash\_c. +## Mailinglist + +https://lists.genivi.org/mailman/listinfo/genivi-diagnostic-log-and-trace_lists.genivi.org ## Contact -Methner, Michael , -Le Van, Khanh +Saya Sugiura , +Quynh Le Hoang Ngoc ![alt text](doc/images/genivilogo.png "GENIVI") diff -Nru dlt-daemon-2.18.9/ReleaseNotes.md dlt-daemon-2.18.4/ReleaseNotes.md --- dlt-daemon-2.18.9/ReleaseNotes.md 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/ReleaseNotes.md 2019-09-03 08:28:13.000000000 +0000 @@ -4,290 +4,10 @@ ## Version -2.18.8 STABLE +2.18.4 STABLE ## Changes -### 2.18.8 - - * lib: Fix wrong type alert from lgtm - * gtest_dlt_daemon_gateway: fix gtest build failed - * lib: generate dlt library internal log file - * tests: add stdlib to dlt_cpp_extension - * dlt_user: Make dlt_init thread safe - * remove clang-tidy analyzer warnings: incompatible pointer type - * debian: improve debian build package - * dlt-control-common: shutdown and close socket - * dlt_common: improve function description - * gtest: Bring-in changes - * gtest: Rework WORKING_DIRECTORY - * gtest: Correct data amount in gtest_dlt_common - * cmake: Set empty to systemd_SRCS - * gtest: Refactor tests/CMakeLists.txt - * lib: Add SOCK_CLOEXEC to socket - * daemon: Create parent directory for unix socket - * cmake: Correct added subdirectories - * console: Add cmake options for control and timestamp - * tests: Adapt to DLT_DISABLE_MACRO - * header: Adapt to DLT_DISABLE_MACRO - * include: Refactor CMakeLists.txt - * gtest: Change script name to gtest_dlt_daemon_offline_log.sh - * daemon: Enable to use FIFO on QNX - * tests: Add new test case with given buffer - * tests: Enable macro disabling - * lib: Add new interfaces with given buffer - * Implemention of tests for the dlt-qnx-system module - * lib: Add MaxFileSize handling - * client: pthread_join for deinit - * doc: update initial log level document - * dlt-system: Fix memory leak in dlt-system config - * dlt_common: remove duplicate stdbool header - * dlt-control: Add option to config port - * system: use signalfd for dlt-system - * console: provides args option to enable send/receive serial header - * fix malformed printf format strings (#295) - * cmake: Set WITH_LEGACY_INCLUDE_PATH to ON as default (#334) - * Make the legacy include path a CMake option (#332) - * daemon: Call dlt_daemon_configuration_load() properly (#330) - * dlt_user: Use pthread_setname_np() if available (#326) - * libdlt: Add legacy include path in exported CMake config file (#327) - * lib: Set TYLE to 1 for BOOL type (#320) - * file-transfer: Abort file transfer if get serial number failed - * dlt_user.c: fixing casting wrong type - * dlt-sortbytimestamp: Remove duplicated conditional statements code - * dlt-convert: Remove duplicated conditional statements code - * doc: Minor fix in dlt_for_developers.md (#321) - * dlt-control-common.c: Fix build failure due to out-of-bound write -Werror=stringop-truncation - * Extend include path in *.pc file (#319) - -### 2.18.7 - - * dlt_common: correct read/write position - * Update document and fix conversion warning - * dlt_common: Increment size after memcpy() - * Using dlt_vlog in verbose option in dlt_client.c - * dlt-logstorage-ctrl: Improve option force to sync - * Do not use Cpack - * Debian packaging - * Update dlt-system.conf documentation - * dlt_user: correct handling return value - * Update dlt-system-syslog with IPv6 - * Alternative solutions for json-c dependency - * dlt-receive:Fix compiler warning - * daemon: Improve signal handler for timers - * dlt-doc:Fix generating HTML documentation and man pages - * Apply uncrustify for src/daemon/* and src/lib/* - * Update uncrustify - * dlt-receive: Implemented gtest for extended filtering - * dlt-receive: Enabled more filtering by using json filter files - * dlt_receive: handle exception in signal handler. - * dlt message header broken - * Add missing string functions (#309) - * gtest: Find system-provided external gtest (#301) - * Make nonverbose mode non exclusive (#300) - * Merge pull request from GHSA-7cqp-2hqj-mh3f - * daemon: check the conf inputs - * Export cmake config file (#289) - * Better formatting of RAWD (#291) - * fix bad funcion cast in dlt_user_log_out_error_handling (#294) - * Contact information update (#299) - * dlt-receive: Add option to configure port of dlt receive (#293) - * Add verbose mode attribute handling (#292) - * Resolving broken link in README (#297) - * fscanf() uses dynamic formatting to prevent buffer overflow (#288) - * Make dlt pipe only readable by user (#285) - * dlt_client_main_loop running in an infinite loop restricts graceful exit of DLT Client code (#284) - -### 2.18.6 - - * Update releaseNotes and version to v2.18.6 - * doc: Limitation to SIGUSR1 usage on Android - * gtest_dlt_common: fix seg fault when using memcpy(). - * example: Added customization of CxtID and AppID - * other: fix remaining conversion warnings - * library: fix conversion warnings - * tests: fix conversion warnings - * daemon: fix conversion warnings - * shared: fix conversion warnings - * logstorage: fix conversion warnings - * console :fix conversion warnings - * gateway: fix compile warnings - * readme: cpack document for debian package - * CMakeList: implement cpack for debian package - * dlt-receive: flush stdout buffer by signal - * gtest: Include necessary header - * doc: Update doc for the maintain logstorage loglevel implementation - * logstorage: Implement general config to maintain logstorage loglevel - * daemon: Correct order of runtime config load. - * libdlt: Use SIGUSR1 for thread on Android - * dlt-daemon: log levels are not controlled - * dlt-daemon: complete logstorage path with '/' - * libdlt: Use poll to avoid CPU high load - * libdlt: Flush all data in atexit_handler - * dlt-convert: replace system() by dlt_execute_command() - * dlt_common: Execute system command using execvp - * logstorage: snprintf return check - * logstorage: Update unit test - * logstorage: Add debug logs - * logstorage: Modify rearranging file - * logstorage: Handle wrap-around - * libdlt: support short version - * design doc: update spec for new environment variable - * doc: update disable injection msg for developer - * libdlt: disable injection msg via env var - * doc: Rewrote the DLT user documentation. - * daemon: Alternative of timerfd in QNX - * bug-fix: fix invalid file descriptor check - * dlt_user: fix invalid poll timeout - * README: Switch from travis-ci.org to travis-ci.com - * Add support for logging with VSOCK (#255) - * Use dlt_defaults for dlt-logd-converter in Android.bp (#271) - * dlt-control.c: return -1 on error (#259) - * Check size of ring buffer (#269) - * dlt_common: Fix buffer overflow in dlt_filter_load (#275) - * dlt-daemon: Adds an option to disable injection mode (#266) - * Add message length check - * Init logd crash buffer - * Avoid memory access errors with 4-chars context ids (#250) - * dlt_client.c: remove misleading error message (#258) - * Fix overflow for -d argument in dlt-example-user (#270) - * dlt-daemon.c: exit early on error (#261) - * Remove nonexistent file from Android.bp (#264) - * dlt-control.c: initialize dltdata via struct literal (#257) - * dlt-common.c: ensure null terminated string (#256) - * Make it easier to use libdlt when building DLT as a CMake subproject (#254) - * Simplify setting of CONFIGURATION_FILES_DIR in CMakeLists.txt (#247) - * Create codeql-analysis.yml (#252) - * Modify CMAKE_C_COMPILER check for QNX to accept "qcc" (#246) - * dlt_offline: fix build failures with gcc-10 (#245) - * Implement DLTClient for UDP multicast (#240) - * Revert "dlt_offline: fix build failures with gcc-10" - * dlt_offline: fix build failures with gcc-10 - * sd-daemon.c: Fix build with newer glibc and musl libc - * dlt_user.c: fix the lack of DLT_NETWORK_TRACE_ENABLE definition - -### 2.18.5 - - * Update releaseNotes and version to v2.18.5 - * slog2 adapter on QNX - * Update gtest_dlt_all.sh to detect core dump - * dlt-daemon.c: fix printf format %d to %ld that formats a long - * doc/CMakeList.txt: replace dlt_design_specification.txt to .md - * network trace: Fix macro usage - * limit logspam in gateway on client overflow - * Android.bp: fix dlt_user.h genrule - * logstorage: Issue with more than 2 filters - * remove unused feature - * gtest_dlt_daemon_gateway: correct comparison operator syntax - * set DLT_NETWORK_TRACE_ENABLE by cmakedefine - * doc: Update dlt_offline_logstorage.md - * UT: Fix segfault in logstorage test - * logstorage: support all stragegies - * update cmake VERSION variables - * simplify and fix android version script - * execute unittests with cmake - * dlt_design_specification: update content - * dlt_design_specification: convert from .txt to .md format - * logstorage: fix syncbehaviour - * daemon: Fix smoketest - * unittest: Update according to API's changes - * offline storage: Improvement log messages at bottom - * common: Isolate FIFO/Unix socket - * libdlt: Relocate dltFifoBaseDir setting - * doc: md file for dlt_gateway.conf - * network trace: Include necessary headers - * network trace: Add mqueue verification - * Unittest for new api - * Remove duplicate definition of DLT_CONVERT_TEXTBUFSIZE - * Improve performance of DLT file parsing - * relocation dlt_check_envvar() and update dlt_init() functions - * Redirect stdout to stderr - * Unittest: Update testcase - * gateway: Improvement of handling Gateway config - * daemon: Avoid spamming message buffer overflow - * gateway: Support infinite loop of retry - * gateway: Configurable interval time - * tests: remove unused zlib include - * disable android services by default - * logstorage: Add NULL check of IDs - * snprintf ret > 0 is not always an error - * fix some gcc9 compiler warnings - * fix clang warnings about GNU stuff - * android logd forwarder - * fix gateway config element search - * doc: update a note for logstorage with wildcard - * daemon: logstorage with wildcards - * Limit log messages on full buffer - * Android: Enable Android build - * logstorage: Filter section handling - * doc: Logstorage non-verbose filter - * correct errno usage in dlt_stop_threads - * shared: Read DLT header until it's found - * Use ssize_t for bytes_written - * Fix dlt-sortbytimestamp - * Remove DLT_PACKED redefinition guard in dlt_common.h - * rename definition PACKED to DLT_PACKED - * daemon: Remove empty line in daemon log - * Revert "dlt_common: Fix buffer overflow in dlt_buffer_get (#215)" - * FIX: prevent usage of uninitialized message queue handle - * Add unit tests for new sized string functions - * Add documentation for new sized string functions - * Add macro wrappers for new sized string functions - * Minor optimization - * Add functions for writing strings with known sizes - * Add helper function for writing strings with known sizes - * Fixed empty internal message in dlt-daemon.c (#225) - * common: Fix uint64 type (#217) - * dlt_common: Fix buffer overflow in dlt_buffer_get (#215) - * FIX: Check validity of `file` pointer before usage. - * doc/dlt_for_developers.md: Fix wrong DLT include directive - * Remove naming of variadic macro parameters - * sys/poll.h: deprecate old sys/poll.h include header, now glibc/musl wants poll.h being included directly. This fixes a build failure on musl systems with strict c hardening flags - * dlt-test-init-free: fix build failure with strict compiler flags, due to uint being undefined. This is actually an "int" type, looking at the test implementation - * dlt_user.h: fix build when musl is the libc implementation, by adding a missing include for pthread_t reference: - * dlt.conf: suppress the warnings udp multicast (#197) - * dlt_daemon_socket: leave while socket binds fails - * dlt_user: init DltContextData before use - * dlt-daemon: fix resource leak - * console: fix memleak of dlt-logstorage-list - * BugFix: SEGFAULT when using AppArmor (#192) - * Fix compiler warnings: pointer of type ‘void *’ used in arithmetic (#196) - * Change the DLT_CHECK_RCV_DATA_SIZE macro to an internal function (#191) - * Fix a potential memory leak in file transfer (#126) - * Provide DLT_GET_APPID macro (#187) (#188) - * dlt-offline-trace: fix bug and hardcode (#174) (#186) - * Avoided Seg fault in dlt_message_payload (#179) (#181) - * Improvement: Make ZLib dependency optional (#182) - * fix the dlt offline trace file name creation (#178) - * libdlt: fix memory leak - * Removed unused headers(epoll) in UDP connection - * Fix: Propper usage of LoggingMode: "uncrustification" - * Fix: Propper usage of LoggingMode in ".../dlt-runtime.cfg" - * libdlt: reattachment and improvement in dlt thread (#171) - * dlt-system: Call tzset before localtime_r (#165) - * Update cmakelist, fix build due to copy-paste error (#170) - * Bugfix: dlt-system-journal - * Proper setup and error checking of pthread_create - * udp: Disable WITH_UDP_CONNECTION as default - * doxygen improvement - * doc: Modify markdown doc generation - * doc: Update dlt_for_developers.md - * cmake improvement for Logstorage console - * cmake add component for libdlt.so - * parser: Change maximum number of config section - * common: Remove unused structure - * dlt_common: Use defined macro - * libdlt: calculate resend buffer memory - * lib: Disable extended header in non verbose mode by env var - * shm: Resend dlt msg when client connect - * lib: Remove else nothing - * network trace: Do not allow DLT usage in forked child - * lib: Assign fd after it's closed - * console: Add get sw version control msg - * console: Tool to merge multiple DLT files - * dlt-test: Add message length option - * Add user custom timestamp interface - ### 2.18.4 * Update ReleaseNotes and version to v2.18.4 diff -Nru dlt-daemon-2.18.9/scripts/pre-commit.sample dlt-daemon-2.18.4/scripts/pre-commit.sample --- dlt-daemon-2.18.9/scripts/pre-commit.sample 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/scripts/pre-commit.sample 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ -#!/bin/sh - -gitclangformat=$(which git-clang-format) - -if [ "$gitclangformat" == "" ] -then - gitclangformat=$(find /usr/bin/ -name "git-clang-format*") -fi - -against=`git rev-parse --verify HEAD 2>&1` - -if [ $against == "" ] -then - # Initial commit: diff against an empty tree object - against=5394c6fa5bf40d9bc8619026cbc4c306211a8499 -fi - -$gitclangformat $against -f -q - -if [ $? != 0 ] -then - echo "Format error!" - echo "Use git clang-format" - exit 1 -fi - -# Now update format changes and commit -git add $(git diff --name-only --cached) diff -Nru dlt-daemon-2.18.9/src/adaptor/CMakeLists.txt dlt-daemon-2.18.4/src/adaptor/CMakeLists.txt --- dlt-daemon-2.18.9/src/adaptor/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/adaptor/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -13,24 +13,18 @@ # For further information see http://www.genivi.org/. ####### -if (WITH_DLT_ADAPTOR_STDIN OR WITH_DLT_ADAPTOR) - set(dlt_adaptor_stdin_SRCS dlt-adaptor-stdin.c) - add_executable(dlt-adaptor-stdin ${dlt_adaptor_stdin_SRCS}) - target_link_libraries(dlt-adaptor-stdin dlt) - set_target_properties(dlt-adaptor-stdin PROPERTIES LINKER_LANGUAGE C) +set(dlt_adaptor_stdin_SRCS dlt-adaptor-stdin.c) +add_executable(dlt-adaptor-stdin ${dlt_adaptor_stdin_SRCS}) +target_link_libraries(dlt-adaptor-stdin dlt) +set_target_properties(dlt-adaptor-stdin PROPERTIES LINKER_LANGUAGE C) - install(TARGETS dlt-adaptor-stdin - RUNTIME DESTINATION bin - COMPONENT base) -endif() +set(dlt_adaptor_udp_SRCS dlt-adaptor-udp.c) +add_executable(dlt-adaptor-udp ${dlt_adaptor_udp_SRCS}) +target_link_libraries(dlt-adaptor-udp dlt) +set_target_properties(dlt-adaptor-udp PROPERTIES LINKER_LANGUAGE C) + +install(TARGETS dlt-adaptor-stdin dlt-adaptor-udp + RUNTIME DESTINATION bin + COMPONENT base) -if (WITH_DLT_ADAPTOR_UDP OR WITH_DLT_ADAPTOR) - set(dlt_adaptor_udp_SRCS dlt-adaptor-udp.c) - add_executable(dlt-adaptor-udp ${dlt_adaptor_udp_SRCS}) - target_link_libraries(dlt-adaptor-udp dlt) - set_target_properties(dlt-adaptor-udp PROPERTIES LINKER_LANGUAGE C) - install(TARGETS dlt-adaptor-udp - RUNTIME DESTINATION bin - COMPONENT base) -endif() diff -Nru dlt-daemon-2.18.9/src/adaptor/dlt-adaptor-stdin.c dlt-daemon-2.18.4/src/adaptor/dlt-adaptor-stdin.c --- dlt-daemon-2.18.9/src/adaptor/dlt-adaptor-stdin.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/adaptor/dlt-adaptor-stdin.c 2019-09-03 08:28:13.000000000 +0000 @@ -69,7 +69,6 @@ #include "dlt_common.h" #include "dlt_user.h" -#include "dlt_user_macros.h" #define MAXSTRLEN 1024 diff -Nru dlt-daemon-2.18.9/src/adaptor/dlt-adaptor-udp.c dlt-daemon-2.18.4/src/adaptor/dlt-adaptor-udp.c --- dlt-daemon-2.18.9/src/adaptor/dlt-adaptor-udp.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/adaptor/dlt-adaptor-udp.c 2019-09-03 08:28:13.000000000 +0000 @@ -75,8 +75,6 @@ #include "dlt_common.h" #include "dlt_user.h" -#include "dlt_user_macros.h" - /* Port number, to which the syslogd-ng sends its log messages */ #define RCVPORT 47111 diff -Nru dlt-daemon-2.18.9/src/android/dlt-logd-converter.cpp dlt-daemon-2.18.4/src/android/dlt-logd-converter.cpp --- dlt-daemon-2.18.9/src/android/dlt-logd-converter.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/android/dlt-logd-converter.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,249 +0,0 @@ -/** - * @licence app begin@ - * Copyright (C) 2019 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * DLT logd converter: Retrieve log entries from logd and forward them to DLT. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \file: dlt-logd-convert - * For further information see http://www.genivi.org/. - * @licence end@ - */ -#include -#include -#include -#include -#include - -#include - -#include - -DLT_DECLARE_CONTEXT(dlt_ctx_self) -DLT_DECLARE_CONTEXT(dlt_ctx_main) -DLT_DECLARE_CONTEXT(dlt_ctx_rdio) -DLT_DECLARE_CONTEXT(dlt_ctx_evnt) /* Binary Buffer */ -DLT_DECLARE_CONTEXT(dlt_ctx_syst) -DLT_DECLARE_CONTEXT(dlt_ctx_crsh) -DLT_DECLARE_CONTEXT(dlt_ctx_stat) /* Binary Buffer */ -DLT_DECLARE_CONTEXT(dlt_ctx_secu) /* Binary Buffer */ -DLT_DECLARE_CONTEXT(dlt_ctx_krnl) - -volatile sig_atomic_t exit_parser_loop = false; - -static inline struct logger *init_logger(struct logger_list *logger_list, log_id_t log_id) -{ - struct logger *logger; - logger = android_logger_open(logger_list, log_id); - if (logger == nullptr) { - DLT_LOG(dlt_ctx_self, DLT_LOG_WARN, DLT_STRING("could not open logd buffer id="), DLT_INT64(log_id)); - } - return logger; -} - -static struct logger_list *init_logger_list(bool skip_binary_buffers) -{ - struct logger_list *logger_list; - logger_list = android_logger_list_alloc(O_RDONLY, 0, 0); - if (logger_list == nullptr) { - DLT_LOG(dlt_ctx_self, DLT_LOG_FATAL, DLT_STRING("could not allocate logger list")); - return nullptr; - } - - /** - * logd buffer types are defined in: - * system/core/include/log/android/log.h - */ - init_logger(logger_list, LOG_ID_MAIN); - init_logger(logger_list, LOG_ID_RADIO); - init_logger(logger_list, LOG_ID_SYSTEM); - init_logger(logger_list, LOG_ID_KERNEL); - init_logger(logger_list, LOG_ID_CRASH); - - if (!skip_binary_buffers) { - init_logger(logger_list, LOG_ID_EVENTS); - init_logger(logger_list, LOG_ID_STATS); - init_logger(logger_list, LOG_ID_SECURITY); - } - - return logger_list; -} - -static DltContext *get_log_context_from_log_msg(struct log_msg *log_msg) -{ - switch (log_msg->id()) { - case LOG_ID_MAIN: - return &dlt_ctx_main; - case LOG_ID_RADIO: - return &dlt_ctx_rdio; - case LOG_ID_EVENTS: - return &dlt_ctx_evnt; - case LOG_ID_SYSTEM: - return &dlt_ctx_syst; - case LOG_ID_CRASH: - return &dlt_ctx_crsh; - case LOG_ID_STATS: - return &dlt_ctx_stat; - case LOG_ID_SECURITY: - return &dlt_ctx_secu; - case LOG_ID_KERNEL: - return &dlt_ctx_krnl; - default: - return &dlt_ctx_self; - } -} - -static uint32_t get_timestamp_from_log_msg(struct log_msg *log_msg) -{ - /* in 0.1 ms = 100 us */ - return (uint32_t)log_msg->entry.sec * 10000 + (uint32_t)log_msg->entry.nsec / 100000; -} - -static DltLogLevelType get_log_level_from_log_msg(struct log_msg *log_msg) -{ - android_LogPriority priority = static_cast(log_msg->msg()[0]); - switch (priority) { - case ANDROID_LOG_VERBOSE: - return DLT_LOG_VERBOSE; - case ANDROID_LOG_DEBUG: - return DLT_LOG_DEBUG; - case ANDROID_LOG_INFO: - return DLT_LOG_INFO; - case ANDROID_LOG_WARN: - return DLT_LOG_WARN; - case ANDROID_LOG_ERROR: - return DLT_LOG_ERROR; - case ANDROID_LOG_FATAL: - return DLT_LOG_FATAL; - case ANDROID_LOG_SILENT: - return DLT_LOG_OFF; - case ANDROID_LOG_UNKNOWN: - case ANDROID_LOG_DEFAULT: - default: - return DLT_LOG_DEFAULT; - } -} - -void signal_handler(int signal) -{ - (void) signal; - if (signal == SIGTERM) { - exit_parser_loop = true; - } -} - -static int logd_parser_loop(struct logger_list *logger_list) -{ - struct log_msg log_msg; - int ret; - - DLT_LOG(dlt_ctx_self, DLT_LOG_VERBOSE, DLT_STRING("Entering parsing loop")); - - while (!exit_parser_loop) { - ret = android_logger_list_read(logger_list, &log_msg); - if (ret == -EAGAIN || ret == -EINTR) { - if (exit_parser_loop == true) { - break; - } - continue; - } else if (ret == -EINVAL || ret == -ENOMEM || ret == -ENODEV || ret == -EIO) { - DLT_LOG(dlt_ctx_self, DLT_LOG_FATAL, DLT_STRING("Could not cannot retrieve logs, permanent error="), DLT_INT32(ret)); - return ret; - } else if (ret <= 0) { - DLT_LOG(dlt_ctx_self, DLT_LOG_ERROR, DLT_STRING("android_logger_list_read unexpected return="), DLT_INT32(ret)); - return ret; - } - - DltContext *ctx = nullptr; - ctx = get_log_context_from_log_msg(&log_msg); - - DltLogLevelType log_level; - log_level = get_log_level_from_log_msg(&log_msg); - - /* Look into system/core/liblog/logprint.c for buffer format. - "\0\0" */ - const char *tag = ""; - const char *message= ""; - if(log_msg.entry.len > 1) - tag = log_msg.msg() + 1; - if (log_msg.entry.len > 1 + strlen(tag) + 1) - message = tag + strlen(tag) + 1; - - - uint32_t ts; - ts = get_timestamp_from_log_msg(&log_msg); - - /* Binary buffers are not supported by DLT_STRING DLT_RAW would need the message length */ - DLT_LOG_TS(*ctx, log_level, ts, - DLT_STRING(tag), - DLT_INT32(log_msg.entry.pid), - DLT_UINT32(log_msg.entry.tid), - DLT_STRING(message)); - } - - DLT_LOG(dlt_ctx_self, DLT_LOG_VERBOSE, DLT_STRING("Exited parsing loop")); - - return EXIT_SUCCESS; -} - -int main(int argc, char *argv[]) -{ - (void) argc; - (void) argv; - bool skip_binary_buffers = true; - - DLT_REGISTER_APP("LOGD", "logd -> dlt adapter"); - DLT_REGISTER_CONTEXT(dlt_ctx_self, "LOGF", "logd retriever"); - DLT_REGISTER_CONTEXT(dlt_ctx_main, "MAIN", "logd type: main"); - DLT_REGISTER_CONTEXT(dlt_ctx_rdio, "RDIO", "logd type: rdio"); - DLT_REGISTER_CONTEXT(dlt_ctx_syst, "SYST", "logd type: syst"); - DLT_REGISTER_CONTEXT(dlt_ctx_crsh, "CRSH", "logd type: crsh"); - DLT_REGISTER_CONTEXT(dlt_ctx_krnl, "KRNL", "logd type: krnl"); - if(!skip_binary_buffers){ - DLT_REGISTER_CONTEXT(dlt_ctx_evnt, "EVNT", "logd type: evnt"); - DLT_REGISTER_CONTEXT(dlt_ctx_stat, "STAT", "logd type: stat"); - DLT_REGISTER_CONTEXT(dlt_ctx_secu, "SECU", "logd type: secu"); - } - - struct sigaction act; - act.sa_handler = signal_handler; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - sigaction(SIGTERM, &act, 0); - - struct logger_list *logger_list; - /* Binary buffers are currently not supported */ - logger_list = init_logger_list(skip_binary_buffers); - if (logger_list == nullptr) - return EXIT_FAILURE; - - int ret; - ret = logd_parser_loop(logger_list); /* Main loop */ - - android_logger_list_free(logger_list); - - DLT_UNREGISTER_CONTEXT(dlt_ctx_krnl); - DLT_UNREGISTER_CONTEXT(dlt_ctx_secu); - DLT_UNREGISTER_CONTEXT(dlt_ctx_stat); - DLT_UNREGISTER_CONTEXT(dlt_ctx_crsh); - DLT_UNREGISTER_CONTEXT(dlt_ctx_syst); - DLT_UNREGISTER_CONTEXT(dlt_ctx_evnt); - DLT_UNREGISTER_CONTEXT(dlt_ctx_rdio); - DLT_UNREGISTER_CONTEXT(dlt_ctx_main); - DLT_UNREGISTER_CONTEXT(dlt_ctx_self); - if(!skip_binary_buffers){ - DLT_UNREGISTER_CONTEXT(dlt_ctx_evnt); - DLT_UNREGISTER_CONTEXT(dlt_ctx_stat); - DLT_UNREGISTER_CONTEXT(dlt_ctx_secu); - } - - DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS(); - - return ret; -} diff -Nru dlt-daemon-2.18.9/src/android/dlt-logd-converter.rc dlt-daemon-2.18.4/src/android/dlt-logd-converter.rc --- dlt-daemon-2.18.9/src/android/dlt-logd-converter.rc 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/android/dlt-logd-converter.rc 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ -service dlt-logd-converter /vendor/bin/dlt-logd-converter - class late_start - user system - group system - disabled diff -Nru dlt-daemon-2.18.9/src/CMakeLists.txt dlt-daemon-2.18.4/src/CMakeLists.txt --- dlt-daemon-2.18.9/src/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -25,9 +25,9 @@ add_subdirectory( examples ) endif( WITH_DLT_EXAMPLES ) -if( WITH_DLT_ADAPTOR_STDIN OR WITH_DLT_ADAPTOR_UDP OR WITH_DLT_ADAPTOR ) +if( WITH_DLT_ADAPTOR ) add_subdirectory( adaptor ) -endif( WITH_DLT_ADAPTOR_STDIN OR WITH_DLT_ADAPTOR_UDP OR WITH_DLT_ADAPTOR ) +endif( WITH_DLT_ADAPTOR ) if( WITH_DLT_TESTS ) add_subdirectory( tests ) @@ -48,7 +48,3 @@ if( WITH_DLT_KPI ) add_subdirectory( kpi ) endif( WITH_DLT_KPI ) - -if( WITH_DLT_QNX_SYSTEM ) - add_subdirectory( dlt-qnx-system ) -endif( WITH_DLT_QNX_SYSTEM ) diff -Nru dlt-daemon-2.18.9/src/console/CMakeLists.txt dlt-daemon-2.18.4/src/console/CMakeLists.txt --- dlt-daemon-2.18.9/src/console/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -14,37 +14,23 @@ ####### set(dlt_control_common_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/dlt-control-common.c) -add_library(dlt_control_common_lib STATIC ${dlt_control_common_SRCS}) -target_link_libraries(dlt_control_common_lib dlt ${DLT_JSON_LIBRARY}) +add_subdirectory(logstorage) -set(TARGET_LIST "") - -if (WITH_DLT_CONSOLE_RECEIVE) - list(APPEND TARGET_LIST dlt-receive) -endif() - -if (WITH_DLT_CONSOLE_CONVERT) - list(APPEND TARGET_LIST dlt-convert) -endif() - -if(NOT WITH_DLT_CONSOLE_WO_CTRL) - add_subdirectory(logstorage) - if (WITH_DLT_CONSOLE_CONTROL) - list(APPEND TARGET_LIST dlt-control) - endif() - if (WITH_DLT_CONSOLE_PASSIVE_NODE_CTRL) - list(APPEND TARGET_LIST dlt-passive-node-ctrl) - endif() -endif() - -if(NOT WITH_DLT_CONSOLE_WO_SBTM) - list(APPEND TARGET_LIST dlt-sortbytimestamp) -endif() - -foreach(target IN LISTS TARGET_LIST) - set(target_SRCS ${target}) - add_executable(${target} ${target_SRCS}) - target_link_libraries(${target} dlt dlt_control_common_lib) +set(dlt-sortbytimestamp_SRCS dlt-sortbytimestamp.c) +set(dlt-convert_SRCS dlt-convert.c) +set(dlt-receive_SRCS dlt-receive.c) +set(dlt-control_SRCS dlt-control.c ${dlt_control_common_SRCS}) +set(dlt-passive-node-ctrl_SRCS dlt-passive-node-ctrl.c ${dlt_control_common_SRCS}) + +foreach(target + dlt-sortbytimestamp + dlt-convert + dlt-receive + dlt-control + dlt-passive-node-ctrl + ) + add_executable(${target} ${${target}_SRCS}) + target_link_libraries(${target} dlt) set_target_properties(${target} PROPERTIES LINKER_LANGUAGE C) install(TARGETS ${target} diff -Nru dlt-daemon-2.18.9/src/console/dlt-control.c dlt-daemon-2.18.4/src/console/dlt-control.c --- dlt-daemon-2.18.9/src/console/dlt-control.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-control.c 2019-09-03 08:28:13.000000000 +0000 @@ -54,6 +54,8 @@ #include /* for isprint() */ #include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ #include /* for writev() */ #include /* for open() */ @@ -61,6 +63,8 @@ #include "dlt_user.h" #include "dlt-control-common.h" + + #define DLT_GLOGINFO_APID_NUM_MAX 150 #define DLT_GLOGINFO_DATA_MAX 800 #define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ @@ -69,16 +73,13 @@ /* Option of GET_LOG_INFO */ #define DLT_SERVICE_GET_LOG_INFO_OPT7 7 /* get Apid, ApDescription, Ctid, CtDescription, loglevel, tracestatus */ -/** - * The structure of the DLT Service header - */ typedef struct { uint32_t service_id; /**< service ID */ - uint8_t status; /**< response status */ -} DLT_PACKED DltServiceHeader; +} PACKED DltServiceGetDefaultLogLevel; DltClient g_dltclient; +DltServiceGetLogInfoResponse *g_resp = NULL; /* Function prototypes */ int dlt_receive_message_callback(DltMessage *message, void *data); @@ -102,11 +103,7 @@ int oflag; int gflag; int jvalue; - int kvalue; int bvalue; - int port; - int sendSerialHeaderFlag; - int resyncSerialHeaderFlag; char ecuid[4]; DltFile file; DltFilter filter; @@ -128,15 +125,13 @@ printf("Options:\n"); printf(" -v Verbose mode\n"); printf(" -h Usage\n"); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode\n"); printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); printf(" -e ecuid Set ECU ID (Default: RECV)\n"); printf("\n"); - printf(" -a id Control message application id\n"); - printf(" -c id Control message context id\n"); - printf(" -s id Control message injection service id\n"); + printf(" -a id Control message application id\n"); + printf(" -c id Control message context id\n"); + printf(" -s id Control message injection service id\n"); printf(" -m message Control message injection in ASCII\n"); printf(" -x message Control message injection in Hex e.g. 'ad 01 24 ef'\n"); printf(" -t milliseconds Timeout to terminate application (Default:1000)'\n"); @@ -156,16 +151,13 @@ printf(" -r tracestatus -c xyz* (set status for all ctxts whose name starts with xyz)\n"); printf(" -r tracestatus -c ctid (set status for the particular ctxt)\n"); printf(" -r tracestatus (set status for all the registered contexts)\n"); - printf(" -d loglevel Set the default log level (0=off - 5=verbose)\n"); + printf(" -d loglevel Set the default log level (0=off - 5=verbose)\n"); printf(" -f tracestatus Set the default trace status (0=off - 1=on)\n"); - printf(" -i enable Enable timing packets (0=off - 1=on)\n"); - printf(" -o Store configuration\n"); - printf(" -g Reset to factory default\n"); - printf(" -j Get log info\n"); - printf(" -k Get software version\n"); - printf(" -u unix port\n"); - printf(" -p port Use the given port instead the default port\n"); - printf(" Cannot be used with serial devices\n"); + printf(" -i enable Enable timing packets (0=off - 1=on)\n"); + printf(" -o Store configuration\n"); + printf(" -g Reset to factory default\n"); + printf(" -j Get log info\n"); + printf(" -u unix port\n"); } /** * Function for sending get log info ctrl msg and printing the response. @@ -179,107 +171,54 @@ int i = 0; int j = 0; - DltServiceGetLogInfoResponse *resp = - (DltServiceGetLogInfoResponse *)calloc(1, - sizeof(DltServiceGetLogInfoResponse)); + g_resp = (DltServiceGetLogInfoResponse *)calloc(1, sizeof(DltServiceGetLogInfoResponse)); - if (NULL == resp) { - fprintf(stderr, "ERROR: calloc for resp data failed.\n"); + if (g_resp == NULL) { + fprintf(stderr, "%s: Calloc failed for resp..\n", __func__); return; } - /* prepare request data */ - resp->service_id = DLT_SERVICE_ID_GET_LOG_INFO; - resp->status = DLT_SERVICE_RESPONSE_ERROR; - /* send control message*/ if (0 != dlt_client_get_log_info(&g_dltclient)) { fprintf(stderr, "ERROR: Could not get log info\n"); - dlt_client_cleanup_get_log_info(resp); - resp = NULL; + dlt_client_cleanup_get_log_info(g_resp); return; } - if (dlt_client_main_loop(&g_dltclient, (void *)resp, 0) == DLT_RETURN_TRUE) + if (dlt_client_main_loop(&g_dltclient, NULL, 0) == DLT_RETURN_TRUE) fprintf(stdout, "DLT-daemon's response is invalid.\n"); - if (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO && - resp->status >= GET_LOG_INFO_STATUS_MIN && - resp->status <= GET_LOG_INFO_STATUS_MAX) { - for (i = 0; i < resp->log_info_type.count_app_ids; i++) { - app = resp->log_info_type.app_ids[i]; - - dlt_print_id(apid, app.app_id); - - if (app.app_description != 0) - printf("APID:%4.4s %s\n", apid, app.app_description); - else - printf("APID:%4.4s \n", apid); - - for (j = 0; j < app.count_context_ids; j++) { - con = app.context_id_info[j]; + for (i = 0; i < g_resp->log_info_type.count_app_ids; i++) { + app = g_resp->log_info_type.app_ids[i]; - dlt_print_id(ctid, con.context_id); - - if (con.context_description != 0) - printf("CTID:%4.4s %2d %2d %s\n", - ctid, - con.log_level, - con.trace_status, - con.context_description); - else - printf("CTID:%4.4s %2d %2d\n", - ctid, - con.log_level, - con.trace_status); - } - } - } - - dlt_client_cleanup_get_log_info(resp); - resp = NULL; -} - -/** - * Function for sending get software version ctrl msg and printing the response. - */ -void dlt_process_get_software_version(void) -{ - DltServiceGetSoftwareVersionResponse *resp = - (DltServiceGetSoftwareVersionResponse *)calloc(1, - sizeof(DltServiceGetSoftwareVersionResponse)); + dlt_print_id(apid, app.app_id); - if (NULL == resp) { - fprintf(stderr, "ERROR: calloc for resp data failed.\n"); - return; - } + if (app.app_description != 0) + printf("APID:%4s %s\n", apid, app.app_description); + else + printf("APID:%4s \n", apid); - /* prepare request data */ - resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; - resp->status = DLT_SERVICE_RESPONSE_ERROR; + for (j = 0; j < app.count_context_ids; j++) { + con = app.context_id_info[j]; - /* send control message*/ - if (0 != dlt_client_get_software_version(&g_dltclient)) { - fprintf(stderr, "ERROR: Get software version failed.\n"); - free(resp); - resp = NULL; - return; - } + dlt_print_id(ctid, con.context_id); - if (dlt_client_main_loop(&g_dltclient, (void *)resp, 0) == DLT_RETURN_TRUE) - fprintf(stdout, "DLT-daemon's response is invalid.\n"); + if (con.context_description != 0) - if (resp->service_id == DLT_SERVICE_ID_GET_SOFTWARE_VERSION && - resp->status == DLT_SERVICE_RESPONSE_OK && - resp->payload != NULL) - { - printf("%s\n", resp->payload); - free(resp->payload); - resp->payload = NULL; + printf("CTID:%4s %2d %2d %s\n", + ctid, + con.log_level, + con.trace_status, + con.context_description); + else + printf("CTID:%4s %2d %2d\n", + ctid, + con.log_level, + con.trace_status); + } } - free(resp); - resp = NULL; + dlt_client_cleanup_get_log_info(g_resp); } /** @@ -289,31 +228,34 @@ { DltReceiveData dltdata; int c; - int ret; int index; char *endptr = NULL; struct timespec ts; /* Initialize dltdata */ - dltdata = (DltReceiveData) { - .tvalue = 1000, - .lvalue = DLT_INVALID_LOG_LEVEL, - .rvalue = DLT_INVALID_TRACE_STATUS, - .dvalue = -1, - .fvalue = -1, - .ivalue = -1, - .oflag = -1, - .gflag = -1, - .port = 3490 - }; - + dltdata.vflag = 0; + dltdata.yflag = 0; + dltdata.evalue = 0; + dltdata.bvalue = 0; + + dltdata.avalue = 0; + dltdata.cvalue = 0; + dltdata.svalue = 0; + dltdata.mvalue = 0; + dltdata.xvalue = 0; + dltdata.tvalue = 1000; + dltdata.lvalue = DLT_INVALID_LOG_LEVEL; + dltdata.rvalue = DLT_INVALID_TRACE_STATUS; + dltdata.dvalue = -1; + dltdata.fvalue = -1; + dltdata.ivalue = -1; + dltdata.oflag = -1; + dltdata.gflag = -1; + dltdata.jvalue = 0; /* Fetch command line arguments */ opterr = 0; - /* Default return value */ - ret = 0; - - while ((c = getopt (argc, argv, "vhSRye:b:a:c:s:m:x:t:l:r:d:f:i:ogjkup:")) != -1) + while ((c = getopt (argc, argv, "vhye:b:a:c:s:m:x:t:l:r:d:f:i:ogju")) != -1) switch (c) { case 'v': { @@ -325,16 +267,6 @@ usage(); return -1; } - case 'S': - { - dltdata.sendSerialHeaderFlag = 1; - break; - } - case 'R': - { - dltdata.resyncSerialHeaderFlag = 1; - break; - } case 'y': { dltdata.yflag = DLT_CLIENT_MODE_SERIAL; @@ -395,7 +327,7 @@ } case 'l': { - dltdata.lvalue = (int) strtol(optarg, &endptr, 10); + dltdata.lvalue = strtol(optarg, &endptr, 10); if ((dltdata.lvalue < DLT_LOG_DEFAULT) || (dltdata.lvalue > DLT_LOG_VERBOSE)) { fprintf (stderr, "invalid log level, supported log level 0-6\n"); @@ -406,7 +338,7 @@ } case 'r': { - dltdata.rvalue = (int) strtol(optarg, &endptr, 10); + dltdata.rvalue = strtol(optarg, &endptr, 10); if ((dltdata.rvalue < DLT_TRACE_STATUS_DEFAULT) || (dltdata.rvalue > DLT_TRACE_STATUS_ON)) { fprintf (stderr, "invalid trace status, supported trace status -1, 0, 1\n"); @@ -445,21 +377,11 @@ dltdata.jvalue = 1; break; } - case 'k': - { - dltdata.kvalue = 1; - break; - } case 'u': { dltdata.yflag = DLT_CLIENT_MODE_UNIX; break; } - case 'p': - { - dltdata.port = atoi(optarg); - break; - } case '?': { if ((optopt == 'o') || (optopt == 'f')) @@ -501,7 +423,6 @@ } if (g_dltclient.mode == DLT_CLIENT_MODE_TCP) { - g_dltclient.port = dltdata.port; for (index = optind; index < argc; index++) if (dlt_client_set_server_ip(&g_dltclient, argv[index]) == -1) { pr_error("set server ip didn't succeed\n"); @@ -538,10 +459,6 @@ dlt_client_setbaudrate(&g_dltclient, dltdata.bvalue); } - /* Update the send and resync serial header flags based on command line option */ - g_dltclient.send_serial_header = dltdata.sendSerialHeaderFlag; - g_dltclient.resync_serial_header = dltdata.resyncSerialHeaderFlag; - /* initialise structure to use DLT file */ dlt_file_init(&(dltdata.file), dltdata.vflag); @@ -580,12 +497,10 @@ if (dlt_client_send_inject_msg(&g_dltclient, dltdata.avalue, dltdata.cvalue, - (uint32_t) dltdata.svalue, + dltdata.svalue, (uint8_t *)dltdata.mvalue, - (uint32_t) strlen(dltdata.mvalue)) != DLT_RETURN_OK) { + strlen(dltdata.mvalue)) != DLT_RETURN_OK) fprintf(stderr, "ERROR: Could not send inject message\n"); - ret = -1; - } } else if (dltdata.xvalue && dltdata.avalue && dltdata.cvalue) { @@ -604,11 +519,9 @@ if (dlt_client_send_inject_msg(&g_dltclient, dltdata.avalue, dltdata.cvalue, - (uint32_t) dltdata.svalue, - buffer, (uint32_t)size) != DLT_RETURN_OK) { + dltdata.svalue, + buffer, size) != DLT_RETURN_OK) fprintf(stderr, "ERROR: Could not send inject message\n"); - ret = -1; - } } else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ { @@ -619,10 +532,8 @@ } if (0 != dlt_client_send_all_log_level(&g_dltclient, - (uint8_t) dltdata.lvalue)) { + dltdata.lvalue)) fprintf(stderr, "ERROR: Could not send log level\n"); - ret = -1; - } } else { /* log level */ @@ -637,10 +548,8 @@ if (0 != dlt_client_send_log_level(&g_dltclient, dltdata.avalue, dltdata.cvalue, - (uint8_t) dltdata.lvalue)) { + dltdata.lvalue)) fprintf(stderr, "ERROR: Could not send log level\n"); - ret = -1; - } } } else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS) @@ -652,10 +561,8 @@ } if (0 != dlt_client_send_all_trace_status(&g_dltclient, - (uint8_t) dltdata.rvalue)) { + dltdata.rvalue)) fprintf(stderr, "ERROR: Could not send trace status\n"); - ret = -1; - } } else { /* trace status */ @@ -670,10 +577,8 @@ if (0 != dlt_client_send_trace_status(&g_dltclient, dltdata.avalue, dltdata.cvalue, - (uint8_t) dltdata.rvalue)) { + dltdata.rvalue)) fprintf(stderr, "ERROR: Could not send trace status\n"); - ret = -1; - } } } else if (dltdata.dvalue != -1) @@ -683,10 +588,8 @@ printf("Loglevel: %d\n", dltdata.dvalue); /* send control message in*/ - if (dlt_client_send_default_log_level(&g_dltclient, (uint8_t) dltdata.dvalue) != DLT_RETURN_OK) { + if (dlt_client_send_default_log_level(&g_dltclient, dltdata.dvalue) != DLT_RETURN_OK) fprintf (stderr, "ERROR: Could not send default log level\n"); - ret = -1; - } } else if (dltdata.fvalue != -1) { @@ -695,10 +598,8 @@ printf("TraceStatus: %d\n", dltdata.fvalue); /* send control message in*/ - if (dlt_client_send_default_trace_status(&g_dltclient, (uint8_t) dltdata.fvalue) != DLT_RETURN_OK) { + if (dlt_client_send_default_trace_status(&g_dltclient, dltdata.fvalue) != DLT_RETURN_OK) fprintf (stderr, "ERROR: Could not send default trace status\n"); - ret = -1; - } } else if (dltdata.ivalue != -1) { @@ -707,10 +608,8 @@ printf("Timing packets: %d\n", dltdata.ivalue); /* send control message in*/ - if (dlt_client_send_timing_pakets(&g_dltclient, (uint8_t) dltdata.ivalue) != DLT_RETURN_OK) { + if (dlt_client_send_timing_pakets(&g_dltclient, dltdata.ivalue) != DLT_RETURN_OK) fprintf (stderr, "ERROR: Could not send timing packets\n"); - ret = -1; - } } else if (dltdata.oflag != -1) { @@ -718,10 +617,8 @@ printf("Store config\n"); /* send control message in*/ - if (dlt_client_send_store_config(&g_dltclient) != DLT_RETURN_OK) { + if (dlt_client_send_store_config(&g_dltclient) != DLT_RETURN_OK) fprintf (stderr, "ERROR: Could not send store config\n"); - ret = -1; - } } else if (dltdata.gflag != -1) { @@ -729,10 +626,8 @@ printf("Reset to factory default\n"); /* send control message in*/ - if (dlt_client_send_reset_to_factory_default(&g_dltclient) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send reset to factory default\n"); - ret = -1; - } + if (dlt_client_send_reset_to_factory_default(&g_dltclient) != DLT_RETURN_OK) + fprintf (stderr, "ERROR: Could send reset to factory default\n"); } else if (dltdata.jvalue == 1) { @@ -740,12 +635,6 @@ printf("Get log info:\n"); dlt_process_get_log_info(); } - else if (dltdata.kvalue == 1) - { - /* Get software version */ - printf("Get software version:\n"); - dlt_process_get_software_version(); - } /* Dlt Client Main Loop */ /*dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); */ @@ -754,8 +643,6 @@ ts.tv_sec = (dltdata.tvalue * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; ts.tv_nsec = (dltdata.tvalue * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); - } else { - ret = -1; } /* Dlt Client Cleanup */ @@ -768,120 +655,60 @@ dlt_filter_free(&(dltdata.filter), dltdata.vflag); - return ret; + return 0; } int dlt_receive_message_callback(DltMessage *message, void *data) { static char resp_text[DLT_RECEIVE_BUFSIZE]; - int ret = DLT_RETURN_OK; - uint32_t id = 0; - uint32_t uint32_tmp = 0; - uint8_t *ptr; - int32_t datalength; - DltServiceHeader *req_header = NULL; + int ret = DLT_RETURN_ERROR; - if ((message == NULL) || (data == NULL) || - !DLT_MSG_IS_CONTROL_RESPONSE(message)) + /* parameter check */ + if (message == NULL) return -1; - /* get request service id */ - req_header = (DltServiceHeader *)data; + /* to avoid warning */ + (void)data; - /* get response service id */ - ptr = message->databuffer; - datalength =(int32_t) message->datasize; - - DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); - id = DLT_ENDIAN_GET_32(message->standardheader->htyp, uint32_tmp); - - if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_LAST_ENTRY) && - (id == req_header->service_id)) { - switch (id) { - case DLT_SERVICE_ID_GET_LOG_INFO: - { - DltServiceGetLogInfoResponse *resp = - (DltServiceGetLogInfoResponse *)data; - - /* prepare storage header */ - if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) - dlt_set_storageheader(message->storageheader, - message->headerextra.ecu); - else - dlt_set_storageheader(message->storageheader, "LCTL"); - - /* get response data */ - ret = dlt_message_header(message, resp_text, - DLT_RECEIVE_BUFSIZE, 0); - - if (ret < 0) { - fprintf(stderr, - "GET_LOG_INFO message_header result failed.\n"); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) + dlt_set_storageheader(message->storageheader, message->headerextra.ecu); + else + dlt_set_storageheader(message->storageheader, "LCTL"); + + /* get response data */ + ret = dlt_message_header(message, resp_text, DLT_RECEIVE_BUFSIZE, 0); + + if (ret < 0) { + fprintf(stderr, "GET_LOG_INFO message_header result failed..\n"); + dlt_client_cleanup(&g_dltclient, 0); + return -1; + } - ret = dlt_message_payload(message, resp_text, - DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); + ret = dlt_message_payload(message, resp_text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); - if (ret < 0) { - fprintf(stderr, - "GET_LOG_INFO message_payload result failed.\n"); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + if (ret < 0) { + fprintf(stderr, "GET_LOG_INFO message_payload result failed..\n"); + dlt_client_cleanup(&g_dltclient, 0); + return -1; + } - ret = dlt_set_loginfo_parse_service_id(resp_text, - &resp->service_id, &resp->status); + /* check service id */ + if (g_resp == NULL) { + fprintf(stderr, "%s: g_resp isn't allocated.\n", __func__); + dlt_client_cleanup(&g_dltclient, 0); + return -1; + } - if ((ret == 0) && - (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { - ret = dlt_client_parse_get_log_info_resp_text(resp, - resp_text); - - if (ret != 0) - { - fprintf(stderr, "GET_LOG_INFO failed [status=%d]\n", - resp->status); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + ret = dlt_set_loginfo_parse_service_id(resp_text, &g_resp->service_id, &g_resp->status); - dlt_client_cleanup(&g_dltclient, 0); - } - break; - } - case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: - { - DltServiceGetSoftwareVersionResponse *resp = - (DltServiceGetSoftwareVersionResponse *)data; - - resp->service_id = id; - DLT_MSG_READ_VALUE(resp->status, ptr, datalength, uint8_t); - DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); - resp->length = DLT_ENDIAN_GET_32(message->standardheader->htyp, - uint32_tmp); - - if (resp->status != DLT_SERVICE_RESPONSE_OK) { - fprintf(stderr, "GET_SOFTWARE_VERSION failed [status=%d]\n", - resp->status); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + if ((ret == 0) && (g_resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { + ret = dlt_client_parse_get_log_info_resp_text(g_resp, resp_text); - resp->payload = (char *)calloc(resp->length + 1, sizeof(char)); - if (resp->payload != NULL) - memcpy(resp->payload, message->databuffer + - message->datasize - resp->length, resp->length); + if (ret != 0) + fprintf(stderr, "GET_LOG_INFO result failed..\n"); - dlt_client_cleanup(&g_dltclient, 0); - break; - } - default: - { - break; - } - } + dlt_client_cleanup(&g_dltclient, 0); } return ret; diff -Nru dlt-daemon-2.18.9/src/console/dlt-control-common.c dlt-daemon-2.18.4/src/console/dlt-control-common.c --- dlt-daemon-2.18.9/src/console/dlt-control-common.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-control-common.c 2019-09-03 08:28:13.000000000 +0000 @@ -64,15 +64,6 @@ #include "dlt-control-common.h" -#ifdef EXTENDED_FILTERING - # if defined(__linux__) || defined(__ANDROID_API__) - # include /* for json filter parsing on Linux and Android */ - # endif - # ifdef __QNX__ - # include /* for json filter parsing on QNX */ - # endif -#endif - #define DLT_CTRL_APID "DLTC" #define DLT_CTRL_CTID "DLTC" #define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock" @@ -97,7 +88,7 @@ static int local_verbose; static char local_ecuid[DLT_CTRL_ECUID_LEN]; /* Name of ECU */ -static int local_timeout; +static long local_timeout; int get_verbosity(void) { @@ -124,8 +115,6 @@ if (dlt_parse_config_param("ECUId", &ecuid_conf) == 0) { memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); strncpy(local_ecuid, ecuid_conf, DLT_CTRL_ECUID_LEN); - if (ecuid_conf !=NULL) - free(ecuid_conf); local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0'; } else { @@ -141,12 +130,12 @@ } } -int get_timeout(void) +long get_timeout(void) { return local_timeout; } -void set_timeout(int t) +void set_timeout(long t) { local_timeout = DLT_CTRL_TIMEOUT; @@ -157,16 +146,6 @@ DLT_CTRL_TIMEOUT); } -void set_send_serial_header(const int value) -{ - g_client.send_serial_header = value; -} - -void set_resync_serial_header(const int value) -{ - g_client.resync_serial_header = value; -} - int dlt_parse_config_param(char *config_id, char **config_data) { FILE *pFile = NULL; @@ -235,6 +214,32 @@ return 0; } +/** @brief Send a message to the daemon through the socket. + * + * The socket as to be opened and active before sending. + * + * @param sock The socket to send the message through + * @param msg The message to be send in DLT format. + * + * @return 0 on success, -1 otherwise. + */ +static int dlt_control_send_message_to_socket(int sock, DltMessage *msg) +{ + if (send(sock, + (const char *)(msg->headerbuffer + sizeof(DltStorageHeader)), + msg->headersize - sizeof(DltStorageHeader), 0) == -1) { + pr_error("Sending message header failed: %s\n", strerror(errno)); + return -1; + } + + if (send(sock, (const char *)msg->databuffer, msg->datasize, 0) == -1) { + pr_error("Sending message failed: %s\n", strerror(errno)); + return -1; + } + + return 0; +} + /** @brief Prepare the extra headers of a DLT message * * Modifies the extra headers of the message so that it can be sent. @@ -246,16 +251,16 @@ */ static int prepare_extra_headers(DltMessage *msg, uint8_t *header) { - uint32_t shift = 0; + int shift = 0; pr_verbose("Preparing extra headers.\n"); if (!msg || !header) return -1; - shift = (uint32_t) (sizeof(DltStorageHeader) + + shift = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp); /* Set header extra parameters */ dlt_set_id(msg->headerextra.ecu, get_ecuid()); @@ -321,12 +326,12 @@ msg->standardheader->mcnt = 0; /* prepare length information */ - msg->headersize = (uint32_t) (sizeof(DltStorageHeader) + + msg->headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp); - len = (uint32_t) (msg->headersize - sizeof(DltStorageHeader) + msg->datasize); + len = msg->headersize - sizeof(DltStorageHeader) + msg->datasize; if (len > UINT16_MAX) { pr_error("Message header is too long.\n"); @@ -372,7 +377,7 @@ } /* prepare payload of data */ - msg->databuffersize = msg->datasize = (uint32_t) data->size; + msg->databuffersize = msg->datasize = data->size; /* Allocate memory for Dlt Message's buffer */ msg->databuffer = (uint8_t *)calloc(1, data->size); @@ -510,7 +515,7 @@ pthread_mutex_lock(&answer_lock); callback_return = response_analyzer_cb(text, message->databuffer, - (int) message->datasize); + message->datasize); pthread_cond_signal(&answer_cond); pthread_mutex_unlock(&answer_lock); @@ -560,10 +565,8 @@ /* Re-init the return value */ callback_return = -1; - if (dlt_client_send_message_to_socket(&g_client, msg) != DLT_RETURN_OK) - { + if (dlt_control_send_message_to_socket(g_client.sock, msg) != 0) { pr_error("Sending message to daemon failed\n"); - dlt_message_free(msg, get_verbosity()); free(msg); return -1; } @@ -632,309 +635,8 @@ */ int dlt_control_deinit(void) { - /* At this stage, we want to stop sending/receiving - * from dlt-daemon. So in order to avoid cancellation - * at recv(), shutdown and close the socket - */ - if (g_client.receiver.fd) { - shutdown(g_client.receiver.fd, SHUT_RDWR); - close(g_client.receiver.fd); - g_client.receiver.fd = -1; - } /* Stopping the listener thread */ pthread_cancel(daemon_connect_thread); - pthread_join(daemon_connect_thread, NULL); /* Closing the socket */ return dlt_client_cleanup(&g_client, get_verbosity()); } - - -#ifdef EXTENDED_FILTERING /* EXTENDED_FILTERING */ -# if defined(__linux__) || defined(__ANDROID_API__) -DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int verbose) -{ - if ((filter == NULL) || (filename == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - if(verbose) - pr_verbose("dlt_json_filter_load()\n"); - - FILE *handle; - char buffer[JSON_FILTER_SIZE*DLT_FILTER_MAX]; - struct json_object *j_parsed_json; - struct json_object *j_app_id; - struct json_object *j_context_id; - struct json_object *j_log_level; - struct json_object *j_payload_min; - struct json_object *j_payload_max; - enum json_tokener_error jerr; - - char app_id[DLT_ID_SIZE + 1] = ""; - char context_id[DLT_ID_SIZE + 1] = ""; - int32_t log_level = 0; - int32_t payload_max = INT32_MAX; - int32_t payload_min = 0; - - handle = fopen(filename, "r"); - - if (handle == NULL) { - pr_error("Filter file %s cannot be opened!\n", filename); - return DLT_RETURN_ERROR; - } - - if (fread(buffer, sizeof(buffer), 1, handle) != 0) { - if (!feof(handle)) { - pr_error("Filter file %s is to big for reading it with current buffer!\n", filename); - return DLT_RETURN_ERROR; - } - } - - j_parsed_json = json_tokener_parse_verbose(buffer, &jerr); - - if (jerr != json_tokener_success) { - pr_error("Faild to parse given filter %s: %s\n", filename, json_tokener_error_desc(jerr)); - return DLT_RETURN_ERROR; - } - - printf("The following filter(s) are applied: \n"); - pr_verbose("The following filter(s) are applied: \n"); - int iterator = 0; - json_object_object_foreach(j_parsed_json, key, val) - { - if (iterator >= DLT_FILTER_MAX) { - pr_error("Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", - DLT_FILTER_MAX); - break; - } - - printf("%s:\n", key); - pr_verbose("%s:\n", key); - - if (json_object_object_get_ex(val, "AppId", &j_app_id)) - strncpy(app_id, json_object_get_string(j_app_id), DLT_ID_SIZE); - else - dlt_set_id(app_id, ""); - - if (json_object_object_get_ex(val, "ContextId", &j_context_id)) - strncpy(context_id, json_object_get_string(j_context_id), DLT_ID_SIZE); - else - dlt_set_id(context_id, ""); - - if (json_object_object_get_ex(val, "LogLevel", &j_log_level)) - log_level = json_object_get_int(j_log_level); - else - log_level = 0; - - if (json_object_object_get_ex(val, "PayloadMin", &j_payload_min)) - payload_min = json_object_get_int(j_payload_min); - else - payload_min = 0; - - if (json_object_object_get_ex(val, "PayloadMax", &j_payload_max)) - payload_max = json_object_get_int(j_payload_max); - else - payload_max = INT32_MAX; - - dlt_filter_add(filter, app_id, context_id, log_level, payload_min, payload_max, verbose); - - printf("\tAppId: %.*s\n", DLT_ID_SIZE, app_id); - pr_verbose("\tAppId: %.*s\n", DLT_ID_SIZE, app_id); - printf("\tConextId: %.*s\n", DLT_ID_SIZE, context_id); - pr_verbose("\tConextId: %.*s\n", DLT_ID_SIZE, context_id); - printf("\tLogLevel: %i\n", log_level); - pr_verbose("\tLogLevel: %i\n", log_level); - printf("\tPayloadMin: %i\n", payload_min); - pr_verbose("\tPayloadMin: %i\n", payload_min); - printf("\tPayloadMax: %i\n", payload_max); - pr_verbose("\tPayloadMax: %i\n", payload_max); - - iterator++; - } - - fclose(handle); - - return DLT_RETURN_OK; -} -# endif /* __Linux__ */ - -# ifdef __QNX__ -DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int verbose) -{ - if ((filter == NULL) || (filename == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - if(verbose) - pr_verbose("dlt_json_filter_load()\n"); - - json_decoder_t *j_decoder = json_decoder_create(); - - const char *s_app_id; - const char *s_context_id; - int32_t log_level = 0; - int32_t payload_max = INT32_MAX; - int32_t payload_min = 0; - - json_decoder_error_t ret = json_decoder_parse_file(j_decoder, filename); - - if (ret != JSON_DECODER_OK) { - pr_error("Faild to parse given filter %s: json_decoder_error_t is %i\n", filename, ret); - return DLT_RETURN_ERROR; - } - - json_decoder_push_object(j_decoder, NULL, true); - - int iterator = 0; - bool end_of_json = false; - - while (!end_of_json) { - if (iterator >= DLT_FILTER_MAX) { - pr_error("Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", - DLT_FILTER_MAX); - break; - } - - if (json_decoder_next(j_decoder) == JSON_DECODER_NOT_FOUND) - end_of_json = true; - - json_decoder_previous(j_decoder); - - printf("%s:\n", json_decoder_name(j_decoder)); - json_decoder_push_object(j_decoder, NULL, true); - - if (json_decoder_get_string(j_decoder, "AppId", &s_app_id, true) != JSON_DECODER_OK) - s_app_id = ""; - - if (json_decoder_get_string(j_decoder, "ContextId", &s_context_id, true) != JSON_DECODER_OK) - s_context_id = ""; - - if (json_decoder_get_int(j_decoder, "LogLevel", &log_level, true) != JSON_DECODER_OK) - log_level = 0; - - if (json_decoder_get_int(j_decoder, "PayloadMin", &payload_min, true) != JSON_DECODER_OK) - payload_min = 0; - - if (json_decoder_get_int(j_decoder, "PayloadMax", &payload_max, true) != JSON_DECODER_OK) - payload_max = INT32_MAX; - - char app_id[DLT_ID_SIZE]; - char context_id[DLT_ID_SIZE]; - strncpy(app_id, s_app_id, DLT_ID_SIZE); - strncpy(context_id, s_context_id, DLT_ID_SIZE); - - dlt_filter_add(filter, app_id, context_id, log_level, payload_min, payload_max, verbose); - - printf("\tAppId: %.*s\n", DLT_ID_SIZE, app_id); - printf("\tConextId: %.*s\n", DLT_ID_SIZE, context_id); - printf("\tLogLevel: %i\n", log_level); - printf("\tPayloadMin: %i\n", payload_min); - printf("\tPayloadMax: %i\n", payload_max); - - json_decoder_pop(j_decoder); - - iterator++; - } - - json_decoder_destroy(j_decoder); - - return DLT_RETURN_OK; -} -# endif /* __QNX__ */ -#endif /* EXTENDED_FILTERING */ - -#ifdef EXTENDED_FILTERING /* EXTENDED_FILTERING */ -# if defined(__linux__) || defined(__ANDROID_API__) -DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose) -{ - if ((filter == NULL) || (filename == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - if(verbose) - pr_verbose("dlt_json_filter_save()\n"); - - struct json_object *json_filter_obj = json_object_new_object(); - - for (int num = 0; num < filter->counter; num++) { - struct json_object *tmp_json_obj = json_object_new_object(); - char filter_name[JSON_FILTER_NAME_SIZE]; - sprintf(filter_name, "filter%i", num); - - if (filter->apid[num][DLT_ID_SIZE - 1] != 0) - json_object_object_add(tmp_json_obj, "AppId", json_object_new_string_len(filter->apid[num], DLT_ID_SIZE)); - else - json_object_object_add(tmp_json_obj, "AppId", json_object_new_string(filter->apid[num])); - - if (filter->ctid[num][DLT_ID_SIZE - 1] != 0) - json_object_object_add(tmp_json_obj, "ContextId", - json_object_new_string_len(filter->ctid[num], DLT_ID_SIZE)); - else - json_object_object_add(tmp_json_obj, "ContextId", json_object_new_string(filter->ctid[num])); - - json_object_object_add(tmp_json_obj, "LogLevel", json_object_new_int(filter->log_level[num])); - json_object_object_add(tmp_json_obj, "PayloadMin", json_object_new_int(filter->payload_min[num])); - json_object_object_add(tmp_json_obj, "PayloadMax", json_object_new_int(filter->payload_max[num])); - - json_object_object_add(json_filter_obj, filter_name, tmp_json_obj); - } - - printf("Saving current filter into '%s'\n", filename); - json_object_to_file((char*)filename, json_filter_obj); - - return DLT_RETURN_OK; -} -# endif /* __Linux__ */ - -# ifdef __QNX__ -DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose) -{ - if ((filter == NULL) || (filename == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - if(verbose) - pr_verbose("dlt_json_filter_save()\n"); - - char s_app_id[DLT_ID_SIZE + 1]; - char s_context_id[DLT_ID_SIZE + 1]; - - json_encoder_t *j_encoder = json_encoder_create(); - json_encoder_start_object(j_encoder, NULL); - - for (int num = 0; num < filter->counter; num++) { - char filter_name[JSON_FILTER_NAME_SIZE]; - sprintf(filter_name, "filter%i", num); - json_encoder_start_object(j_encoder, filter_name); - - strncpy(s_app_id, filter->apid[num], DLT_ID_SIZE); - - if (filter->apid[num][DLT_ID_SIZE - 1] != 0) - s_app_id[DLT_ID_SIZE] = '\0'; - - strncpy(s_context_id, filter->ctid[num], DLT_ID_SIZE); - - if (filter->ctid[num][DLT_ID_SIZE - 1] != 0) - s_context_id[DLT_ID_SIZE] = '\0'; - - json_encoder_add_string(j_encoder, "AppId", s_app_id); - json_encoder_add_string(j_encoder, "ContextId", s_context_id); - json_encoder_add_int(j_encoder, "LogLevel", filter->log_level[num]); - json_encoder_add_int(j_encoder, "PayloadMin", filter->payload_min[num]); - json_encoder_add_int(j_encoder, "PayloadMax", filter->payload_max[num]); - - json_encoder_end_object(j_encoder); - } - - json_encoder_end_object(j_encoder); - - printf("Saving current filter into '%s'\n", filename); - FILE *handle = fopen(filename, "w"); - int filter_buffer_size = 100 * (filter->counter); - char filter_buffer[filter_buffer_size]; - snprintf(filter_buffer, filter_buffer_size, json_encoder_buffer(j_encoder)); - fprintf(handle, filter_buffer); - - fclose(handle); - json_encoder_destroy(j_encoder); - - return DLT_RETURN_OK; -} -# endif /* __QNX__ */ -#endif /* EXTENDED_FILTERING */ diff -Nru dlt-daemon-2.18.9/src/console/dlt-control-common.h dlt-daemon-2.18.4/src/console/dlt-control-common.h --- dlt-daemon-2.18.9/src/console/dlt-control-common.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-control-common.h 2019-09-03 08:28:13.000000000 +0000 @@ -31,9 +31,6 @@ #define DLT_CTRL_ECUID_LEN 10 #define DLT_DAEMON_FLAG_MAX 256 -#define JSON_FILTER_NAME_SIZE 16 /* Size of buffer for the filter names in json filter files */ -#define JSON_FILTER_SIZE 200 /* Size in bytes, that the definition of one filter with all parameters needs */ - #ifndef pr_fmt # define pr_fmt(fmt) fmt #endif @@ -58,11 +55,11 @@ typedef struct { void *data; /**< data to be send to DLT Daemon */ - uint32_t size; /**< size of that data */ + int size; /**< size of that data */ } DltControlMsgBody; -/* As verbosity, ecuid, timeout, send_serial_header, resync_serial_header are - * needed during the communication, defining getter and setters here. +/* As verbosity, ecuid and timeout are needed during the communication, + * defining getter and setters here. * Then there is no need to define them in the control's user application. */ int get_verbosity(void); @@ -71,11 +68,8 @@ char *get_ecuid(void); void set_ecuid(char *); -int get_timeout(void); -void set_timeout(int); - -void set_send_serial_header(const int value); -void set_resync_serial_header(const int value); +long get_timeout(void); +void set_timeout(long); /* Parse dlt.conf file and return the value of requested configuration */ int dlt_parse_config_param(char *config_id, char **config_data); @@ -90,23 +84,4 @@ /* Destroys the connection to the daemon */ int dlt_control_deinit(void); - -#ifdef EXTENDED_FILTERING -/** - * Load json filter from file. - * @param filter pointer to structure of organising DLT filter - * @param filename filename to load filters from - * @param verbose if set to true verbose information is printed out. - * @return negative value if there was an error - */ -DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int verbose); -/** - * Save filter in json format to file. - * @param filter pointer to structure of organising DLT filter - * @param filename filename to safe filters into - * @param verbose if set to true verbose information is printed out. - * @return negative value if there was an error - */ -DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose); -#endif #endif diff -Nru dlt-daemon-2.18.9/src/console/dlt-convert.c dlt-daemon-2.18.4/src/console/dlt-convert.c --- dlt-daemon-2.18.9/src/console/dlt-convert.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-convert.c 2019-09-03 08:28:13.000000000 +0000 @@ -73,14 +73,11 @@ * Initials Date Comment * aw 13.01.2010 initial */ - -#include #include #include #include #include #include -#include #include #include @@ -89,10 +86,7 @@ #include "dlt_common.h" -#define COMMAND_SIZE 1024 /* Size of command */ -#define FILENAME_SIZE 1024 /* Size of filename */ -#define DLT_EXTENSION "dlt" -#define DLT_CONVERT_WS "/tmp/dlt_convert_workspace/" +#define DLT_CONVERT_TEXTBUFSIZE 10024 /* Size of buffer for text output */ /** * Print usage information of tool. @@ -123,55 +117,6 @@ printf(" -b number First messages to be handled\n"); printf(" -e number Last message to be handled\n"); printf(" -w Follow dlt file while file is increasing\n"); - printf(" -t Handling input compressed files (tar.gz)\n"); -} - -void empty_dir(const char *dir) -{ - struct dirent **files = { 0 }; - struct stat st; - uint32_t n = 0; - char tmp_filename[FILENAME_SIZE] = { 0 }; - uint32_t i; - - if (dir == NULL) - fprintf(stderr, "ERROR: %s: invalid arguments\n", __FUNCTION__); - - if (stat(dir, &st) == 0) { - if (S_ISDIR(st.st_mode)) { - n = (uint32_t) scandir(dir, &files, NULL, alphasort); - - /* Do not include /. and /.. */ - if (n < 2) - fprintf(stderr, "ERROR: Failed to scan %s with error %s\n", - dir, strerror(errno)); - else if (n == 2) - printf("%s is already empty\n", dir); - else { - for (i = 2; i < n; i++) { - memset(tmp_filename, 0, FILENAME_SIZE); - snprintf(tmp_filename, FILENAME_SIZE, "%s%s", dir, files[i]->d_name); - - if (remove(tmp_filename) != 0) - fprintf(stderr, "ERROR: Failed to delete %s with error %s\n", - tmp_filename, strerror(errno)); - } - if (files) { - for (i = 0; i < n ; i++) - if (files[i]) { - free(files[i]); - files[i] = NULL; - } - free(files); - files = NULL; - } - } - } - else - fprintf(stderr, "ERROR: %s is not a directory\n", dir); - } - else - fprintf(stderr, "ERROR: Failed to stat %s with error %s\n", dir, strerror(errno)); } /** @@ -186,7 +131,6 @@ int xflag = 0; int mflag = 0; int wflag = 0; - int tflag = 0; char *fvalue = 0; char *bvalue = 0; char *evalue = 0; @@ -202,24 +146,15 @@ int num, begin, end; - char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 }; - - /* For handling compressed files */ - char tmp_filename[FILENAME_SIZE] = { 0 }; - struct stat st = { 0 }; - struct dirent **files = { 0 }; - int n = 0; - int i = 0; + char text[DLT_CONVERT_TEXTBUFSIZE]; struct iovec iov[2]; - int bytes_written = 0; - int syserr = 0; + int bytes_written; opterr = 0; - while ((c = getopt (argc, argv, "vcashxmwtf:b:e:o:")) != -1) { - switch (c) - { + while ((c = getopt (argc, argv, "vcashxmwf:b:e:o:")) != -1) + switch (c) { case 'v': { vflag = 1; @@ -255,11 +190,6 @@ wflag = 1; break; } - case 't': - { - tflag = 1; - break; - } case 'h': { usage(); @@ -300,12 +230,12 @@ } default: { + abort(); return -1; /*for parasoft */ } } - } - /* Initialize structure to use DLT file */ + /* initialise structure to use DLT file */ dlt_file_init(&file, vflag); /* first parse filter file if filter parameter is used */ @@ -328,69 +258,10 @@ } } - if (tflag) { - /* Prepare the temp dir to untar compressed files */ - if (stat(DLT_CONVERT_WS, &st) == -1) { - if (mkdir(DLT_CONVERT_WS, 0700) != 0) { - fprintf(stderr,"ERROR: Cannot create temp dir %s!\n", DLT_CONVERT_WS); - if (ovalue) - close(ohandle); - - return -1; - } - } - else { - if (S_ISDIR(st.st_mode)) - empty_dir(DLT_CONVERT_WS); - else - fprintf(stderr, "ERROR: %s is not a directory", DLT_CONVERT_WS); - } - - for (index = optind; index < argc; index++) { - /* Check extension of input file - * If it is a compressed file, uncompress it - */ - if (strcmp(get_filename_ext(argv[index]), DLT_EXTENSION) != 0) { - syserr = dlt_execute_command(NULL, "tar", "xf", argv[index], "-C", DLT_CONVERT_WS, NULL); - if (syserr != 0) - fprintf(stderr, "ERROR: Failed to uncompress %s to %s with error [%d]\n", - argv[index], DLT_CONVERT_WS, WIFEXITED(syserr)); - } - else { - syserr = dlt_execute_command(NULL, "cp", argv[index], DLT_CONVERT_WS, NULL); - if (syserr != 0) - fprintf(stderr, "ERROR: Failed to copy %s to %s with error [%d]\n", - argv[index], DLT_CONVERT_WS, WIFEXITED(syserr)); - } - - } - - n = scandir(DLT_CONVERT_WS, &files, NULL, alphasort); - if (n == -1) { - fprintf(stderr,"ERROR: Cannot scan temp dir %s!\n", DLT_CONVERT_WS); - if (ovalue) - close(ohandle); - - return -1; - } - - /* do not include ./ and ../ in the files */ - argc = optind + (n - 2); - } - for (index = optind; index < argc; index++) { - if (tflag) { - memset(tmp_filename, 0, FILENAME_SIZE); - snprintf(tmp_filename, FILENAME_SIZE, "%s%s", - DLT_CONVERT_WS, files[index - optind + 2]->d_name); - - argv[index] = tmp_filename; - } - - /* load, analyze data file and create index list */ + /* load, analyse data file and create index list */ if (dlt_file_open(&file, argv[index], vflag) >= DLT_RETURN_OK) { - while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) { - } + while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) {} } if (aflag || sflag || xflag || mflag || ovalue) { @@ -406,54 +277,43 @@ if ((begin < 0) || (begin >= file.counter)) { fprintf(stderr, "ERROR: Selected first message %d is out of range!\n", begin); - if (ovalue) - close(ohandle); - - dlt_file_free(&file, vflag); return -1; } if ((end < 0) || (end >= file.counter) || (end < begin)) { fprintf(stderr, "ERROR: Selected end message %d is out of range!\n", end); - if (ovalue) - close(ohandle); - - dlt_file_free(&file, vflag); return -1; } for (num = begin; num <= end; num++) { - if (dlt_file_message(&file, num, vflag) < DLT_RETURN_OK) - continue; + dlt_file_message(&file, num, vflag); if (xflag) { printf("%d ", num); - if (dlt_message_print_hex(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) - continue; + dlt_message_print_hex(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); } - else if (aflag) { + else if (aflag) + { printf("%d ", num); - if (dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) - continue; + dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); printf("%s ", text); - if (dlt_message_payload(&file.msg, text, DLT_CONVERT_TEXTBUFSIZE, DLT_OUTPUT_ASCII, vflag) < DLT_RETURN_OK) - continue; + dlt_message_payload(&file.msg, text, DLT_CONVERT_TEXTBUFSIZE, DLT_OUTPUT_ASCII, vflag); printf("[%s]\n", text); } - else if (mflag) { + else if (mflag) + { printf("%d ", num); - if (dlt_message_print_mixed_plain(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) - continue; + dlt_message_print_mixed_plain(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); } - else if (sflag) { + else if (sflag) + { printf("%d ", num); - if (dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) - continue; + dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag); printf("%s \n", text); } @@ -461,15 +321,14 @@ /* if file output enabled write message */ if (ovalue) { iov[0].iov_base = file.msg.headerbuffer; - iov[0].iov_len = (uint32_t) file.msg.headersize; + iov[0].iov_len = file.msg.headersize; iov[1].iov_base = file.msg.databuffer; - iov[1].iov_len = (uint32_t) file.msg.datasize; + iov[1].iov_len = file.msg.datasize; - bytes_written =(int) writev(ohandle, iov, 2); + bytes_written = writev(ohandle, iov, 2); if (0 > bytes_written) { printf("in main: writev(ohandle, iov, 2); returned an error!"); - close(ohandle); dlt_file_free(&file, vflag); return -1; } @@ -478,8 +337,7 @@ /* check for new messages if follow flag set */ if (wflag && (num == end)) { while (1) { - while (dlt_file_read(&file, 0) >= 0){ - } + while (dlt_file_read(&file, 0) >= 0) {} if (end == (file.counter - 1)) { /* Sleep if no new message was received */ @@ -509,17 +367,6 @@ if (ovalue) close(ohandle); - if (tflag) { - empty_dir(DLT_CONVERT_WS); - if (files) { - for (i = 0; i < n ; i++) - if (files[i]) - free(files[i]); - - free(files); - } - rmdir(DLT_CONVERT_WS); - } if (index == optind) { /* no file selected, show usage and terminate */ fprintf(stderr, "ERROR: No file selected\n"); diff -Nru dlt-daemon-2.18.9/src/console/dlt-passive-node-ctrl.c dlt-daemon-2.18.4/src/console/dlt-passive-node-ctrl.c --- dlt-daemon-2.18.9/src/console/dlt-passive-node-ctrl.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-passive-node-ctrl.c 2019-09-03 08:28:13.000000000 +0000 @@ -318,8 +318,6 @@ printf(" -s Show passive node(s) connection status\n"); printf(" -t Specify connection timeout (Default: %ds)\n", DLT_CTRL_TIMEOUT); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -v Set verbose flag (Default:%d)\n", get_verbosity()); } @@ -340,13 +338,13 @@ /* Get command line arguments */ opterr = 0; - while ((c = getopt(argc, argv, "c:hn:st:SRv")) != -1) + while ((c = getopt(argc, argv, "c:hn:stv")) != -1) switch (c) { case 'c': state = (int)strtol(optarg, NULL, 10); if ((state == DLT_NODE_CONNECT) || (state == DLT_NODE_DISCONNECT)) { - set_connection_state((unsigned int) state); + set_connection_state(state); set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECT); } else { @@ -365,18 +363,8 @@ set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS); break; case 't': - set_timeout((int) strtol(optarg, NULL, 10)); + set_timeout(strtol(optarg, NULL, 10)); break; - case 'S': - { - set_send_serial_header(1); - break; - } - case 'R': - { - set_resync_serial_header(1); - break; - } case 'v': set_verbosity(1); pr_verbose("Now in verbose mode.\n"); @@ -413,8 +401,6 @@ set_ecuid(NULL); set_timeout(DLT_CTRL_TIMEOUT); - set_send_serial_header(0); - set_resync_serial_header(0); /* Get command line arguments */ if (parse_args(argc, argv) != 0) diff -Nru dlt-daemon-2.18.9/src/console/dlt-receive.c dlt-daemon-2.18.4/src/console/dlt-receive.c --- dlt-daemon-2.18.9/src/console/dlt-receive.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-receive.c 2019-09-03 08:28:13.000000000 +0000 @@ -75,8 +75,6 @@ #include #include #include -#include -#include #ifdef __linux__ # include #else @@ -85,29 +83,9 @@ #include #include "dlt_client.h" -#include "dlt-control-common.h" #define DLT_RECEIVE_ECU_ID "RECV" -DltClient dltclient; - -void signal_handler(int signal) -{ - switch (signal) { - case SIGHUP: - case SIGTERM: - case SIGINT: - case SIGQUIT: - /* stop main loop */ - shutdown(dltclient.receiver.fd, SHUT_RD); - break; - default: - /* This case should never happen! */ - break; - } /* switch */ - -} - /* Function prototypes */ int dlt_receive_message_callback(DltMessage *message, void *data); @@ -118,15 +96,11 @@ int mflag; int vflag; int yflag; - int uflag; char *ovalue; char *ovaluebase; /* ovalue without ".dlt" */ - char *fvalue; /* filename for space separated filter file ( ) */ - char *jvalue; /* filename for json filter file */ + char *fvalue; char *evalue; int bvalue; - int sendSerialHeaderFlag; - int resyncSerialHeaderFlag; int64_t climit; char ecuid[4]; int ohandle; @@ -134,8 +108,6 @@ int part_num; /* number of current output file if limit was exceeded */ DltFile file; DltFilter filter; - int port; - char *ifaddr; } DltReceiveData; /** @@ -158,21 +130,14 @@ printf(" -s Print DLT messages; only headers\n"); printf(" -v Verbose mode\n"); printf(" -h Usage\n"); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode\n"); - printf(" -u UDP multicast mode\n"); - printf(" -i addr Host interface address\n"); printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); printf(" -e ecuid Set ECU ID (Default: RECV)\n"); printf(" -o filename Output messages in new DLT file\n"); printf(" -c limit Restrict file size to bytes when output to file\n"); printf(" When limit is reached, a new file is opened. Use K,M,G as\n"); printf(" suffix to specify kilo-, mega-, giga-bytes respectively\n"); - printf(" -f filename Enable filtering of messages with space separated list ( )\n"); - printf(" -j filename Enable filtering of messages with filter defined in json file\n"); - printf(" -p port Use the given port instead the default port\n"); - printf(" Cannot be used with serial devices\n"); + printf(" -f filename Enable filtering of messages\n"); } @@ -190,12 +155,17 @@ /* last character */ factor = 1; - if ((arg[strlen(arg) - 1] == 'K') || (arg[strlen(arg) - 1] == 'k')) + if ((arg[strlen(arg) - 1] == 'K') || (arg[strlen(arg) - 1] == 'k')) { factor = 1024; + } else if ((arg[strlen(arg) - 1] == 'M') || (arg[strlen(arg) - 1] == 'm')) + { factor = 1024 * 1024; + } else if ((arg[strlen(arg) - 1] == 'G') || (arg[strlen(arg) - 1] == 'g')) + { factor = 1024 * 1024 * 1024; + } else if (!isdigit(arg[strlen(arg) - 1])) return -2; @@ -235,13 +205,10 @@ /* if (file_already_exists) */ glob_t outer; - if (glob(dltdata->ovalue, -#ifndef __ANDROID_API__ - GLOB_TILDE | -#endif - GLOB_NOSORT, NULL, &outer) == 0) { - if (dltdata->vflag) + if (glob(dltdata->ovalue, GLOB_TILDE | GLOB_NOSORT, NULL, &outer) == 0) { + if (dltdata->vflag) { dlt_vlog(LOG_INFO, "File %s already exists, need to rename first\n", dltdata->ovalue); + } if (dltdata->part_num < 0) { char pattern[PATH_MAX + 1]; @@ -256,11 +223,7 @@ * foo.1000.dlt * foo.11.dlt */ - if (glob(pattern, -#ifndef __ANDROID_API__ - GLOB_TILDE | -#endif - GLOB_NOSORT, NULL, &inner) == 0) { + if (glob(pattern, GLOB_TILDE | GLOB_NOSORT, NULL, &inner) == 0) { /* search for the highest number used */ size_t i; @@ -286,12 +249,14 @@ snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num++); - if (rename(dltdata->ovalue, filename) != 0) + if (rename(dltdata->ovalue, filename) != 0) { dlt_vlog(LOG_ERR, "ERROR: rename %s to %s failed with error %s\n", dltdata->ovalue, filename, strerror(errno)); - else if (dltdata->vflag) + } + else if (dltdata->vflag) { dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n", dltdata->ovalue, filename); + } } /* if (file_already_exists) */ globfree(&outer); @@ -315,33 +280,32 @@ */ int main(int argc, char *argv[]) { + DltClient dltclient; DltReceiveData dltdata; - memset(&dltdata, 0, sizeof(dltdata)); int c; int index; /* Initialize dltdata */ + dltdata.aflag = 0; + dltdata.sflag = 0; + dltdata.xflag = 0; + dltdata.mflag = 0; + dltdata.vflag = 0; + dltdata.yflag = 0; + dltdata.ovalue = 0; + dltdata.ovaluebase = 0; + dltdata.fvalue = 0; + dltdata.evalue = 0; + dltdata.bvalue = 0; dltdata.climit = -1; /* default: -1 = unlimited */ dltdata.ohandle = -1; + dltdata.totalbytes = 0; dltdata.part_num = -1; - dltdata.port = 3490; - - /* Config signal handler */ - struct sigaction act; - - /* Initialize signal handler struct */ - memset(&act, 0, sizeof(act)); - act.sa_handler = signal_handler; - sigemptyset(&act.sa_mask); - sigaction(SIGHUP, &act, 0); - sigaction(SIGTERM, &act, 0); - sigaction(SIGINT, &act, 0); - sigaction(SIGQUIT, &act, 0); /* Fetch command line arguments */ opterr = 0; - while ((c = getopt (argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:")) != -1) + while ((c = getopt (argc, argv, "vashyxmf:o:e:b:c:")) != -1) switch (c) { case 'v': { @@ -373,47 +337,16 @@ usage(); return -1; } - case 'S': - { - dltdata.sendSerialHeaderFlag = 1; - break; - } - case 'R': - { - dltdata.resyncSerialHeaderFlag = 1; - break; - } case 'y': { dltdata.yflag = 1; break; } - case 'u': - { - dltdata.uflag = 1; - break; - } - case 'i': - { - dltdata.ifaddr = optarg; - break; - } case 'f': { dltdata.fvalue = optarg; break; } - case 'j': - { - #ifdef EXTENDED_FILTERING - dltdata.jvalue = optarg; - break; - #else - fprintf (stderr, - "Extended filtering is not supported. Please build with the corresponding cmake option to use it.\n"); - return -1; - #endif - } case 'o': { dltdata.ovalue = optarg; @@ -443,11 +376,6 @@ dltdata.bvalue = atoi(optarg); break; } - case 'p': - { - dltdata.port = atoi(optarg); - break; - } case 'c': { @@ -489,40 +417,16 @@ dlt_client_register_message_callback(dlt_receive_message_callback); /* Setup DLT Client structure */ - if(dltdata.uflag) { - dltclient.mode = DLT_CLIENT_MODE_UDP_MULTICAST; - } - else { - dltclient.mode = dltdata.yflag; - } - - if (dltclient.mode == DLT_CLIENT_MODE_TCP || dltclient.mode == DLT_CLIENT_MODE_UDP_MULTICAST) { - dltclient.port = dltdata.port; - - unsigned int servIPLength = 1; // Counting the terminating 0 byte - for (index = optind; index < argc; index++) { - servIPLength += strlen(argv[index]); - if (index > optind) { - servIPLength++; // For the comma delimiter - } - } - if (servIPLength > 1) { - char* servIPString = malloc(servIPLength); - strcpy(servIPString, argv[optind]); - - for (index = optind + 1; index < argc; index++) { - strcat(servIPString, ","); - strcat(servIPString, argv[index]); - } + dltclient.mode = dltdata.yflag; - int retval = dlt_client_set_server_ip(&dltclient, servIPString); - free(servIPString); - - if (retval == -1) { + if (dltclient.mode == DLT_CLIENT_MODE_TCP) { + for (index = optind; index < argc; index++) + if (dlt_client_set_server_ip(&dltclient, argv[index]) == -1) { fprintf(stderr, "set server ip didn't succeed\n"); return -1; } - } + + if (dltclient.servIP == 0) { /* no hostname selected, show usage and terminate */ @@ -531,13 +435,6 @@ dlt_client_cleanup(&dltclient, dltdata.vflag); return -1; } - - if (dltdata.ifaddr != 0) { - if (dlt_client_set_host_if_address(&dltclient, dltdata.ifaddr) != DLT_RETURN_OK) { - fprintf(stderr, "set host interface address didn't succeed\n"); - return -1; - } - } } else { for (index = optind; index < argc; index++) @@ -546,6 +443,8 @@ return -1; } + + if (dltclient.serialDevice == 0) { /* no serial device name selected, show usage and terminate */ fprintf(stderr, "ERROR: No serial device name specified\n"); @@ -556,10 +455,6 @@ dlt_client_setbaudrate(&dltclient, dltdata.bvalue); } - /* Update the send and resync serial header flags based on command line option */ - dltclient.send_serial_header = dltdata.sendSerialHeaderFlag; - dltclient.resync_serial_header = dltdata.resyncSerialHeaderFlag; - /* initialise structure to use DLT file */ dlt_file_init(&(dltdata.file), dltdata.vflag); @@ -575,19 +470,6 @@ dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); } - #ifdef EXTENDED_FILTERING - - if (dltdata.jvalue) { - if (dlt_json_filter_load(&(dltdata.filter), dltdata.jvalue, dltdata.vflag) < DLT_RETURN_OK) { - dlt_file_free(&(dltdata.file), dltdata.vflag); - return -1; - } - - dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); - } - - #endif - /* open DLT output file */ if (dltdata.ovalue) { if (dltdata.climit > -1) { @@ -653,8 +535,9 @@ else dlt_set_storageheader(message->storageheader, dltdata->ecuid); - if (((dltdata->fvalue || dltdata->jvalue) == 0) || - (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE)) { + if ((dltdata->fvalue == 0) || + (dltdata->fvalue && + (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE))) { /* if no filter set or filter is matching display message */ if (dltdata->xflag) { dlt_message_print_hex(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); @@ -685,12 +568,12 @@ /* if file output enabled write message */ if (dltdata->ovalue) { iov[0].iov_base = message->headerbuffer; - iov[0].iov_len = (uint32_t)message->headersize; + iov[0].iov_len = message->headersize; iov[1].iov_base = message->databuffer; - iov[1].iov_len = (uint32_t)message->datasize; + iov[1].iov_len = message->datasize; if (dltdata->climit > -1) { - uint32_t bytes_to_write = message->headersize + message->datasize; + int bytes_to_write = message->headersize + message->datasize; if ((bytes_to_write + dltdata->totalbytes > dltdata->climit)) { dlt_receive_close_output_file(dltdata); @@ -705,7 +588,7 @@ } } - bytes_written = (int)writev(dltdata->ohandle, iov, 2); + bytes_written = writev(dltdata->ohandle, iov, 2); dltdata->totalbytes += bytes_written; diff -Nru dlt-daemon-2.18.9/src/console/dlt-sortbytimestamp.c dlt-daemon-2.18.4/src/console/dlt-sortbytimestamp.c --- dlt-daemon-2.18.9/src/console/dlt-sortbytimestamp.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/dlt-sortbytimestamp.c 2019-09-03 08:28:13.000000000 +0000 @@ -64,7 +64,6 @@ #include #include #include -#include #include #include @@ -74,13 +73,10 @@ #include "dlt_common.h" #define DLT_VERBUFSIZE 255 -#define FIFTY_SEC_IN_MSEC 500000 -#define THREE_MIN_IN_SEC 180 typedef struct sTimestampIndex { int num; uint32_t tmsp; - uint32_t systmsp; } TimestampIndex; int verbosity = 0; @@ -88,8 +84,8 @@ /** * Print information, conditional upon requested verbosity level */ -void verbose(int level, char *msg, ...) PRINTF_FORMAT(2, 3); -void verbose(int level, char *msg, ...) { +void verbose(int level, char *msg, ...) +{ if (level <= verbosity) { if (verbosity > 1) { /* timestamp */ time_t tnow = time((time_t *)0); @@ -103,11 +99,10 @@ } } - int len = (int) strlen(msg); + int len = strlen(msg); va_list args; va_start (args, msg); vprintf(msg, args); - va_end(args); /* lines without a terminal newline aren't guaranteed to be displayed */ if (msg[len - 1] != '\n') @@ -117,72 +112,41 @@ /** * Comparison function for use with qsort - * Used for time stamp */ -int compare_index_timestamps(const void *a, const void *b) { - int ret = -1; +int compare_index_timestamps(const void *a, const void *b) +{ if (((TimestampIndex *)a)->tmsp > ((TimestampIndex *)b)->tmsp) - ret = 1; + return 1; else if (((TimestampIndex *)a)->tmsp == ((TimestampIndex *)b)->tmsp) - ret = 0; + return 0; - return ret; -} - -/** - * Comparison function for use with qsort - * Used for system time - */ -int compare_index_systime(const void *a, const void *b) { - int ret = -1; - if(((TimestampIndex *) a)->systmsp > ((TimestampIndex *) b)->systmsp) - ret = 1; - else if(((TimestampIndex *) a)->systmsp == ((TimestampIndex *) b)->systmsp) - ret = 0; - - return ret; + return -1; } /** * Write the messages in the order specified by the given index */ -void write_messages(int ohandle, DltFile *file, - TimestampIndex *timestamps, uint32_t message_count) { +void write_messages(int ohandle, DltFile *file, TimestampIndex *timestamps, int message_count) +{ struct iovec iov[2]; - ssize_t bytes_written; - uint32_t i = 0; - int last_errno = 0; + int bytes_written; verbose(1, "Writing %d messages\n", message_count); - for (i = 0; i < message_count; ++i) { - errno = 0; + for (int i = 0; i < message_count; ++i) { if ((0 == i % 1001) || (i == message_count - 1)) verbose(2, "Writing message %d\r", i); - if (dlt_file_message(file, timestamps[i].num, 0) < DLT_RETURN_OK) - continue; + dlt_file_message(file, timestamps[i].num, 0); iov[0].iov_base = file->msg.headerbuffer; iov[0].iov_len = file->msg.headersize; iov[1].iov_base = file->msg.databuffer; iov[1].iov_len = file->msg.datasize; bytes_written = writev(ohandle, iov, 2); - last_errno = errno; if (0 > bytes_written) { - printf("%s: returned an error [%s]!\n", - __func__, - strerror(last_errno)); - if (ohandle > 0) { - close(ohandle); - ohandle = -1; - } - if (timestamps) { - free(timestamps); - timestamps = NULL; - } - + printf("in main: writev(ohandle, iov, 2); returned an error!"); dlt_file_free(file, 0); exit (-1); } @@ -194,7 +158,8 @@ /** * Print usage information of tool. */ -void usage() { +void usage() +{ char version[DLT_VERBUFSIZE]; dlt_get_version(version, DLT_VERBUFSIZE); @@ -217,7 +182,8 @@ /** * Main function of tool. */ -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ int vflag = 0; int cflag = 0; char *fvalue = 0; @@ -227,14 +193,7 @@ char *ovalue = 0; TimestampIndex *timestamp_index = 0; - TimestampIndex *temp_timestamp_index = 0; - uint32_t message_count = 0; - - uint32_t count = 0; - uint32_t start = 0; - uint32_t delta_tmsp = 0; - uint32_t delta_systime = 0; - size_t i; + int32_t message_count = 0; int c; @@ -249,7 +208,7 @@ verbose(1, "Configuring\n"); - while ((c = getopt (argc, argv, "vchf:b:e:")) != -1) { + while ((c = getopt (argc, argv, "vchf:b:e:")) != -1) switch (c) { case 'v': { @@ -296,11 +255,10 @@ } default: { - usage(); + abort(); return -1; /*for parasoft */ } } - } /* Don't use vflag on quietest levels */ if (verbosity > 2) @@ -308,7 +266,7 @@ verbose (1, "Initializing\n"); - /* Initialize structure to use DLT file */ + /* initialise structure to use DLT file */ dlt_file_init(&file, vflag); /* first parse filter file if filter parameter is used */ @@ -354,10 +312,9 @@ verbose(1, "Loading\n"); - /* load, analyze data file and create index list */ + /* load, analyse data file and create index list */ if (dlt_file_open(&file, ivalue, vflag) >= DLT_RETURN_OK) { - while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) { - } + while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) {} } if (cflag) { @@ -377,11 +334,13 @@ else end = file.counter - 1; - if ((begin < 0) || (end < 0) || (begin > end) || - (begin >= file.counter) || (end >= file.counter)) { - fprintf(stderr, "ERROR: Selected message [begin-end]-[%d-%d] is out of range!\n", begin, end); - dlt_file_free(&file, vflag); - close(ohandle); + if ((begin < 0) || (begin >= file.counter) || (begin > end)) { + fprintf(stderr, "ERROR: Selected first message %d is out of range!\n", begin); + return -1; + } + + if (end >= file.counter) { + fprintf(stderr, "ERROR: Selected end message %d is out of range!\n", end); return -1; } @@ -389,87 +348,32 @@ verbose(1, "Allocating memory\n"); - message_count = (uint32_t) (1 + end - begin); + message_count = 1 + end - begin; - timestamp_index = (TimestampIndex *) malloc(sizeof(TimestampIndex) * (message_count + 1)); + timestamp_index = (TimestampIndex *)malloc(sizeof(TimestampIndex) * message_count); - if (timestamp_index == NULL) { + if (timestamp_index == 0) { fprintf(stderr, "ERROR: Failed to allocate memory for message index!\n"); dlt_file_free(&file, vflag); - close(ohandle); return -1; } verbose(1, "Filling %d entries\n", message_count); for (num = begin; num <= end; num++) { - if (dlt_file_message(&file, num, vflag) < DLT_RETURN_OK) - continue; + dlt_file_message(&file, num, vflag); timestamp_index[num - begin].num = num; - timestamp_index[num - begin].systmsp = file.msg.storageheader->seconds; timestamp_index[num - begin].tmsp = file.msg.headerextra.tmsp; } - /* This step is extending the array one more element by copying the first element */ - timestamp_index[num].num = timestamp_index[0].num; - timestamp_index[num].systmsp = timestamp_index[0].systmsp; - timestamp_index[num].tmsp = timestamp_index[0].tmsp; - verbose(1, "Sorting\n"); - qsort((void *) timestamp_index, message_count, sizeof(TimestampIndex), compare_index_systime); - - for (num = begin; num <= end; num++) { - delta_tmsp = (uint32_t)llabs((int64_t)timestamp_index[num + 1].tmsp - timestamp_index[num].tmsp); - delta_systime = (uint32_t)llabs((int64_t)timestamp_index[num + 1].systmsp - timestamp_index[num].systmsp); - - /* - * Here is a try to detect a new cycle of boot in system. - * Relatively, if there are gaps whose systime is larger than 3 mins and - * timestamp is larger than 15 secs should be identified as a new boot cycle. - */ - count++; - if(delta_tmsp > FIFTY_SEC_IN_MSEC || delta_systime >= THREE_MIN_IN_SEC) { - verbose(1, "Detected a new cycle of boot\n"); - temp_timestamp_index = (TimestampIndex *) malloc(sizeof(TimestampIndex) * count); - - if (temp_timestamp_index == NULL) { - fprintf(stderr, "ERROR: Failed to allocate memory for array\n"); - dlt_file_free(&file, vflag); - close(ohandle); - return -1; - } - - for (i = 0; i < count; i++) { - memcpy((void*) &temp_timestamp_index[i], - (void*) ×tamp_index[start + i], - sizeof(TimestampIndex)); - } - qsort((void *) temp_timestamp_index, count, sizeof(TimestampIndex), - compare_index_timestamps); - - write_messages(ohandle, &file, temp_timestamp_index, count); - free(temp_timestamp_index); - temp_timestamp_index = NULL; - start = start + count; - count = 0; - } - } - - /* - * In case there is only cycle of boot in DLT file, - * sort the DLT file again by timestamp then write - * all messages out. - */ - if (count == message_count) { - qsort((void *) timestamp_index, message_count + 1, - sizeof(TimestampIndex), compare_index_timestamps); - write_messages(ohandle, &file, timestamp_index, count); - } + qsort((void *)timestamp_index, message_count, sizeof(TimestampIndex), compare_index_timestamps); + write_messages(ohandle, &file, timestamp_index, message_count); close(ohandle); + verbose(1, "Tidying up.\n"); free(timestamp_index); - timestamp_index = NULL; dlt_file_free(&file, vflag); return 0; } diff -Nru dlt-daemon-2.18.9/src/console/logstorage/CMakeLists.txt dlt-daemon-2.18.4/src/console/logstorage/CMakeLists.txt --- dlt-daemon-2.18.9/src/console/logstorage/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/logstorage/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -12,31 +12,28 @@ # # For further information see http://www.genivi.org/. ####### -add_definitions(-Werror) +add_definitions( -Werror ) -set(dlt-logstorage-ctrl_SRCS - dlt-logstorage-ctrl.c - dlt-logstorage-common.c - dlt-logstorage-list.c) +set(dlt_logstorage_ctrl_SRCS dlt-logstorage-ctrl.c dlt-logstorage-common.c dlt-logstorage-list.c) if(WITH_DLT_LOGSTORAGE_CTRL_UDEV) - set(dlt-logstorage-ctrl_SRCS - ${dlt-logstorage-ctrl_SRCS} - dlt-logstorage-udev.c) - set(LOGSTORAGE_LIBRARY udev) -endif() + set(dlt_logstorage_ctrl_SRCS ${dlt_logstorage_ctrl_SRCS} dlt-logstorage-udev.c) +endif(WITH_DLT_LOGSTORAGE_CTRL_UDEV) if(WITH_SYSTEMD) - set(dlt-logstorage-ctrl_SRCS - ${dlt-logstorage-ctrl_SRCS} - ${PROJECT_SOURCE_DIR}/systemd/3rdparty/sd-daemon.c) -endif() - -add_executable(dlt-logstorage-ctrl - ${dlt-logstorage-ctrl_SRCS} - ${dlt_control_common_SRCS}) + set(dlt_logstorage_ctrl_SRCS ${dlt_logstorage_ctrl_SRCS} ${PROJECT_SOURCE_DIR}/systemd/3rdparty/sd-daemon.c) +endif(WITH_SYSTEMD) + +add_executable(dlt-logstorage-ctrl ${dlt_logstorage_ctrl_SRCS} ${dlt_control_common_SRCS} ${dlt_most_SRCS}) + +set(DLT_LOGSTORAGE_LIBRARIES dlt-logstorage-ctrl dlt ${EXPAT_LIBRARIES}) + +if(WITH_DLT_LOGSTORAGE_CTRL_UDEV) + set(DLT_LOGSTORAGE_LIBRARIES ${DLT_LOGSTORAGE_LIBRARIES} udev) +endif(WITH_DLT_LOGSTORAGE_CTRL_UDEV) + +target_link_libraries(${DLT_LOGSTORAGE_LIBRARIES}) -target_link_libraries(dlt-logstorage-ctrl dlt ${LOGSTORAGE_LIBRARY} dlt_control_common_lib) set_target_properties(dlt-logstorage-ctrl PROPERTIES LINKER_LANGUAGE C) install(TARGETS dlt-logstorage-ctrl diff -Nru dlt-daemon-2.18.9/src/console/logstorage/dlt-logstorage-common.c dlt-daemon-2.18.4/src/console/logstorage/dlt-logstorage-common.c --- dlt-daemon-2.18.9/src/console/logstorage/dlt-logstorage-common.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/logstorage/dlt-logstorage-common.c 2019-09-03 08:28:13.000000000 +0000 @@ -104,7 +104,7 @@ void set_default_event_type(long type) { - g_options.event_type = (int) type; + g_options.event_type = type; } char *get_default_path(void) @@ -285,7 +285,7 @@ serv = (DltServiceOfflineLogstorage *)(*body)->data; serv->service_id = DLT_SERVICE_ID_OFFLINE_LOGSTORAGE; - serv->connection_type = (uint8_t) conn_type; + serv->connection_type = conn_type; /* mount_point is DLT_MOUNT_PATH_MAX + 1 long, * and the memory is already zeroed. */ diff -Nru dlt-daemon-2.18.9/src/console/logstorage/dlt-logstorage-ctrl.c dlt-daemon-2.18.4/src/console/logstorage/dlt-logstorage-ctrl.c --- dlt-daemon-2.18.9/src/console/logstorage/dlt-logstorage-ctrl.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/logstorage/dlt-logstorage-ctrl.c 2019-09-03 08:28:13.000000000 +0000 @@ -61,7 +61,7 @@ #include #include -#include +#include #if defined(__linux__) # include "sd-daemon.h" @@ -166,17 +166,17 @@ snprintf(resp_ok, MAX_RESPONSE_LENGTH, - "service(%d), ok", + "service(%u), ok", DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); snprintf(resp_warning, MAX_RESPONSE_LENGTH, - "service(%d), warning", + "service(%u), warning", DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); snprintf(resp_perm_denied, MAX_RESPONSE_LENGTH, - "service(%d), perm_denied", + "service(%u), perm_denied", DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); if (strncmp(data, resp_ok, strlen(resp_ok)) == 0) @@ -308,8 +308,8 @@ while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && !dlt_logstorage_must_exit()) { pr_error("Failed to initialize connection with the daemon.\n"); - pr_error("Retrying to connect in %ds.\n", get_timeout()); - sleep((unsigned int) get_timeout()); + pr_error("Retrying to connect in %lds.\n", get_timeout()); + sleep(get_timeout()); } if (dlt_logstorage_must_exit()) { @@ -370,8 +370,8 @@ while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && !dlt_logstorage_must_exit()) { pr_error("Failed to initialize connection with the daemon.\n"); - pr_error("Retrying to connect in %ds.\n", get_timeout()); - sleep( (unsigned int) get_timeout()); + pr_error("Retrying to connect in %lds.\n", get_timeout()); + sleep(get_timeout()); } pr_verbose("event type is [%d]\t device path is [%s]\n", @@ -406,23 +406,19 @@ printf(" Don't use -s together with -d and -c\n"); printf(" -t Specify connection timeout (Default: %ds)\n", DLT_CTRL_TIMEOUT); - printf(" -S --send-header Send message with serial header (Default: Without serial header)\n"); - printf(" -R --resync-header Enable resync serial header\n"); printf(" -v --verbose Set verbose flag (Default:%d)\n", get_verbosity()); } static struct option long_options[] = { - {"command", required_argument, 0, 'c'}, - {"daemonize", optional_argument, 0, 'd'}, - {"ecuid", required_argument, 0, 'e'}, - {"help", no_argument, 0, 'h'}, - {"path", required_argument, 0, 'p'}, - {"snapshot", optional_argument, 0, 's'}, - {"timeout", required_argument, 0, 't'}, - {"send-header", no_argument, 0, 'S'}, - {"resync-header", no_argument, 0, 'R'}, - {"verbose", no_argument, 0, 'v'}, - {0, 0, 0, 0} + { "command", required_argument, 0, 'c' }, + { "daemonize", optional_argument, 0, 'd' }, + { "ecuid", required_argument, 0, 'e' }, + { "help", no_argument, 0, 'h' }, + { "path", required_argument, 0, 'p' }, + { "snapshot", optional_argument, 0, 's' }, + { "timeout", required_argument, 0, 't' }, + { "verbose", no_argument, 0, 'v' }, + { 0, 0, 0, 0 } }; /** @brief Parses the application arguments @@ -441,7 +437,7 @@ while ((c = getopt_long(argc, argv, - ":s::t:hSRe:p:d::c:v", + ":s::t:he:p:d::c:v", long_options, &long_index)) != -1) switch (c) { @@ -456,18 +452,8 @@ set_default_path(optarg); break; case 't': - set_timeout((int) strtol(optarg, NULL, 10)); + set_timeout(strtol(optarg, NULL, 10)); break; - case 'S': - { - set_send_serial_header(1); - break; - } - case 'R': - { - set_resync_serial_header(1); - break; - } case 'h': usage(); return -1; @@ -549,8 +535,6 @@ set_ecuid(NULL); set_timeout(DLT_CTRL_TIMEOUT); - set_send_serial_header(0); - set_resync_serial_header(0); /* Get command line arguments */ if (parse_args(argc, argv) != 0) diff -Nru dlt-daemon-2.18.9/src/console/logstorage/dlt-logstorage-list.c dlt-daemon-2.18.4/src/console/logstorage/dlt-logstorage-list.c --- dlt-daemon-2.18.9/src/console/logstorage/dlt-logstorage-list.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/console/logstorage/dlt-logstorage-list.c 2019-09-03 08:28:13.000000000 +0000 @@ -165,8 +165,6 @@ if (ptr->mnt_point == NULL) { pr_error("memory allocation failed for mnt_point\n"); - free(ptr); - ptr = NULL; return -1; } diff -Nru dlt-daemon-2.18.9/src/core_dump_handler/CMakeLists.txt dlt-daemon-2.18.4/src/core_dump_handler/CMakeLists.txt --- dlt-daemon-2.18.9/src/core_dump_handler/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/core_dump_handler/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -29,7 +29,7 @@ endif(WITH_CITYHASH) add_executable(dlt-cdh ${dlt_cdh_SRCS}) - target_link_libraries(dlt-cdh ${ZLIB_LIBRARY}) + target_link_libraries(dlt-cdh z) set_target_properties(dlt-cdh PROPERTIES LINKER_LANGUAGE C) configure_file(${PROJECT_SOURCE_DIR}/src/core_dump_handler/50-coredump.conf.cmake ${PROJECT_BINARY_DIR}/core_dump_handler/50-coredump.conf) diff -Nru dlt-daemon-2.18.9/src/daemon/CMakeLists.txt dlt-daemon-2.18.4/src/daemon/CMakeLists.txt --- dlt-daemon-2.18.9/src/daemon/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -32,7 +32,6 @@ ${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 @@ -46,7 +45,7 @@ ${PROJECT_SOURCE_DIR}/src/shared/dlt_shm.c) endif() -if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN") +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(RT_LIBRARY rt) set(SOCKET_LIBRARY "") else() @@ -62,9 +61,6 @@ add_executable(dlt-daemon ${dlt_daemon_SRCS} ${systemd_SRCS}) target_link_libraries(dlt-daemon ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) -if (WITH_SYSTEMD_SOCKET_ACTIVATION) - target_link_libraries(dlt-daemon systemd) -endif() install(TARGETS dlt-daemon RUNTIME DESTINATION bin diff -Nru dlt-daemon-2.18.9/src/daemon/dlt.conf dlt-daemon-2.18.4/src/daemon/dlt.conf --- dlt-daemon-2.18.9/src/daemon/dlt.conf 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt.conf 2019-09-03 08:28:13.000000000 +0000 @@ -35,10 +35,7 @@ # PersistanceStoragePath = /tmp # The logging console for internal logging of dlt-daemon (Default: 0) -# 0 = log to stdout -# 1 = log to syslog -# 2 = log to file (see LoggingFilename) -# 3 = log to stderr +# 0 = log to stdout, 1 = log to syslog, 2 = log to file (see LoggingFilename) LoggingMode = 0 # The internal log level, up to which logs are written (Default: 6) @@ -46,19 +43,8 @@ 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 -# 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 @@ -72,7 +58,6 @@ RingbufferStepSize = 500000 # The size of Daemon FIFO (/tmp/dlt) (Default: 65536, MinSize: depend on pagesize of system, MaxSize: please check /proc/sys/fs/pipe-max-size) -# This is only supported for Linux. # DaemonFIFOSize = 65536 # Initial log-level that is sent when an application registers (Default: 4) @@ -87,9 +72,6 @@ # If set to 1 (ON) whenever a context registers or changes the log-level it has to be lower or equal to ContextLogLevel # ForceContextLogLevelAndTraceStatus = 1 -# Allows injection mode usage (Default: 1) -# InjectionMode = 1 - ######################################################################## # Gateway Configuration # ######################################################################## @@ -206,13 +188,13 @@ # UDP Multicast Configuration # ############################################################################## # Enable UDP connection support for daemon(Control Message/Multicast is enabled) -# UDPConnectionSetup = 1 +UDPConnectionSetup = 1 # UDP multicast address(default:225.0.0.37) -# UDPMulticastIPAddress = 225.0.0.37 +UDPMulticastIPAddress = 225.0.0.37 # UDP multicast port(default:3491) -# UDPMulticastIPPort = 3491 +UDPMulticastIPPort = 3491 ############################################################################## # BindAddress Limitation # diff -Nru dlt-daemon-2.18.9/src/daemon/dlt-daemon.c dlt-daemon-2.18.4/src/daemon/dlt-daemon.c --- dlt-daemon-2.18.9/src/daemon/dlt-daemon.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt-daemon.c 2019-09-03 08:28:13.000000000 +0000 @@ -33,7 +33,7 @@ #include /* for sockaddr_in and inet_addr() */ #include /* for atoi() and exit() */ #include /* for memset() */ -#include /* for close() and access */ +#include /* for close() */ #include #include #include @@ -46,21 +46,10 @@ #endif #include #include -#include - #if defined(linux) && defined(__NR_statx) # include #endif -#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE -# ifdef linux -# include -# endif -# ifdef __QNX__ -# include -# endif -#endif - #include "dlt_types.h" #include "dlt-daemon.h" #include "dlt-daemon_cfg.h" @@ -91,10 +80,6 @@ static int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, char *str, int verbose); -static int dlt_daemon_check_numeric_setting(char *token, - char *value, - unsigned long *data); - #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE static uint32_t watchdog_trigger_interval; /* watchdog trigger interval in [s] */ #endif @@ -104,73 +89,6 @@ int g_signo = 0; -/* used for value from conf file */ -static int value_length = 1024; - -static char dlt_timer_conn_types[DLT_TIMER_UNKNOWN + 1] = { - [DLT_TIMER_PACKET] = DLT_CONNECTION_ONE_S_TIMER, - [DLT_TIMER_ECU] = DLT_CONNECTION_SIXTY_S_TIMER, -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - [DLT_TIMER_SYSTEMD] = DLT_CONNECTION_SYSTEMD_TIMER, -#endif - [DLT_TIMER_GATEWAY] = DLT_CONNECTION_GATEWAY_TIMER, - [DLT_TIMER_UNKNOWN] = DLT_CONNECTION_TYPE_MAX -}; - -static char dlt_timer_names[DLT_TIMER_UNKNOWN + 1][32] = { - [DLT_TIMER_PACKET] = "Timing packet", - [DLT_TIMER_ECU] = "ECU version", -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - [DLT_TIMER_SYSTEMD] = "Systemd watchdog", -#endif - [DLT_TIMER_GATEWAY] = "Gateway", - [DLT_TIMER_UNKNOWN] = "Unknown timer" -}; - -#ifdef __QNX__ -static int dlt_timer_pipes[DLT_TIMER_UNKNOWN][2] = { - /* [timer_id] = {read_pipe, write_pipe} */ - [DLT_TIMER_PACKET] = {DLT_FD_INIT, DLT_FD_INIT}, - [DLT_TIMER_ECU] = {DLT_FD_INIT, DLT_FD_INIT}, -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - [DLT_TIMER_SYSTEMD] = {DLT_FD_INIT, DLT_FD_INIT}, -#endif - [DLT_TIMER_GATEWAY] = {DLT_FD_INIT, DLT_FD_INIT} -}; - -static pthread_t timer_threads[DLT_TIMER_UNKNOWN] = { - [DLT_TIMER_PACKET] = 0, - [DLT_TIMER_ECU] = 0, -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - [DLT_TIMER_SYSTEMD] = 0, -#endif - [DLT_TIMER_GATEWAY] = 0 -}; - -static DltDaemonPeriodicData *timer_data[DLT_TIMER_UNKNOWN] = { - [DLT_TIMER_PACKET] = NULL, - [DLT_TIMER_ECU] = NULL, -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - [DLT_TIMER_SYSTEMD] = NULL, -#endif - [DLT_TIMER_GATEWAY] = NULL -}; - -void close_pipes(int fds[2]) -{ - if (fds[0] > 0) { - close(fds[0]); - fds[0] = DLT_FD_INIT; - } - - if (fds[1] > 0) { - close(fds[1]); - fds[1] = DLT_FD_INIT; - } -} - -#endif // __QNX__ - /** * Print usage information of tool. */ @@ -187,14 +105,10 @@ printf(" -d Daemonize\n"); printf(" -h Usage\n"); printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n"); - -#ifdef DLT_DAEMON_USE_FIFO_IPC printf(" -t directory Directory for local fifo and user-pipes (Default: /tmp)\n"); printf(" (Applications wanting to connect to a daemon using a\n"); printf(" custom directory need to be started with the environment \n"); printf(" variable DLT_PIPE_DIR set appropriately)\n"); -#endif - #ifdef DLT_SHM_ENABLE printf(" -s filename The file name to create the share memory (Default: /dlt-shm)\n"); printf(" (Applications wanting to connect to a daemon using a\n"); @@ -224,10 +138,8 @@ /* default values */ daemon_local->flags.port = DLT_DAEMON_TCP_PORT; - -#ifdef DLT_DAEMON_USE_FIFO_IPC - dlt_log_set_fifo_basedir(DLT_USER_IPC_PATH); -#endif + strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, DLT_PATH_MAX); + dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; #ifdef DLT_SHM_ENABLE strncpy(dltShmName, "/dlt-shm", NAME_MAX); @@ -236,10 +148,8 @@ opterr = 0; #ifdef DLT_SHM_ENABLE - while ((c = getopt (argc, argv, "hdc:t:s:p:")) != -1) #else - while ((c = getopt (argc, argv, "hdc:t:p:")) != -1) #endif switch (c) { @@ -253,14 +163,12 @@ strncpy(daemon_local->flags.cvalue, optarg, NAME_MAX); break; } -#ifdef DLT_DAEMON_USE_FIFO_IPC case 't': { - dlt_log_set_fifo_basedir(optarg); + strncpy(dltFifoBaseDir, optarg, DLT_PATH_MAX); + dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; break; } -#endif - #ifdef DLT_SHM_ENABLE case 's': { @@ -270,7 +178,7 @@ #endif case 'p': { - daemon_local->flags.port = (unsigned int) atoi(optarg); + daemon_local->flags.port = atoi(optarg); if (daemon_local->flags.port == 0) { fprintf (stderr, "Invalid port `%s' specified.\n", optarg); @@ -291,7 +199,7 @@ else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", (uint32_t)optopt); + fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); @@ -306,7 +214,7 @@ /* switch() */ -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX, "%s/dltpipes", dltFifoBaseDir); snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX, @@ -327,41 +235,26 @@ int option_file_parser(DltDaemonLocal *daemon_local) { FILE *pFile; + int value_length = 1024; char line[value_length - 1]; char token[value_length]; char value[value_length]; char *pch; const char *filename; - ssize_t n; /* set default values for configuration */ daemon_local->flags.sharedMemorySize = DLT_SHM_SIZE; daemon_local->flags.sendMessageTime = 0; daemon_local->flags.offlineTraceDirectory[0] = 0; daemon_local->flags.offlineTraceFileSize = 1000000; - daemon_local->flags.offlineTraceMaxSize = 4000000; - daemon_local->flags.offlineTraceFilenameTimestampBased = true; + daemon_local->flags.offlineTraceMaxSize = 0; + daemon_local->flags.offlineTraceFilenameTimestampBased = 1; daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE; daemon_local->flags.loggingLevel = LOG_INFO; - -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC - n = snprintf(daemon_local->flags.loggingFilename, - sizeof(daemon_local->flags.loggingFilename), - "%s/dlt.log", DLT_USER_IPC_PATH); -#else /* DLT_DAEMON_USE_FIFO_IPC */ - n = snprintf(daemon_local->flags.loggingFilename, - sizeof(daemon_local->flags.loggingFilename), - "%s/dlt.log", dltFifoBaseDir); -#endif - - if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) { - 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; - + snprintf(daemon_local->flags.loggingFilename, + sizeof(daemon_local->flags.loggingFilename), + "%s/dlt.log", + dltFifoBaseDir); daemon_local->timeoutOnSend = 4; daemon_local->RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; daemon_local->RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; @@ -372,6 +265,7 @@ daemon_local->flags.sendTimezone = 0; daemon_local->flags.offlineLogstorageMaxDevices = 0; daemon_local->flags.offlineLogstorageDirPath[0] = 0; + daemon_local->flags.offlineLogstorageMaxDevices = 0; daemon_local->flags.offlineLogstorageTimestamp = 1; daemon_local->flags.offlineLogstorageDelimiter = '_'; daemon_local->flags.offlineLogstorageMaxCounter = UINT_MAX; @@ -381,21 +275,20 @@ daemon_local->flags.offlineLogstorageCacheSize); strncpy(daemon_local->flags.ctrlSockPath, DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH, - sizeof(daemon_local->flags.ctrlSockPath)); -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC + sizeof(daemon_local->flags.ctrlSockPath) - 1); +#ifdef DLT_USE_UNIX_SOCKET_IPC snprintf(daemon_local->flags.appSockPath, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH); if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX) fprintf(stderr, "Provided path too long...trimming it to path[%s]\n", daemon_local->flags.appSockPath); - -#else /* DLT_DAEMON_USE_FIFO_IPC */ +#else memset(daemon_local->flags.daemonFifoGroup, 0, sizeof(daemon_local->flags.daemonFifoGroup)); #endif daemon_local->flags.gatewayMode = 0; strncpy(daemon_local->flags.gatewayConfigFile, DLT_GATEWAY_CONFIG_PATH, - DLT_DAEMON_FLAG_MAX); + DLT_DAEMON_FLAG_MAX - 1); daemon_local->flags.autoResponseGetLogInfoOption = 7; daemon_local->flags.contextLogLevel = DLT_LOG_INFO; daemon_local->flags.contextTraceStatus = DLT_TRACE_STATUS_OFF; @@ -406,7 +299,6 @@ daemon_local->UDPMulticastIPPort = MULTICASTIPPORT; #endif daemon_local->flags.ipNodes = NULL; - daemon_local->flags.injectionMode = 1; /* open configuration file */ if (daemon_local->flags.cvalue[0]) @@ -519,7 +411,7 @@ } else if (strcmp(token, "LoggingMode") == 0) { - daemon_local->flags.loggingMode = (DltLoggingMode)atoi(value); + daemon_local->flags.loggingMode = atoi(value); /*printf("Option: %s=%s\n",token,value); */ } else if (strcmp(token, "LoggingLevel") == 0) @@ -535,18 +427,6 @@ 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); @@ -554,21 +434,19 @@ } else if (strcmp(token, "RingbufferMinSize") == 0) { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->RingbufferMinSize)) < 0) - return -1; + sscanf(value, "%lu", &(daemon_local->RingbufferMinSize)); } else if (strcmp(token, "RingbufferMaxSize") == 0) { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->RingbufferMaxSize)) < 0) - return -1; + sscanf(value, "%lu", &(daemon_local->RingbufferMaxSize)); } else if (strcmp(token, "RingbufferStepSize") == 0) { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->RingbufferStepSize)) < 0) - return -1; + sscanf(value, "%lu", &(daemon_local->RingbufferStepSize)); + } + else if (strcmp(token, "DaemonFIFOSize") == 0) + { + sscanf(value, "%lu", &(daemon_local->daemonFifoSize)); } else if (strcmp(token, "SharedMemorySize") == 0) { @@ -595,7 +473,7 @@ } else if (strcmp(token, "OfflineTraceFileNameTimestampBased") == 0) { - daemon_local->flags.offlineTraceFilenameTimestampBased = (bool)atoi(value); + daemon_local->flags.offlineTraceFilenameTimestampBased = atoi(value); /*printf("Option: %s=%s\n",token,value); */ } else if (strcmp(token, "SendECUSoftwareVersion") == 0) @@ -618,7 +496,7 @@ } else if (strcmp(token, "OfflineLogstorageMaxDevices") == 0) { - daemon_local->flags.offlineLogstorageMaxDevices = (uint32_t) atoi(value); + daemon_local->flags.offlineLogstorageMaxDevices = atoi(value); } else if (strcmp(token, "OfflineLogstorageDirPath") == 0) { @@ -640,8 +518,8 @@ } else if (strcmp(token, "OfflineLogstorageMaxCounter") == 0) { - daemon_local->flags.offlineLogstorageMaxCounter = (unsigned int) atoi(value); - daemon_local->flags.offlineLogstorageMaxCounterIdx = (unsigned int) strlen(value); + daemon_local->flags.offlineLogstorageMaxCounter = atoi(value); + daemon_local->flags.offlineLogstorageMaxCounterIdx = strlen(value); } else if (strcmp(token, "OfflineLogstorageCacheSize") == 0) { @@ -723,18 +601,8 @@ intval); } } - -#ifdef DLT_DAEMON_USE_FIFO_IPC - else if (strcmp(token, "DaemonFIFOSize") == 0) - { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->daemonFifoSize)) < 0) - return -1; -#ifndef __linux__ - printf("Option DaemonFIFOSize is set but only supported on Linux. Ignored.\n"); -#endif - } - else if (strcmp(token, "DaemonFifoGroup") == 0) +#ifndef DLT_USE_UNIX_SOCKET_IPC + else if(strcmp(token, "DaemonFifoGroup") == 0) { strncpy(daemon_local->flags.daemonFifoGroup, value, NAME_MAX); daemon_local->flags.daemonFifoGroup[NAME_MAX] = 0; @@ -779,7 +647,6 @@ if (daemon_local->flags.ipNodes == NULL) { dlt_vlog(LOG_ERR, "Could not allocate for IP list\n"); - fclose(pFile); return -1; } else { @@ -796,7 +663,6 @@ if (newNode == NULL) { dlt_vlog(LOG_ERR, "Could not allocate for IP list\n"); - fclose(pFile); return -1; } else { @@ -813,9 +679,6 @@ dlt_vlog(LOG_WARNING, "BindAddress option is empty\n"); } } - else if (strcmp(token, "InjectionMode") == 0) { - daemon_local->flags.injectionMode = atoi(value); - } else { fprintf(stderr, "Unknown option: %s=%s\n", token, value); } @@ -835,55 +698,7 @@ return 0; } -static int dlt_mkdir_recursive(const char *dir) -{ - int ret = 0; - char tmp[PATH_MAX + 1]; - char *p = NULL; - char *end = NULL; - size_t len; - - strncpy(tmp, dir, PATH_MAX); - len = strlen(tmp); - - if (tmp[len - 1] == '/') - tmp[len - 1] = 0; - - end = tmp + len; - - for (p = tmp + 1; ((*p) && (ret == 0)) || ((ret == -1 && errno == EEXIST) && (p != end)); p++) - if (*p == '/') { - *p = 0; - - if (access(tmp, F_OK) != 0 && errno == ENOENT) { - ret = mkdir(tmp, - #ifdef DLT_DAEMON_USE_FIFO_IPC - S_IRWXU); - #else - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); - #endif - } - - *p = '/'; - } - - - - if ((ret == 0) || ((ret == -1) && (errno == EEXIST))) - ret = mkdir(tmp, - #ifdef DLT_DAEMON_USE_FIFO_IPC - S_IRWXU); - #else - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); - #endif - - if ((ret == -1) && (errno == EEXIST)) - ret = 0; - - return ret; -} - -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC static DltReturnValue dlt_daemon_create_pipes_dir(char *dir) { int ret = DLT_RETURN_OK; @@ -957,28 +772,7 @@ /* Initialize internal logging facility */ dlt_log_set_filename(daemon_local.flags.loggingFilename); dlt_log_set_level(daemon_local.flags.loggingLevel); - 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 - } + dlt_log_init(daemon_local.flags.loggingMode); /* Print version information */ dlt_get_version(version, DLT_DAEMON_TEXTBUFSIZE); @@ -987,18 +781,12 @@ PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag); -/* Make sure the parent user directory is created */ -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC + /* Make sure the parent user directory is created */ 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) { - dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", daemon_local.flags.appSockPath); - return -1; } #endif @@ -1025,17 +813,6 @@ /* --- Daemon connection init end */ - if (dlt_daemon_init_runtime_configuration(&daemon, daemon_local.flags.ivalue, daemon_local.flags.vflag) == -1) { - 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 - */ - dlt_daemon_configuration_load(&daemon, daemon.runtime_configuration, daemon_local.flags.vflag); - /* --- Daemon init phase 2 begin --- */ if (dlt_daemon_local_init_p2(&daemon, &daemon_local, daemon_local.flags.vflag) == -1) { dlt_log(LOG_CRIT, "Initialization of phase 2 failed!\n"); @@ -1083,14 +860,14 @@ /* initiate gateway */ if (daemon_local.flags.gatewayMode == 1) { if (dlt_gateway_init(&daemon_local, daemon_local.flags.vflag) == -1) { - dlt_log(LOG_CRIT, "Failed to create gateway\n"); + dlt_log(LOG_CRIT, "Fail to create gateway\n"); return -1; } /* create gateway timer */ create_timer_fd(&daemon_local, - daemon_local.pGateway.interval, - daemon_local.pGateway.interval, + DLT_GATEWAY_TIMER_INTERVAL, + DLT_GATEWAY_TIMER_INTERVAL, DLT_TIMER_GATEWAY); } @@ -1107,15 +884,10 @@ daemon_local.flags.gatewayMode, daemon_local.flags.vflag); - /* - * Check for app and ctx runtime cfg. - * These cfg must be loaded after ecuId and num_user_lists are available - */ - if ((dlt_daemon_applications_load(&daemon, daemon.runtime_application_cfg, - daemon_local.flags.vflag) == 0) && - (dlt_daemon_contexts_load(&daemon, daemon.runtime_context_cfg, - daemon_local.flags.vflag) == 0)) - daemon.runtime_context_cfg_loaded = 1; + if (dlt_daemon_load_runtime_configuration(&daemon, daemon_local.flags.ivalue, daemon_local.flags.vflag) == -1) { + dlt_log(LOG_ERR, "Could not load runtime config\n"); + return -1; + } dlt_daemon_log_internal(&daemon, &daemon_local, @@ -1132,22 +904,16 @@ g_signo); dlt_daemon_log_internal(&daemon, &daemon_local, local_str, daemon_local.flags.vflag); - dlt_vlog(LOG_NOTICE, "%s%s", local_str, "\n"); + dlt_log(LOG_NOTICE, local_str); dlt_daemon_local_cleanup(&daemon, &daemon_local, daemon_local.flags.vflag); -#ifdef UDP_CONNECTION_SUPPORT - dlt_daemon_udp_close_connection(); -#endif - dlt_gateway_deinit(&daemon_local.pGateway, daemon_local.flags.vflag); dlt_daemon_free(&daemon, daemon_local.flags.vflag); dlt_log(LOG_NOTICE, "Leaving DLT daemon\n"); - dlt_log_free(); - return 0; } /* main() */ @@ -1179,7 +945,7 @@ #endif -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC if (dlt_daemon_create_pipes_dir(daemon_local->flags.userPipesDir) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; @@ -1193,12 +959,7 @@ /* Re-Initialize internal logging facility after fork */ dlt_log_set_filename(daemon_local->flags.loggingFilename); dlt_log_set_level(daemon_local->flags.loggingLevel); - // '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); + dlt_log_init(daemon_local->flags.loggingMode); /* initialise structure to use DLT file */ ret = dlt_file_init(&(daemon_local->file), daemon_local->flags.vflag); @@ -1216,9 +977,6 @@ signal(SIGHUP, dlt_daemon_signal_handler); /* hangup signal */ signal(SIGQUIT, dlt_daemon_signal_handler); signal(SIGINT, dlt_daemon_signal_handler); -#ifdef __QNX__ - signal(SIGUSR1, dlt_daemon_signal_handler); /* for timer threads */ -#endif return DLT_RETURN_OK; } @@ -1245,14 +1003,11 @@ /* init offline trace */ if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) { - 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) { + 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) { dlt_log(LOG_ERR, "Could not initialize offline trace\n"); return -1; } @@ -1283,18 +1038,12 @@ /* init shared memory */ if (dlt_shm_init_server(&(daemon_local->dlt_shm), daemon_local->flags.dltShmName, - daemon_local->flags.sharedMemorySize) == DLT_RETURN_ERROR) { + daemon_local->flags.sharedMemorySize) == DLT_RETURN_ERROR) + { dlt_log(LOG_ERR, "Could not initialize shared memory\n"); return -1; } - daemon_local->recv_buf_shm = (unsigned char *)calloc(1, DLT_SHM_RCV_BUFFER_SIZE); - - if (NULL == daemon_local->recv_buf_shm) { - dlt_log(LOG_ERR, "failed to allocated the buffer to receive shm data\n"); - return -1; - } - #endif /* prepare main loop */ @@ -1325,9 +1074,6 @@ dlt_get_version(daemon->ECUVersionString, DLT_DAEMON_TEXTBUFSIZE); } - /* Set to allows to maintain logstorage loglevel as default */ - daemon->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; - return 0; } @@ -1358,7 +1104,7 @@ daemon_local->baudrate = dlt_convert_serial_speed(speed); - if (dlt_setup_serial(fd, (speed_t) daemon_local->baudrate) < 0) { + if (dlt_setup_serial(fd, daemon_local->baudrate) < 0) { close(fd); daemon_local->flags.yvalue[0] = 0; @@ -1388,7 +1134,7 @@ DLT_CONNECTION_CLIENT_MSG_SERIAL); } -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) { int ret; @@ -1402,7 +1148,7 @@ const char *tmpFifo = daemon_local->flags.daemonFifoName; unlink(tmpFifo); - ret = mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IWGRP); + ret = mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (ret == -1) { dlt_vlog(LOG_WARNING, "FIFO user %s cannot be created (%s)!\n", @@ -1411,17 +1157,19 @@ } /* if */ /* Set group of daemon FIFO */ - if (daemon_local->flags.daemonFifoGroup[0] != 0) { + if (daemon_local->flags.daemonFifoGroup[0] != 0) + { errno = 0; - struct group *group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup); - - if (group_dlt) { + struct group * group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup); + if (group_dlt) + { ret = chown(tmpFifo, -1, group_dlt->gr_gid); - if (ret == -1) + { dlt_vlog(LOG_ERR, "FIFO user %s cannot be chowned to group %s (%s)\n", tmpFifo, daemon_local->flags.daemonFifoGroup, strerror(errno)); + } } else if ((errno == 0) || (errno == ENOENT) || (errno == EBADF) || (errno == EPERM)) { @@ -1429,7 +1177,8 @@ daemon_local->flags.daemonFifoGroup, strerror(errno)); } - else { + else + { dlt_vlog(LOG_ERR, "Failed to get group id of %s (%s)\n", daemon_local->flags.daemonFifoGroup, strerror(errno)); @@ -1444,22 +1193,20 @@ return -1; } /* if */ -#ifdef __linux__ - /* F_SETPIPE_SZ and F_GETPIPE_SZ are only supported for Linux. - * For other OSes it depends on its system e.g. pipe manager. - */ if (daemon_local->daemonFifoSize != 0) { /* Set Daemon FIFO size */ - if (fcntl(fd, F_SETPIPE_SZ, daemon_local->daemonFifoSize) == -1) + if (fcntl(fd, F_SETPIPE_SZ, daemon_local->daemonFifoSize) == -1) { dlt_vlog(LOG_ERR, "set FIFO size error: %s\n", strerror(errno)); + } } /* Get Daemon FIFO size */ - if ((fifo_size = fcntl(fd, F_GETPIPE_SZ, 0)) == -1) + if ((fifo_size = fcntl(fd, F_GETPIPE_SZ, 0)) == -1) { dlt_vlog(LOG_ERR, "get FIFO size error: %s\n", strerror(errno)); - else + } + else { dlt_vlog(LOG_INFO, "FIFO size: %d\n", fifo_size); -#endif + } /* Early init, to be able to catch client (app) connections * as soon as possible. This registration is automatically ignored @@ -1473,166 +1220,45 @@ } #endif -#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE -static int dlt_daemon_init_vsock(DltDaemonLocal *daemon_local) -{ - int fd; - struct sockaddr_vm addr; - - fd = socket(AF_VSOCK, SOCK_STREAM, 0); - if (fd == -1) { - dlt_vlog(LOG_ERR, "Failed to create VSOCK socket: %s\n", strerror(errno)); - return -1; - } - - memset(&addr, 0, sizeof(addr)); - addr.svm_family = AF_VSOCK; - addr.svm_port = DLT_VSOCK_PORT; - addr.svm_cid = VMADDR_CID_ANY; - - if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) != 0) { - dlt_vlog(LOG_ERR, "Failed to bind VSOCK socket: %s\n", strerror(errno)); - close(fd); - return -1; - } - - if (listen(fd, 1) != 0) { - dlt_vlog(LOG_ERR, "Failed to listen on VSOCK socket: %s\n", strerror(errno)); - close(fd); - return -1; - } - - return dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_APP_CONNECT); -} -#endif - -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC -static DltReturnValue dlt_daemon_init_app_socket(DltDaemonLocal *daemon_local) +int dlt_daemon_local_connection_init(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + int verbose) { - /* socket access permission set to srw-rw-rw- (666) */ - int mask = S_IXUSR | S_IXGRP | S_IXOTH; - DltReturnValue ret = DLT_RETURN_OK; int fd = -1; + int mask = 0; + DltBindAddress_t *head = daemon_local->flags.ipNodes; - if (daemon_local == NULL) { + PRINT_FUNCTION_VERBOSE(verbose); + + if ((daemon == NULL) || (daemon_local == NULL)) { dlt_vlog(LOG_ERR, "%s: Invalid function parameters\n", __func__); - return DLT_RETURN_ERROR; + return -1; } -#ifdef ANDROID - /* on android if we want to use security contexts on Unix sockets, - * they should be created by init (see dlt-daemon.rc in src/daemon) - * and recovered through the below API */ - ret = dlt_daemon_unix_android_get_socket(&fd, daemon_local->flags.appSockPath); - if (ret < DLT_RETURN_OK) { - /* we failed to get app socket created by init. - * To avoid blocking users to launch dlt-daemon only through - * init on android (e.g: by hand for debugging purpose), try to - * create app socket by ourselves */ - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.appSockPath, - SOCK_STREAM, - mask); - } -#else - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.appSockPath, - SOCK_STREAM, - mask); -#endif - if (ret == DLT_RETURN_OK) { +#ifdef DLT_USE_UNIX_SOCKET_IPC + /* create and open socket to receive incoming connections from user application + * socket access permission set to srw-rw-rw- (666) */ + mask = S_IXUSR | S_IXGRP | S_IXOTH; + + if (dlt_daemon_unix_socket_open(&fd, + daemon_local->flags.appSockPath, + SOCK_STREAM, + mask) == DLT_RETURN_OK) { if (dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_APP_CONNECT)) { - dlt_log(LOG_CRIT, "Could not create connection for app socket.\n"); + dlt_log(LOG_CRIT, "Could not initialize app socket.\n"); return DLT_RETURN_ERROR; } } else { - dlt_log(LOG_CRIT, "Could not create and open app socket.\n"); + dlt_log(LOG_CRIT, "Could not initialize app socket.\n"); return DLT_RETURN_ERROR; } - return ret; -} -#endif - -static DltReturnValue dlt_daemon_initialize_control_socket(DltDaemonLocal *daemon_local) -{ - /* socket access permission set to srw-rw---- (660) */ - int mask = S_IXUSR | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; - DltReturnValue ret = DLT_RETURN_OK; - int fd = -1; - - if (daemon_local == NULL) { - dlt_vlog(LOG_ERR, "%s: Invalid function parameters\n", __func__); - return -1; - } - -#ifdef ANDROID - /* on android if we want to use security contexts on Unix sockets, - * they should be created by init (see dlt-daemon.rc in src/daemon) - * and recovered through the below API */ - ret = dlt_daemon_unix_android_get_socket(&fd, daemon_local->flags.ctrlSockPath); - if (ret < DLT_RETURN_OK) { - /* we failed to get app socket created by init. - * To avoid blocking users to launch dlt-daemon only through - * init on android (e.g by hand for debugging purpose), try to - * create app socket by ourselves */ - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.ctrlSockPath, - SOCK_STREAM, - mask); - } #else - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.ctrlSockPath, - SOCK_STREAM, - mask); -#endif - if (ret == DLT_RETURN_OK) { - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_CONTROL_CONNECT) < DLT_RETURN_OK) { - dlt_log(LOG_ERR, "Could not initialize control socket.\n"); - ret = DLT_RETURN_ERROR; - } - } - - return ret; -} - -int dlt_daemon_local_connection_init(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) -{ - int fd = -1; - - PRINT_FUNCTION_VERBOSE(verbose); - - if ((daemon == NULL) || (daemon_local == NULL)) { - dlt_vlog(LOG_ERR, "%s: Invalid function parameters\n", __func__); - return -1; - } - - DltBindAddress_t *head = daemon_local->flags.ipNodes; - -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC - /* create and open socket to receive incoming connections from user application */ - if (dlt_daemon_init_app_socket(daemon_local) < DLT_RETURN_OK) { - dlt_log(LOG_ERR, "Unable to initialize app socket.\n"); - return DLT_RETURN_ERROR; - } - -#else /* DLT_DAEMON_USE_FIFO_IPC */ if (dlt_daemon_init_fifo(daemon_local)) { dlt_log(LOG_ERR, "Unable to initialize fifo.\n"); @@ -1641,13 +1267,6 @@ #endif -#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE - if (dlt_daemon_init_vsock(daemon_local) != 0) { - dlt_log(LOG_ERR, "Unable to initialize app VSOCK socket.\n"); - return DLT_RETURN_ERROR; - } -#endif - /* create and open socket to receive incoming connections from client */ daemon_local->client_connections = 0; @@ -1669,7 +1288,6 @@ } } 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) { @@ -1678,41 +1296,52 @@ fd, POLLIN, DLT_CONNECTION_CLIENT_CONNECT)) { - dlt_vlog(LOG_ERR, "Could not create connection, for binding %s\n", head->ip); - } else { - any_open = true; + dlt_log(LOG_ERR, "Could not initialize main socket.\n"); + return DLT_RETURN_ERROR; } } else { - dlt_vlog(LOG_ERR, "Could not open main socket, for binding %s\n", head->ip); + dlt_log(LOG_ERR, "Could not initialize main socket.\n"); + return DLT_RETURN_ERROR; } 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 if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) { if (dlt_daemon_udp_connection_setup(daemon_local) < 0) { - dlt_log(LOG_ERR, "UDP fd creation failed\n"); + dlt_log(LOG_ERR, "UDP fd creation and register in epoll failed\n"); return DLT_RETURN_ERROR; } else { - dlt_log(LOG_INFO, "UDP fd creation success\n"); + dlt_log(LOG_INFO, "UDP fd creation and register in epoll success\n"); } } #endif /* create and open unix socket to receive incoming connections from - * control application */ - if (dlt_daemon_initialize_control_socket(daemon_local) < DLT_RETURN_OK) { + * control application + * socket access permission set to srw-rw---- (660) */ + mask = S_IXUSR | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; + + if (dlt_daemon_unix_socket_open(&fd, + daemon_local->flags.ctrlSockPath, + SOCK_STREAM, + mask) == DLT_RETURN_OK) { + if (dlt_connection_create(daemon_local, + &daemon_local->pEvent, + fd, + POLLIN, + DLT_CONNECTION_CONTROL_CONNECT)) { + dlt_log(LOG_ERR, "Could not initialize control socket.\n"); + return DLT_RETURN_ERROR; + } + } + else { dlt_log(LOG_ERR, "Could not initialize control socket.\n"); return DLT_RETURN_ERROR; } @@ -1766,7 +1395,7 @@ } /* Allocate permanent buffer for version info */ - version = malloc((size_t) (size + 1)); + version = malloc(size + 1); if (version == 0) { dlt_log(LOG_WARNING, "Cannot allocate memory for ECU version.\n"); @@ -1777,7 +1406,7 @@ off_t offset = 0; while (!feof(f)) { - offset += (off_t) fread(version + offset, 1, (size_t) size, f); + offset += fread(version + offset, 1, size, f); if (ferror(f)) { dlt_log(LOG_WARNING, "Failed to read ECU Software version file.\n"); @@ -1816,15 +1445,15 @@ /* free shared memory */ if (daemon_local->flags.offlineTraceDirectory[0]) - multiple_files_buffer_free(&(daemon_local->offlineTrace)); + dlt_offline_trace_free(&(daemon_local->offlineTrace)); /* Ignore result */ dlt_file_free(&(daemon_local->file), daemon_local->flags.vflag); -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC /* Try to delete existing pipe, ignore result of unlink() */ unlink(daemon_local->flags.daemonFifoName); -#else /* DLT_DAEMON_USE_UNIX_SOCKET_IPC */ +#else /* Try to delete existing pipe, ignore result of unlink() */ unlink(daemon_local->flags.appSockPath); #endif @@ -1832,8 +1461,6 @@ #ifdef DLT_SHM_ENABLE /* free shared memory */ dlt_shm_free_server(&(daemon_local->dlt_shm), daemon_local->flags.dltShmName); - free(daemon_local->recv_buf_shm); - daemon_local->recv_buf_shm = NULL; #endif if (daemon_local->flags.offlineLogstorageMaxDevices > 0) { @@ -1856,26 +1483,13 @@ void dlt_daemon_exit_trigger() { - /* stop event loop */ - g_exit = -1; - -#ifdef DLT_DAEMON_USE_FIFO_IPC char tmp[DLT_PATH_MAX] = { 0 }; - ssize_t n; - n = snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir); - if (n < 0 || (size_t)n > DLT_PATH_MAX) { - dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n", - __func__, n, tmp); - } - + snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir); (void)unlink(tmp); -#endif - -#ifdef __QNX__ - dlt_daemon_cleanup_timers(); -#endif + /* stop event loop */ + g_exit = -1; } void dlt_daemon_signal_handler(int sig) @@ -1883,50 +1497,26 @@ g_signo = sig; switch (sig) { - case SIGHUP: - case SIGTERM: - case SIGINT: - case SIGQUIT: - { - /* finalize the server */ - dlt_vlog(LOG_NOTICE, "Exiting DLT daemon due to signal: %s\n", - strsignal(sig)); - dlt_daemon_exit_trigger(); - break; - } - default: - { - /* This case should never happen! */ - break; - } + case SIGHUP: + case SIGTERM: + case SIGINT: + case SIGQUIT: + { + /* finalize the server */ + dlt_vlog(LOG_NOTICE, "Exiting DLT daemon due to signal: %s\n", + strsignal(sig)); + dlt_daemon_exit_trigger(); + break; + } + default: + { + /* This case should never happen! */ + break; + } } /* switch */ } /* dlt_daemon_signal_handler() */ -#ifdef __QNX__ -void dlt_daemon_cleanup_timers() -{ - int i = 0; - while (i < DLT_TIMER_UNKNOWN) { - /* Remove FIFO of every timer and kill timer thread */ - if (0 != timer_threads[i]) { - pthread_kill(timer_threads[i], SIGUSR1); - pthread_join(timer_threads[i], NULL); - timer_threads[i] = 0; - - close_pipes(dlt_timer_pipes[i]); - - /* Free data of every timer */ - if (NULL != timer_data[i]) { - free(timer_data[i]); - timer_data[i] = NULL; - } - } - i++; - } -} -#endif - void dlt_daemon_daemonize(int verbose) { int i; @@ -2005,6 +1595,7 @@ uint32_t uiType; uint16_t uiSize; uint32_t uiExtraSize; + int ret; PRINT_FUNCTION_VERBOSE(verbose); @@ -2018,16 +1609,16 @@ DLT_HTYP_PROTOCOL_VERSION1; msg.standardheader->mcnt = uiMsgCount++; - uiExtraSize = (uint32_t) (DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) + - (DLT_IS_HTYP_UEH(msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); - msg.headersize = (uint32_t) sizeof(DltStorageHeader) + (uint32_t) sizeof(DltStandardHeader) + uiExtraSize; + uiExtraSize = DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) + + (DLT_IS_HTYP_UEH(msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0); + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + uiExtraSize; /* Set extraheader */ pStandardExtra = (DltStandardHeaderExtra *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)); dlt_set_id(pStandardExtra->ecu, daemon->ecuid); pStandardExtra->tmsp = DLT_HTOBE_32(dlt_uptime()); - pStandardExtra->seid = (unsigned int) DLT_HTOBE_32(getpid()); + pStandardExtra->seid = DLT_HTOBE_32(getpid()); /* Set extendedheader */ msg.extendedheader = @@ -2041,10 +1632,10 @@ /* Set payload data... */ uiType = DLT_TYPE_INFO_STRG; - uiSize = (uint16_t) (strlen(str) + 1); - msg.datasize = (uint32_t) (sizeof(uint32_t) + sizeof(uint16_t) + uiSize); + uiSize = strlen(str) + 1; + msg.datasize = sizeof(uint32_t) + sizeof(uint16_t) + uiSize; - msg.databuffer = (uint8_t *)malloc((size_t) msg.datasize); + msg.databuffer = (uint8_t *)malloc(msg.datasize); msg.databuffersize = msg.datasize; if (msg.databuffer == 0) { @@ -2054,39 +1645,40 @@ msg.datasize = 0; memcpy((uint8_t *)(msg.databuffer + msg.datasize), (uint8_t *)(&uiType), sizeof(uint32_t)); - msg.datasize += (uint32_t) sizeof(uint32_t); + msg.datasize += sizeof(uint32_t); memcpy((uint8_t *)(msg.databuffer + msg.datasize), (uint8_t *)(&uiSize), sizeof(uint16_t)); - msg.datasize += (uint32_t) sizeof(uint16_t); + msg.datasize += sizeof(uint16_t); memcpy((uint8_t *)(msg.databuffer + msg.datasize), str, uiSize); msg.datasize += uiSize; - /* Calc length */ + /* Calc lengths */ msg.standardheader->len = DLT_HTOBE_16(msg.headersize - sizeof(DltStorageHeader) + msg.datasize); - dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, - msg.headerbuffer, sizeof(DltStorageHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (int) (msg.headersize - sizeof(DltStorageHeader)), - msg.databuffer, (int) msg.datasize, verbose); - - free(msg.databuffer); + /* Sending data... */ + { + /* check if overflow occurred */ + if (daemon->overflow_counter) { + if (dlt_daemon_send_message_overflow(daemon, daemon_local, verbose) == 0) { + dlt_vlog(LOG_WARNING, "%u messages discarded!\n", + daemon->overflow_counter); + daemon->overflow_counter = 0; + } + } - return 0; -} + /* look if TCP connection to client is available */ + if ((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) -int dlt_daemon_check_numeric_setting(char *token, - char *value, - unsigned long *data) -{ - char value_check[value_length]; - value_check[0] = 0; - sscanf(value, "%lu%s", data, value_check); - if (value_check[0] || !isdigit(value[0])) { - fprintf(stderr, "Invalid input [%s] detected in option %s\n", - value, - token); - return -1; + if ((ret = + dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, msg.headerbuffer, + sizeof(DltStorageHeader), msg.headerbuffer + sizeof(DltStorageHeader), + msg.headersize - sizeof(DltStorageHeader), + msg.databuffer, msg.datasize, verbose))) + if (ret == DLT_DAEMON_ERROR_BUFFER_FULL) + daemon->overflow_counter++; } + + free(msg.databuffer); + return 0; } @@ -2114,8 +1706,6 @@ cli_size = sizeof(cli); if ((in_sock = accept(receiver->fd, (struct sockaddr *)&cli, &cli_size)) < 0) { - if (errno == ECONNABORTED) // Caused by nmap -v -p 3490 -Pn - return 0; dlt_vlog(LOG_ERR, "accept() for socket %d failed: %s\n", receiver->fd, strerror(errno)); return -1; } @@ -2171,13 +1761,10 @@ daemon_local->flags.vflag); } - snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "New client connection #%d established, Total Clients : %d", + dlt_vlog(LOG_DEBUG, + "New client connection #%d established, Total Clients : %d\n", in_sock, daemon_local->client_connections); - - dlt_daemon_log_internal(daemon, daemon_local, local_str, - daemon_local->flags.vflag); - dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); + dlt_daemon_log_internal(daemon, daemon_local, local_str, daemon_local->flags.vflag); if (daemon_local->client_connections == 1) { if (daemon_local->flags.vflag) @@ -2187,8 +1774,6 @@ 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; } @@ -2217,7 +1802,7 @@ return -1; } - must_close_socket = dlt_receiver_receive(receiver); + must_close_socket = dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET); if (must_close_socket < 0) { dlt_daemon_close_socket(receiver->fd, @@ -2230,7 +1815,7 @@ /* Process all received messages */ while (dlt_message_read(&(daemon_local->msg), (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, + receiver->bytesRcvd, daemon_local->flags.nflag, daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ @@ -2242,12 +1827,12 @@ &(daemon_local->msg), daemon_local->flags.vflag); - bytes_to_be_removed = (int) (daemon_local->msg.headersize + + bytes_to_be_removed = daemon_local->msg.headersize + daemon_local->msg.datasize - - sizeof(DltStorageHeader)); + sizeof(DltStorageHeader); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; @@ -2293,7 +1878,7 @@ return -1; } - if (dlt_receiver_receive(receiver) <= 0) { + if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD) <= 0) { dlt_log(LOG_WARNING, "dlt_receiver_receive_fd() for messages from serial interface " "failed!\n"); @@ -2303,7 +1888,7 @@ /* Process all received messages */ while (dlt_message_read(&(daemon_local->msg), (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, + receiver->bytesRcvd, daemon_local->flags.mflag, daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ @@ -2319,12 +1904,12 @@ } } - bytes_to_be_removed = (int) (daemon_local->msg.headersize + + bytes_to_be_removed = daemon_local->msg.headersize + daemon_local->msg.datasize - - sizeof(DltStorageHeader)); + sizeof(DltStorageHeader); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; @@ -2389,19 +1974,22 @@ return -1; } - if (verbose) + if (verbose) { dlt_vlog(LOG_INFO, "New connection to control client established\n"); + } return 0; } -#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE +#ifdef DLT_USE_UNIX_SOCKET_IPC int dlt_daemon_process_app_connect( DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose) { + socklen_t app_size; + struct sockaddr_un app; int in_sock = -1; PRINT_FUNCTION_VERBOSE(verbose); @@ -2413,15 +2001,16 @@ return DLT_RETURN_WRONG_PARAMETER; } - /* event from server socket, new connection */ + /* event from UNIX server socket, new connection */ + app_size = sizeof(app); - if ((in_sock = accept(receiver->fd, NULL, NULL)) < 0) { + if ((in_sock = accept(receiver->fd, (struct sockaddr *)&app, &app_size)) < 0) { dlt_vlog(LOG_ERR, "accept() on UNIX socket %d failed: %s\n", receiver->fd, strerror(errno)); return -1; } /* check if file file descriptor was already used, and make it invalid if it - * is reused. This prevents sending messages to wrong file descriptor */ + * is reused. This prevents sending messages to wrong file descriptor */ dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); @@ -2435,8 +2024,9 @@ return -1; } - if (verbose) + if (verbose) { dlt_vlog(LOG_INFO, "New connection to application established\n"); + } return 0; } @@ -2459,7 +2049,7 @@ return -1; } - if (dlt_receiver_receive(receiver) <= 0) { + if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0) { dlt_daemon_close_socket(receiver->fd, daemon, daemon_local, @@ -2474,7 +2064,7 @@ while (dlt_message_read( &(daemon_local->msg), (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, + receiver->bytesRcvd, daemon_local->flags.nflag, daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ @@ -2485,12 +2075,12 @@ &(daemon_local->msg), daemon_local->flags.vflag); - bytes_to_be_removed = (int) (daemon_local->msg.headersize + + bytes_to_be_removed = daemon_local->msg.headersize + daemon_local->msg.datasize - - sizeof(DltStorageHeader)); + sizeof(DltStorageHeader); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; @@ -2521,7 +2111,7 @@ PRINT_FUNCTION_VERBOSE(verbose); - dlt_vlog(LOG_ERR, "Invalid user message type received: %u!\n", + dlt_vlog(LOG_ERR, "Invalid user message type received: %d!\n", userheader->message); /* remove user header */ @@ -2543,7 +2133,11 @@ dlt_daemon_process_user_message_not_sup, dlt_daemon_process_user_message_overflow, dlt_daemon_process_user_message_set_app_ll_ts, +#ifdef DLT_SHM_ENABLE + dlt_daemon_process_user_message_log_shm, +#else dlt_daemon_process_user_message_not_sup, +#endif dlt_daemon_process_user_message_not_sup, dlt_daemon_process_user_message_not_sup, dlt_daemon_process_user_message_marker, @@ -2558,7 +2152,7 @@ { int offset = 0; int run_loop = 1; - int32_t min_size = (int32_t) sizeof(DltUserHeader); + int32_t min_size = (int32_t)sizeof(DltUserHeader); DltUserHeader *userheader; int recv; @@ -2571,21 +2165,28 @@ return -1; } - recv = dlt_receiver_receive(receiver); +#ifdef DLT_USE_UNIX_SOCKET_IPC + recv = dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET); - if (recv <= 0 && receiver->type == DLT_RECEIVE_SOCKET) { + if (recv <= 0) { dlt_daemon_close_socket(receiver->fd, daemon, daemon_local, verbose); return 0; } - else if (recv < 0) { + +#else + recv = dlt_receiver_receive(receiver, DLT_RECEIVE_FD); + + if (recv < 0) { dlt_log(LOG_WARNING, "dlt_receiver_receive_fd() for user messages failed!\n"); return -1; } +#endif + /* look through buffer as long as data is in there */ while ((receiver->bytesRcvd >= min_size) && run_loop) { dlt_daemon_process_user_message_func func = NULL; @@ -2695,14 +2296,13 @@ int verbose) { uint32_t len = sizeof(DltUserControlMsgRegisterApplication); - uint32_t to_remove = 0; + int to_remove = 0; DltDaemonApplication *application = NULL; DltDaemonApplication *old_application = NULL; pid_t old_pid = 0; char description[DLT_DAEMON_DESCSIZE + 1] = { '\0' }; DltUserControlMsgRegisterApplication userapp; char *origin; - int fd = -1; PRINT_FUNCTION_VERBOSE(verbose); @@ -2715,21 +2315,15 @@ memset(&userapp, 0, sizeof(DltUserControlMsgRegisterApplication)); origin = rec->buf; - /* Adding temp variable to check the return value */ - int temp = 0; - /* We shall not remove data before checking that everything is there. */ - temp = dlt_receiver_check_and_get(rec, + to_remove = dlt_receiver_check_and_get(rec, &userapp, len, DLT_RCV_SKIP_HEADER); - if (temp < 0) + if (to_remove < 0) /* Not enough bytes received */ return -1; - else { - to_remove = (uint32_t) temp; - } len = userapp.description_length; @@ -2744,8 +2338,7 @@ if (dlt_receiver_check_and_get(rec, description, len, DLT_RCV_NONE) < 0) { dlt_log(LOG_ERR, "Unable to get application description\n"); /* in case description was not readable, set dummy description */ - memcpy(description, "Unknown", sizeof("Unknown")); - + strncpy(description, "Unknown", sizeof("Unknown")); /* unknown len of original description, set to 0 to not remove in next * step. Because message buffer is re-adjusted the corrupted description * is ignored. */ @@ -2753,12 +2346,12 @@ } /* adjust to_remove */ - to_remove += (uint32_t) sizeof(DltUserHeader) + len; + to_remove += sizeof(DltUserHeader) + len; /* point to begin of message */ rec->buf = origin; /* We can now remove data. */ - if (dlt_receiver_remove(rec, (int) to_remove) != DLT_RETURN_OK) { + if (dlt_receiver_remove(rec, to_remove) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return -1; } @@ -2768,14 +2361,11 @@ if (old_application != NULL) old_pid = old_application->pid; - if (rec->type == DLT_RECEIVE_SOCKET) - fd = rec->fd; /* For sockets, an app specific fd has already been created with accept(). */ - application = dlt_daemon_application_add(daemon, userapp.apid, userapp.pid, description, - fd, + rec->fd, daemon->ecuid, verbose); @@ -2787,13 +2377,12 @@ userapp.apid, userapp.pid); return -1; } - else if (old_pid != application->pid) - { + else if (old_pid != application->pid) { char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "ApplicationID '%.4s' registered for PID %d, Description=%s", + "ApplicationID '%.4s' registered for PID %d, Description=%s\n", application->apid, application->pid, application->application_description); @@ -2801,7 +2390,7 @@ daemon_local, local_str, daemon_local->flags.vflag); - dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); + dlt_log(LOG_DEBUG, local_str); } return 0; @@ -2812,7 +2401,7 @@ DltReceiver *rec, int verbose) { - uint32_t to_remove = 0; + int to_remove = 0; uint32_t len = sizeof(DltUserControlMsgRegisterContext); DltUserControlMsgRegisterContext userctxt; char description[DLT_DAEMON_DESCSIZE + 1] = { '\0' }; @@ -2834,25 +2423,19 @@ memset(&userctxt, 0, sizeof(DltUserControlMsgRegisterContext)); origin = rec->buf; - /* Adding temp variable to check the return value */ - int temp = 0; - - temp = dlt_receiver_check_and_get(rec, + to_remove = dlt_receiver_check_and_get(rec, &userctxt, len, DLT_RCV_SKIP_HEADER); - if (temp < 0) + if (to_remove < 0) /* Not enough bytes received */ return -1; - else { - to_remove = (uint32_t) temp; - } len = userctxt.description_length; if (len > DLT_DAEMON_DESCSIZE) { - dlt_vlog(LOG_WARNING, "Context description exceeds limit: %u\n", len); + dlt_vlog(LOG_WARNING, "Context description exceeds limit: %d\n", len); len = DLT_DAEMON_DESCSIZE; } @@ -2862,8 +2445,7 @@ if (dlt_receiver_check_and_get(rec, description, len, DLT_RCV_NONE) < 0) { dlt_log(LOG_ERR, "Unable to get context description\n"); /* in case description was not readable, set dummy description */ - memcpy(description, "Unknown", sizeof("Unknown")); - + strncpy(description, "Unknown", sizeof("Unknown")); /* unknown len of original description, set to 0 to not remove in next * step. Because message buffer is re-adjusted the corrupted description * is ignored. */ @@ -2871,12 +2453,12 @@ } /* adjust to_remove */ - to_remove += (uint32_t) sizeof(DltUserHeader) + len; + to_remove += sizeof(DltUserHeader) + len; /* point to begin of message */ rec->buf = origin; /* We can now remove data. */ - if (dlt_receiver_remove(rec, (int) to_remove) != DLT_RETURN_OK) { + if (dlt_receiver_remove(rec, to_remove) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return -1; } @@ -2897,26 +2479,22 @@ } /* Set log level */ - if (userctxt.log_level == DLT_USER_LOG_LEVEL_NOT_SET) { + if (userctxt.log_level == DLT_USER_LOG_LEVEL_NOT_SET) userctxt.log_level = DLT_LOG_DEFAULT; - } else { - /* Plausibility check */ - if ((userctxt.log_level < DLT_LOG_DEFAULT) || - (userctxt.log_level > DLT_LOG_VERBOSE)) { - return -1; - } - } + else + /* Plausibility check */ + if ((userctxt.log_level < DLT_LOG_DEFAULT) || + (userctxt.log_level > DLT_LOG_VERBOSE)) + return -1; /* Set trace status */ - if (userctxt.trace_status == DLT_USER_TRACE_STATUS_NOT_SET) { + if (userctxt.trace_status == DLT_USER_TRACE_STATUS_NOT_SET) userctxt.trace_status = DLT_TRACE_STATUS_DEFAULT; - } else { - /* Plausibility check */ - if ((userctxt.trace_status < DLT_TRACE_STATUS_DEFAULT) || - (userctxt.trace_status > DLT_TRACE_STATUS_ON)) { - return -1; - } - } + else + /* Plausibility check */ + if ((userctxt.trace_status < DLT_TRACE_STATUS_DEFAULT) || + (userctxt.trace_status > DLT_TRACE_STATUS_ON)) + return -1; context = dlt_daemon_context_add(daemon, userctxt.apid, @@ -2940,7 +2518,7 @@ snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "ContextID '%.4s' registered for ApID '%.4s', Description=%s", + "ContextID '%.4s' registered for ApID '%.4s', Description=%s\n", context->ctid, context->apid, context->context_description); @@ -2948,14 +2526,14 @@ if (verbose) dlt_daemon_log_internal(daemon, daemon_local, local_str, verbose); - dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); + dlt_log(LOG_DEBUG, local_str); } if (daemon_local->flags.offlineLogstorageMaxDevices) /* Store log level set for offline logstorage into context structure*/ context->storage_log_level = - (int8_t) dlt_daemon_logstorage_get_loglevel(daemon, - (int8_t) daemon_local->flags.offlineLogstorageMaxDevices, + dlt_daemon_logstorage_get_loglevel(daemon, + daemon_local->flags.offlineLogstorageMaxDevices, userctxt.apid, userctxt.ctid); else @@ -2989,7 +2567,7 @@ req = (DltServiceGetLogInfoRequest *)msg.databuffer; req->service_id = DLT_SERVICE_ID_GET_LOG_INFO; - req->options = (uint8_t) daemon_local->flags.autoResponseGetLogInfoOption; + req->options = daemon_local->flags.autoResponseGetLogInfoOption; dlt_set_id(req->apid, userctxt.apid); dlt_set_id(req->ctid, userctxt.ctid); dlt_set_id(req->com, "remo"); @@ -3099,13 +2677,13 @@ snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "Unregistered ApID '%.4s'", + "Unregistered ApID '%.4s'\n", userapp.apid); dlt_daemon_log_internal(daemon, daemon_local, local_str, verbose); - dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); + dlt_log(LOG_DEBUG, local_str); } } } @@ -3149,7 +2727,7 @@ * unregisters, the context information will not be deleted from daemon's * table until its parent application is unregistered. */ - if (context && (context->predefined == false)) { + if (context && context->predefined == false) { /* Delete this connection entry from internal table*/ if (dlt_daemon_context_del(daemon, context, daemon->ecuid, verbose) == -1) { dlt_vlog(LOG_WARNING, @@ -3164,7 +2742,7 @@ snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "Unregistered CtID '%.4s' for ApID '%.4s'", + "Unregistered CtID '%.4s' for ApID '%.4s'\n", userctxt.ctid, userctxt.apid); @@ -3174,7 +2752,7 @@ local_str, verbose); - dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); + dlt_log(LOG_DEBUG, local_str); } } @@ -3196,56 +2774,21 @@ DltReceiver *rec, int verbose) { - int ret = 0; - int size = 0; + int ret; + int bytes_to_be_removed; + + static char text[DLT_DAEMON_TEXTSIZE]; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "%s: invalid function parameters.\n", __func__); + dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_message_log()\n"); return DLT_DAEMON_ERROR_UNKNOWN; } -#ifdef DLT_SHM_ENABLE - - /** In case of SHM, the header still received via fifo/unix_socket receiver, - * so we need to remove header from the receiver. - */ - if (dlt_receiver_remove(rec, sizeof(DltUserHeader)) < 0) - /* Not enough bytes received to remove*/ - return DLT_DAEMON_ERROR_UNKNOWN; - - while (1) { - /* get log message from SHM then store into receiver buffer */ - size = dlt_shm_pull(&(daemon_local->dlt_shm), - daemon_local->recv_buf_shm, - DLT_SHM_RCV_BUFFER_SIZE); - - if (size <= 0) - break; - - ret = dlt_message_read(&(daemon_local->msg), - daemon_local->recv_buf_shm, size, 0, verbose); - - if (DLT_MESSAGE_ERROR_OK != ret) { - dlt_shm_remove(&(daemon_local->dlt_shm)); - dlt_log(LOG_WARNING, "failed to read messages from shm.\n"); - return DLT_DAEMON_ERROR_UNKNOWN; - } - - /* 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"); - } - -#else ret = dlt_message_read(&(daemon_local->msg), (unsigned char *)rec->buf + sizeof(DltUserHeader), - (unsigned int) ((unsigned int) rec->bytesRcvd - sizeof(DltUserHeader)), + rec->bytesRcvd - sizeof(DltUserHeader), 0, verbose); @@ -3263,40 +2806,224 @@ return DLT_DAEMON_ERROR_UNKNOWN; } - /* 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); + /* set overwrite ecu id */ + if ((daemon_local->flags.evalue[0]) && (strncmp(daemon_local->msg.headerextra.ecu, DLT_DAEMON_ECU_ID, 4) == 0)) { + /* Set header extra parameters */ + dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid); + + /*msg.headerextra.seid = 0; */ + if (dlt_message_set_extraparameters(&(daemon_local->msg), 0) == DLT_RETURN_ERROR) { + dlt_log(LOG_WARNING, "Can't set message extra parameters in process user message log\n"); + return DLT_DAEMON_ERROR_UNKNOWN; + } + + /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ + daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + } + + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) { + if (dlt_set_storageheader(daemon_local->msg.storageheader, + daemon_local->msg.headerextra.ecu) == DLT_RETURN_ERROR) { + dlt_log(LOG_WARNING, "Can't set storage header in process user message log\n"); + return DLT_DAEMON_ERROR_UNKNOWN; + } + } + else if (dlt_set_storageheader(daemon_local->msg.storageheader, daemon->ecuid) == DLT_RETURN_ERROR) + { + dlt_log(LOG_WARNING, "Can't set storage header in process user message log\n"); + return DLT_DAEMON_ERROR_UNKNOWN; + } + + { + /* if no filter set or filter is matching display message */ + if (daemon_local->flags.xflag) { + if (dlt_message_print_hex(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose) == DLT_RETURN_ERROR) + dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n"); + } /* if */ + else if (daemon_local->flags.aflag) + { + if (dlt_message_print_ascii(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose) == DLT_RETURN_ERROR) + dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n"); + } /* if */ + else if (daemon_local->flags.sflag) + { + if (dlt_message_print_header(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose) == DLT_RETURN_ERROR) + dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n"); + + /* print message header only */ + } /* if */ + + /* check if overflow occurred */ + if (daemon->overflow_counter) { + if (dlt_daemon_send_message_overflow(daemon, daemon_local, verbose) == 0) { + dlt_vlog(LOG_WARNING, "%u messages discarded!\n", + daemon->overflow_counter); + daemon->overflow_counter = 0; + } + } + + /* send message to client or write to log file */ + if ((ret = + dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->msg.headerbuffer, + sizeof(DltStorageHeader), + daemon_local->msg.headerbuffer + sizeof(DltStorageHeader), + daemon_local->msg.headersize - sizeof(DltStorageHeader), + daemon_local->msg.databuffer, daemon_local->msg.datasize, verbose))) + if (ret == DLT_DAEMON_ERROR_BUFFER_FULL) + daemon->overflow_counter++; + } /* keep not read data in buffer */ - size = (int) (daemon_local->msg.headersize + - daemon_local->msg.datasize - sizeof(DltStorageHeader) + - sizeof(DltUserHeader)); + bytes_to_be_removed = daemon_local->msg.headersize + daemon_local->msg.datasize - sizeof(DltStorageHeader) + + sizeof(DltUserHeader); if (daemon_local->msg.found_serialheader) - size += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += sizeof(dltSerialHeader); - if (dlt_receiver_remove(rec, size) != DLT_RETURN_OK) { - dlt_log(LOG_WARNING, "failed to remove bytes from receiver.\n"); + if (dlt_receiver_remove(rec, bytes_to_be_removed) == -1) { + dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return DLT_DAEMON_ERROR_UNKNOWN; } -#endif - 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; +#ifdef DLT_SHM_ENABLE +# define DLT_SHM_RCV_BUFFER_SIZE 10000 +int dlt_daemon_process_user_message_log_shm(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + DltReceiver *rec, + int verbose) +{ + int sent; + uint8_t *rcv_buffer = NULL; + int size; + uint32_t len = sizeof(DltUserHeader); + DltUserHeader userheader; + + static char text[DLT_DAEMON_TEXTSIZE]; + + PRINT_FUNCTION_VERBOSE(verbose); + + if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", + __func__); + return -1; + } + + rcv_buffer = calloc(1, DLT_SHM_RCV_BUFFER_SIZE); + + if (!rcv_buffer) { + dlt_vlog(LOG_ERR, "No memory to allocate receiver buffer in %s.\n", + __func__); + return -1; + } + + memset(&userheader, 0, len); + + if (dlt_receiver_check_and_get(rec, &userheader, len, DLT_RCV_REMOVE) < 0) + /* Not enough bytes received */ + return -1; + + /*dlt_shm_status(&(daemon_local->dlt_shm)); */ + while (1) { + /* log message in SHM */ + size = dlt_shm_copy(&(daemon_local->dlt_shm), + rcv_buffer, + DLT_SHM_RCV_BUFFER_SIZE); + + if (size <= 0) + break; + + if (dlt_message_read(&(daemon_local->msg), rcv_buffer, size, 0, verbose) != 0) { + break; + dlt_log(LOG_WARNING, "Can't read messages from shm\n"); + return -1; + } + + /* set overwrite ecu id */ + if ((daemon_local->flags.evalue[0]) && + (strncmp(daemon_local->msg.headerextra.ecu, DLT_DAEMON_ECU_ID, 4) == 0)) { + /* Set header extra parameters */ + dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid); + + /*msg.headerextra.seid = 0; */ + if (dlt_message_set_extraparameters(&(daemon_local->msg), 0) == -1) { + dlt_log(LOG_WARNING, "Can't set message extra parameters in process user message log\n"); + dlt_shm_remove(&(daemon_local->dlt_shm)); + return -1; + } + + /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ + daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + } + + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) { + if (dlt_set_storageheader(daemon_local->msg.storageheader, daemon_local->msg.headerextra.ecu) == -1) { + dlt_log(LOG_WARNING, "Can't set storage header in process user message log\n"); + dlt_shm_remove(&(daemon_local->dlt_shm)); + return -1; + } + } + else if (dlt_set_storageheader(daemon_local->msg.storageheader, daemon->ecuid) == -1) + { + dlt_log(LOG_WARNING, "Can't set storage header in process user message log\n"); + dlt_shm_remove(&(daemon_local->dlt_shm)); + return -1; + } + + /* display message */ + if (daemon_local->flags.xflag) { + if (dlt_message_print_hex(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose) == -1) + dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n"); + } /* if */ + else if (daemon_local->flags.aflag) + { + if (dlt_message_print_ascii(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose) == -1) + dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n"); + } /* if */ + else if (daemon_local->flags.sflag) + { + if (dlt_message_print_header(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose) == -1) + dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n"); + + /* print message header only */ + } /* if */ + + sent = 0; + + /* write message to offline trace */ + if (daemon_local->flags.offlineTraceDirectory[0]) { + dlt_offline_trace_write(&(daemon_local->offlineTrace), + daemon_local->msg.headerbuffer, + daemon_local->msg.headersize, + daemon_local->msg.databuffer, + daemon_local->msg.datasize, + 0, + 0); + sent = 1; + } + + sent = dlt_daemon_client_send_all(daemon, daemon_local, verbose); + + /* Message was not sent to client, so store it in client ringbuffer */ + if (sent == 1) { + if (userheader.message == DLT_USER_MESSAGE_LOG_SHM) + /* dlt message was sent, remove from buffer if log message from shm */ + dlt_shm_remove(&(daemon_local->dlt_shm)); + } + else { + /* dlt message was not sent, keep in buffer */ + break; + } } - } - return true; + return 0; } +# undef DLT_SHM_RCV_BUFFER_SIZE +#endif int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLocal *daemon_local, @@ -3353,10 +3080,10 @@ if (context) { old_log_level = context->log_level; - context->log_level = (int8_t) userctxt.log_level; /* No endianess conversion necessary*/ + context->log_level = userctxt.log_level; /* No endianess conversion necessary*/ old_trace_status = context->trace_status; - context->trace_status = (int8_t) userctxt.trace_status; /* No endianess conversion necessary */ + context->trace_status = userctxt.trace_status; /* No endianess conversion necessary */ /* The following function sends also the trace status */ if ((context->user_handle >= DLT_FD_MINIMUM) && @@ -3497,55 +3224,32 @@ return DLT_DAEMON_ERROR_OK; } -#ifdef __QNX__ -static void *timer_thread(void *data) -{ - int pexit = 0; - unsigned int sleep_ret = 0; - - DltDaemonPeriodicData* timer_thread_data = (DltDaemonPeriodicData*) data; - - /* Timer will start in starts_in sec*/ - if ((sleep_ret = sleep(timer_thread_data->starts_in))) { - dlt_vlog(LOG_NOTICE, "Sleep remains [%u] for starting!" - "Stop thread of timer [%d]\n", - sleep_ret, timer_thread_data->timer_id); - close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); - return NULL; - } +static char dlt_timer_conn_types[DLT_TIMER_UNKNOWN + 1] = { + [DLT_TIMER_PACKET] = DLT_CONNECTION_ONE_S_TIMER, + [DLT_TIMER_ECU] = DLT_CONNECTION_SIXTY_S_TIMER, +#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE + [DLT_TIMER_SYSTEMD] = DLT_CONNECTION_SYSTEMD_TIMER, +#endif + [DLT_TIMER_GATEWAY] = DLT_CONNECTION_GATEWAY_TIMER, + [DLT_TIMER_UNKNOWN] = DLT_CONNECTION_TYPE_MAX +}; - while (1) { - if (0 > write(dlt_timer_pipes[timer_thread_data->timer_id][1], "1", 1)) { - dlt_vlog(LOG_ERR, "Failed to send notification for timer [%s]!\n", - dlt_timer_names[timer_thread_data->timer_id]); - pexit = 1; - } - - if (pexit || g_exit) { - dlt_vlog(LOG_NOTICE, "Received signal!" - "Stop thread of timer [%d]\n", - timer_thread_data->timer_id); - close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); - return NULL; - } - - if ((sleep_ret = sleep(timer_thread_data->period_sec))) { - dlt_vlog(LOG_NOTICE, "Sleep remains [%u] for interval!" - "Stop thread of timer [%d]\n", - sleep_ret, timer_thread_data->timer_id); - close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); - return NULL; - } - } -} +static char dlt_timer_names[DLT_TIMER_UNKNOWN + 1][32] = { + [DLT_TIMER_PACKET] = "Timing packet", + [DLT_TIMER_ECU] = "ECU version", +#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE + [DLT_TIMER_SYSTEMD] = "Systemd watchdog", #endif + [DLT_TIMER_GATEWAY] = "Gateway", + [DLT_TIMER_UNKNOWN] = "Unknown timer" +}; int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, DltTimers timer_id) { - int local_fd = DLT_FD_INIT; + int local_fd = -1; char *timer_name = NULL; if (timer_id >= DLT_TIMER_UNKNOWN) { @@ -3556,23 +3260,25 @@ timer_name = dlt_timer_names[timer_id]; if (daemon_local == NULL) { - dlt_log(DLT_LOG_ERROR, "Daemon local structure is NULL"); + dlt_log(DLT_LOG_ERROR, "Daemaon local structure is NULL"); return -1; } if ((period_sec <= 0) || (starts_in <= 0)) { /* timer not activated via the service file */ dlt_vlog(LOG_INFO, "<%s> not set: period=0\n", timer_name); - local_fd = DLT_FD_INIT; + local_fd = -1; } - else { + #ifdef linux + else { struct itimerspec l_timer_spec; local_fd = timerfd_create(CLOCK_MONOTONIC, 0); - if (local_fd < 0) + if (local_fd < 0) { dlt_vlog(LOG_WARNING, "<%s> timerfd_create failed: %s\n", timer_name, strerror(errno)); + } l_timer_spec.it_interval.tv_sec = period_sec; l_timer_spec.it_interval.tv_nsec = 0; @@ -3582,46 +3288,17 @@ if (timerfd_settime(local_fd, 0, &l_timer_spec, NULL) < 0) { dlt_vlog(LOG_WARNING, "<%s> timerfd_settime failed: %s\n", timer_name, strerror(errno)); - local_fd = DLT_FD_INIT; + local_fd = -1; } -#elif __QNX__ - /* - * Since timerfd is not valid in QNX, new threads are introduced - * to manage timers and communicate with main thread when timer expires. - */ - if(0 != pipe(dlt_timer_pipes[timer_id])) { - dlt_vlog(LOG_ERR, "Failed to create pipe for timer [%s]", - dlt_timer_names[timer_id]); - return -1; - } - if (NULL == timer_data[timer_id]) { - timer_data[timer_id] = calloc(1, sizeof(DltDaemonPeriodicData)); - if (NULL == timer_data[timer_id]) { - dlt_vlog(LOG_ERR, "Failed to allocate memory for timer_data [%s]!\n", - dlt_timer_names[timer_id]); - close_pipes(dlt_timer_pipes[timer_id]); - return -1; - } - } - - timer_data[timer_id]->timer_id = timer_id; - timer_data[timer_id]->period_sec = period_sec; - timer_data[timer_id]->starts_in = starts_in; - timer_data[timer_id]->wakeups_missed = 0; - - if (0 != pthread_create(&timer_threads[timer_id], NULL, - &timer_thread, (void*)timer_data[timer_id])) { - dlt_vlog(LOG_ERR, "Failed to create new thread for timer [%s]!\n", - dlt_timer_names[timer_id]); - /* Clean up timer before returning */ - close_pipes(dlt_timer_pipes[timer_id]); - free(timer_data[timer_id]); - timer_data[timer_id] = NULL; - - return -1; - } - local_fd = dlt_timer_pipes[timer_id][0]; + } #endif + + /* If fully initialized we are done. + * Event handling registration is done later on with other connections. + */ + if (local_fd > 0) { + dlt_vlog(LOG_INFO, "<%s> initialized with %d timer\n", timer_name, + period_sec); } return dlt_connection_create(daemon_local, @@ -3668,11 +3345,11 @@ verbose); snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "Client connection #%d closed. Total Clients : %d", + "Client connection #%d closed. Total Clients : %d\n", sock, daemon_local->client_connections); + dlt_log(LOG_DEBUG, local_str); dlt_daemon_log_internal(daemon, daemon_local, local_str, daemon_local->flags.vflag); - dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); return 0; } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt-daemon_cfg.h dlt-daemon-2.18.4/src/daemon/dlt-daemon_cfg.h --- dlt-daemon-2.18.9/src/daemon/dlt-daemon_cfg.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt-daemon_cfg.h 2019-09-03 08:28:13.000000000 +0000 @@ -76,8 +76,6 @@ /* Stack size of ecu version thread */ #define DLT_DAEMON_ECU_VERSION_THREAD_STACKSIZE 100000 -/* Size of receive buffer for shm connection (from user application) */ -#define DLT_SHM_RCV_BUFFER_SIZE 10000 /* Size of receive buffer for fifo connection (from user application) */ #define DLT_DAEMON_RCVBUFSIZE 10024 /* Size of receive buffer for socket connection (from dlt client) */ diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_client.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_client.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_client.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_client.c 2019-09-03 08:28:13.000000000 +0000 @@ -29,11 +29,11 @@ #include #include /* for printf() and fprintf() */ #include /* for socket(), connect(), (), and recv() */ -#include /* for stat() */ #include /* for sockaddr_in and inet_addr() */ #include /* for atoi() and exit() */ #include /* for memset() */ #include /* for close() */ +#include #include #include #include @@ -42,6 +42,7 @@ #ifdef linux # include #endif +#include #include #if defined(linux) && defined(__NR_statx) # include @@ -163,6 +164,48 @@ return sent; } +/** @brief Send out message to all the clients. + * + * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure + * @param verbose if set to true verbose information is printed out. + * + * @return 1 if transfer succeed, 0 otherwise. + */ +int dlt_daemon_client_send_all(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + int verbose) +{ + void *msg1, *msg2; + int msg1_sz, msg2_sz; + int ret = 0; + + if ((daemon == NULL) || (daemon_local == NULL)) { + dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); + return 0; + } + + /* FIXME: the lock shall include the for loop but + * dlt_daemon_close_socket may call us too ... + */ + DLT_DAEMON_SEM_LOCK(); + msg1 = daemon_local->msg.headerbuffer + sizeof(DltStorageHeader); + msg1_sz = daemon_local->msg.headersize - sizeof(DltStorageHeader); + msg2 = daemon_local->msg.databuffer; + msg2_sz = daemon_local->msg.datasize; + DLT_DAEMON_SEM_FREE(); + + ret = dlt_daemon_client_send_all_multiple(daemon, + daemon_local, + msg1, + msg1_sz, + msg2, + msg2_sz, + verbose); + + return ret; +} + int dlt_daemon_client_send(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, @@ -186,9 +229,9 @@ if (isatty(sock)) { DLT_DAEMON_SEM_LOCK(); - if ((ret = dlt_daemon_serial_send(sock, data1, size1, data2, size2, (char) daemon->sendserialheader))) { + if ((ret = dlt_daemon_serial_send(sock, data1, size1, data2, size2, daemon->sendserialheader))) { DLT_DAEMON_SEM_FREE(); - dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__); + dlt_log(LOG_WARNING, "dlt_daemon_client_send: serial send dlt message failed\n"); return ret; } @@ -197,9 +240,9 @@ else { DLT_DAEMON_SEM_LOCK(); - if ((ret = dlt_daemon_socket_send(sock, data1, size1, data2, size2, (char) daemon->sendserialheader))) { + if ((ret = dlt_daemon_socket_send(sock, data1, size1, data2, size2, daemon->sendserialheader))) { DLT_DAEMON_SEM_FREE(); - dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__); + dlt_log(LOG_WARNING, "dlt_daemon_client_send: socket send dlt message failed\n"); return ret; } @@ -221,7 +264,7 @@ static int error_dlt_offline_trace_write_failed = 0; if (!error_dlt_offline_trace_write_failed) { - dlt_vlog(LOG_ERR, "%s: dlt_offline_trace_write failed!\n", __func__); + dlt_log(LOG_ERR, "dlt_daemon_client_send: dlt_offline_trace_write failed!\n"); error_dlt_offline_trace_write_failed = 1; } @@ -274,108 +317,23 @@ if ((sock != DLT_DAEMON_SEND_FORCE) && ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) || (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) { - if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) { - DLT_DAEMON_SEM_LOCK(); - /* Store message in history buffer */ - ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, (unsigned int) size1, data2, (unsigned int) size2, 0, 0); - DLT_DAEMON_SEM_FREE(); + if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL) + return DLT_DAEMON_ERROR_BUFFER_FULL; - if (ret < DLT_RETURN_OK) { - dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL); - } - } - if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL) { - daemon->overflow_counter += 1; - if (daemon->overflow_counter == 1) - dlt_vlog(LOG_INFO, "%s: Buffer is full! Messages will be discarded.\n", __func__); + DLT_DAEMON_SEM_LOCK(); + /* Store message in history buffer */ + if (dlt_buffer_push3(&(daemon->client_ringbuffer), data1, size1, data2, size2, 0, 0) < DLT_RETURN_OK) { + DLT_DAEMON_SEM_FREE(); + dlt_log(LOG_DEBUG, "dlt_daemon_client_send: Buffer is full! Message discarded.\n"); + dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL); return DLT_DAEMON_ERROR_BUFFER_FULL; } - } else { - if ((daemon->overflow_counter > 0) && - (daemon_local->client_connections > 0) && - (dlt_daemon_send_message_overflow(daemon, daemon_local, verbose) == DLT_DAEMON_ERROR_OK)) { - dlt_vlog(LOG_WARNING, "%s: %u messages discarded! Now able to send messages to the client.\n", - __func__, daemon->overflow_counter); - daemon->overflow_counter = 0; - } - } - - return DLT_DAEMON_ERROR_OK; - -} - -int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) -{ - static char text[DLT_DAEMON_TEXTSIZE]; - char * ecu_ptr = NULL; - PRINT_FUNCTION_VERBOSE(verbose); - - if ((daemon == NULL) || (daemon_local == NULL)) { - dlt_vlog(LOG_ERR, "%s: invalid arguments\n", __func__); - return DLT_DAEMON_ERROR_UNKNOWN; - } - - /* set overwrite ecu id */ - if ((daemon_local->flags.evalue[0]) && - (strncmp(daemon_local->msg.headerextra.ecu, - DLT_DAEMON_ECU_ID, DLT_ID_SIZE) == 0)) { - /* Set header extra parameters */ - dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid); - - /*msg.headerextra.seid = 0; */ - if (dlt_message_set_extraparameters(&(daemon_local->msg), 0)) { - dlt_vlog(LOG_WARNING, - "%s: failed to set message extra parameters.\n", __func__); - return DLT_DAEMON_ERROR_UNKNOWN; - } - - /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ - daemon_local->msg.headerextra.tmsp = - DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); - } - - /* prepare storage header */ - if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) { - ecu_ptr = daemon_local->msg.headerextra.ecu; - } else { - ecu_ptr = daemon->ecuid; - } - - if (dlt_set_storageheader(daemon_local->msg.storageheader, ecu_ptr)) { - dlt_vlog(LOG_WARNING, - "%s: failed to set storage header with header type: 0x%x\n", - __func__, daemon_local->msg.standardheader->htyp); - return DLT_DAEMON_ERROR_UNKNOWN; + DLT_DAEMON_SEM_FREE(); } - /* if no filter set or filter is matching display message */ - if (daemon_local->flags.xflag) { - if (DLT_RETURN_OK != - dlt_message_print_hex(&(daemon_local->msg), text, - DLT_DAEMON_TEXTSIZE, verbose)) - dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n"); - } else if (daemon_local->flags.aflag) { - if (DLT_RETURN_OK != - dlt_message_print_ascii(&(daemon_local->msg), text, - DLT_DAEMON_TEXTSIZE, verbose)) - dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n"); - } else if (daemon_local->flags.sflag) { - if (DLT_RETURN_OK != - dlt_message_print_header(&(daemon_local->msg), text, - DLT_DAEMON_TEXTSIZE, verbose)) - dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n"); - } - - /* send message to client or write to log file */ - return dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, - daemon_local->msg.headerbuffer, sizeof(DltStorageHeader), - daemon_local->msg.headerbuffer + sizeof(DltStorageHeader), - (int) (daemon_local->msg.headersize - sizeof(DltStorageHeader)), - daemon_local->msg.databuffer, (int) daemon_local->msg.datasize, verbose); + return DLT_DAEMON_ERROR_OK; } @@ -439,10 +397,10 @@ dlt_set_id(msg->extendedheader->ctid, ctid); /* prepare length information */ - msg->headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + msg->headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp); - len = (int32_t) (msg->headersize - sizeof(DltStorageHeader) + msg->datasize); + len = msg->headersize - sizeof(DltStorageHeader) + msg->datasize; if (len > UINT16_MAX) { dlt_log(LOG_WARNING, "Huge control message discarded!\n"); @@ -454,8 +412,8 @@ if ((ret = dlt_daemon_client_send(sock, daemon, daemon_local, msg->headerbuffer, sizeof(DltStorageHeader), msg->headerbuffer + sizeof(DltStorageHeader), - (int) (msg->headersize - sizeof(DltStorageHeader)), - msg->databuffer, (int) msg->datasize, verbose))) { + msg->headersize - sizeof(DltStorageHeader), + msg->databuffer, msg->datasize, verbose))) { dlt_log(LOG_DEBUG, "dlt_daemon_control_send_control_message: DLT message send to all failed!.\n"); return ret; } @@ -484,7 +442,7 @@ /* check if the message needs to be forwarded */ if (daemon_local->flags.gatewayMode == 1) { - if (strncmp(daemon_local->flags.evalue, extra.ecu, DLT_ID_SIZE) != 0) + if (strcmp(daemon_local->flags.evalue, extra.ecu) != 0) return dlt_gateway_forward_control_message(&daemon_local->pGateway, daemon_local, msg, @@ -748,10 +706,9 @@ } /* prepare payload of data */ - len = (uint32_t) strlen(daemon->ECUVersionString); + len = strlen(daemon->ECUVersionString); - /* msg.datasize = sizeof(serviceID) + sizeof(status) + sizeof(length) + len */ - msg.datasize = (uint32_t) (sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t) + len); + msg.datasize = sizeof(DltServiceGetSoftwareVersionResponse) + len; if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); @@ -777,7 +734,7 @@ resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; resp->status = DLT_SERVICE_RESPONSE_OK; resp->length = len; - memcpy(msg.databuffer + msg.datasize - len, daemon->ECUVersionString, len); + memcpy(msg.databuffer + sizeof(DltServiceGetSoftwareVersionResponse), daemon->ECUVersionString, len); /* send message */ dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -832,7 +789,7 @@ resp = (DltServiceGetDefaultLogLevelResponse *)msg.databuffer; resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; resp->status = DLT_SERVICE_RESPONSE_OK; - resp->log_level = (uint8_t) daemon->default_log_level; + resp->log_level = daemon->default_log_level; /* send message */ dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -859,13 +816,12 @@ char buf[255]; #endif - int32_t i, j; - size_t offset = 0; + int32_t i, j, offset = 0; char *apid = 0; int8_t ll, ts; uint16_t len; int8_t value; - size_t sizecont = 0; + int32_t sizecont = 0; int offset_base; uint32_t sid; @@ -877,7 +833,7 @@ if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceGetLogInfoRequest)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceGetLogInfoRequest)) < 0) return; user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose); @@ -958,10 +914,10 @@ if ((req->options == 5) || (req->options == 6) || (req->options == 7)) sizecont += sizeof(int8_t); /* trace status */ - resp.datasize += (uint32_t) (((uint32_t) num_applications * (sizeof(uint32_t) /* app_id */ + sizeof(uint16_t) /* count_con_ids */)) + - ((size_t) num_contexts * sizecont)); + resp.datasize += (num_applications * (sizeof(uint32_t) /* app_id */ + sizeof(uint16_t) /* count_con_ids */)) + + (num_contexts * sizecont); - resp.datasize += (uint32_t) sizeof(uint16_t) /* count_app_ids */; + resp.datasize += sizeof(uint16_t) /* count_app_ids */; /* Add additional size for response of Mode 7 */ if (req->options == 7) { @@ -970,10 +926,10 @@ /* One application, one context */ /* context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose); */ if (context) { - resp.datasize += (uint32_t) sizeof(uint16_t) /* len_context_description */; + resp.datasize += sizeof(uint16_t) /* len_context_description */; if (context->context_description != 0) - resp.datasize += (uint32_t) strlen(context->context_description); /* context_description */ + resp.datasize += strlen(context->context_description); /* context_description */ } } else @@ -991,44 +947,44 @@ context = &(user_list->contexts[offset_base + j]); if (context) { - resp.datasize += (uint32_t) sizeof(uint16_t) /* len_context_description */; + resp.datasize += sizeof(uint16_t) /* len_context_description */; if (context->context_description != 0) - resp.datasize += (uint32_t) strlen(context->context_description); /* context_description */ + resp.datasize += strlen(context->context_description); /* context_description */ } } } /* Space for application description */ if (application) { - resp.datasize += (uint32_t) sizeof(uint16_t) /* len_app_description */; + resp.datasize += sizeof(uint16_t) /* len_app_description */; if (application->application_description != 0) - resp.datasize += (uint32_t) strlen(application->application_description); /* app_description */ + resp.datasize += strlen(application->application_description); /* app_description */ } } else { /* All applications, all contexts */ for (i = 0; i < user_list->num_contexts; i++) { - resp.datasize += (uint32_t) sizeof(uint16_t) /* len_context_description */; + resp.datasize += sizeof(uint16_t) /* len_context_description */; if (user_list->contexts[i].context_description != 0) resp.datasize += - (uint32_t) strlen(user_list->contexts[i].context_description); + strlen(user_list->contexts[i].context_description); } for (i = 0; i < user_list->num_applications; i++) { - resp.datasize += (uint32_t) sizeof(uint16_t) /* len_app_description */; + resp.datasize += sizeof(uint16_t) /* len_app_description */; if (user_list->applications[i].application_description != 0) - resp.datasize += (uint32_t) strlen(user_list->applications[i].application_description); /* app_description */ + resp.datasize += strlen(user_list->applications[i].application_description); /* app_description */ } } } if (verbose) dlt_vlog(LOG_DEBUG, - "Allocate %u bytes for response msg databuffer\n", + "Allocate %d bytes for response msg databuffer\n", resp.datasize); /* Allocate buffer for response message */ @@ -1053,12 +1009,12 @@ memcpy(resp.databuffer, &sid, sizeof(uint32_t)); offset += sizeof(uint32_t); - value = (int8_t) (((num_applications != 0) && (num_contexts != 0)) ? req->options : 8); /* 8 = no matching context found */ + value = (((num_applications != 0) && (num_contexts != 0)) ? req->options : 8); /* 8 = no matching context found */ memcpy(resp.databuffer + offset, &value, sizeof(int8_t)); offset += sizeof(int8_t); - count_app_ids = (uint16_t) num_applications; + count_app_ids = num_applications; if (count_app_ids != 0) { memcpy(resp.databuffer + offset, &count_app_ids, sizeof(uint16_t)); @@ -1085,7 +1041,7 @@ daemon->ecuid, verbose); - if ((user_list->applications) && (application)) { + if (application) { /* Calculate start offset within contexts[] */ offset_base = 0; @@ -1101,9 +1057,9 @@ #endif if (req->apid[0] != '\0') - count_con_ids = (uint16_t) num_contexts; + count_con_ids = num_contexts; else - count_con_ids = (uint16_t) application->num_contexts; + count_con_ids = application->num_contexts; memcpy(resp.databuffer + offset, &count_con_ids, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -1153,7 +1109,7 @@ /* Mode 7 */ if (req->options == 7) { if (context->context_description) { - len = (uint16_t) strlen(context->context_description); + len = strlen(context->context_description); memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); memcpy(resp.databuffer + offset, context->context_description, @@ -1181,7 +1137,7 @@ /* Mode 7 */ if (req->options == 7) { if (application->application_description) { - len = (uint16_t) strlen(application->application_description); + len = strlen(application->application_description); memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); memcpy(resp.databuffer + offset, application->application_description, @@ -1307,7 +1263,7 @@ resp = (DltServiceResponse *)msg.databuffer; resp->service_id = service_id; - resp->status = (uint8_t) status; + resp->status = status; /* send message */ dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -1460,7 +1416,6 @@ time_t t = time(NULL); struct tm lt; - tzset(); localtime_r(&t, <); #if !defined(__CYGWIN__) resp->timezone = (int32_t)lt.tm_gmtoff; @@ -1535,7 +1490,7 @@ uint32_t id = 0, id_tmp = 0; uint8_t *ptr; DltDaemonContext *context; - uint32_t data_length_inject = 0; + int32_t data_length_inject = 0; uint32_t data_length_inject_tmp = 0; int32_t datalength; @@ -1546,21 +1501,15 @@ PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL)) + if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - datalength = (int32_t) msg->datasize; + datalength = msg->datasize; ptr = msg->databuffer; DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); /* Get service id */ id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); - /* injectionMode is disabled */ - if (daemon_local->flags.injectionMode == 0) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_PERM_DENIED, verbose); - return; - } - /* id is always less than DLT_DAEMON_INJECTION_MAX since its type is uinit32_t */ if (id >= DLT_DAEMON_INJECTION_MIN) { /* This a a real SW-C injection call */ @@ -1603,7 +1552,7 @@ usercontext.log_level_pos = context->log_level_pos; - if (data_length_inject > (uint32_t) msg->databuffersize) { + if (data_length_inject > msg->databuffersize) { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -1615,16 +1564,16 @@ return; } - usercontext.data_length_inject = (uint32_t) data_length_inject; + usercontext.data_length_inject = data_length_inject; usercontext.service_id = id; - memcpy(userbuffer, ptr, (size_t) data_length_inject); /* Copy received injection to send buffer */ + memcpy(userbuffer, ptr, data_length_inject); /* Copy received injection to send buffer */ /* write to FIFO */ DltReturnValue ret = dlt_user_log_out3(context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgInjection), - userbuffer, (size_t) data_length_inject); + userbuffer, data_length_inject); if (ret < DLT_RETURN_OK) { if (ret == DLT_RETURN_PIPE_ERROR) { @@ -1667,12 +1616,12 @@ if ((context->user_handle >= DLT_FD_MINIMUM) && (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose); + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); } else { dlt_log(LOG_ERR, "Log level could not be sent!\n"); context->log_level = old_log_level; - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } @@ -1690,7 +1639,7 @@ int count = 0; DltDaemonContext *context = NULL; char src_str[DLT_ID_SIZE + 1] = { 0 }; - int ret = 0; + int8_t ret = 0; DltDaemonRegisteredUsers *user_list = NULL; if (daemon == 0) { @@ -1742,18 +1691,18 @@ if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0) return; req = (DltServiceSetLogLevel *)(msg->databuffer); if (daemon_local->flags.enforceContextLLAndTS) - req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextLogLevel); + req->log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel); dlt_set_id(apid, req->apid); dlt_set_id(ctid, req->ctid); - apid_length = (int8_t) strlen(apid); - ctid_length = (int8_t) strlen(ctid); + apid_length = strlen(apid); + ctid_length = strlen(ctid); if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/ dlt_daemon_find_multiple_context_and_send_log_level(sock, @@ -1761,8 +1710,8 @@ daemon_local, 1, apid, - (int8_t) (apid_length - 1), - (int8_t) req->log_level, + apid_length - 1, + req->log_level, verbose); } else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and apid is null*/ @@ -1772,8 +1721,8 @@ daemon_local, 0, ctid, - (int8_t) (ctid_length - 1), - (int8_t) req->log_level, + ctid_length - 1, + req->log_level, verbose); } else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/ @@ -1784,7 +1733,7 @@ 1, apid, DLT_ID_SIZE, - (int8_t) req->log_level, + req->log_level, verbose); } else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/ @@ -1795,7 +1744,7 @@ 0, ctid, DLT_ID_SIZE, - (int8_t) req->log_level, + req->log_level, verbose); } else { @@ -1807,7 +1756,7 @@ /* Set log level */ if (context != 0) { - dlt_daemon_send_log_level(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose); + dlt_daemon_send_log_level(sock, daemon, daemon_local, context, req->log_level, verbose); } else { dlt_vlog(LOG_ERR, "Could not set log level: %d. Context [%.4s:%.4s] not found:", req->log_level, apid, @@ -1840,12 +1789,12 @@ if ((context->user_handle >= DLT_FD_MINIMUM) && (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose); + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); } else { dlt_log(LOG_ERR, "Trace status could not be sent!\n"); context->trace_status = old_trace_status; - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } @@ -1863,7 +1812,7 @@ int count = 0; DltDaemonContext *context = NULL; char src_str[DLT_ID_SIZE + 1] = { 0 }; - int ret = 0; + int8_t ret = 0; DltDaemonRegisteredUsers *user_list = NULL; if (daemon == 0) { @@ -1915,18 +1864,18 @@ if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0) return; req = (DltServiceSetLogLevel *)(msg->databuffer); if (daemon_local->flags.enforceContextLLAndTS) - req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextTraceStatus); + req->log_level = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); dlt_set_id(apid, req->apid); dlt_set_id(ctid, req->ctid); - apid_length = (int8_t) strlen(apid); - ctid_length = (int8_t) strlen(ctid); + apid_length = strlen(apid); + ctid_length = strlen(ctid); if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/ dlt_daemon_find_multiple_context_and_send_trace_status(sock, @@ -1934,8 +1883,8 @@ daemon_local, 1, apid, - (int8_t) (apid_length - 1), - (int8_t) req->log_level, + apid_length - 1, + req->log_level, verbose); } else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and apid is null*/ @@ -1946,8 +1895,8 @@ daemon_local, 0, ctid, - (int8_t) (ctid_length - 1), - (int8_t) req->log_level, + ctid_length - 1, + req->log_level, verbose); } else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/ @@ -1958,7 +1907,7 @@ 1, apid, DLT_ID_SIZE, - (int8_t) req->log_level, + req->log_level, verbose); } else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/ @@ -1969,7 +1918,7 @@ 0, ctid, DLT_ID_SIZE, - (int8_t) req->log_level, + req->log_level, verbose); } else { @@ -1977,7 +1926,7 @@ /* Set trace status */ if (context != 0) { - dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose); + dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, req->log_level, verbose); } else { dlt_vlog(LOG_ERR, @@ -2004,12 +1953,12 @@ PRINT_FUNCTION_VERBOSE(verbose); DltServiceSetDefaultLogLevel *req; - uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL; + int32_t id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); @@ -2020,7 +1969,7 @@ if (daemon_local->flags.enforceContextLLAndTS) daemon->default_log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel); else - daemon->default_log_level = (int8_t) req->log_level; /* No endianess conversion necessary */ + daemon->default_log_level = req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the default log level */ dlt_daemon_user_send_default_update(daemon, verbose); @@ -2041,7 +1990,7 @@ PRINT_FUNCTION_VERBOSE(verbose); DltServiceSetDefaultLogLevel *req = NULL; - uint32_t id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL; + int32_t id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL; int8_t loglevel = 0; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) { @@ -2049,7 +1998,7 @@ return; } - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); @@ -2059,7 +2008,7 @@ if (daemon_local->flags.enforceContextLLAndTS) loglevel = getStatus(req->log_level, daemon_local->flags.contextLogLevel); else - loglevel = (int8_t) req->log_level; /* No endianess conversion necessary */ + loglevel = req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the new log level */ dlt_daemon_user_send_all_log_level_update(daemon, loglevel, verbose); @@ -2081,12 +2030,12 @@ /* Payload of request message */ DltServiceSetDefaultLogLevel *req; - uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS; + int32_t id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); @@ -2097,7 +2046,7 @@ if (daemon_local->flags.enforceContextLLAndTS) daemon->default_trace_status = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); else - daemon->default_trace_status = (int8_t) req->log_level; /* No endianess conversion necessary*/ + daemon->default_trace_status = req->log_level; /* No endianess conversion necessary*/ /* Send Update to all contexts using the default trace status */ dlt_daemon_user_send_default_update(daemon, verbose); @@ -2118,7 +2067,7 @@ PRINT_FUNCTION_VERBOSE(verbose); DltServiceSetDefaultLogLevel *req = NULL; - uint32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS; + int32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS; int8_t tracestatus = 0; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) { @@ -2126,7 +2075,7 @@ return; } - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); @@ -2137,7 +2086,7 @@ if (daemon_local->flags.enforceContextLLAndTS) tracestatus = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); else - tracestatus = (int8_t) req->log_level; /* No endianess conversion necessary */ + tracestatus = req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the new log level */ dlt_daemon_user_send_all_trace_status_update(daemon, tracestatus, verbose); @@ -2158,12 +2107,12 @@ PRINT_FUNCTION_VERBOSE(verbose); DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */ - uint32_t id = DLT_SERVICE_ID_SET_TIMING_PACKETS; + int32_t id = DLT_SERVICE_ID_SET_TIMING_PACKETS; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetVerboseMode)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceSetVerboseMode)) < 0) return; req = (DltServiceSetVerboseMode *)(msg->databuffer); @@ -2225,10 +2174,10 @@ dlt_set_id(msg.extendedheader->ctid, ""); /* context id */ /* prepare length information */ - msg.headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); - len = (int32_t) (msg.headersize - sizeof(DltStorageHeader) + msg.datasize); + len = msg.headersize - sizeof(DltStorageHeader) + msg.datasize; if (len > UINT16_MAX) { dlt_log(LOG_WARNING, "Huge control message discarded!\n"); @@ -2245,8 +2194,8 @@ dlt_daemon_client_send(sock, daemon, daemon_local, msg.headerbuffer, sizeof(DltStorageHeader), msg.headerbuffer + sizeof(DltStorageHeader), - (int) msg.headersize - (int) sizeof(DltStorageHeader), - msg.databuffer, (int) msg.datasize, verbose); + msg.headersize - sizeof(DltStorageHeader), + msg.databuffer, msg.datasize, verbose); /* free message */ dlt_message_free(&msg, 0); @@ -2334,7 +2283,6 @@ /*Added memset to avoid compiler warning for near initialization */ memset((void *)<, 0, sizeof(lt)); - tzset(); localtime_r(&t, <); dlt_daemon_control_message_timezone(DLT_DAEMON_SEND_TO_ALL, @@ -2407,15 +2355,7 @@ unsigned int connection_type = 0; DltLogStorage *device = NULL; int device_index = -1; - uint32_t i = 0; - - int tmp_errno = 0; - - struct stat daemon_mpoint_st = {0}; - int daemon_st_status = 0; - - struct stat req_mpoint_st = {0}; - int req_st_status = 0; + int i = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -2439,64 +2379,25 @@ return; } - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceOfflineLogstorage)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceOfflineLogstorage)) < 0) return; req = (DltServiceOfflineLogstorage *)(msg->databuffer); - if(req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { - req_st_status = stat(req->mount_point, &req_mpoint_st); - tmp_errno = errno; - if (req_st_status < 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - - dlt_vlog(LOG_WARNING, - "%s: Failed to stat requested mount point [%s] with error [%s]\n", - __func__, req->mount_point, strerror(tmp_errno)); - return; - } - } - - for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) { + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) { connection_type = daemon->storage_handle[i].connection_type; - memset(&daemon_mpoint_st, 0, sizeof(struct stat)); - if (strlen(daemon->storage_handle[i].device_mount_point) > 1) { - daemon_st_status = stat(daemon->storage_handle[i].device_mount_point, - &daemon_mpoint_st); - tmp_errno = errno; - - if (daemon_st_status < 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - dlt_vlog(LOG_WARNING, - "%s: Failed to stat daemon mount point [%s] with error [%s]\n", - __func__, daemon->storage_handle[i].device_mount_point, - strerror(tmp_errno)); - return; - } - - /* Check if the requested device path is already used as log storage device */ - if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev && - req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) { - device_index = (int) i; - break; - } + /* Check if the requested device path is already used as log storage device */ + if (strncmp(daemon->storage_handle[i].device_mount_point, + req->mount_point, strlen(req->mount_point)) == 0) { + device_index = i; + break; } /* Get first available device index here */ if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && (device_index == -1)) - device_index = (int) i; + device_index = i; } /* It might be possible to sync all caches of all devices */ @@ -2549,12 +2450,6 @@ DLT_SERVICE_RESPONSE_OK, verbose); - /* Update maintain logstorage loglevel if necessary */ - if (daemon->storage_handle[device_index].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) - { - daemon->maintain_logstorage_loglevel = daemon->storage_handle[device_index].maintain_logstorage_loglevel; - } - /* Check if log level of running application needs an update */ dlt_daemon_logstorage_update_application_loglevel(daemon, daemon_local, @@ -2570,7 +2465,7 @@ daemon, daemon_local, device_index, - (int) daemon_local->flags.offlineLogstorageMaxDevices, + daemon_local->flags.offlineLogstorageMaxDevices, verbose); dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]), @@ -2587,11 +2482,11 @@ /* Check for cache synchronization request from log storage ctrl app */ else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { - ret = 0; + int ret = 0; if (device_index == -1) { /* sync all Logstorage devices */ - for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) if (daemon->storage_handle[i].connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ret = dlt_daemon_logstorage_sync_cache( @@ -2665,7 +2560,7 @@ return; } - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServicePassiveNodeConnect)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServicePassiveNodeConnect)) < 0) return; req = (DltServicePassiveNodeConnect *)msg->databuffer; @@ -2673,7 +2568,7 @@ if (dlt_gateway_process_on_demand_request(&daemon_local->pGateway, daemon_local, req->node_id, - (int) req->connection_status, + req->connection_status, verbose) < 0) dlt_daemon_control_service_response(sock, daemon, @@ -2746,7 +2641,7 @@ memset(resp, 0, msg.datasize); resp->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS; resp->status = DLT_SERVICE_RESPONSE_OK; - resp->num_connections = (uint32_t) daemon_local->pGateway.num_connections; + resp->num_connections = daemon_local->pGateway.num_connections; for (i = 0; i < resp->num_connections; i++) { if ((i * DLT_ID_SIZE) > DLT_ENTRY_MAX) { diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_client.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_client.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_client.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_client.h 2019-09-03 08:28:13.000000000 +0000 @@ -65,6 +65,15 @@ #include /** + * Send out message to all the clients. + * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure + * @param verbose if set to true verbose information is printed out. + * @return 1 if transfer succeed, 0 otherwise. + */ +int dlt_daemon_client_send_all(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); + +/** * Send out message to client or store message in offline trace. * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure @@ -88,16 +97,7 @@ void *data2, int size2, int verbose); -/** - * Send out message to all client or store message in offline trace. - * @param daemon pointer to dlt daemon structure - * @param daemon_local pointer to dlt daemon local structure - * @param verbose if set to true verbose information is printed out. - * @return 0 if success, less than 0 if there is an error or buffer is full - */ -int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose); + /** * Send out response message to dlt client * @param sock connection handle used for sending response diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_common.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_common.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_common.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_common.c 2019-09-03 08:28:13.000000000 +0000 @@ -65,7 +65,6 @@ * aw 13.01.2010 initial */ -#include #include #include #include @@ -74,6 +73,7 @@ #include #include +#include /* send() */ #include /* send() */ #include "dlt_types.h" @@ -141,18 +141,11 @@ dlt_vlog(LOG_ERR, "Cannot find user list for ECU: %4s\n", ecu); return (DltDaemonRegisteredUsers *)NULL; } -int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, const char *runtime_directory, int verbose) +int dlt_daemon_load_runtime_configuration(DltDaemon *daemon, const char *runtime_directory, int verbose) { - PRINT_FUNCTION_VERBOSE(verbose); - size_t append_length = 0; - - if (daemon == NULL) - return DLT_RETURN_ERROR; + int append_length = 0; - /* Default */ - daemon->mode = DLT_USER_MODE_EXTERNAL; - - if (runtime_directory == NULL) + if ((daemon == NULL) || (runtime_directory == NULL)) return DLT_RETURN_ERROR; /* prepare filenames for configuration */ @@ -195,6 +188,14 @@ strcat(daemon->runtime_configuration, DLT_RUNTIME_CONFIGURATION); /* strcat uncritical here, because max length already checked */ + /* Check for runtime cfg, if it is loadable, load it! */ + if ((dlt_daemon_applications_load(daemon, daemon->runtime_application_cfg, verbose) == 0) && + (dlt_daemon_contexts_load(daemon, daemon->runtime_context_cfg, verbose) == 0)) + daemon->runtime_context_cfg_loaded = 1; + + /* load configuration if available */ + dlt_daemon_configuration_load(daemon, daemon->runtime_configuration, verbose); + return DLT_RETURN_OK; } @@ -216,14 +217,16 @@ daemon->user_list = NULL; daemon->num_user_lists = 0; - daemon->default_log_level = (int8_t) InitialContextLogLevel; - daemon->default_trace_status = (int8_t) InitialContextTraceStatus; - daemon->force_ll_ts = (int8_t) ForceLLTS; + daemon->default_log_level = InitialContextLogLevel; + daemon->default_trace_status = InitialContextTraceStatus; + daemon->force_ll_ts = ForceLLTS; daemon->overflow_counter = 0; daemon->runtime_context_cfg_loaded = 0; + daemon->mode = DLT_USER_MODE_EXTERNAL; + daemon->connectionState = 0; /* no logger connected */ daemon->state = DLT_DAEMON_STATE_INIT; /* initial logging state */ @@ -237,10 +240,8 @@ dlt_vlog(LOG_INFO, "Ringbuffer configuration: %lu/%lu/%lu\n", RingbufferMinSize, RingbufferMaxSize, RingbufferStepSize); - if (dlt_buffer_init_dynamic(&(daemon->client_ringbuffer), - (uint32_t) RingbufferMinSize, - (uint32_t) RingbufferMaxSize, - (uint32_t) RingbufferStepSize) < DLT_RETURN_OK) + if (dlt_buffer_init_dynamic(&(daemon->client_ringbuffer), RingbufferMinSize, RingbufferMaxSize, + RingbufferStepSize) == DLT_RETURN_ERROR) return -1; daemon->storage_handle = NULL; @@ -294,7 +295,7 @@ if (gateway_mode == 0) { /* initialize application list */ - daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers)); + daemon->user_list = calloc(nodes, sizeof(DltDaemonRegisteredUsers)); if (daemon->user_list == NULL) { dlt_log(LOG_ERR, "Allocating memory for user information"); @@ -308,7 +309,7 @@ nodes += gateway->num_connections; /* initialize application list */ - daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers)); + daemon->user_list = calloc(nodes, sizeof(DltDaemonRegisteredUsers)); if (daemon->user_list == NULL) { dlt_log(LOG_ERR, "Allocating memory for user information"); @@ -372,6 +373,8 @@ user_list->applications[i].application_description = NULL; } + + if (user_list->applications != NULL) free(user_list->applications); @@ -381,33 +384,6 @@ return 0; } -static void dlt_daemon_application_reset_user_handle(DltDaemon *daemon, - DltDaemonApplication *application, - int verbose) -{ - DltDaemonRegisteredUsers *user_list; - DltDaemonContext *context; - int i; - - if (application->user_handle == DLT_FD_INIT) - return; - - user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose); - if (user_list != NULL) { - for (i = 0; i < user_list->num_contexts; i++) { - context = &user_list->contexts[i]; - if (context->user_handle == application->user_handle) - context->user_handle = DLT_FD_INIT; - } - } - - if (application->owns_user_handle) - close(application->user_handle); - - application->user_handle = DLT_FD_INIT; - application->owns_user_handle = false; -} - DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, @@ -420,9 +396,8 @@ DltDaemonApplication *old; int new_application; int dlt_user_handle; - bool owns_user_handle; DltDaemonRegisteredUsers *user_list = NULL; -#ifdef DLT_DAEMON_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC (void)fd; /* To avoid compiler warning : unused variable */ char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE]; #endif @@ -480,7 +455,6 @@ application->application_description = NULL; application->num_contexts = 0; application->user_handle = DLT_FD_INIT; - application->owns_user_handle = false; new_application = 1; @@ -505,47 +479,54 @@ application->application_description = malloc(strlen(description) + 1); if (application->application_description) { - memcpy(application->application_description, description, strlen(description) + 1); - } else { + strncpy(application->application_description, + description, + strlen(description)); + application->application_description[strlen(description)] = '\0'; + } + else { dlt_log(LOG_ERR, "Cannot allocate memory to store application description\n"); free(application); return (DltDaemonApplication *)NULL; } } - if (application->pid != pid) { - dlt_daemon_application_reset_user_handle(daemon, application, verbose); - application->pid = 0; + if (application->user_handle != DLT_FD_INIT) { + if (application->pid != pid) { +#ifndef DLT_USE_UNIX_SOCKET_IPC + + if (close(application->user_handle) < 0) + dlt_vlog(LOG_WARNING, + "close() failed to %s/dltpipes/dlt%d, errno=%d (%s)!\n", + dltFifoBaseDir, + pid, + errno, + strerror(errno)); /* errno 2: ENOENT - No such file or directory */ + +#endif + application->user_handle = DLT_FD_INIT; + application->pid = 0; + } } /* open user pipe only if it is not yet opened */ if ((application->user_handle == DLT_FD_INIT) && (pid != 0)) { - dlt_user_handle = DLT_FD_INIT; - owns_user_handle = false; +#ifdef DLT_USE_UNIX_SOCKET_IPC + dlt_user_handle = fd; +#else + snprintf(filename, + DLT_DAEMON_COMMON_TEXTBUFSIZE, + "%s/dltpipes/dlt%d", + dltFifoBaseDir, + pid); + + dlt_user_handle = open(filename, O_WRONLY | O_NONBLOCK); + + if (dlt_user_handle < 0) { + int prio = (errno == ENOENT) ? LOG_INFO : LOG_WARNING; + dlt_vlog(prio, "open() failed to %s, errno=%d (%s)!\n", filename, errno, strerror(errno)); + } /* if */ -#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE - if (fd >= DLT_FD_MINIMUM) { - dlt_user_handle = fd; - owns_user_handle = false; - } -#endif -#ifdef DLT_DAEMON_USE_FIFO_IPC - if (dlt_user_handle < DLT_FD_MINIMUM) { - snprintf(filename, - DLT_DAEMON_COMMON_TEXTBUFSIZE, - "%s/dltpipes/dlt%d", - dltFifoBaseDir, - pid); - - dlt_user_handle = open(filename, O_WRONLY | O_NONBLOCK); - - if (dlt_user_handle < 0) { - int prio = (errno == ENOENT) ? LOG_INFO : LOG_WARNING; - dlt_vlog(prio, "open() failed to %s, errno=%d (%s)!\n", filename, errno, strerror(errno)); - } else { - owns_user_handle = true; - } - } #endif /* check if file descriptor was already used, and make it invalid if it * is reused. This prevents sending messages to wrong file descriptor */ @@ -553,14 +534,13 @@ dlt_daemon_contexts_invalidate_fd(daemon, ecu, dlt_user_handle, verbose); application->user_handle = dlt_user_handle; - application->owns_user_handle = owns_user_handle; application->pid = pid; } /* Sort */ if (new_application) { qsort(user_list->applications, - (size_t) user_list->num_applications, + user_list->num_applications, sizeof(DltDaemonApplication), dlt_daemon_cmp_apid); @@ -590,7 +570,13 @@ return -1; if (user_list->num_applications > 0) { - dlt_daemon_application_reset_user_handle(daemon, application, verbose); + /* Check if user handle is open; if yes, close it */ + if (application->user_handle >= DLT_FD_MINIMUM) { +#ifndef DLT_USE_UNIX_SOCKET_IPC + close(application->user_handle); +#endif + application->user_handle = DLT_FD_INIT; + } /* Free description of application to be deleted */ if (application->application_description) { @@ -598,7 +584,7 @@ application->application_description = NULL; } - pos = (int) (application - (user_list->applications)); + pos = application - (user_list->applications); /* move all applications above pos to pos */ memmove(&(user_list->applications[pos]), @@ -645,7 +631,7 @@ dlt_set_id(application.apid, apid); return (DltDaemonApplication *)bsearch(&application, user_list->applications, - (size_t) user_list->num_applications, + user_list->num_applications, sizeof(DltDaemonApplication), dlt_daemon_cmp_apid); } @@ -848,7 +834,7 @@ if ((user_list->num_contexts % DLT_DAEMON_CONTEXT_ALLOC_SIZE) == 0) { /* allocate memory for context in steps of DLT_DAEMON_CONTEXT_ALLOC_SIZE, e.g 100 */ old = user_list->contexts; - user_list->contexts = (DltDaemonContext *)malloc((size_t) sizeof(DltDaemonContext) * + user_list->contexts = (DltDaemonContext *)malloc(sizeof(DltDaemonContext) * ((user_list->num_contexts / DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) * DLT_DAEMON_CONTEXT_ALLOC_SIZE); @@ -861,7 +847,7 @@ memcpy(user_list->contexts, old, - (size_t) sizeof(DltDaemonContext) * user_list->num_contexts); + sizeof(DltDaemonContext) * user_list->num_contexts); free(old); } } @@ -886,7 +872,8 @@ context->context_description = malloc(strlen(description) + 1); if (context->context_description) { - memcpy(context->context_description, description, strlen(description) + 1); + strncpy(context->context_description, description, strlen(description)); + context->context_description[strlen(description)] = '\0'; } } @@ -928,7 +915,7 @@ /* Sort */ if (new_context) { qsort(user_list->contexts, - (size_t) user_list->num_contexts, + user_list->num_contexts, sizeof(DltDaemonContext), dlt_daemon_cmp_apid_ctid); @@ -967,7 +954,7 @@ context->context_description = NULL; } - pos = (int) (context - (user_list->contexts)); + pos = context - (user_list->contexts); /* move all contexts above pos to pos */ memmove(&(user_list->contexts[pos]), @@ -1021,7 +1008,7 @@ return (DltDaemonContext *)bsearch(&context, user_list->contexts, - (size_t) user_list->num_contexts, + user_list->num_contexts, sizeof(DltDaemonContext), dlt_daemon_cmp_apid_ctid); } @@ -1073,6 +1060,8 @@ users->contexts[i].context_description = NULL; } + + if (users->contexts) { free(users->contexts); users->contexts = NULL; @@ -1343,7 +1332,6 @@ DltUserHeader userheader; DltUserControlMsgLogLevel usercontext; DltReturnValue ret; - DltDaemonApplication *app; PRINT_FUNCTION_VERBOSE(verbose); @@ -1357,16 +1345,15 @@ return -1; } - if ((context->storage_log_level != DLT_LOG_DEFAULT) && - (daemon->maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF)) - usercontext.log_level = (uint8_t) (context->log_level > - context->storage_log_level ? context->log_level : context->storage_log_level); + if (context->storage_log_level != DLT_LOG_DEFAULT) + usercontext.log_level = context->log_level > + context->storage_log_level ? context->log_level : context->storage_log_level; else /* Storage log level is not updated (is DEFAULT) then no device is yet connected so ignore */ usercontext.log_level = - (uint8_t) ((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); + ((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); usercontext.trace_status = - (uint8_t) ((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : context->trace_status); + ((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : context->trace_status); usercontext.log_level_pos = context->log_level_pos; @@ -1390,9 +1377,11 @@ errno != 0 ? strerror(errno) : "Unknown error"); if (errno == EPIPE) { - app = dlt_daemon_application_find(daemon, context->apid, daemon->ecuid, verbose); - if (app != NULL) - dlt_daemon_application_reset_user_handle(daemon, app, verbose); +#ifndef DLT_USE_UNIX_SOCKET_IPC + /* Close connection */ + close(context->user_handle); +#endif + context->user_handle = DLT_FD_INIT; } } @@ -1421,8 +1410,13 @@ &(logstate), sizeof(DltUserControlMsgLogState)); if (ret < DLT_RETURN_OK) { - if (errno == EPIPE) - dlt_daemon_application_reset_user_handle(daemon, app, verbose); + if (errno == EPIPE) { +#ifndef DLT_USE_UNIX_SOCKET_IPC + /* Close connection */ + close(app->user_handle); +#endif + app->user_handle = DLT_FD_INIT; + } } return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR; @@ -1467,9 +1461,9 @@ unlink(filename1); } - daemon->default_log_level = (int8_t) InitialContextLogLevel; - daemon->default_trace_status = (int8_t) InitialContextTraceStatus; - daemon->force_ll_ts = (int8_t) InitialEnforceLlTsStatus; + daemon->default_log_level = InitialContextLogLevel; + daemon->default_trace_status = InitialContextTraceStatus; + daemon->force_ll_ts = InitialEnforceLlTsStatus; /* Reset all other things (log level, trace status, etc. * to default values */ @@ -1502,11 +1496,12 @@ if (context != NULL) { if ((context->log_level == DLT_LOG_DEFAULT) || (context->trace_status == DLT_TRACE_STATUS_DEFAULT)) { - if (context->user_handle >= DLT_FD_MINIMUM) + if (context->user_handle >= DLT_FD_MINIMUM) { if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) dlt_vlog(LOG_WARNING, "Cannot update default of %.4s:%.4s\n", context->apid, context->ctid); + } } } } @@ -1606,9 +1601,10 @@ app = &(user_list->applications[count]); if (app != NULL) { - if (app->user_handle >= DLT_FD_MINIMUM) + if (app->user_handle >= DLT_FD_MINIMUM) { if (dlt_daemon_user_send_log_state(daemon, app, verbose) == -1) dlt_vlog(LOG_WARNING, "Cannot send log state to Apid: %.4s, PID: %d\n", app->apid, app->pid); + } } } } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_common_cfg.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_common_cfg.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_common_cfg.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_common_cfg.h 2019-09-03 08:28:13.000000000 +0000 @@ -86,8 +86,8 @@ #define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \ "/dlt-ctrl.sock" -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC -#define DLT_DAEMON_DEFAULT_APP_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \ +#ifdef DLT_USE_UNIX_SOCKET_IPC +# define DLT_DAEMON_DEFAULT_APP_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \ "/dlt-app.sock" #endif diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_common.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_common.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_common.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_common.h 2019-09-03 08:28:13.000000000 +0000 @@ -133,7 +133,6 @@ char apid[DLT_ID_SIZE]; /**< application id */ pid_t pid; /**< process id of user application */ int user_handle; /**< connection handle for connection to user application */ - bool owns_user_handle; /**< user_handle should be closed when reset */ char *application_description; /**< context description */ int num_contexts; /**< number of contexts for this application */ } DltDaemonApplication; @@ -190,7 +189,6 @@ char *ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */ DltDaemonState state; /**< the current logging state of dlt daemon. */ DltLogStorage *storage_handle; - int maintain_logstorage_loglevel; /* Permission to maintain the logstorage loglevel*/ } DltDaemon; /** @@ -247,16 +245,13 @@ char *ecu, int verbose); /** - * Init the user saved configurations to daemon. - * Since the order of loading runtime config could be different, - * this function won't be the place to do that. - * This is just for preparation of real load later. + * Loads the user saved configurations to daemon * @param daemon pointer to dlt daemon structure * @param runtime_directory directory path * @param verbose if set to true verbose information is printed out * @return DLT_RETURN_OK on success, DLT_RETURN_ERROR otherwise */ -int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, +int dlt_daemon_load_runtime_configuration(DltDaemon *daemon, const char *runtime_directory, int verbose); diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_connection.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_connection.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_connection.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_connection.c 2019-09-03 08:28:13.000000000 +0000 @@ -33,7 +33,6 @@ #include #include -#include #include #include "dlt_daemon_connection_types.h" @@ -163,7 +162,7 @@ /* We rely on the gateway for clean-up */ break; case DLT_CONNECTION_APP_MSG: - dlt_receiver_free_global_buffer(con->receiver); + dlt_receiver_free_unix_socket(con->receiver); free(con->receiver); con->receiver = NULL; break; @@ -194,8 +193,6 @@ int fd) { DltReceiver *ret = NULL; - DltReceiverType receiver_type = DLT_RECEIVE_FD; - struct stat statbuf; switch (type) { case DLT_CONNECTION_CONTROL_CONNECT: @@ -208,34 +205,29 @@ ret = calloc(1, sizeof(DltReceiver)); if (ret) - dlt_receiver_init(ret, fd, DLT_RECEIVE_SOCKET, DLT_DAEMON_RCVBUFSIZESOCK); + dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESOCK); break; case DLT_CONNECTION_CLIENT_MSG_SERIAL: ret = calloc(1, sizeof(DltReceiver)); if (ret) - dlt_receiver_init(ret, fd, DLT_RECEIVE_FD, DLT_DAEMON_RCVBUFSIZESERIAL); + dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESERIAL); break; case DLT_CONNECTION_APP_MSG: ret = calloc(1, sizeof(DltReceiver)); - receiver_type = DLT_RECEIVE_FD; - - if (fstat(fd, &statbuf) == 0) { - if (S_ISSOCK(statbuf.st_mode)) - receiver_type = DLT_RECEIVE_SOCKET; - } else { - dlt_vlog(LOG_WARNING, - "Failed to determine receive type for DLT_CONNECTION_APP_MSG, using \"FD\"\n"); + if (ret) { + #ifdef DLT_USE_UNIX_SOCKET_IPC + dlt_receiver_init_unix_socket(ret, fd, &app_recv_buffer); + #else + dlt_receiver_init(ret, fd, DLT_RECEIVE_BUFSIZE); + #endif } - if (ret) - dlt_receiver_init_global_buffer(ret, fd, receiver_type, &app_recv_buffer); - break; -#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE +#ifdef DLT_USE_UNIX_SOCKET_IPC case DLT_CONNECTION_APP_CONNECT: /* FALL THROUGH */ #endif @@ -251,7 +243,7 @@ ret = calloc(1, sizeof(DltReceiver)); if (ret) - dlt_receiver_init(ret, fd, DLT_RECEIVE_FD, DLT_DAEMON_RCVBUFSIZE); + dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZE); break; case DLT_CONNECTION_GATEWAY: @@ -294,7 +286,7 @@ case DLT_CONNECTION_CLIENT_MSG_SERIAL: ret = dlt_daemon_process_client_messages_serial; break; -#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE +#ifdef DLT_USE_UNIX_SOCKET_IPC case DLT_CONNECTION_APP_CONNECT: ret = dlt_daemon_process_app_connect; break; @@ -396,27 +388,12 @@ temp->receiver = dlt_connection_get_receiver(daemon_local, type, fd); if (!temp->receiver) { - dlt_vlog(LOG_CRIT, "Unable to get receiver from %u connection.\n", + dlt_vlog(LOG_CRIT, "Unable to get receiver from %d connection.\n", type); free(temp); return -1; } - struct timeval timeout; - timeout.tv_sec = 5; - timeout.tv_usec = 0; -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - char *watchdogUSec = getenv("WATCHDOG_USEC"); - if (watchdogUSec) { - timeout.tv_sec = atoi(watchdogUSec) / 1000000; - timeout.tv_usec = atoi(watchdogUSec) % 1000000; - } -#endif - - if (setsockopt (temp->receiver->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof timeout) < 0) { - dlt_vlog(LOG_WARNING, "Unable to set send timeout %s.\n", strerror(errno)); - } - /* We are single threaded no need for protection. */ temp->id = connectionId++; diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_event_handler.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_event_handler.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_event_handler.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_event_handler.c 2019-09-03 08:28:13.000000000 +0000 @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include "dlt_common.h" @@ -246,7 +246,7 @@ callback = dlt_connection_get_callback(con); if (!callback) { - dlt_vlog(LOG_CRIT, "Unable to find function for %u handle type.\n", + dlt_vlog(LOG_CRIT, "Unable to find function for %d handle type.\n", type); return -1; } @@ -256,7 +256,7 @@ daemon_local, con->receiver, daemon_local->flags.vflag) == -1) { - dlt_vlog(LOG_CRIT, "Processing from %u handle type failed!\n", + dlt_vlog(LOG_CRIT, "Processing from %d handle type failed!\n", type); return -1; } @@ -402,7 +402,7 @@ case ACTIVE: if (activation_type == DEACTIVATE) { - dlt_vlog(LOG_INFO, "Deactivate connection type: %u\n", con->type); + dlt_vlog(LOG_INFO, "Deactivate connection type: %d\n", con->type); dlt_event_handler_disable_fd(evhdl, con->receiver->fd); @@ -416,7 +416,7 @@ case INACTIVE: if (activation_type == ACTIVATE) { - dlt_vlog(LOG_INFO, "Activate connection type: %u\n", con->type); + dlt_vlog(LOG_INFO, "Activate connection type: %d\n", con->type); dlt_event_handler_enable_fd(evhdl, con->receiver->fd, @@ -427,7 +427,7 @@ break; default: - dlt_vlog(LOG_ERR, "Unknown connection status: %u\n", con->status); + dlt_vlog(LOG_ERR, "Unknown connection status: %d\n", con->status); return -1; } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_event_handler.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_event_handler.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_event_handler.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_event_handler.h 2019-09-03 08:28:13.000000000 +0000 @@ -25,14 +25,14 @@ * \file dlt_daemon_event_handler.h */ -#include +#include #include "dlt_daemon_connection_types.h" #include "dlt_daemon_event_handler_types.h" #include "dlt-daemon.h" #ifndef DLT_DAEMON_EVENT_HANDLER_H -#define DLT_DAEMON_EVENT_HANDLER_H +# define DLT_DAEMON_EVENT_HANDLER_H int dlt_daemon_prepare_event_handling(DltEventHandler *); int dlt_daemon_handle_event(DltEventHandler *, DltDaemon *, DltDaemonLocal *); @@ -56,11 +56,11 @@ int dlt_connection_check_activate(DltEventHandler *, DltConnection *, int); -#ifdef DLT_UNIT_TESTS +# ifdef DLT_UNIT_TESTS int dlt_daemon_remove_connection(DltEventHandler *ev, DltConnection *to_remove); void dlt_daemon_add_connection(DltEventHandler *ev, DltConnection *connection); -#endif +# endif #endif /* DLT_DAEMON_EVENT_HANDLER_H */ diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_event_handler_types.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_event_handler_types.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_event_handler_types.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_event_handler_types.h 2019-09-03 08:28:13.000000000 +0000 @@ -25,12 +25,12 @@ * \file dlt_daemon_event_handler_types.h */ -#include +#include #include "dlt_daemon_connection_types.h" #ifndef DLT_DAEMON_EVENT_HANDLER_TYPES_H -#define DLT_DAEMON_EVENT_HANDLER_TYPES_H +# define DLT_DAEMON_EVENT_HANDLER_TYPES_H /* FIXME: Remove the need for DltDaemonLocal everywhere in the code * These typedefs are needed by DltDaemonLocal which is @@ -41,9 +41,9 @@ typedef enum { DLT_TIMER_PACKET = 0, DLT_TIMER_ECU, -#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE +# ifdef DLT_SYSTEMD_WATCHDOG_ENABLE DLT_TIMER_SYSTEMD, -#endif +# endif DLT_TIMER_GATEWAY, DLT_TIMER_UNKNOWN } DltTimers; diff -Nru dlt-daemon-2.18.9/src/daemon/dlt-daemon.h dlt-daemon-2.18.4/src/daemon/dlt-daemon.h --- dlt-daemon-2.18.9/src/daemon/dlt-daemon.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt-daemon.h 2019-09-03 08:28:13.000000000 +0000 @@ -69,7 +69,6 @@ #include /* for NAME_MAX */ #include -#include #include "dlt_daemon_common.h" #include "dlt_user_shared.h" @@ -104,13 +103,10 @@ 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) */ - 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 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) */ 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 */ @@ -121,9 +117,9 @@ unsigned int offlineLogstorageMaxCounter; /**< (int) Maximum offline logstorage file counter index until wraparound */ unsigned int offlineLogstorageMaxCounterIdx; /**< (int) String len of offlineLogstorageMaxCounter*/ unsigned int offlineLogstorageCacheSize; /**< Max cache size offline logstorage cache */ -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */ -#else /* DLT_DAEMON_USE_FIFO_IPC */ +#else char userPipesDir[DLT_PATH_MAX]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */ char daemonFifoName[DLT_PATH_MAX]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */ char daemonFifoGroup[DLT_PATH_MAX]; /**< (String: Group name) Owner group of local fifo (Default: Primary Group) */ @@ -139,8 +135,7 @@ int contextLogLevel; /**< (int) log level sent to context if registered with default log-level or if enforced*/ int contextTraceStatus; /**< (int) trace status sent to context if registered with default trace status or if enforced*/ int enforceContextLLAndTS; /**< (Boolean) Enforce log-level, trace-status not to exceed contextLogLevel, contextTraceStatus */ - DltBindAddress_t* ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */ - int injectionMode; /**< (Boolean) Injection mode */ + DltBindAddress_t *ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */ } DltDaemonFlags; /** * The global parameters of a dlt daemon. @@ -156,10 +151,8 @@ size_t baudrate; /**< Baudrate of serial connection */ #ifdef DLT_SHM_ENABLE DltShm dlt_shm; /**< Shared memory handling */ - unsigned char *recv_buf_shm; /**< buffer for receive message from shm */ #endif - MultipleFilesRingBuffer offlineTrace; /**< Offline trace handling */ - MultipleFilesRingBuffer dltLogging; /**< Dlt logging handling */ + DltOfflineTrace offlineTrace; /**< Offline trace handling */ int timeoutOnSend; unsigned long RingbufferMinSize; unsigned long RingbufferMaxSize; @@ -174,10 +167,8 @@ typedef struct { + int timer_fd; unsigned long long wakeups_missed; - int period_sec; - int starts_in; - int timer_id; } DltDaemonPeriodicData; typedef struct @@ -204,10 +195,6 @@ void dlt_daemon_daemonize(int verbose); void dlt_daemon_exit_trigger(); void dlt_daemon_signal_handler(int sig); -#ifdef __QNX__ -void dlt_daemon_cleanup_timers(); -void close_pipes(int fds[2]); -#endif int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *revc, int verbose); int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, @@ -220,7 +207,7 @@ int dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); -#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE +#ifdef DLT_USE_UNIX_SOCKET_IPC int dlt_daemon_process_app_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); #endif int dlt_daemon_process_control_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, @@ -250,13 +237,13 @@ DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose); -int dlt_daemon_process_user_message_log(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); - -bool enforce_context_ll_and_ts_keep_message(DltDaemonLocal *daemon_local); - +int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose); +#ifdef DLT_SHM_ENABLE +int dlt_daemon_process_user_message_log_shm(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + DltReceiver *rec, + int verbose); +#endif int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, @@ -278,3 +265,4 @@ int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); #endif /* DLT_DAEMON_H */ + diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_offline_logstorage.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_offline_logstorage.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_offline_logstorage.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_offline_logstorage.c 2019-09-03 08:28:13.000000000 +0000 @@ -49,14 +49,13 @@ if ((len > (DLT_ID_SIZE + 2)) || (len < 2)) return DLT_RETURN_ERROR; - memcpy(ecuid, key, (len - 2)); - memcpy(apid, ".*", 2); - memcpy(ctid, ".*", 2); + strncpy(ecuid, key, (len - 2)); + strncpy(apid, ".*", 2); + strncpy(ctid, ".*", 2); return DLT_RETURN_OK; } -unsigned int g_logstorage_cache_max; /** * dlt_logstorage_split_ctid * @@ -77,7 +76,7 @@ return DLT_RETURN_ERROR; strncpy(ctid, (key + 2), (len - 1)); - memcpy(apid, ".*", 2); + strncpy(apid, ".*", 2); return DLT_RETURN_OK; } @@ -102,7 +101,7 @@ return DLT_RETURN_ERROR; strncpy(apid, key + 1, (len - 2)); - memcpy(ctid, ".*", 2); + strncpy(ctid, ".*", 2); return DLT_RETURN_OK; } @@ -184,7 +183,7 @@ else return DLT_RETURN_ERROR; - memcpy(ctid, ".*", 2); + strncpy(ctid, ".*", 2); return DLT_RETURN_OK; } @@ -228,19 +227,14 @@ if (tok != NULL) strncpy(ctid, tok, DLT_ID_SIZE); - memcpy(apid, ".*", 2); + strncpy(apid, ".*", 2); } else { strncpy(ecuid, tok, DLT_ID_SIZE); tok = strtok(NULL, ":"); - - if (tok != NULL) - strncpy(apid, tok, DLT_ID_SIZE); - + strncpy(apid, tok, DLT_ID_SIZE); tok = strtok(NULL, ":"); - - if (tok != NULL) - strncpy(ctid, tok, DLT_ID_SIZE); + strncpy(ctid, tok, DLT_ID_SIZE); } return DLT_RETURN_OK; @@ -539,7 +533,7 @@ * @param daemon_local DltDaemonLocal structure * @param id application id or context id * @param curr_log_level log level to be set to context - * @param cmp_flag compare flag + * @param cmp_flag compare flag (1 id is apid, 2 id is ctid) * @param ecuid ecu id where application runs * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error @@ -557,8 +551,8 @@ char tmp_id[DLT_ID_SIZE + 1] = { '\0' }; if ((daemon == NULL) || (daemon_local == NULL) || (id == NULL) || - (ecuid == NULL) || (cmp_flag <= DLT_DAEMON_LOGSTORAGE_CMP_MIN) || - (cmp_flag >= DLT_DAEMON_LOGSTORAGE_CMP_MAX)) { + (ecuid == NULL) || (cmp_flag < DLT_DAEMON_LOGSTORAGE_CMP_APID) || + (cmp_flag > DLT_DAEMON_LOGSTORAGE_CMP_CTID)) { dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -569,13 +563,10 @@ return DLT_RETURN_ERROR; for (i = 0; i < user_list->num_contexts; i++) { - if (cmp_flag == DLT_DAEMON_LOGSTORAGE_CMP_APID) + if (cmp_flag == 1) dlt_set_id(tmp_id, user_list->contexts[i].apid); - else if (cmp_flag == DLT_DAEMON_LOGSTORAGE_CMP_CTID) - dlt_set_id(tmp_id, user_list->contexts[i].ctid); else - /* this is for the case when both apid and ctid are wildcard */ - dlt_set_id(tmp_id, ".*"); + dlt_set_id(tmp_id, user_list->contexts[i].ctid); if (strncmp(id, tmp_id, DLT_ID_SIZE) == 0) { if (curr_log_level > 0) @@ -713,20 +704,8 @@ if (ecuid[0] == '\0') /* ECU id was not specified in filter configuration */ dlt_set_id(ecuid, daemon->ecuid); - /* check wildcard for both apid and ctid first of all */ - if (strcmp(ctid, ".*") == 0 && strcmp(apid, ".*") == 0) { - cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_ECID; - - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - apid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) - return DLT_RETURN_ERROR; - } - else if (strcmp(ctid, ".*") == 0) { + /* wildcard for context id, find all contexts of given application id */ + if (strcmp(ctid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_APID; if (dlt_logstorage_update_all_contexts(daemon, @@ -793,6 +772,7 @@ DltLogStorageFilterList **tmp = NULL; int i = 0; char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' }; + int num_device_configured = 0; unsigned int status; int log_level = 0; @@ -812,6 +792,14 @@ (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return; + /* First, check number of devices configured */ + for (i = 0; i < max_device; i++) { + status = daemon->storage_handle[i].config_status; + + if (status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) + num_device_configured++; + } + /* for all filters (keys) check if application context are already running * and log level need to be reset*/ tmp = &(handle->config_list); @@ -825,10 +813,19 @@ + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); - /* dlt-daemon wants to reset loglevel if - * a logstorage device is disconnected. - */ - log_level = DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL; + if (num_device_configured == 1) + { + /* Reset context log level and send to application */ + log_level = DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL; + } + else + { + /** + * Reset context log level do not send to application as other + * devices can have same configuration + * */ + log_level = DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL; + } dlt_logstorage_update_context_loglevel( daemon, @@ -1100,16 +1097,6 @@ 0, verbose); - if (daemon->storage_handle[0].maintain_logstorage_loglevel != - DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) { - daemon->maintain_logstorage_loglevel = - daemon->storage_handle[0].maintain_logstorage_loglevel; - - dlt_vlog(LOG_DEBUG, "[%s] Startup with maintain loglevel: [%d]\n", - __func__, - daemon->storage_handle[0].maintain_logstorage_loglevel); - } - return ret; } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_offline_logstorage.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_offline_logstorage.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_offline_logstorage.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_offline_logstorage.h 2019-09-03 08:28:13.000000000 +0000 @@ -58,13 +58,8 @@ #define DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL -1 #define DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL 0 -typedef enum { - DLT_DAEMON_LOGSTORAGE_CMP_MIN = 0, - DLT_DAEMON_LOGSTORAGE_CMP_APID = 1, - DLT_DAEMON_LOGSTORAGE_CMP_CTID = 2, - DLT_DAEMON_LOGSTORAGE_CMP_ECID = 3, - DLT_DAEMON_LOGSTORAGE_CMP_MAX, -} DltCompareFlags; +#define DLT_DAEMON_LOGSTORAGE_CMP_APID 1 +#define DLT_DAEMON_LOGSTORAGE_CMP_CTID 2 /** * dlt_daemon_logstorage_get_loglevel diff -Nru dlt-daemon-2.18.9/src/daemon/dlt-daemon.rc dlt-daemon-2.18.4/src/daemon/dlt-daemon.rc --- dlt-daemon-2.18.9/src/daemon/dlt-daemon.rc 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt-daemon.rc 1970-01-01 00:00:00.000000000 +0000 @@ -1,7 +0,0 @@ -service dlt-daemon /vendor/bin/dlt-daemon - class late_start - user root - group root - socket dlt stream 666 root root - socket dlt-ctrl.sock stream 660 root root - disabled diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_serial.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_serial.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_serial.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_serial.c 2019-09-03 08:28:13.000000000 +0000 @@ -57,7 +57,9 @@ #include #include #include +#include +#include /* send() */ #include /* send() */ #include "dlt-daemon.h" @@ -66,33 +68,24 @@ #include "dlt_daemon_serial.h" -int dlt_daemon_serial_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader) +int dlt_daemon_serial_send(int sock, void *data1, int size1, void *data2, int size2, char serialheader) { /* Optional: Send serial header, if requested */ - if (serialheader) { - if (0 > write(sock, dltSerialHeader, sizeof(dltSerialHeader))) { + if (serialheader) + if (0 > write(sock, dltSerialHeader, sizeof(dltSerialHeader))) return DLT_DAEMON_ERROR_SEND_FAILED; - } - } /* Send data */ - if (data1 && (size1 > 0)) { - if (0 > write(sock, data1, size1)) { + if (data1 && (size1 > 0)) + if (0 > write(sock, data1, size1)) return DLT_DAEMON_ERROR_SEND_FAILED; - } - } - if (data2 && (size2 > 0)) { - if (0 > write(sock, data2, size2)) { + + + if (data2 && (size2 > 0)) + if (0 > write(sock, data2, size2)) return DLT_DAEMON_ERROR_SEND_FAILED; - } - } return DLT_DAEMON_ERROR_OK; } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_serial.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_serial.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_serial.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_serial.h 2019-09-03 08:28:13.000000000 +0000 @@ -60,11 +60,6 @@ #include "dlt_common.h" #include "dlt_user.h" -int dlt_daemon_serial_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader); +int dlt_daemon_serial_send(int sock, void *data1, int size1, void *data2, int size2, char serialheader); #endif /* DLT_DAEMON_SERIAL_H */ diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_socket.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_socket.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_socket.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_socket.c 2019-09-03 08:28:13.000000000 +0000 @@ -34,6 +34,7 @@ #include /* for atoi() and exit() */ #include /* for memset() */ #include /* for close() */ +#include #include #include #include @@ -41,11 +42,12 @@ #include #ifdef linux -#include +# include #endif +#include #include #if defined(linux) && defined(__NR_statx) -#include +# include #endif #include "dlt_types.h" @@ -66,18 +68,14 @@ /* create socket */ if ((*sock = socket(AF_INET6, SOCK_STREAM, 0)) == -1) { lastErrno = errno; - dlt_vlog(LOG_ERR, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, - strerror(lastErrno)); - return -1; + dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, strerror(lastErrno)); } #else if ((*sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { lastErrno = errno; - dlt_vlog(LOG_ERR, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, - strerror(lastErrno)); - return -1; + dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, strerror(lastErrno)); } #endif @@ -87,12 +85,10 @@ /* setsockpt SO_REUSEADDR */ if (setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { lastErrno = errno; - dlt_vlog( - LOG_ERR, - "dlt_daemon_socket_open: Setsockopt error %d in dlt_daemon_local_connection_init: %s\n", - lastErrno, - strerror(lastErrno)); - return -1; + dlt_vlog(LOG_WARNING, + "dlt_daemon_socket_open: Setsockopt error %d in dlt_daemon_local_connection_init: %s\n", + lastErrno, + strerror(lastErrno)); } /* bind */ @@ -101,13 +97,10 @@ memset(&forced_addr, 0, sizeof(forced_addr)); forced_addr.sin6_family = AF_INET6; forced_addr.sin6_port = htons(servPort); - - if (0 == strcmp(ip, "0.0.0.0")) { + if (0 == strcmp(ip, "0.0.0.0")) forced_addr.sin6_addr = in6addr_any; - } else { + else ret_inet_pton = inet_pton(AF_INET6, ip, &forced_addr.sin6_addr); - } - #else struct sockaddr_in forced_addr; memset(&forced_addr, 0, sizeof(forced_addr)); @@ -119,21 +112,18 @@ /* inet_pton returns 1 on success */ if (ret_inet_pton != 1) { lastErrno = errno; - dlt_vlog( - LOG_WARNING, - "dlt_daemon_socket_open: inet_pton() error %d: %s. Cannot convert IP address: %s\n", - lastErrno, - strerror(lastErrno), - ip); + dlt_vlog(LOG_WARNING, + "dlt_daemon_socket_open: inet_pton() error %d: %s. Cannot convert IP address: %s\n", + lastErrno, + strerror(lastErrno), + ip); return -1; } if (bind(*sock, (struct sockaddr *)&forced_addr, sizeof(forced_addr)) == -1) { lastErrno = errno; /*close() may set errno too */ close(*sock); - dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: bind() error %d: %s\n", lastErrno, - strerror(lastErrno)); - return -1; + dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: bind() error %d: %s\n", lastErrno, strerror(lastErrno)); } /*listen */ @@ -145,9 +135,7 @@ if (listen(*sock, 3) < 0) { lastErrno = errno; - dlt_vlog(LOG_WARNING, - "dlt_daemon_socket_open: listen() failed with error %d: %s\n", - lastErrno, + dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: listen() failed with error %d: %s\n", lastErrno, strerror(lastErrno)); return -1; } @@ -162,12 +150,7 @@ return 0; } -int dlt_daemon_socket_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader) +int dlt_daemon_socket_send(int sock, void *data1, int size1, void *data2, int size2, char serialheader) { int ret = DLT_RETURN_OK; @@ -177,23 +160,20 @@ (void *)dltSerialHeader, sizeof(dltSerialHeader)); - if (ret != DLT_RETURN_OK) { + if (ret != DLT_RETURN_OK) return ret; - } } /* Send data */ if ((data1 != NULL) && (size1 > 0)) { ret = dlt_daemon_socket_sendreliable(sock, data1, size1); - if (ret != DLT_RETURN_OK) { + if (ret != DLT_RETURN_OK) return ret; - } } - if ((data2 != NULL) && (size2 > 0)) { + if ((data2 != NULL) && (size2 > 0)) ret = dlt_daemon_socket_sendreliable(sock, data2, size2); - } return ret; } @@ -212,16 +192,15 @@ int data_sent = 0; while (data_sent < message_size) { - ssize_t ret = send(sock, - (uint8_t *)data_buffer + data_sent, - message_size - data_sent, - 0); + ssize_t ret = send(sock, data_buffer + data_sent, message_size - data_sent, 0); if (ret < 0) { dlt_vlog(LOG_WARNING, - "%s: socket send failed [errno: %d]!\n", __func__, errno); + "dlt_daemon_socket_sendreliable: socket send failed [errno: %d]!\n", + errno); return DLT_DAEMON_ERROR_SEND_FAILED; - } else { + } + else { data_sent += ret; } } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_socket.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_socket.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_socket.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_socket.h 2019-09-03 08:28:13.000000000 +0000 @@ -65,12 +65,7 @@ int dlt_daemon_socket_get_send_qeue_max_size(int sock); -int dlt_daemon_socket_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader); +int dlt_daemon_socket_send(int sock, void *data1, int size1, void *data2, int size2, char serialheader); /** * @brief dlt_daemon_socket_sendreliable - sends data to socket with additional checks and resending functionality - trying to be reliable diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_unix_socket.c dlt-daemon-2.18.4/src/daemon/dlt_daemon_unix_socket.c --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_unix_socket.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_unix_socket.c 2019-09-03 08:28:13.000000000 +0000 @@ -28,62 +28,17 @@ #include #include #include -#if defined(ANDROID) -# include /* for android_get_control_socket() */ -# include /* for basename() */ -#else -# include /* for socket(), connect(), (), and recv() */ -#endif +#include #include #include #include #include -#if DLT_SYSTEM_SOCKET_ACTIVATION_ENABLE -#include -#endif - #include "dlt-daemon.h" #include "dlt_common.h" #include "dlt-daemon_cfg.h" #include "dlt_daemon_socket.h" #include "dlt_daemon_unix_socket.h" -#ifdef ANDROID -DltReturnValue dlt_daemon_unix_android_get_socket(int *sock, const char *sock_path) -{ - DltReturnValue ret = DLT_RETURN_OK; - - if ((sock == NULL) || (sock_path == NULL)) { - dlt_log(LOG_ERR, "dlt_daemon_unix_android_get_socket: arguments invalid"); - ret = DLT_RETURN_WRONG_PARAMETER; - } - else { - const char* sock_name = basename(sock_path); - if (sock_name == NULL) { - dlt_log(LOG_WARNING, - "dlt_daemon_unix_android_get_socket: can't get socket name from its path"); - ret = DLT_RETURN_ERROR; - } - else { - *sock = android_get_control_socket(sock_name); - if (*sock < 0) { - dlt_log(LOG_WARNING, - "dlt_daemon_unix_android_get_socket: can get socket from init"); - ret = DLT_RETURN_ERROR; - } - else { - if (listen(*sock, 1) == -1) { - dlt_vlog(LOG_WARNING, "unix socket: listen error: %s", strerror(errno)); - ret = DLT_RETURN_ERROR; - } - } - } - } - - return ret; -} -#endif - int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) { struct sockaddr_un addr; @@ -94,48 +49,6 @@ return -1; } -#ifdef DLT_SYSTEM_SOCKET_ACTIVATION_ENABLE - - char **names = NULL; - const int num_fds = sd_listen_fds_with_names(0, &names); - bool sd_socket_open = false; - int i; - - if (num_fds <= 0) { - dlt_vlog(LOG_WARNING, "unix socket: no sockets configured via systemd, error: %s\n", strerror(errno)); - } else { - for (i = 0; i < num_fds; ++i) { - if (strcmp(sock_path, names[i]) != 0) { - continue; - } - - if (sd_is_socket_unix(i + SD_LISTEN_FDS_START, type, 1, names[i], strlen(names[i])) < 0) { - dlt_vlog(LOG_WARNING, - "unix socket: socket with matching name is not of correct type or not in listen mode, error: %s\n", - strerror(errno)); - continue; - } - - *sock = i + SD_LISTEN_FDS_START; - sd_socket_open = true; - dlt_vlog(LOG_INFO, "unix socket: sock_path %s found systemd socket %s\n", sock_path, names[i]); - break; - } - - /* - * The caller [of sd_listen_fds_with_names] needs to free the array - * itself and each of its elements with libc's free() call after use. - * */ - for (i = 0; i < num_fds; ++i) { - free(names[i]); - } - free(names); - } - - if (!sd_socket_open) { - dlt_vlog(LOG_INFO, "unix socket: sock_path %s no systemd socket found\n", sock_path); -#endif - if ((*sock = socket(AF_UNIX, type, 0)) == -1) { dlt_log(LOG_WARNING, "unix socket: socket() error"); return -1; @@ -163,11 +76,6 @@ /* restore permissions */ umask(old_mask); -#ifdef DLT_SYSTEM_SOCKET_ACTIVATION_ENABLE - } // end of: if (!sd_socket_open) { -#endif - - return 0; } diff -Nru dlt-daemon-2.18.9/src/daemon/dlt_daemon_unix_socket.h dlt-daemon-2.18.4/src/daemon/dlt_daemon_unix_socket.h --- dlt-daemon-2.18.9/src/daemon/dlt_daemon_unix_socket.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/dlt_daemon_unix_socket.h 2019-09-03 08:28:13.000000000 +0000 @@ -56,9 +56,6 @@ #ifndef DLT_DAEMON_UNIX_SOCKET_H #define DLT_DAEMON_UNIX_SOCKET_H -#ifdef ANDROID -DltReturnValue dlt_daemon_unix_android_get_socket(int *sock, const char *sock_path); -#endif int dlt_daemon_unix_socket_open(int *sock, char *socket_path, int type, int mask); int dlt_daemon_unix_socket_close(int sock); diff -Nru dlt-daemon-2.18.9/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h dlt-daemon-2.18.4/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h --- dlt-daemon-2.18.9/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h 2019-09-03 08:28:13.000000000 +0000 @@ -15,7 +15,7 @@ * Sachin Sudhakar Shetty * Sunil Kovila Sampath * - * \copyright Copyright (c) 2019 LG Electronics Inc. + * \Copyright (c) 2019 LG Electronics Inc. * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt_daemon_udp_common_socket.h @@ -33,10 +33,15 @@ #include /* for memset() */ #include #include /* for socket(), connect(), (), and recv() */ +#include +#include #include /* for close() */ #include "dlt_common.h" #include "dlt-daemon.h" +#include "dlt_daemon_common_cfg.h" +#include "dlt_daemon_client.h" +#include "dlt_daemon_connection.h" #include "dlt_daemon_udp_socket.h" #include "dlt_types.h" diff -Nru dlt-daemon-2.18.9/src/daemon/udp_connection/dlt_daemon_udp_socket.c dlt-daemon-2.18.4/src/daemon/udp_connection/dlt_daemon_udp_socket.c --- dlt-daemon-2.18.9/src/daemon/udp_connection/dlt_daemon_udp_socket.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/udp_connection/dlt_daemon_udp_socket.c 2019-09-03 08:28:13.000000000 +0000 @@ -15,7 +15,7 @@ * Sachin Sudhakar Shetty * Sunil Kovila Sampath * - * \copyright Copyright (c) 2019 LG Electronics Inc. + * \Copyright (c) 2019 LG Electronics Inc. * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt_daemon_udp_socket.c @@ -46,8 +46,10 @@ clientinfo_struct->clientaddr_size = sizeof(clientinfo_struct->clientaddr); clientinfo_struct->isvalidflag = ADDRESS_INVALID; /* info is invalid */ dlt_vlog(LOG_DEBUG, "%s: client addr struct init success \n", __func__); + dlt_log(LOG_INFO, "dlt_daemon_udp_init_clientstruct: client addr struct init success \n"); } + /* ************************************************************************** */ /* Function : dlt_daemon_udp_setmulticast_addr */ /* In Param : NIL */ @@ -77,6 +79,7 @@ /* In Param : contains daemon param values used globally */ /* Out Param : status of udp connection setup and fd registration */ /* Description: DataGram socket fd connection is setup */ +/* fd is registered with the epoll */ /* ************************************************************************** */ DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal *daemon_local) { @@ -253,16 +256,3 @@ dlt_vlog(LOG_ERR, "%s: size2 <= 0\n", __func__); } } - -/* ************************************************************************** */ -/* Function : dlt_daemon_udp_close_connection */ -/* In Param : NIL */ -/* Out Param : NIL */ -/* Description: Closes UDP Connection */ -/* ************************************************************************** */ -void dlt_daemon_udp_close_connection(void) -{ - if (close(g_udp_sock_fd) == SYSTEM_CALL_ERROR) - dlt_vlog(LOG_WARNING, "[%s:%d] close error %s\n", __func__, __LINE__, - strerror(errno)); -} diff -Nru dlt-daemon-2.18.9/src/daemon/udp_connection/dlt_daemon_udp_socket.h dlt-daemon-2.18.4/src/daemon/udp_connection/dlt_daemon_udp_socket.h --- dlt-daemon-2.18.9/src/daemon/udp_connection/dlt_daemon_udp_socket.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/daemon/udp_connection/dlt_daemon_udp_socket.h 2019-09-03 08:28:13.000000000 +0000 @@ -15,7 +15,7 @@ * Sachin Sudhakar Shetty * Sunil Kovila Sampath * - * \copyright Copyright (c) 2019 LG Electronics Inc. + * \Copyright (c) 2019 LG Electronics Inc. * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt_daemon_udp_socket.h @@ -29,6 +29,4 @@ DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal *daemon_local); void dlt_daemon_udp_dltmsg_multicast(void *data1, int size1, void *data2, int size2, int verbose); -void dlt_daemon_udp_close_connection(void); - #endif /* DLT_DAEMON_UDP_SOCKET_H */ diff -Nru dlt-daemon-2.18.9/src/dlt-qnx-system/CMakeLists.txt dlt-daemon-2.18.4/src/dlt-qnx-system/CMakeLists.txt --- dlt-daemon-2.18.9/src/dlt-qnx-system/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/dlt-qnx-system/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -####### -# @licence make begin@ -# SPDX license identifier: MPL-2.0 -# -# Copyright (C) 2018 Advanced Driver Information Technology. -# -# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -# @licence end@ -####### - -if(NOT WITH_DLT_CXX11_EXT) - message(FATAL_ERROR "DLT_QNX_SYSTEM needs the C++ features of dlt, please enable the WITH_DLT_CXX11_EXT option.") -endif() - -set(dlt-qnx-system_SRCS dlt-qnx-system.c dlt-qnx-slogger2-adapter.cpp) -add_executable(dlt-qnx-system ${dlt-qnx-system_SRCS}) - -target_link_libraries(dlt-qnx-system dlt slog2parse json) - -install(TARGETS dlt-qnx-system - RUNTIME DESTINATION bin - COMPONENT base) - -install(FILES dlt-qnx-system.conf dlt-slog2ctxt.json - DESTINATION ${CONFIGURATION_FILES_DIR} - COMPONENT base) diff -Nru dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp --- dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,254 +0,0 @@ -/** - * Copyright (C) 2018-2020 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * DLT QNX system functionality source file. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Nguyen Dinh Thi ADIT 2018 - * \author Felix Herrmann ADIT 2020 - * - * \file: dlt-qnx-slogger2-adapter.cpp - * For further information see http://www.genivi.org/. - */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "dlt-qnx-system.h" -#include "dlt_cpp_extension.hpp" - -/* Teach dlt about json_decoder_error_t */ -template<> -inline int32_t logToDlt(DltContextData &log, const json_decoder_error_t &value) -{ - return logToDlt(log, static_cast(value)); -} - -extern DltContext dltQnxSystem; - -static DltContext dltQnxSlogger2Context; - -extern DltQnxSystemThreads g_threads; -static std::unordered_map g_slog2file; - -static void dlt_context_map_read(const char *json_filename) -{ - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_VERBOSE, - "Loading Slog2Ctxt Map from json file: ", json_filename); - - auto dec = json_decoder_create(); - if (json_decoder_parse_file(dec, json_filename) != JSON_DECODER_OK) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_ERROR, - "Could not load Slog2Ctxt Map from json file: ", json_filename); - return; - } - - const char *ctxtID, *name, *description; - - /* go to first element in dlt-slog2ctxt.json e.g. "ADIO" */ - auto ret = json_decoder_push_object(dec, nullptr, false); - while (ret == JSON_DECODER_OK) { - ctxtID = json_decoder_name(dec); - - /* go into the element e.g. { name: "", description: "" } */ - ret = json_decoder_push_object(dec, nullptr, false); - if (ret != JSON_DECODER_OK) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_WARN, __func__, - ": json parser error while descending into context dict. ret=", ret); - break; - } - - ret = json_decoder_get_string(dec, "name", &name, false); - if (ret != JSON_DECODER_OK) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_WARN, __func__, - ": json parser error while retrieving 'name' element of ", ctxtID, ". ret=", ret); - break; - } - - ret = json_decoder_get_string(dec, "description", &description, false); - if (ret != JSON_DECODER_OK) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_WARN, __func__, - ": json parser error while retrieving 'description' element of ", ctxtID, ". ret=", ret); - break; - } - - auto ctxt = new DltContext; - g_slog2file.emplace(name, ctxt); - - auto search = g_slog2file.find(name); - if (search == g_slog2file.end()) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_INFO, - "Could not emplace slog2ctxt map key: ", name); - } else { - dlt_register_context(ctxt, ctxtID, description); - } - - ret = json_decoder_pop(dec); - } - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_DEBUG, - "Added ", g_slog2file.size(), " elements into the mapping table."); -} - -/** - * Map the slog2 logfile name to a dlt context - * e.g. i2c_service.2948409 -> Context with id "I2CS" - */ -static DltContext *dlt_context_from_slog2file(const char *file_name) { - auto d = strchr(file_name, '.'); - - if (d == nullptr) - return &dltQnxSlogger2Context; - - auto name = std::string(file_name).substr(0, d - file_name); - - auto search = g_slog2file.find(name); - if (search == g_slog2file.end()) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_VERBOSE, - "slog2 filename not found in mapping: ", name.c_str()); - return &dltQnxSlogger2Context; - } else { - return search->second; - } -} - -/** - * Function which is invoked by slog2_parse_all() - * See slog2_parse_all api docs on qnx.com for details - */ -static int sloggerinfo_callback(slog2_packet_info_t *info, void *payload, void *param) -{ - DltQnxSystemConfiguration* conf = (DltQnxSystemConfiguration*) param; - - if (param == NULL) - return -1; - - if (info->data_type == SLOG2_TYPE_ONLINE) - info->severity = SLOG2_INFO; - - DltLogLevelType loglevel; - switch (info->severity) - { - case SLOG2_SHUTDOWN: - case SLOG2_CRITICAL: - loglevel = DLT_LOG_FATAL; - break; - case SLOG2_ERROR: - loglevel = DLT_LOG_ERROR; - break; - case SLOG2_WARNING: - loglevel = DLT_LOG_WARN; - break; - case SLOG2_NOTICE: - case SLOG2_INFO: - loglevel = DLT_LOG_INFO; - break; - case SLOG2_DEBUG1: - loglevel = DLT_LOG_DEBUG; - break; - case SLOG2_DEBUG2: - loglevel = DLT_LOG_VERBOSE; - break; - default: - loglevel = DLT_LOG_INFO; - break; - } - - DltContextData log_local; /* Used in DLT_* macros, do not rename */ - DltContext *ctxt = dlt_context_from_slog2file(info->file_name); - - int ret; - ret = dlt_user_log_write_start(ctxt, &log_local, loglevel); - - /* OK means loglevel under threshold */ - if (ret == DLT_RETURN_OK) { - return 0; - } - - if (ret != DLT_RETURN_TRUE) { - fprintf(stderr, "%s: could not log to DLT status=%d\n", __func__, ret); - return -1; - } - - if (conf->qnxslogger2.useOriginalTimestamp == 1) { - /* convert from ns to .1 ms */ - log_local.user_timestamp = (uint32_t) (info->timestamp / 100000); - log_local.use_timestamp = DLT_USER_TIMESTAMP; - } else { - DLT_UINT64(info->timestamp); - } - - DLT_UINT16(info->sequence_number); - DLT_STRING((char *)info->file_name); - DLT_STRING((char *)info->buffer_name); - DLT_UINT16(info->thread_id); - DLT_UINT8(info->severity); - DLT_STRING((char *)payload); - - dlt_user_log_write_finish(&log_local); - - return 0; -} - -static void *slogger2_thread(void *v_conf) -{ - DltQnxSystemConfiguration *conf = (DltQnxSystemConfiguration *)v_conf; - - if (v_conf == NULL) - return reinterpret_cast(EINVAL); - - slog2_packet_info_t packet_info = SLOG2_PACKET_INFO_INIT; - - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-qnx-slogger2-adapter, in thread.")); - DLT_REGISTER_CONTEXT(dltQnxSlogger2Context, conf->qnxslogger2.contextId, - "SLOGGER2 Adapter"); - - dlt_context_map_read(CONFIGURATION_FILES_DIR "/dlt-slog2ctxt.json"); - - /** - * Thread will block inside this function to get new log because - * flag = SLOG2_PARSE_FLAGS_DYNAMIC - */ - int ret = slog2_parse_all( - SLOG2_PARSE_FLAGS_DYNAMIC, /* live streaming of all buffers merged */ - NULL, NULL, &packet_info, sloggerinfo_callback, (void*) conf); - if (ret == -1) { - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_ERROR, - "slog2_parse_all() returned error=", ret); - ret = EBADMSG; - } - - DLT_LOG_CXX(dltQnxSystem, DLT_LOG_DEBUG, __func__, ": Exited main loop."); - - DLT_UNREGISTER_CONTEXT(dltQnxSlogger2Context); - - /* Send a signal to main thread to wake up sigwait */ - pthread_kill(g_threads.mainThread, SIGTERM); - return reinterpret_cast(ret); -} - -void start_qnx_slogger2(DltQnxSystemConfiguration *conf) -{ - static pthread_attr_t t_attr; - static pthread_t pt; - - DLT_LOG_CXX(dltQnxSlogger2Context, DLT_LOG_DEBUG, - "dlt-qnx-slogger2-adapter, start syslog"); - pthread_create(&pt, &t_attr, slogger2_thread, conf); - g_threads.threads[g_threads.count++] = pt; -} diff -Nru dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-system.c dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-system.c --- dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-system.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-system.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,432 +0,0 @@ -/** - * Copyright (C) 2020 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * DLT QNX system functionality source file. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Nguyen Dinh Thi - * - * \file: dlt-qnx-system.c - * For further information see http://www.genivi.org/. - * @licence end@ - */ - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dlt.h" -#include "dlt-qnx-system.h" - -DLT_DECLARE_CONTEXT(dltQnxSystem) - -/* Global variables */ -volatile DltQnxSystemThreads g_threads; - -/* Function prototype */ -static void daemonize(); -static void start_threads(DltQnxSystemConfiguration *config); -static void join_threads(); -static int read_configuration_file(DltQnxSystemConfiguration *config, - const char *file_name); -static int read_command_line(DltQnxSystemCliOptions *options, int argc, char *argv[]); - -int main(int argc, char* argv[]) -{ - DltQnxSystemCliOptions options; - DltQnxSystemConfiguration config; - int sigNo = 0; - int ret = 0; - sigset_t mask; - int i; - - if (read_command_line(&options, argc, argv) < 0) - { - fprintf(stderr, "Failed to read command line!\n"); - return -1; - } - - if (read_configuration_file(&config, options.configurationFileName) < 0) - { - fprintf(stderr, "Failed to read configuration file!\n"); - return -1; - } - - if (options.daemonize > 0) - { - daemonize(); - } - - sigemptyset(&mask); - sigaddset(&mask, SIGTERM); - sigaddset(&mask, SIGHUP); - sigaddset(&mask, SIGQUIT); - sigaddset(&mask, SIGINT); - sigaddset(&mask, SIGALRM); - if (pthread_sigmask(SIG_BLOCK, &mask, NULL) != 0) - { - fprintf(stderr, "Couldn't set mask for potential future threads.\n"); - return -1; - } - - DLT_REGISTER_APP(config.applicationId, "DLT QNX System"); - DLT_REGISTER_CONTEXT(dltQnxSystem, config.applicationContextId, - "Context of main dlt qnx system manager"); - - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("Setting signals wait for abnormal exit")); - - g_threads.mainThread = pthread_self(); - - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, DLT_STRING("Launching threads.")); - start_threads(&config); - - ret = sigwait(&mask, &sigNo); - - for (i = 0; i < MAX_THREADS; i++) { - pthread_cancel(g_threads.threads[i]); - } - join_threads(); - - if (ret != 0) { - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("sigwait failed with error: "), - DLT_INT(ret)); - DLT_UNREGISTER_APP(); - return -1; - } - - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("Received signal: "), - DLT_STRING(strsignal(sigNo))); - - DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS(); - return 0; - -} - -/** - * Print information how to use this program. - */ -static void usage(char *prog_name) -{ - char version[255]; - dlt_get_version(version, 255); - - printf("Usage: %s [options]\n", prog_name); - printf("Application to manage QNX system, such as:\n"); - printf(" - forward slogger2 messages from QNX to DLT) .\n"); - printf("%s\n", version); - printf("Options:\n"); - printf(" -d Daemonize. Detach from terminal and run in background.\n"); - printf(" -c filename Use configuration file. \n"); - printf(" Default: %s\n", DEFAULT_CONF_FILE); - printf(" -h This help message.\n"); -} - -/** - * Initialize command line options with default values. - */ -static void init_cli_options(DltQnxSystemCliOptions *options) -{ - options->configurationFileName = DEFAULT_CONF_FILE; - options->daemonize = 0; -} - -/** - * Read command line options and set the values in provided structure - */ -static int read_command_line(DltQnxSystemCliOptions *options, int argc, char *argv[]) -{ - init_cli_options(options); - int opt; - - while ((opt = getopt(argc, argv, "c:hd")) != -1) - { - switch (opt) { - case 'd': - { - options->daemonize = 1; - break; - } - case 'c': - { - options->configurationFileName = (char *)malloc(strlen(optarg)+1); - MALLOC_ASSERT(options->configurationFileName); - /** - * strcpy unritical here, because size matches exactly the size - * to be copied - */ - strcpy(options->configurationFileName, optarg); - break; - } - case 'h': - { - usage(argv[0]); - exit(0); - return -1; - } - default: - { - fprintf(stderr, "Unknown option '%c'\n", optopt); - usage(argv[0]); - return -1; - } - } - } - return 0; -} - -/** - * Initialize configuration to default values. - */ -static void init_configuration(DltQnxSystemConfiguration *config) -{ - /* Common */ - config->applicationId = "QSYM"; - config->applicationContextId = "QSYC"; - - /* Slogger2 */ - config->qnxslogger2.enable = 0; - config->qnxslogger2.contextId = "QSLA"; - config->qnxslogger2.useOriginalTimestamp = 1; -} - -/** - * Read options from the configuration file - */ -static int read_configuration_file(DltQnxSystemConfiguration *config, - const char *file_name) -{ - FILE *file; - char *line; - char *token; - char *value; - char *pch; - int ret = 0; - - init_configuration(config); - - file = fopen(file_name, "r"); - - if (file == NULL) - { - fprintf(stderr, - "dlt-qnx-system, could not open configuration file.\n"); - return -1; - } - - line = malloc(MAX_LINE); - token = malloc(MAX_LINE); - value = malloc(MAX_LINE); - - MALLOC_ASSERT(line); - MALLOC_ASSERT(token); - MALLOC_ASSERT(value); - - while (fgets(line, MAX_LINE, file) != NULL) - { - token[0] = 0; - value[0] = 0; - - pch = strtok(line, " =\r\n"); - while (pch != NULL) - { - if (pch[0] == '#') - { - break; - } - - if (token[0] == 0) - { - strncpy(token, pch, MAX_LINE-1); - token[MAX_LINE-1] = 0; - } - else - { - strncpy(value, pch, MAX_LINE); - value[MAX_LINE-1] = 0; - break; - } - - pch = strtok(NULL, " =\r\n"); - } - - if (token[0] && value[0]) - { - /* Common */ - if (strcmp(token, "ApplicationId") == 0) - { - config->applicationId = (char *)malloc(strlen(value) + 1); - MALLOC_ASSERT(config->applicationId); - /** - * strcpy unritical here, because size matches exactly the - * size to be copied - */ - strcpy(config->applicationId, value); - } - else if (strcmp(token, "ApplicationContextID") == 0) - { - config->applicationContextId = (char *)malloc(strlen(value) + 1); - MALLOC_ASSERT(config->applicationContextId); - /** - * strcpy unritical here, because size matches exactly - * the size to be copied - */ - strcpy(config->applicationContextId, value); - } - /* Slogger2 */ - else if (strcmp(token, "QnxSlogger2Enable") == 0) - { - config->qnxslogger2.enable = atoi(value); - } - else if (strcmp(token, "QnxSlogger2ContextId") == 0) - { - config->qnxslogger2.contextId = (char *)malloc(strlen(value) + 1); - MALLOC_ASSERT(config->qnxslogger2.contextId); - /** - * strcpy unritical here, because size matches exactly - * the size to be copied - */ - strcpy(config->qnxslogger2.contextId, value); - } - else if (strcmp(token, "QnxSlogger2UseOriginalTimestamp") == 0) - { - config->qnxslogger2.useOriginalTimestamp = atoi(value); - } - else - { - /* Do nothing */ - } - } - } - - fclose(file); - file = NULL; - - free(value); - value = NULL; - - free(token); - token = NULL; - - free(line); - line = NULL; - - return ret; -} - -static void daemonize() -{ - pid_t pid = fork(); - - if (pid == -1) { - err(-1, "%s failed on fork()", __func__); - } - - if (pid > 0) { /* parent process*/ - exit(0); - } - - /* Create a new process group */ - if (setsid() == -1) { - err(-1, "%s failed on setsid()", __func__); - } - - /* Point std(in,out,err) to /dev/null */ - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - - int fd = open("/dev/null", O_RDWR); - if (fd == -1) { - err(-1, "%s failed on open() /dev/null", __func__); - } - - if ((dup2(fd, STDIN_FILENO) == -1) || - (dup2(fd, STDOUT_FILENO) == -1 ) || - (dup2(fd, STDERR_FILENO) == -1 )) { - err(-1, "%s failed on dup2()", __func__); - } - - /** - * Ignore signals related to child processes and - * terminal handling. - */ - signal(SIGCHLD, SIG_IGN); - signal(SIGTSTP, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - signal(SIGTTIN, SIG_IGN); -} - -static void start_threads(DltQnxSystemConfiguration *config) -{ - int i = 0; - - /* Check parameter */ - if (!config) - { - return; - } - - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-qnx-system, start threads")); - - g_threads.count = 0; - g_threads.shutdown = 0; - - for (i = 0; i < MAX_THREADS; i++) - { - g_threads.threads[i] = 0; - } - - if (config->qnxslogger2.enable) - { - start_qnx_slogger2(config); - } -} - -/** - * Wait for threads to exit. - */ -static void join_threads() -{ - int i = 0; - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-qnx-system, waiting for threads to exit")); - - if (g_threads.count < 1) - { - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-qnx-system, no threads, waiting for signal.")); - } - else - { - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-qnx-system, thread count: "), - DLT_INT(g_threads.count)); - - for (i = 0; i < g_threads.count; i++) - { - pthread_join(g_threads.threads[i], NULL); - DLT_LOG(dltQnxSystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-qnx-system, thread exit: "), - DLT_INT(g_threads.threads[i])); - } - } - - DLT_UNREGISTER_CONTEXT(dltQnxSystem); -} diff -Nru dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-system.conf dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-system.conf --- dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-system.conf 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-system.conf 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -# Configuration file of DLT QNX Slogger2 Manager -# - -######################################################################## -# General configuration -######################################################################## - -# The application Id used for the QNX system Manager (Default: QSYM) -ApplicationId = QSYM - -# Context of main dlt QNX system -ApplicationContextID = QSYC - -######################################################################## -# Syslog Adapter configuration -######################################################################## - -# Enable the Qnx slogger2 Adapter (Default: 1) -QnxSlogger2Enable = 1 - -# The Context Id of the Qnx syslog adapter (Default: QSLA) -QnxSlogger2ContextId = QSLA - -# Use slogger2 event timestamps as DLT timestamps (Default: 1) -QnxSlogger2UseOriginalTimestamp = 1 diff -Nru dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-system.h dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-system.h --- dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-qnx-system.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-qnx-system.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,110 +0,0 @@ -/** - * Copyright (C) 2020 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * DLT QNX system functionality header file. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Nguyen Dinh Thi ADIT 2020 - * - * \file: dlt-qnx-system.h - * For further information see http://www.genivi.org/. - * @licence end@ - */ - -/******************************************************************************* -** ** -** SRC-MODULE: dlt_qnx-system.h ** -** ** -** TARGET : QNX ** -** ** -** PROJECT : DLT ** -** ** -** AUTHOR : Thi.NguyenDinh@vn.bosch.com ** -** ** -** PURPOSE : ** -** ** -** REMARKS : ** -** ** -** PLATFORM DEPENDANT [yes/no]: yes ** -** ** -** TO BE CHANGED BY USER [yes/no]: no ** -** ** -*******************************************************************************/ - -/******************************************************************************* -** Author Identity ** -******************************************************************************** -** ** -** Initials Name Company ** -** -------- ------------------------- ---------------------------------- ** -** ndt Nguyen Dinh Thi ADIT ** -** ** -*******************************************************************************/ - -#ifndef DLT_QNX_SYSTEM_H_ -#define DLT_QNX_SYSTEM_H_ - -#include "dlt.h" -#include "dlt_user_macros.h" - -/* Constants */ -#define DEFAULT_CONF_FILE ( CONFIGURATION_FILES_DIR "/dlt-qnx-system.conf") - -#define MAX_LINE 1024 -#define MAX_THREADS 8 - -/* Macros */ -#define MALLOC_ASSERT(x)\ - do\ - {\ - if(x == NULL) {\ - fprintf(stderr, "%s - %d: Out of memory\n", __func__, __LINE__);\ - abort();\ - }\ - }\ - while (0) - -#ifdef __cplusplus -extern "C" { -#endif - -/* Command line options */ -typedef struct { - char *configurationFileName; - int daemonize; -} DltQnxSystemCliOptions; - -/* Configuration slogger2 options */ -typedef struct { - int enable; - char *contextId; - int useOriginalTimestamp; -} Qnxslogger2Options; - -typedef struct { - char *applicationId; - char *applicationContextId; - Qnxslogger2Options qnxslogger2; -} DltQnxSystemConfiguration; - -typedef struct { - pthread_t threads[MAX_THREADS]; - pthread_t mainThread; - int count; - int shutdown; -} DltQnxSystemThreads; - -void start_qnx_slogger2(DltQnxSystemConfiguration *conf); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* DLT_QNX_SYSTEM_H_ */ diff -Nru dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-slog2ctxt.json dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-slog2ctxt.json --- dlt-daemon-2.18.9/src/dlt-qnx-system/dlt-slog2ctxt.json 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/dlt-qnx-system/dlt-slog2ctxt.json 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -{ - "SRCN": { - "name": "screen", - "description": "" - }, - "SLM ": { - "name": "slm", - "description": "" - }, - "SYSL": { - "name": "syslogd", - "description": "" - } -} diff -Nru dlt-daemon-2.18.9/src/examples/CMakeLists.txt dlt-daemon-2.18.4/src/examples/CMakeLists.txt --- dlt-daemon-2.18.9/src/examples/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/examples/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -13,23 +13,38 @@ # For further information see http://www.genivi.org/. ####### -set(TARGET_LIST dlt-example-user-func) -set(TARGET_LIST ${TARGET_LIST} dlt-example-filetransfer) -if(NOT WITH_DLT_DISABLE_MACRO) - set(TARGET_LIST ${TARGET_LIST} dlt-example-user) - set(TARGET_LIST ${TARGET_LIST} dlt-example-user-common-api) -endif() +set(dlt_example_user_SRCS dlt-example-user.c) +add_executable(dlt-example-user ${dlt_example_user_SRCS}) +target_link_libraries(dlt-example-user dlt) +set_target_properties(dlt-example-user PROPERTIES LINKER_LANGUAGE C) + +set(dlt_example_user_common_api_SRCS dlt-example-user-common-api.c) +add_executable(dlt-example-user-common-api ${dlt_example_user_common_api_SRCS}) +target_link_libraries(dlt-example-user-common-api dlt) +set_target_properties(dlt-example-user-common-api PROPERTIES LINKER_LANGUAGE C) + +set(dlt_example_user_func_SRCS dlt-example-user-func.c) +add_executable(dlt-example-user-func ${dlt_example_user_func_SRCS}) +target_link_libraries(dlt-example-user-func dlt) +set_target_properties(dlt-example-user-func PROPERTIES LINKER_LANGUAGE C) + +set(dlt_example_filetransfer_SRCS dlt-example-filetransfer.c) +add_executable( dlt-example-filetransfer ${dlt_example_filetransfer_SRCS}) +target_link_libraries(dlt-example-filetransfer dlt ) +set_target_properties(dlt-example-filetransfer PROPERTIES LINKER_LANGUAGE C) if(WITH_UDP_CONNECTION) - set(TARGET_LIST ${TARGET_LIST} dlt-example-multicast-clientmsg-view) -endif() + set(dlt-example-multicast-clientmsg-view_SRCS dlt-example-multicast-clientmsg-view.c) + add_executable(dlt-example-multicast-clientmsg-view ${dlt-example-multicast-clientmsg-view_SRCS} ${dlt_most_SRCS}) + target_link_libraries(dlt-example-multicast-clientmsg-view dlt ) + set_target_properties(dlt-example-multicast-clientmsg-view PROPERTIES LINKER_LANGUAGE C) + + install(TARGETS dlt-example-multicast-clientmsg-view + RUNTIME DESTINATION bin + COMPONENT base) + +endif(WITH_UDP_CONNECTION) -foreach(TARGET IN LISTS TARGET_LIST) - set(TARGET_SRCS ${TARGET}) - add_executable(${TARGET} ${TARGET_SRCS}) - target_link_libraries(${TARGET} dlt) - set_target_properties(${TARGET} PROPERTIES LINKER_LANGUAGE C) - install(TARGETS ${TARGET} - RUNTIME DESTINATION bin - COMPONENT base) -endforeach() +install(TARGETS dlt-example-user dlt-example-user-func dlt-example-user-common-api dlt-example-filetransfer + RUNTIME DESTINATION bin + COMPONENT base) diff -Nru dlt-daemon-2.18.9/src/examples/dlt-example-multicast-clientmsg-view.c dlt-daemon-2.18.4/src/examples/dlt-example-multicast-clientmsg-view.c --- dlt-daemon-2.18.9/src/examples/dlt-example-multicast-clientmsg-view.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/examples/dlt-example-multicast-clientmsg-view.c 2019-09-03 08:28:13.000000000 +0000 @@ -15,7 +15,7 @@ * Sachin Sudhakar Shetty * Sunil Kovila Sampath * - * \copyright Copyright (c) 2019 LG Electronics Inc. + * \Copyright (c) 2019 LG Electronics Inc. * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt-example-multicast-clientmsg-view.c @@ -164,9 +164,7 @@ if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - if (dlt_receiver_init(&(clientinfo.receiver), - clientinfo.fd, - DLT_RECEIVE_UDP_SOCKET, + if (dlt_receiver_init(&(clientinfo.receiver), clientinfo.fd, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) return DLT_RETURN_ERROR; diff -Nru dlt-daemon-2.18.9/src/examples/dlt-example-user.c dlt-daemon-2.18.4/src/examples/dlt-example-user.c --- dlt-daemon-2.18.9/src/examples/dlt-example-user.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/examples/dlt-example-user.c 2019-09-03 08:28:13.000000000 +0000 @@ -98,15 +98,12 @@ printf("Options:\n"); printf(" -d delay Milliseconds to wait between sending messages (Default: 500)\n"); printf(" -f filename Use local log file instead of sending to daemon\n"); - printf(" -S filesize Set maximum size of local log file (Default: UINT_MAX)\n"); printf(" -n count Number of messages to be generated (Default: 10)\n"); printf(" -g Switch to non-verbose mode (Default: verbose mode)\n"); printf(" -a Enable local printing of DLT messages (Default: disabled)\n"); printf(" -k Send marker message\n"); - printf(" -m mode Set log mode 0=off, 1=external, 2=internal, 3=both\n"); + printf(" -m mode Set log mode 0=off,1=external,2=internal,3=both\n"); printf(" -l level Set log level to , level=-1..6\n"); - printf(" -C ContextID Set context ID for send message (Default: TEST)\n"); - printf(" -A AppID Set app ID for send message (Default: LOG)\n"); printf(" -t timeout Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n"); printf(" -r size Send raw data with specified size instead of string\n"); #ifdef DLT_TEST_ENABLE @@ -131,7 +128,6 @@ #endif /* DLT_TEST_ENABLE */ char *dvalue = 0; char *fvalue = 0; - unsigned int filesize = 0; char *nvalue = 0; char *mvalue = 0; char *message = 0; @@ -141,9 +137,6 @@ int index; int c; - char *appID = "LOG"; - char *contextID = "TEST"; - char *text; int num, maxnum; int delay; @@ -154,10 +147,10 @@ opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgakcd:f:S:n:m:z:r:s:l:t:A:C:")) != -1) + while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:r:s:l:t:")) != -1) #else - while ((c = getopt (argc, argv, "vgakd:f:S:n:m:l:r:t:A:C:")) != -1) + while ((c = getopt (argc, argv, "vgakd:f:n:m:l:r:t:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) { @@ -203,11 +196,6 @@ fvalue = optarg; break; } - case 'S': - { - filesize = atoi(optarg); - break; - } case 'n': { nvalue = optarg; @@ -223,16 +211,6 @@ lvalue = atoi(optarg); break; } - case 'A': - { - appID = optarg; - break; - } - case 'C': - { - contextID = optarg; - break; - } case 't': { tvalue = optarg; @@ -245,8 +223,7 @@ } case '?': { - if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n') || - (optopt == 'l') || (optopt == 't') || (optopt == 'S')) + if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n') || (optopt == 'l') || (optopt == 't')) fprintf (stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); @@ -287,18 +264,13 @@ return -1; } - if (filesize != 0) { - if (dlt_set_filesize_max(filesize) < 0) - return -1; - } - dlt_with_session_id(1); dlt_with_timestamp(1); dlt_with_ecu_id(1); dlt_verbose_mode(); - DLT_REGISTER_APP(appID, "Test Application for Logging"); - DLT_REGISTER_CONTEXT(mycontext1, contextID, "Test Context for Logging"); + DLT_REGISTER_APP("LOG", "Test Application for Logging"); + DLT_REGISTER_CONTEXT(mycontext1, "TEST", "Test Context for Logging"); DLT_REGISTER_CONTEXT_LLCCB(mycontext2, "TS1", "Test Context1 for injection", dlt_user_log_level_changed_callback); DLT_REGISTER_CONTEXT_LLCCB(mycontext3, "TS2", "Test Context2 for injection", dlt_user_log_level_changed_callback); @@ -338,9 +310,9 @@ maxnum = 10; if (dvalue) - delay = atoi(dvalue); + delay = atoi(dvalue) * 1000000; else - delay = 500; + delay = 500 * 1000000; if (tvalue) dlt_set_resend_timeout_atexit(atoi(tvalue)); @@ -406,8 +378,8 @@ } if (delay > 0) { - ts.tv_sec = delay / 1000; - ts.tv_nsec = (delay % 1000) * 1000000; + ts.tv_sec = delay / 1000000000; + ts.tv_nsec = delay % 1000000000; nanosleep(&ts, NULL); } } diff -Nru dlt-daemon-2.18.9/src/gateway/dlt_gateway.c dlt-daemon-2.18.4/src/gateway/dlt_gateway.c --- dlt-daemon-2.18.9/src/gateway/dlt_gateway.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/gateway/dlt_gateway.c 2019-09-03 08:28:13.000000000 +0000 @@ -193,31 +193,7 @@ con->timeout = (int)strtol(value, NULL, 10); - - if (con->timeout >= 0) - return DLT_RETURN_OK; - - return DLT_RETURN_ERROR; -} - -/** - * Check connection interval value in General section - * - * @param con DltGateway to be updated - * @param value string to be tested - * @return Value from DltReturnValue enum - */ -DLT_STATIC DltReturnValue dlt_gateway_check_interval(DltGateway *gateway, - char *value) -{ - if ((gateway == NULL) || (value == NULL)) { - dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); - return DLT_RETURN_WRONG_PARAMETER; - } - - gateway->interval = (int)strtol(value, NULL, 10); - - if (gateway->interval > 0) + if (con->timeout > 0) return DLT_RETURN_OK; return DLT_RETURN_ERROR; @@ -516,40 +492,9 @@ } }; -DLT_STATIC DltGatewayGeneralConf general_entries[GW_CONF_COUNT] = { - [GW_CONF_GENERAL_INTERVAL] = { - .key = "Interval", - .func = dlt_gateway_check_interval, - .is_opt = 1 - } -}; - #define DLT_GATEWAY_NUM_PROPERTIES_MAX GW_CONF_COUNT /** - * Check if gateway connection general configuration parameter is valid. - * - * @param gateway DltGateway - * @param ctype DltGatwayGeneralConnection property - * @param value specified property value from configuration file - * @return Value from DltReturnValue enum - */ -DLT_STATIC DltReturnValue dlt_gateway_check_general_param(DltGateway *gateway, - DltGatewayGeneralConfType ctype, - char *value) -{ - if ((gateway == NULL) || (value == NULL)) { - dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); - return DLT_RETURN_WRONG_PARAMETER; - } - - if (ctype < GW_CONF_GENEREL_COUNT) - return general_entries[ctype].func(gateway, value); - - return DLT_RETURN_ERROR; -} - -/** * Check if gateway connection configuration parameter is valid. * * @param gateway DltGateway @@ -658,7 +603,6 @@ int ret = 0; int i = 0; DltConfigFile *file = NULL; - int num_sections = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -669,39 +613,18 @@ /* read configuration file */ file = dlt_config_file_init(config_file); - if(file == NULL) { - return DLT_RETURN_ERROR; - } /* get number of entries and allocate memory to store information */ - ret = dlt_config_file_get_num_sections(file, &num_sections); + ret = dlt_config_file_get_num_sections(file, &gateway->num_connections); + if (ret != 0) { dlt_config_file_release(file); dlt_log(LOG_ERR, "Invalid number of sections in configuration file\n"); return DLT_RETURN_ERROR; } - ret = dlt_config_file_check_section_name_exists(file, DLT_GATEWAY_GENERAL_SECTION_NAME); - if (ret == -1) { - /* - * No General section in configuration file. - * Try to use default for interval. - */ - gateway->num_connections = num_sections; - dlt_vlog(LOG_WARNING, - "Missing General section in gateway. Using default interval %d (secs)\n", - gateway->interval); - } - else { - /* - * Since the General section is also counted in num_sections, - * so number of connections must be number of sections - 1. - */ - gateway->num_connections = num_sections - 1; - } - - gateway->connections = calloc(gateway->num_connections, - sizeof(DltGatewayConnection)); + gateway->connections = calloc(sizeof(DltGatewayConnection), + gateway->num_connections); if (gateway->connections == NULL) { dlt_config_file_release(file); @@ -709,11 +632,10 @@ return DLT_RETURN_ERROR; } - for (i = 0; i < num_sections; i++) { + for (i = 0; i < gateway->num_connections; i++) { DltGatewayConnection tmp; int invalid = 0; DltGatewayConfType j = 0; - DltGatewayGeneralConfType g = 0; char section[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; @@ -724,103 +646,57 @@ tmp.port = DLT_DAEMON_TCP_PORT; ret = dlt_config_file_get_section_name(file, i, section); - if (ret != 0) { - dlt_log(LOG_WARNING, "Get section name failed\n"); - continue; - } - - if (strncmp(section, DLT_GATEWAY_GENERAL_SECTION_NAME, - sizeof(DLT_GATEWAY_GENERAL_SECTION_NAME)) == 0) { - for (g = 0; g < GW_CONF_GENEREL_COUNT; g++) { - ret = dlt_config_file_get_value(file, - section, - general_entries[g].key, - value); - - if ((ret != 0) && general_entries[g].is_opt) { - /* Use default values for this key */ - dlt_vlog(LOG_WARNING, - "Using default for %s.\n", - general_entries[g].key); - continue; - } - else if (ret != 0) - { - dlt_vlog(LOG_WARNING, - "Missing configuration for %s.\n", - general_entries[g].key); - break; - } - - /* check value and store general configuration */ - ret = dlt_gateway_check_general_param(gateway, g, value); - if (ret != 0) - dlt_vlog(LOG_ERR, - "Configuration %s = %s is invalid. Using default.\n", - general_entries[g].key, value); - } - } - else { - for (j = 0; j < GW_CONF_COUNT; j++) { - ret = dlt_config_file_get_value(file, - section, - configuration_entries[j].key, - value); + for (j = 0; j < GW_CONF_COUNT; j++) { + ret = dlt_config_file_get_value(file, + section, + configuration_entries[j].key, + value); - if ((ret != 0) && configuration_entries[j].is_opt) { - /* Use default values for this key */ - dlt_vlog(LOG_WARNING, - "Using default for %s.\n", - configuration_entries[j].key); - continue; - } - else if (ret != 0) - { - dlt_vlog(LOG_WARNING, - "Missing configuration for %s.\n", - configuration_entries[j].key); - invalid = 1; - break; - } - - /* check value and store temporary */ - ret = dlt_gateway_check_param(gateway, &tmp, j, value); - - if (ret != 0) - dlt_vlog(LOG_ERR, - "Configuration %s = %s is invalid.\n" - "Using default.\n", - configuration_entries[j].key, value); + if ((ret != 0) && configuration_entries[j].is_opt) { + /* Use default values for this key */ + dlt_vlog(LOG_WARNING, + "Using default for %s.\n", + configuration_entries[j].key); + continue; } - - if (!tmp.ip_address) { + else if (ret != 0) + { + dlt_vlog(LOG_WARNING, + "Missing configuration for %s.\n", + configuration_entries[j].key); invalid = 1; + break; } - if (invalid) { + /* check value and store temporary */ + ret = dlt_gateway_check_param(gateway, &tmp, j, value); + + if (ret != 0) dlt_vlog(LOG_ERR, - "%s configuration is invalid.\n" - "Ignoring.\n", - section); - } - else { - ret = dlt_gateway_store_connection(gateway, &tmp, verbose); + "Configuration %s = %s is invalid.\n" + "Using default.\n", + configuration_entries[j].key, value); + } - if (ret != 0) - dlt_log(LOG_ERR, "Storing gateway connection data failed\n"); - } + if (invalid) { + dlt_vlog(LOG_ERR, + "%s configuration is invalid.\n" + "Ignoring.\n", + section); } + else { + ret = dlt_gateway_store_connection(gateway, &tmp, verbose); - /* strdup used inside some get_value function */ - if (tmp.ecuid != NULL) { - free(tmp.ecuid); - tmp.ecuid = NULL; - } - if (tmp.ip_address != NULL) { - free(tmp.ip_address); - tmp.ip_address = NULL; + if (ret != 0) + dlt_log(LOG_ERR, "Storing gateway connection data failed\n"); } + + /* strdup used inside some get_value function */ + free(tmp.ecuid); + tmp.ecuid = NULL; + free(tmp.ip_address); + tmp.ip_address = NULL; } dlt_config_file_release(file); @@ -841,7 +717,6 @@ if (gateway != NULL) { /* Get default value from daemon_local */ gateway->send_serial = daemon_local->flags.lflag; - gateway->interval = DLT_GATEWAY_TIMER_DEFAULT_INTERVAL; if (dlt_gateway_configure(gateway, daemon_local->flags.gatewayConfigFile, @@ -998,16 +873,11 @@ con->timeout_cnt++; - if (con->timeout > 0) { - if (con->timeout_cnt > con->timeout) { - con->trigger = DLT_GATEWAY_DISABLED; - dlt_log(LOG_WARNING, - "Passive Node connection retry timed out. " - "Give up.\n"); - } - } - else if (con->timeout == 0) { - dlt_vlog(LOG_DEBUG, "Retried [%d] times\n", con->timeout_cnt); + if (con->timeout_cnt > con->timeout) { + con->trigger = DLT_GATEWAY_DISABLED; + dlt_log(LOG_WARNING, + "Passive Node connection retry timed out. " + "Give up.\n"); } } } @@ -1101,7 +971,7 @@ return DLT_RETURN_WRONG_PARAMETER; } - if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceGetLogInfoResponse)) < 0) + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceGetLogInfoResponse)) < 0) return DLT_RETURN_ERROR; /* if the request was send from gateway, clear all application and context list */ @@ -1223,7 +1093,7 @@ return DLT_RETURN_WRONG_PARAMETER; } - if (dlt_check_rcv_data_size(msg->datasize, + if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceGetDefaultLogLevelResponse)) < 0) { dlt_log(LOG_ERR, "Received data incomplete.\n"); return DLT_RETURN_ERROR; @@ -1292,7 +1162,6 @@ DltGateway *gateway = NULL; DltGatewayConnection *con = NULL; DltMessage msg = { 0 }; - bool b_reset_receiver = false; if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -1309,11 +1178,13 @@ } for (i = 0; i < gateway->num_connections; i++) - if ((gateway->connections[i].status == DLT_GATEWAY_CONNECTED) && (gateway->connections[i].client.sock == receiver->fd)) { + if (gateway->connections[i].client.sock == receiver->fd) { con = &gateway->connections[i]; break; } + + if (con == NULL) { dlt_log(LOG_ERR, "Cannot associate fd to passive Node connection\n"); return DLT_RETURN_ERROR; @@ -1327,7 +1198,7 @@ } /* nearly copy and paste of dlt_client_main_loop function */ - if (dlt_receiver_receive(receiver) <= 0) { + if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0) { /* No more data to be received */ if (dlt_message_free(&msg, verbose) < 0) { dlt_log(LOG_ERR, "Cannot free DLT message\n"); @@ -1364,15 +1235,14 @@ sizeof(DltStandardHeader)); /* only forward messages if the received ECUid is the expected one */ - if (strncmp(header->ecu, con->ecuid, DLT_ID_SIZE) == 0) { + if (strncmp(header->ecu, con->ecuid, strlen(con->ecuid)) == 0) { uint32_t id; uint32_t id_tmp; DltPassiveControlMessage *control_msg = con->p_control_msgs; dlt_vlog(LOG_DEBUG, - "Received ECUid (%.*s) similar to configured ECUid(%s). " + "Received ECUid (%s) similar to configured ECUid(%s). " "Forwarding message (%s).\n", - DLT_ID_SIZE, header->ecu, con->ecuid, msg.databuffer); @@ -1423,7 +1293,7 @@ return DLT_RETURN_ERROR; } - dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, + if (dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, msg.headerbuffer, @@ -1432,12 +1302,13 @@ msg.headersize - sizeof(DltStorageHeader), msg.databuffer, msg.datasize, - verbose); - } else { /* otherwise remove this connection and do not connect again */ + verbose) != DLT_DAEMON_ERROR_OK) + dlt_log(LOG_WARNING, "Forward message to clients failed!\n"); + } + else { /* otherwise remove this connection and do not connect again */ dlt_vlog(LOG_WARNING, - "Received ECUid (%.*s) differs to configured ECUid(%s). " + "Received ECUid (%s) differs to configured ECUid(%s). " "Discard this message.\n", - DLT_ID_SIZE, header->ecu, con->ecuid); @@ -1453,11 +1324,6 @@ dlt_log(LOG_WARNING, "Disconnect from passive node due to invalid ECUid\n"); - - /* it is possible that a partial log was received through the last recv call */ - /* however, the rest will never be received since the socket will be closed by above method */ - /* as such, we need to reset the receiver to prevent permanent corruption */ - b_reset_receiver = true; } if (msg.found_serialheader) { @@ -1481,9 +1347,6 @@ } } - if (b_reset_receiver) - dlt_receiver_remove(receiver, receiver->bytesRcvd); - if (dlt_receiver_move_to_begin(receiver) == -1) { /* Return value ignored */ dlt_message_free(&msg, verbose); @@ -1555,7 +1418,7 @@ for (i = 0; i < gateway->num_connections; i++) if (strncmp(gateway->connections[i].ecuid, ecu, - DLT_ID_SIZE) == 0) { + strlen(gateway->connections[i].ecuid)) == 0) { con = &gateway->connections[i]; break; } @@ -1613,7 +1476,7 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway, DltDaemonLocal *daemon_local, - char node_id[DLT_ID_SIZE], + char *node_id, int connection_status, int verbose) { @@ -1628,12 +1491,13 @@ } /* find connection by ECU id */ - for (i = 0; i < gateway->num_connections; i++) { - if (strncmp(node_id, gateway->connections[i].ecuid, DLT_ID_SIZE) == 0) { + for (i = 0; i < gateway->num_connections; i++) + if (strncmp(node_id, gateway->connections->ecuid, DLT_ID_SIZE) == 0) { con = &gateway->connections[i]; break; } - } + + if (con == NULL) { dlt_log(LOG_WARNING, "Specified ECUid not found\n"); diff -Nru dlt-daemon-2.18.9/src/gateway/dlt_gateway.conf dlt-daemon-2.18.4/src/gateway/dlt_gateway.conf --- dlt-daemon-2.18.9/src/gateway/dlt_gateway.conf 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/gateway/dlt_gateway.conf 2019-09-03 08:28:13.000000000 +0000 @@ -1,7 +1,3 @@ -[General] -; Time interval for reconnection to passive Node in second. -; Interval=1 - [PassiveNode1] IPaddress=192.168.2.11 ; TCP port. Default 3490 is used if no port is specified. @@ -10,11 +6,8 @@ EcuID=ECU2 ; Try connect to passive Node on DLT Daemon startup. Default OnStartup if not specified. ; Connect=OnStartup - -; Stop connecting to passive node, if not successful after 10 retries. -; Set to 0 for endless retry. +; Stop connecting to passive node, if not successful after 10 seconds Timeout=10 - ; Send following control messages after connection is established ; SendControl=0x03,0x04,0x13 ; Send Serial Header with control messages. Value in dlt.conf is used as default if not specified. diff -Nru dlt-daemon-2.18.9/src/gateway/dlt_gateway_types.h dlt-daemon-2.18.4/src/gateway/dlt_gateway_types.h --- dlt-daemon-2.18.9/src/gateway/dlt_gateway_types.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/gateway/dlt_gateway_types.h 2019-09-03 08:28:13.000000000 +0000 @@ -60,8 +60,7 @@ #include "dlt_client.h" #define DLT_GATEWAY_CONFIG_PATH CONFIGURATION_FILES_DIR "/dlt_gateway.conf" -#define DLT_GATEWAY_TIMER_DEFAULT_INTERVAL 1 -#define DLT_GATEWAY_GENERAL_SECTION_NAME "General" +#define DLT_GATEWAY_TIMER_INTERVAL 1 #define DLT_GATEWAY_RECONNECT_MAX 1 /* reconnect once after connection loss */ @@ -140,7 +139,6 @@ int send_serial; /* Default: Send serial header with control messages */ DltGatewayConnection *connections; /* pointer to connections */ int num_connections; /* number of connections */ - int interval; /* interval of retry connection */ } DltGateway; typedef struct { @@ -149,12 +147,6 @@ int is_opt; /* If the configuration is optional or not */ } DltGatewayConf; -typedef struct { - char *key; /* The configuration key*/ - int (*func)(DltGateway *gateway, char *value); /* Conf handler */ - int is_opt; /* If the configuration is optional or not */ -} DltGatewayGeneralConf; - typedef enum { GW_CONF_IP_ADDRESS = 0, GW_CONF_PORT, @@ -167,9 +159,4 @@ GW_CONF_COUNT } DltGatewayConfType; -typedef enum { - GW_CONF_GENERAL_INTERVAL = 0, - GW_CONF_GENEREL_COUNT -} DltGatewayGeneralConfType; - #endif /* DLT_GATEWAY_TYPES_H_ */ diff -Nru dlt-daemon-2.18.9/src/lib/CMakeLists.txt dlt-daemon-2.18.4/src/lib/CMakeLists.txt --- dlt-daemon-2.18.9/src/lib/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -19,7 +19,6 @@ dlt_filetransfer.c dlt_env_ll.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_common.c - ${PROJECT_SOURCE_DIR}/src/shared/dlt_multiple_files.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_protocol.c ${PROJECT_SOURCE_DIR}/src/shared/dlt_user_shared.c ) @@ -30,7 +29,7 @@ add_library(dlt ${dlt_LIB_SRCS}) -if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN") +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(RT_LIBRARY rt) set(SOCKET_LIBRARY "") else() @@ -45,63 +44,11 @@ message(STATUS "pthread_setname_np API not available on this platform") endif() -target_link_libraries(dlt ${RT_LIBRARY} ${SOCKET_LIBRARY} Threads::Threads) - -target_include_directories(dlt - PUBLIC - $ - $ - $ -) -# With this option set, a legacy include path is added in addition to the regular one. -if(WITH_LEGACY_INCLUDE_PATH) - target_include_directories(dlt - PUBLIC - $ - ) -endif() - -if(WITH_LIB_SHORT_VERSION) - set_target_properties(dlt PROPERTIES VERSION ${PROJECT_VERSION_MAJOR} SOVERSION ${PROJECT_VERSION_MAJOR}) -else() - set_target_properties(dlt PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) -endif() - -add_library(Genivi::dlt ALIAS dlt) +target_link_libraries(dlt ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) +set_target_properties(dlt PROPERTIES VERSION ${DLT_VERSION} SOVERSION ${DLT_MAJOR_VERSION}) install(TARGETS dlt - EXPORT - ${PROJECT_NAME}-targets - RUNTIME - DESTINATION bin - COMPONENT base - LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT base - ARCHIVE - DESTINATION ${CMAKE_INSTALL_LIBDIR}/static + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static COMPONENT base) - -# Install *-targets.cmake file -install( - EXPORT ${PROJECT_NAME}-targets - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - NAMESPACE Genivi:: -) - -# Create *-config.cmake file -include(CMakePackageConfigHelpers) -configure_package_config_file( - ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake.in - ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - NO_SET_AND_CHECK_MACRO -) - -# Install *-config.cmake file -install( - FILES - ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake - DESTINATION - ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} -) diff -Nru dlt-daemon-2.18.9/src/lib/dlt_client.c dlt-daemon-2.18.4/src/lib/dlt_client.c --- dlt-daemon-2.18.9/src/lib/dlt_client.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/dlt_client.c 2019-09-03 08:28:13.000000000 +0000 @@ -91,32 +91,22 @@ #include /* for strlen(), memcmp(), memmove() */ #include #include -#include #include "dlt_types.h" #include "dlt_client.h" #include "dlt_client_cfg.h" static int (*message_callback_function)(DltMessage *message, void *data) = NULL; -static bool (*fetch_next_message_callback_function)(void *data) = NULL; void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data)) { message_callback_function = registerd_callback; } -void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void *data)) -{ - fetch_next_message_callback_function = registerd_callback; -} - DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose) { if (verbose && (port != DLT_DAEMON_TCP_PORT)) - dlt_vlog(LOG_INFO, - "%s: Init dlt client struct with port %d\n", - __func__, - port); + dlt_vlog(LOG_INFO, "Init dlt client struct with port %d\n", port); if (client == NULL) return DLT_RETURN_ERROR; @@ -131,7 +121,6 @@ client->receiver.buffer = NULL; client->receiver.buf = NULL; client->receiver.backup_buf = NULL; - client->hostip = NULL; return DLT_RETURN_OK; } @@ -151,8 +140,7 @@ if ((tmp_port < IPPORT_RESERVED) || ((unsigned)tmp_port > USHRT_MAX)) { dlt_vlog(LOG_ERR, - "%s: Specified port is out of possible range: %d.\n", - __func__, + "Specified port is out of possible range: %d.\n", tmp_port); return DLT_RETURN_ERROR; } @@ -163,28 +151,18 @@ if (verbose) dlt_vlog(LOG_INFO, - "%s: Init dlt client struct with default port: %hu.\n", - __func__, + "Init dlt client struct with default port: %hu.\n", servPort); + return dlt_client_init_port(client, servPort, verbose); } DltReturnValue dlt_client_connect(DltClient *client, int verbose) { - const int yes = 1; - char portnumbuffer[33] = {0}; + char portnumbuffer[33]; struct addrinfo hints, *servinfo, *p; struct sockaddr_un addr; int rv; - struct ip_mreq mreq; - DltReceiverType receiver_type = DLT_RECEIVE_FD; - - struct pollfd pfds[1]; - int ret; - int n; - socklen_t m = sizeof(n); - int connect_errno = 0; - memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; @@ -196,97 +174,35 @@ snprintf(portnumbuffer, 32, "%d", client->port); if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) { - dlt_vlog(LOG_ERR, - "%s: getaddrinfo: %s\n", - __func__, - gai_strerror(rv)); + fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return DLT_RETURN_ERROR; } for (p = servinfo; p != NULL; p = p->ai_next) { if ((client->sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) { - dlt_vlog(LOG_WARNING, - "%s: socket() failed! %s\n", - __func__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "socket() failed! %s\n", strerror(errno)); continue; } - /* Set socket to Non-blocking mode */ - if(fcntl(client->sock, F_SETFL, fcntl(client->sock,F_GETFL,0) | O_NONBLOCK) < 0) - { - dlt_vlog(LOG_WARNING, - "%s: Socket cannot be changed to NON BLOCK: %s\n", - __func__, strerror(errno)); + if (connect(client->sock, p->ai_addr, p->ai_addrlen) < 0) { close(client->sock); + dlt_vlog(LOG_WARNING, "connect() failed! %s\n", + strerror(errno)); continue; } - if (connect(client->sock, p->ai_addr, p->ai_addrlen) < 0) { - if (errno == EINPROGRESS) { - pfds[0].fd = client->sock; - pfds[0].events = POLLOUT; - ret = poll(pfds, 1, 500); - if (ret < 0) { - dlt_vlog(LOG_ERR, "%s: Failed to poll with err [%s]\n", - __func__, strerror(errno)); - close(client->sock); - continue; - } - else if ((pfds[0].revents & POLLOUT) && - getsockopt(client->sock, SOL_SOCKET, - SO_ERROR, (void*)&n, &m) == 0) { - if (n == 0) { - dlt_vlog(LOG_DEBUG, "%s: Already connect\n", __func__); - if(fcntl(client->sock, F_SETFL, - fcntl(client->sock,F_GETFL,0) & ~O_NONBLOCK) < 0) { - dlt_vlog(LOG_WARNING, - "%s: Socket cannot be changed to BLOCK with err [%s]\n", - __func__, strerror(errno)); - close(client->sock); - continue; - } - } - else { - connect_errno = n; - close(client->sock); - continue; - } - } - else { - connect_errno = errno; - close(client->sock); - continue; - } - } - else { - connect_errno = errno; - close(client->sock); - continue; - } - } - break; } freeaddrinfo(servinfo); if (p == NULL) { - dlt_vlog(LOG_ERR, - "%s: ERROR: failed to connect! %s\n", - __func__, - strerror(connect_errno)); + dlt_log(LOG_ERR, "ERROR: failed to connect.\n"); return DLT_RETURN_ERROR; } - if (verbose) { - dlt_vlog(LOG_INFO, - "%s: Connected to DLT daemon (%s)\n", - __func__, - client->servIP); - } - - receiver_type = DLT_RECEIVE_SOCKET; + if (verbose) + printf("Connected to DLT daemon (%s)\n", client->servIP); break; case DLT_CLIENT_MODE_SERIAL: @@ -294,10 +210,7 @@ client->sock = open(client->serialDevice, O_RDWR); if (client->sock < 0) { - dlt_vlog(LOG_ERR, - "%s: ERROR: Failed to open device %s\n", - __func__, - client->serialDevice); + fprintf(stderr, "ERROR: Failed to open device %s\n", client->serialDevice); return DLT_RETURN_ERROR; } @@ -305,11 +218,8 @@ #if !defined (__WIN32__) if (dlt_setup_serial(client->sock, client->baudrate) < DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, - "%s: ERROR: Failed to configure serial device %s (%s) \n", - __func__, - client->serialDevice, - strerror(errno)); + fprintf(stderr, "ERROR: Failed to configure serial device %s (%s) \n", client->serialDevice, + strerror(errno)); return DLT_RETURN_ERROR; } @@ -319,32 +229,22 @@ } else { if (verbose) - dlt_vlog(LOG_ERR, - "%s: ERROR: Device is not a serial device, device = %s (%s) \n", - __func__, - client->serialDevice, - strerror(errno)); + fprintf(stderr, + "ERROR: Device is not a serial device, device = %s (%s) \n", + client->serialDevice, + strerror(errno)); return DLT_RETURN_ERROR; } if (verbose) - dlt_vlog(LOG_INFO, - "%s: Connected to %s\n", - __func__, - client->serialDevice); - - receiver_type = DLT_RECEIVE_FD; + printf("Connected to %s\n", client->serialDevice); break; case DLT_CLIENT_MODE_UNIX: if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - dlt_vlog(LOG_ERR, - "%s: ERROR: (unix) socket error: %s\n", - __func__, - strerror(errno)); - + fprintf(stderr, "ERROR: (unix) socket error: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } @@ -355,119 +255,27 @@ if (connect(client->sock, (struct sockaddr *) &addr, sizeof(addr)) == -1) { - dlt_vlog(LOG_ERR, - "%s: ERROR: (unix) connect error: %s\n", - __func__, - strerror(errno)); - + fprintf(stderr, "ERROR: (unix) connect error: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } if (client->sock < 0) { - dlt_vlog(LOG_ERR, - "%s: ERROR: Failed to open device %s\n", - __func__, - client->socketPath); - + fprintf(stderr, "ERROR: Failed to open device %s\n", + client->socketPath); return DLT_RETURN_ERROR; } - receiver_type = DLT_RECEIVE_SOCKET; - - break; - case DLT_CLIENT_MODE_UDP_MULTICAST: - - if ((client->sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: socket error: %s\n", - __func__, - strerror(errno)); - - return DLT_RETURN_ERROR; - } - - /* allow multiple sockets to use the same PORT number */ - if (setsockopt(client->sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: Reusing address failed: %s\n", - __func__, - strerror(errno)); - - return DLT_RETURN_ERROR; - } - - memset(&client->receiver.addr, 0, sizeof(client->receiver.addr)); - client->receiver.addr.sin_family = AF_INET; - client->receiver.addr.sin_addr.s_addr = htonl(INADDR_ANY); - client->receiver.addr.sin_port = htons(client->port); - - /* bind to receive address */ - if (bind(client->sock, (struct sockaddr*) &client->receiver.addr, sizeof(client->receiver.addr)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: bind failed: %s\n", - __func__, - strerror(errno)); - - return DLT_RETURN_ERROR; - } - - mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if (client->hostip) - { - mreq.imr_interface.s_addr = inet_addr(client->hostip); - } - if (client->servIP == NULL) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: server address not set\n", - __func__); - - return DLT_RETURN_ERROR; - } - - char delimiter[] = ","; - char* servIP = strtok(client->servIP, delimiter); - - while(servIP != NULL) { - mreq.imr_multiaddr.s_addr = inet_addr(servIP); - if (mreq.imr_multiaddr.s_addr == (in_addr_t)-1) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: server address not not valid %s\n", - __func__, - servIP); - - return DLT_RETURN_ERROR; - } - - if (setsockopt(client->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: setsockopt add membership failed: %s\n", - __func__, - strerror(errno)); - - return DLT_RETURN_ERROR; - } - servIP = strtok(NULL, delimiter); - } - receiver_type = DLT_RECEIVE_UDP_SOCKET; - break; default: - dlt_vlog(LOG_ERR, - "%s: ERROR: Mode not supported: %d\n", - __func__, - client->mode); + + if (verbose) + fprintf(stderr, "ERROR: Mode not supported: %d\n", client->mode); return DLT_RETURN_ERROR; } - if (dlt_receiver_init(&(client->receiver), client->sock, receiver_type, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, "%s: ERROR initializing receiver\n", __func__); + if (dlt_receiver_init(&(client->receiver), client->sock, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR initializing receiver\n"); return DLT_RETURN_ERROR; } @@ -479,7 +287,7 @@ int ret = DLT_RETURN_OK; if (verbose) - dlt_vlog(LOG_INFO, "%s: Cleanup dlt client\n", __func__); + printf("Cleanup dlt client\n"); if (client == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -488,8 +296,8 @@ close(client->sock); if (dlt_receiver_free(&(client->receiver)) != DLT_RETURN_OK) { - dlt_vlog(LOG_WARNING, "%s: Failed to free receiver\n", __func__); - ret = DLT_RETURN_ERROR; + dlt_vlog(LOG_WARNING, "Failed to free receiver\n"); + ret = DLT_RETURN_ERROR; } if (client->serialDevice) { @@ -507,10 +315,6 @@ client->socketPath = NULL; } - if (client->hostip) { - free(client->hostip); - client->hostip = NULL; - } return ret; } @@ -525,10 +329,9 @@ if (dlt_message_init(&msg, verbose) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - bool fetch_next_message = true; - while (fetch_next_message) { + while (1) { /* wait for data from socket or serial connection */ - ret = dlt_receiver_receive(&(client->receiver)); + ret = dlt_receiver_receive(&(client->receiver), client->mode); if (ret <= 0) { /* No more data to be received */ @@ -538,19 +341,16 @@ return DLT_RETURN_TRUE; } - while (dlt_message_read(&msg, (unsigned char *)(client->receiver.buf), - client->receiver.bytesRcvd, - client->resync_serial_header, - verbose) == DLT_MESSAGE_ERROR_OK) - { + while (dlt_message_read(&msg, (unsigned char *)(client->receiver.buf), client->receiver.bytesRcvd, 0, + verbose) == DLT_MESSAGE_ERROR_OK) { /* Call callback function */ if (message_callback_function) (*message_callback_function)(&msg, data); if (msg.found_serialheader) { if (dlt_receiver_remove(&(client->receiver), - (int) (msg.headersize + msg.datasize - sizeof(DltStorageHeader) + - sizeof(dltSerialHeader))) == + msg.headersize + msg.datasize - sizeof(DltStorageHeader) + + sizeof(dltSerialHeader)) == DLT_RETURN_ERROR) { /* Return value ignored */ dlt_message_free(&msg, verbose); @@ -558,7 +358,7 @@ } } else if (dlt_receiver_remove(&(client->receiver), - (int) (msg.headersize + msg.datasize - sizeof(DltStorageHeader))) == + msg.headersize + msg.datasize - sizeof(DltStorageHeader)) == DLT_RETURN_ERROR) { /* Return value ignored */ dlt_message_free(&msg, verbose); @@ -571,8 +371,6 @@ dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; } - if (fetch_next_message_callback_function) - fetch_next_message = (*fetch_next_message_callback_function)(data); } if (dlt_message_free(&msg, verbose) == DLT_RETURN_ERROR) @@ -581,48 +379,6 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *msg) -{ - int ret = 0; - - if ((client == NULL) || (client->sock < 0) - || (msg == NULL) || (msg->databuffer == NULL)) - { - dlt_log(LOG_ERR, "Invalid parameters\n"); - return DLT_RETURN_ERROR; - } - - if (client->send_serial_header) - { - ret = send(client->sock, (const char *)dltSerialHeader, - sizeof(dltSerialHeader), 0); - if (ret < 0) - { - dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", - strerror(errno)); - return DLT_RETURN_ERROR; - } - } - - ret = send(client->sock, - (const char *)(msg->headerbuffer + sizeof(DltStorageHeader)), - msg->headersize - sizeof(DltStorageHeader), 0); - if (ret < 0) - { - dlt_vlog(LOG_ERR, "Sending message header failed: %s\n", strerror(errno)); - return DLT_RETURN_ERROR; - } - - ret = send(client->sock, (const char *)msg->databuffer, msg->datasize, 0); - if ( ret < 0) - { - dlt_vlog(LOG_ERR, "Sending message failed: %s\n", strerror(errno)); - return DLT_RETURN_ERROR; - } - - return DLT_RETURN_OK; -} - DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size) { DltMessage msg; @@ -703,19 +459,16 @@ dlt_set_id(msg.extendedheader->ctid, (ctid[0] == '\0') ? DLT_CLIENT_DUMMY_CON_ID : ctid); /* prepare length information */ - msg.headersize = (uint32_t) (sizeof(DltStorageHeader) + + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); - len = (int32_t) (msg.headersize - sizeof(DltStorageHeader) + msg.datasize); + len = msg.headersize - sizeof(DltStorageHeader) + msg.datasize; if (len > UINT16_MAX) { - dlt_vlog(LOG_ERR, - "%s: Critical: Huge injection message discarded!\n", - __func__); - - dlt_message_free(&msg, 0); + fprintf(stderr, "Critical: Huge injection message discarded!\n"); + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } @@ -725,29 +478,19 @@ /* Send data (without storage header) */ if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) { /* via FileDescriptor */ - if (client->send_serial_header) - { - ret = write(client->sock, dltSerialHeader, sizeof(dltSerialHeader)); - if (ret < 0) - { - dlt_log(LOG_ERR, "Sending message failed\n"); - dlt_message_free(&msg, 0); - return DLT_RETURN_ERROR; - } - } ret = - (int) write(client->sock, msg.headerbuffer + sizeof(DltStorageHeader), msg.headersize - sizeof(DltStorageHeader)); + write(client->sock, msg.headerbuffer + sizeof(DltStorageHeader), msg.headersize - sizeof(DltStorageHeader)); if (0 > ret) { - dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__); + dlt_log(LOG_ERR, "Sending message failed\n"); dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } - ret = (int) write(client->sock, msg.databuffer, msg.datasize); + ret = write(client->sock, msg.databuffer, msg.datasize); if (0 > ret) { - dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__); + dlt_log(LOG_ERR, "Sending message failed\n"); dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } @@ -756,18 +499,14 @@ id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp); dlt_vlog(LOG_INFO, - "%s: Control message forwarded : %s\n", - __func__, + "Control message forwarded : %s\n", dlt_get_service_name(id)); } else { /* via Socket */ - if (dlt_client_send_message_to_socket(client, &msg) == DLT_RETURN_ERROR) - { - dlt_log(LOG_ERR, "Sending message to socket failed\n"); - dlt_message_free(&msg, 0); - return DLT_RETURN_ERROR; - } + send(client->sock, (const char *)(msg.headerbuffer + sizeof(DltStorageHeader)), + msg.headersize - sizeof(DltStorageHeader), 0); + send(client->sock, (const char *)msg.databuffer, msg.datasize, 0); } /* free message */ @@ -794,14 +533,14 @@ offset = 0; memcpy(payload, &serviceID, sizeof(serviceID)); - offset += (int) sizeof(uint32_t); + offset += sizeof(uint32_t); memcpy(payload + offset, &size, sizeof(size)); - offset += (int) sizeof(uint32_t); + offset += sizeof(uint32_t); memcpy(payload + offset, buffer, size); /* free message */ if (dlt_client_send_ctrl_msg(client, apid, ctid, payload, - (uint32_t) (sizeof(uint32_t) + sizeof(uint32_t) + size)) == DLT_RETURN_ERROR) { + sizeof(uint32_t) + sizeof(uint32_t) + size) == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -820,11 +559,12 @@ if (client == NULL) return ret; - req = calloc(1, sizeof(DltServiceSetLogLevel)); + req = (DltServiceSetLogLevel *)malloc(sizeof(DltServiceSetLogLevel)); if (req == NULL) return ret; + memset(req, 0, sizeof(DltServiceSetLogLevel)); req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL; dlt_set_id(req->apid, apid); dlt_set_id(req->ctid, ctid); @@ -930,12 +670,15 @@ DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus) { DltServiceSetLogLevel *req; + uint8_t *payload; - req = calloc(1,sizeof(DltServiceSetLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetLogLevel)); - if (req == 0) + if (payload == 0) return DLT_RETURN_ERROR; + req = (DltServiceSetLogLevel *)payload; + memset(req, 0, sizeof(DltServiceSetLogLevel)); req->service_id = DLT_SERVICE_ID_SET_TRACE_STATUS; dlt_set_id(req->apid, apid); dlt_set_id(req->ctid, ctid); @@ -943,13 +686,12 @@ dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR) { - free(req); + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR) { + free(payload); return DLT_RETURN_ERROR; } - free(req); + free(payload); return DLT_RETURN_OK; } @@ -957,24 +699,27 @@ DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel) { DltServiceSetDefaultLogLevel *req; + uint8_t *payload; - req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if (req == 0) + if (payload == 0) return DLT_RETURN_ERROR; + req = (DltServiceSetDefaultLogLevel *)payload; + req->service_id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL; req->log_level = defaultLogLevel; dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { - free(req); + free(payload); return DLT_RETURN_ERROR; } - free(req); + free(payload); return DLT_RETURN_OK; } @@ -982,24 +727,26 @@ DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel) { DltServiceSetDefaultLogLevel *req; + uint8_t *payload; - req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if (req == 0) + if (payload == 0) return DLT_RETURN_ERROR; + req = (DltServiceSetDefaultLogLevel *)payload; + req->service_id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL; req->log_level = LogLevel; dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == -1) { - free(req); + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1) { + free(payload); return DLT_RETURN_ERROR; } - free(req); + free(payload); return DLT_RETURN_OK; } @@ -1007,24 +754,27 @@ DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus) { DltServiceSetDefaultLogLevel *req; + uint8_t *payload; - req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if (req == 0) + if (payload == 0) return DLT_RETURN_ERROR; + req = (DltServiceSetDefaultLogLevel *)payload; + req->service_id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS; req->log_level = defaultTraceStatus; dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { - free(req); + free(payload); return DLT_RETURN_ERROR; } - free(req); + free(payload); return DLT_RETURN_OK; } @@ -1032,31 +782,33 @@ DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t traceStatus) { DltServiceSetDefaultLogLevel *req; + uint8_t *payload; if (client == NULL) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); return DLT_RETURN_ERROR; } - req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if (req == 0) { + if (payload == 0) { dlt_vlog(LOG_ERR, "%s: Could not allocate memory %zu\n", __func__, sizeof(DltServiceSetDefaultLogLevel)); return DLT_RETURN_ERROR; } + req = (DltServiceSetDefaultLogLevel *)payload; + req->service_id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS; req->log_level = traceStatus; dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == -1) { - free(req);; + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1) { + free(payload); return DLT_RETURN_ERROR; } - free(req); + free(payload); return DLT_RETURN_OK; } @@ -1064,23 +816,25 @@ DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets) { DltServiceSetVerboseMode *req; + uint8_t *payload; - req = calloc(1, sizeof(DltServiceSetVerboseMode)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetVerboseMode)); - if (req == 0) + if (payload == 0) return DLT_RETURN_ERROR; + req = (DltServiceSetVerboseMode *)payload; + req->service_id = DLT_SERVICE_ID_SET_TIMING_PACKETS; req->new_status = timingPakets; /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR) { - free(req); + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR) { + free(payload); return DLT_RETURN_ERROR; } - free(req); + free(payload); return DLT_RETURN_OK; } @@ -1121,34 +875,12 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode) -{ - if (client == 0) - return DLT_RETURN_ERROR; - - client->mode = mode; - return DLT_RETURN_OK; - -} - int dlt_client_set_server_ip(DltClient *client, char *ipaddr) { client->servIP = strdup(ipaddr); if (client->servIP == NULL) { - dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate server IP\n", __func__); - return DLT_RETURN_ERROR; - } - - return DLT_RETURN_OK; -} - -int dlt_client_set_host_if_address(DltClient *client, char *hostip) -{ - client->hostip = strdup(hostip); - - if (client->hostip == NULL) { - dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate UDP interface address\n", __func__); + dlt_log(LOG_ERR, "ERROR: failed to duplicate server IP\n"); return DLT_RETURN_ERROR; } @@ -1160,7 +892,7 @@ client->serialDevice = strdup(serial_device); if (client->serialDevice == NULL) { - dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate serial device\n", __func__); + dlt_log(LOG_ERR, "ERROR: failed to duplicate serial device\n"); return DLT_RETURN_ERROR; } @@ -1172,7 +904,7 @@ client->socketPath = strdup(socket_path); if (client->socketPath == NULL) { - dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate socket path\n", __func__); + dlt_log(LOG_ERR, "ERROR: failed to duplicate socket path\n"); return DLT_RETURN_ERROR; } @@ -1211,7 +943,6 @@ free(resp->log_info_type.app_ids); resp->log_info_type.app_ids = NULL; - resp->log_info_type.count_app_ids = 0; return; } @@ -1258,32 +989,29 @@ (resp->status > GET_LOG_INFO_STATUS_MAX)) { if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX) dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid: NO matching Context IDs\n", - __func__, + "The status(%d) is invalid: NO matching Context IDs\n", resp->status); else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW) dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid: Response data over flow\n", - __func__, + "The status(%d) is invalid: Response data over flow\n", resp->status); else dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid\n", - __func__, + "The status(%d) is invalid\n", resp->status); return DLT_RETURN_ERROR; } /* count_app_ids */ - resp->log_info_type.count_app_ids = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, + resp->log_info_type.count_app_ids = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); resp->log_info_type.app_ids = (AppIDsType *)calloc (resp->log_info_type.count_app_ids, sizeof(AppIDsType)); if (resp->log_info_type.app_ids == NULL) { - dlt_vlog(LOG_ERR, "%s: calloc failed for app_ids\n", __func__); + dlt_vlog(LOG_ERR, "calloc failed for app_ids\n"); dlt_client_free_calloc_failed_get_log_info(resp, 0); return DLT_RETURN_ERROR; } @@ -1294,7 +1022,7 @@ dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id, DLT_ID_SIZE); /* count_con_ids */ - app->count_context_ids = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, + app->count_context_ids = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); app->context_id_info = (ContextIDsInfoType *)calloc @@ -1302,7 +1030,7 @@ if (app->context_id_info == NULL) { dlt_vlog(LOG_ERR, - "%s: calloc failed for context_id_info\n", __func__); + "calloc failed for context_id_info\n"); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } @@ -1327,18 +1055,18 @@ /* context desc */ if (resp->status == 7) { - con->len_context_description = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, + con->len_context_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); con->context_description = (char *)calloc - ((size_t) (con->len_context_description + 1), sizeof(char)); + (con->len_context_description + 1, sizeof(char)); - if (con->context_description == NULL) { - dlt_vlog(LOG_ERR, "%s: calloc failed for context description\n", __func__); + if (con->context_description == 0) { + dlt_log(LOG_ERR, "calloc failed for context description\n"); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } - dlt_getloginfo_conv_ascii_to_string(rp, + dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, con->context_description, con->len_context_description); @@ -1347,18 +1075,18 @@ /* application desc */ if (resp->status == 7) { - app->len_app_description = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, + app->len_app_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); app->app_description = (char *)calloc - ((size_t) (app->len_app_description + 1), sizeof(char)); + (app->len_app_description + 1, sizeof(char)); - if (app->app_description == NULL) { - dlt_vlog(LOG_ERR, "%s: calloc failed for application description\n", __func__); + if (app->app_description == 0) { + dlt_log(LOG_ERR, "calloc failed for application description\n"); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } - dlt_getloginfo_conv_ascii_to_string(rp, + dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_description, app->len_app_description); diff -Nru dlt-daemon-2.18.9/src/lib/dlt_client_cfg.h dlt-daemon-2.18.4/src/lib/dlt_client_cfg.h --- dlt-daemon-2.18.9/src/lib/dlt_client_cfg.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/dlt_client_cfg.h 2019-09-03 08:28:13.000000000 +0000 @@ -82,9 +82,9 @@ /* Initial baudrate */ #if !defined (__WIN32__) && !defined(_MSC_VER) -#define DLT_CLIENT_INITIAL_BAUDRATE B115200 +# define DLT_CLIENT_INITIAL_BAUDRATE B115200 #else -#define DLT_CLIENT_INITIAL_BAUDRATE 0 +# define DLT_CLIENT_INITIAL_BAUDRATE 0 #endif /* Name of environment variable for specifying the daemon port */ diff -Nru dlt-daemon-2.18.9/src/lib/dlt_env_ll.c dlt-daemon-2.18.4/src/lib/dlt_env_ll.c --- dlt-daemon-2.18.9/src/lib/dlt_env_ll.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/dlt_env_ll.c 2019-09-03 08:28:13.000000000 +0000 @@ -59,24 +59,20 @@ { int i; - if (!env || !id) { + if (!env || !id) return -1; - } - if (!(*env)) { + if (!(*env)) return -1; - } memset(id, 0, 4); - for (i = 0; (i < 4) && (**env != ':') && (**env != 0); ++i) { + for (i = 0; (i < 4) && (**env != ':') && (**env != 0); ++i) *id++ = *((*env)++); - } /* the next/last character must be ':' */ - if ((0 != **env) && (':' == **env)) { + if ((0 != **env) && (':' == **env)) return 0; - } return -1; } @@ -92,22 +88,19 @@ int count = 0; char ch; - if (!env || !result) { + if (!env || !result) return -1; - } - if (!(*env)) { + if (!(*env)) return -1; - } ch = *(*env); while (ch && (count < res_len - 1) && (ch != ';')) { - if ((ch >= 'A') && (ch <= 'Z')) { + if ((ch >= 'A') && (ch <= 'Z')) result[count] = ch + 'a' - 'A'; - } else { + else result[count] = ch; - } ch = *(++(*env)); ++count; @@ -115,11 +108,10 @@ result[count] = 0; - if (!ch || (ch == ';')) { /* full input was parsed */ + if (!ch || (ch == ';')) /* full input was parsed */ return 0; - } else { + else return -1; - } } @@ -127,41 +119,38 @@ { char result[strlen("verbose") + 1]; - if (!env || !ll) { + if (!env || !ll) return -1; - } - if (!(*env)) { + if (!(*env)) return -1; - } if (dlt_env_helper_to_lower(env, &result[0], sizeof(result)) == 0) { - if (strncmp("default", result, sizeof(result)) == 0) { + if (strncmp("default", result, sizeof(result)) == 0) *ll = -1; - } else if (strncmp("off", result, sizeof(result)) == 0) { + else if (strncmp("off", result, sizeof(result)) == 0) *ll = 0; - } else if (strncmp("fatal", result, sizeof(result)) == 0) { + else if (strncmp("fatal", result, sizeof(result)) == 0) *ll = 1; - } else if (strncmp("error", result, sizeof(result)) == 0) { + else if (strncmp("error", result, sizeof(result)) == 0) *ll = 2; - } else if (strncmp("warning", result, sizeof(result)) == 0) { + else if (strncmp("warning", result, sizeof(result)) == 0) *ll = 3; - } else if (strncmp("info", result, sizeof(result)) == 0) { + else if (strncmp("info", result, sizeof(result)) == 0) *ll = 4; - } else if (strncmp("debug", result, sizeof(result)) == 0) { + else if (strncmp("debug", result, sizeof(result)) == 0) *ll = 5; - } else if (strncmp("verbose", result, sizeof(result)) == 0) { + else if (strncmp("verbose", result, sizeof(result)) == 0) *ll = 6; - } else { + else return -1; - } - if (**env != 0) { + if (**env != 0) (*env)++; - } return 0; - } else { + } + else { return -1; } } @@ -197,13 +186,11 @@ */ int dlt_env_extract_ll(char **const env, int8_t *ll) { - if (!env || !ll) { + if (!env || !ll) return -1; - } - if (!(*env)) { + if (!(*env)) return -1; - } /* extract number */ if (**env == '-') { @@ -213,19 +200,19 @@ *ll = -1; (*env)++; } - } else { + } + else { if ((**env >= '0') && (**env < '7')) { *ll = **env - '0'; (*env)++; - } else if (dlt_env_extract_symbolic_ll(env, ll) != 0) { - return -1; } + else if (dlt_env_extract_symbolic_ll(env, ll) != 0) + return -1; } /* check end, either next char is NULL or ';' */ - if ((**env == ';') || (**env == 0)) { + if ((**env == ';') || (**env == 0)) return 0; - } return -1; } @@ -240,34 +227,29 @@ { int ret = -1; - if (!env || !item) { + if (!env || !item) return -1; - } - if (!(*env)) { + if (!(*env)) return -1; - } memset(item, 0, sizeof(dlt_env_ll_item)); ret = dlt_env_extract_id(env, item->appId); - if (ret == -1) { + if (ret == -1) return -1; - } (*env)++; ret = dlt_env_extract_id(env, item->ctxId); - if (ret == -1) { + if (ret == -1) return -1; - } (*env)++; ret = dlt_env_extract_ll(env, &item->ll); - if (ret == -1) { + if (ret == -1) return -1; - } return 0; } @@ -283,9 +265,8 @@ */ int dlt_env_init_ll_set(dlt_env_ll_set *const ll_set) { - if (!ll_set) { + if (!ll_set) return -1; - } ll_set->array_size = DLT_ENV_LL_SET_INCREASE; ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); @@ -306,9 +287,8 @@ */ void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set) { - if (!ll_set) { + if (!ll_set) return; - } if (ll_set->item != NULL) { free(ll_set->item); @@ -331,9 +311,8 @@ dlt_env_ll_item *old_set; size_t old_size; - if (!ll_set) { + if (!ll_set) return -1; - } old_set = ll_set->item; old_size = ll_set->array_size; @@ -345,7 +324,8 @@ /* should trigger a warning: no memory left */ ll_set->array_size -= DLT_ENV_LL_SET_INCREASE; return -1; - } else { + } + else { memcpy(ll_set->item, old_set, sizeof(dlt_env_ll_item) * old_size); free(old_set); return 0; @@ -363,32 +343,26 @@ */ int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set) { - if (!env || !ll_set) { + if (!env || !ll_set) return -1; - } - if (!(*env)) { + if (!(*env)) return -1; - } - if (dlt_env_init_ll_set(ll_set) == -1) { + if (dlt_env_init_ll_set(ll_set) == -1) return -1; - } do { if (ll_set->num_elem == ll_set->array_size) { - if (dlt_env_increase_ll_set(ll_set) == -1) { + if (dlt_env_increase_ll_set(ll_set) == -1) return -1; - } } - if (dlt_env_extract_ll_item(env, &ll_set->item[ll_set->num_elem++]) == -1) { + if (dlt_env_extract_ll_item(env, &ll_set->item[ll_set->num_elem++]) == -1) return -1; - } - if (**env == ';') { + if (**env == ';') (*env)++; - } } while (**env != 0); return 0; @@ -402,21 +376,17 @@ */ int dlt_env_ids_match(char const *const a, char const *const b) { - if (a[0] != b[0]) { + if (a[0] != b[0]) return 0; - } - if (a[1] != b[1]) { + if (a[1] != b[1]) return 0; - } - if (a[2] != b[2]) { + if (a[2] != b[2]) return 0; - } - if (a[3] != b[3]) { + if (a[3] != b[3]) return 0; - } return 1; } @@ -433,26 +403,23 @@ * * In case of error, -1 is returned. */ -int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const *const item, - char const *const apid, - char const *const ctid) +int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const *const item, char const *const apid, char const *const ctid) { - if ((!item) || (!apid) || (!ctid)) { + if ((!item) || (!apid) || (!ctid)) return -1; - } if (item->appId[0] == 0) { if (item->ctxId[0] == 0) { return 1; - } else if (dlt_env_ids_match(item->ctxId, ctid)) { - return 2; } - } else if (dlt_env_ids_match(item->appId, apid)) { - if (item->ctxId[0] == 0) { + else if (dlt_env_ids_match(item->ctxId, ctid)) + return 2; + } + else if (dlt_env_ids_match(item->appId, apid)) { + if (item->ctxId[0] == 0) return 3; - } else if (dlt_env_ids_match(item->ctxId, ctid)) { + else if (dlt_env_ids_match(item->ctxId, ctid)) return 4; - } } return 0; @@ -473,9 +440,8 @@ char const *const ctid, int const ll) { - if ((!ll_set) || (!apid) || (!ctid)) { + if ((!ll_set) || (!apid) || (!ctid)) return ll; - } int res = ll; int prio = 0; /* no match so far */ @@ -488,9 +454,8 @@ prio = p; res = ll_set->item[i].ll; - if (p == 4) { /* maximum reached, immediate return */ + if (p == 4) /* maximum reached, immediate return */ return res; - } } } diff -Nru dlt-daemon-2.18.9/src/lib/dlt_filetransfer.c dlt-daemon-2.18.4/src/lib/dlt_filetransfer.c --- dlt-daemon-2.18.9/src/lib/dlt_filetransfer.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/dlt_filetransfer.c 2019-09-03 08:28:13.000000000 +0000 @@ -56,7 +56,6 @@ #include #include "dlt_filetransfer.h" #include "dlt_common.h" -#include "dlt_user_macros.h" /*!Defines the buffer size of a single file package which will be logged to dlt */ #define BUFFER_SIZE 1024 @@ -102,21 +101,18 @@ */ void stringHash(const char *str, uint32_t *hash) { - if (!str || !hash) { + if (!str || !hash) return; - } unsigned int len = strlen(str); unsigned int i = 0; - if (len <= 0) { + if (len <= 0) return; - } - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) *hash = 53 * *hash + str[i]; - } } @@ -134,7 +130,8 @@ if (-1 == stat(file, &st)) { *ok = 0; ret = 0; - } else { + } + else { *ok = 1; ret = st.st_ino; ret = ret << (sizeof(ret) * 8) / 2; @@ -179,11 +176,10 @@ if (-1 == stat(file, &st)) { *ok = 0; - return; + date = 0; } *ok = 1; - tzset(); localtime_r(&st.st_ctime, &ts); asctime_r(&ts, date); } @@ -220,9 +216,8 @@ dlt_user_check_buffer(&total_size, &used_size); - if ((total_size - used_size) < (total_size / 2)) { + if ((total_size - used_size) < (total_size / 2)) return -1; - } return 1; } @@ -244,30 +239,27 @@ int ok = 0; uint32_t fserial = getFileSerialNumber(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFileSerialNumber for: "), DLT_STRING(filename)); - } uint32_t fsize = getFilesize(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), DLT_STRING(filename)); - } - char fcreationdate[50] = {0}; + char fcreationdate[50]; getFileCreationDate2(filename, &ok, fcreationdate); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), DLT_STRING(filename)); - } int package_count = dlt_user_log_file_packagesCount(fileContext, filename); @@ -283,7 +275,8 @@ DLT_UINT(BUFFER_SIZE), DLT_STRING("FLER") ); - } else { + } + else { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("FLER"), DLT_INT(errorCode), @@ -310,31 +303,28 @@ uint32_t fsize = getFilesize(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting size of file:"), DLT_STRING(filename)); - } uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting serial number of file:"), DLT_STRING(filename)); - } - char creationdate[50] = {0}; + char creationdate[50]; getFileCreationDate2(filename, &ok, creationdate); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting creation date of file:"), DLT_STRING(filename)); - } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLIF"), @@ -342,12 +332,12 @@ DLT_STRING("filename"), DLT_STRING(filename), DLT_STRING("file size in bytes"), DLT_UINT(fsize), DLT_STRING("file creation date"), DLT_STRING(creationdate), - DLT_STRING("number of packages"), - DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), + DLT_STRING("number of packages"), DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), DLT_STRING("FLIF") ); return 0; - } else { + } + else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_INFO_ABOUT); return DLT_FILETRANSFER_ERROR_INFO_ABOUT; } @@ -365,28 +355,21 @@ * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to many messages in a short period of time. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_complete(DltContext *fileContext, - const char *filename, - int deleteFlag, - int timeout) +int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, int timeout) { if (!isFile(filename)) { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_COMPLETE); return DLT_FILETRANSFER_ERROR_FILE_COMPLETE; } - if (dlt_user_log_file_header(fileContext, filename) != 0) { + if (dlt_user_log_file_header(fileContext, filename) != 0) return DLT_FILETRANSFER_ERROR_FILE_COMPLETE1; - } - if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, - timeout) != 0) { + if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, timeout) != 0) return DLT_FILETRANSFER_ERROR_FILE_COMPLETE2; - } - if (dlt_user_log_file_end(fileContext, filename, deleteFlag) != 0) { + if (dlt_user_log_file_end(fileContext, filename, deleteFlag) != 0) return DLT_FILETRANSFER_ERROR_FILE_COMPLETE3; - } return 0; } @@ -421,16 +404,17 @@ if (filesize < BUFFER_SIZE) { return packages; - } else { + } + else { packages = filesize / BUFFER_SIZE; - if (filesize % BUFFER_SIZE == 0) { + if (filesize % BUFFER_SIZE == 0) return packages; - } else { + else return packages + 1; - } } - } else { + } + else { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("Error in: dlt_user_log_file_packagesCount, !isFile"), @@ -458,32 +442,24 @@ uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header_alias, Error getting serial number of file:"), + DLT_STRING("dlt_user_log_file_header_alias, Error getting serial number of file:"), DLT_STRING(filename)); - return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; - } uint32_t fsize = getFilesize(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header_alias, Error getting size of file:"), - DLT_STRING(filename)); - } + DLT_STRING("dlt_user_log_file_header_alias, Error getting size of file:"), DLT_STRING(filename)); - char fcreationdate[50] = {0}; + char fcreationdate[50]; getFileCreationDate2(filename, &ok, fcreationdate); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header_alias, Error getting creation date of file:"), + DLT_STRING("dlt_user_log_file_header_alias, Error getting creation date of file:"), DLT_STRING(filename)); - } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), @@ -497,7 +473,8 @@ ); return 0; - } else { + } + else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); return DLT_FILETRANSFER_ERROR_FILE_HEAD; } @@ -520,31 +497,24 @@ uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header, Error getting serial number of file:"), - DLT_STRING(filename)); - } + DLT_STRING("dlt_user_log_file_header, Error getting serial number of file:"), DLT_STRING(filename)); uint32_t fsize = getFilesize(filename, &ok); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_header, Error getting size of file:"), DLT_STRING(filename)); - } - char fcreationdate[50] = {0}; + char fcreationdate[50]; getFileCreationDate2(filename, &ok, fcreationdate); - if (!ok) { + if (!ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header, Error getting creation date of file:"), - DLT_STRING(filename)); - } + DLT_STRING("dlt_user_log_file_header, Error getting creation date of file:"), DLT_STRING(filename)); DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), @@ -558,7 +528,8 @@ ); return 0; - } else { + } + else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); return DLT_FILETRANSFER_ERROR_FILE_HEAD; } @@ -572,10 +543,7 @@ * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_data(DltContext *fileContext, - const char *filename, - int packageToTransfer, - int timeout) +int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, int timeout) { FILE *file; int pkgNumber; @@ -592,8 +560,7 @@ if (((packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) && (packageToTransfer > - dlt_user_log_file_packagesCount(fileContext, - filename))) || (packageToTransfer <= 0)) { + dlt_user_log_file_packagesCount(fileContext, filename))) || (packageToTransfer <= 0)) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("Error at dlt_user_log_file_data: packageToTransfer out of scope"), DLT_STRING("packageToTransfer:"), @@ -624,6 +591,7 @@ fclose (file); return -1; + } readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); @@ -631,13 +599,10 @@ uint32_t fserial = getFileSerialNumber(filename, &ok); - if (1 != ok) { + if (1 != ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); - fclose (file); - return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; - } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), @@ -648,7 +613,9 @@ ); doTimeout(timeout); - } else { + + } + else { pkgNumber = 0; while (!feof(file)) { @@ -657,24 +624,14 @@ if (checkUserBufferForFreeSpace() > 0) { pkgNumber++; readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); - - if (readBytes == 0) { - // If the file size is divisible by the package size don't send - // one empty FLDA. Also we send the correct number of FLDAs too. - break; - } - int ok; uint32_t fserial = getFileSerialNumber(filename, &ok); - if (1 != ok) { + if (1 != ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); - fclose(file); - return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; - } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), @@ -683,10 +640,8 @@ DLT_RAW(buffer, readBytes), DLT_STRING("FLDA") ); - } else { - fclose(file); - return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; } + doTimeout(timeout); } } @@ -694,7 +649,9 @@ fclose(file); return 0; - } else { + + } + else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_DATA); return DLT_FILETRANSFER_ERROR_FILE_DATA; } @@ -716,12 +673,10 @@ int ok; uint32_t fserial = getFileSerialNumber(filename, &ok); - if (1 != ok) { + if (1 != ok) DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); - return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; - } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLFI"), @@ -731,15 +686,14 @@ if (deleteFlag) { if (doRemoveFile(filename) != 0) { - dlt_user_log_file_errorMessage(fileContext, - filename, - DLT_FILETRANSFER_ERROR_FILE_END); + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); return -1; } } return 0; - } else { + } + else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); return DLT_FILETRANSFER_ERROR_FILE_END; } diff -Nru dlt-daemon-2.18.9/src/lib/dlt_user.c dlt-daemon-2.18.4/src/lib/dlt_user.c --- dlt-daemon-2.18.9/src/lib/dlt_user.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/dlt_user.c 2019-09-03 08:28:13.000000000 +0000 @@ -43,33 +43,19 @@ #include #include /* writev() */ -#include #include #ifdef linux -# include /* for PR_SET_NAME */ +# include #endif #include /* needed for getpid() */ #include #include - -#include - -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC -# include -#endif -#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC # include -#endif -#ifdef DLT_LIB_USE_VSOCK_IPC -# ifdef linux -# include -# endif -# ifdef __QNX__ -# include -# endif +# include #endif #include "dlt_user.h" @@ -90,30 +76,17 @@ # define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) #endif /* DLT_FATAL_LOG_RESET_ENABLE */ -enum InitState { - INIT_UNITIALIZED, - INIT_IN_PROGRESS, - INIT_DONE -}; - static DltUser dlt_user; -static _Atomic enum InitState dlt_user_init_state = INIT_UNITIALIZED; -#define DLT_USER_INITALIZED (dlt_user_init_state == INIT_DONE) +static bool dlt_user_initialised = false; +static int dlt_user_freeing = 0; -static _Atomic int dlt_user_freeing = 0; -static bool dlt_user_file_reach_max = false; - -#ifdef DLT_LIB_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC static char dlt_user_dir[DLT_PATH_MAX]; static char dlt_daemon_fifo[DLT_PATH_MAX]; #endif static sem_t dlt_mutex; -static pthread_t dlt_housekeeperthread_handle; - -/* Sync housekeeper thread start */ -pthread_mutex_t dlt_housekeeper_running_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t dlt_housekeeper_running_cond; +static pthread_t dlt_receiverthread_handle; /* calling dlt_user_atexit_handler() second time fails with error message */ static int atexit_registered = 0; @@ -121,7 +94,7 @@ /* used to disallow DLT usage in fork() child */ static int g_dlt_is_child = 0; /* String truncate message */ -static const char STR_TRUNCATED_MESSAGE[] = "... <>"; +static const char *STR_TRUNCATED_MESSAGE = "... <>"; /* Enum for type of string */ enum StringType @@ -130,35 +103,19 @@ UTF8_STRING = 1 }; -/* Data type holding "Variable Info" (VARI) properties - * Some of the supported data types (eg. bool, string, raw) have only "name", but not "unit". - */ -typedef struct VarInfo -{ - const char *name; // the "name" attribute (can be NULL) - const char *unit; // the "unit" attribute (can be NULL) - bool with_unit; // true if the "unit" field is to be considered -} VarInfo; - -#define DLT_UNUSED(x) (void)(x) - -/* Network trace */ -#ifdef DLT_NETWORK_TRACE_ENABLE -#define DLT_USER_SEGMENTED_THREAD (1<<2) +/*Max DLT message size is 1390 bytes plus some extra header space to accomidate the resend buffer*/ +#define DLT_USER_EXTRA_BUFF_SIZE 100 /* Segmented Network Trace */ #define DLT_MAX_TRACE_SEGMENT_SIZE 1024 #define DLT_MESSAGE_QUEUE_NAME "/dlt_message_queue" #define DLT_DELAYED_RESEND_INDICATOR_PATTERN 0xFFFF +#define DLT_UNUSED(x) (void)(x) + /* Mutex to wait on while message queue is not initialized */ pthread_mutex_t mq_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t mq_init_condition; -#endif /* DLT_NETWORK_TRACE_ENABLE */ - -/* use these variables from common.c*/ -extern int logging_mode; -extern FILE *logging_handle; void dlt_lock_mutex(pthread_mutex_t *mutex) { @@ -188,7 +145,7 @@ } s_segmented_data; /* Function prototypes for internally used functions */ -static void dlt_user_housekeeperthread_function(void *ptr); +static void dlt_user_receiverthread_function(void *ptr); static void dlt_user_atexit_handler(void); static DltReturnValue dlt_user_log_init(DltContext *handle, DltContextData *log); static DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype); @@ -205,6 +162,9 @@ static DltReturnValue dlt_user_log_check_user_message(void); static void dlt_user_log_reattach_to_daemon(void); static DltReturnValue dlt_user_log_send_overflow(void); +static void dlt_user_trace_network_segmented_thread(void *unused); +static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data); +static DltReturnValue dlt_user_queue_resend(void); static DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void *ptr2, @@ -215,16 +175,9 @@ static int dlt_start_threads(); static void dlt_stop_threads(); static void dlt_fork_child_fork_handler(); -#ifdef DLT_NETWORK_TRACE_ENABLE -static void dlt_user_trace_network_segmented_thread(void *unused); -static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data); -#endif - -static DltReturnValue dlt_user_log_write_string_utils_attr(DltContextData *log, const char *text, const enum StringType type, const char *name, bool with_var_info); -static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData *log, const char *text, size_t length, const enum StringType type, const char *name, bool with_var_info); - -static DltReturnValue dlt_unregister_app_util(bool force_sending_messages); +static DltReturnValue dlt_user_log_write_string_utils(DltContextData *log, const char *text, + const enum StringType type); DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version) { @@ -249,36 +202,16 @@ return DLT_RETURN_OK; } -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC -static DltReturnValue dlt_socket_set_nonblock_and_linger(int sockfd) -{ - int status; - struct linger l_opt; - - status = fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK); - if (status == -1) { - dlt_log(LOG_INFO, "Socket cannot be changed to NON BLOCK\n"); - return DLT_RETURN_ERROR; - } - - l_opt.l_onoff = 1; - l_opt.l_linger = 10; - - if (setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &l_opt, sizeof l_opt) < 0) - dlt_log(LOG_WARNING, "Failed to set socket linger option\n"); - - return DLT_RETURN_OK; -} -#endif - -#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC static DltReturnValue dlt_initialize_socket_connection(void) { struct sockaddr_un remote; + int status = 0; char dltSockBaseDir[DLT_IPC_PATH_MAX]; + struct linger l_opt; DLT_SEM_LOCK(); - int sockfd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sockfd == DLT_FD_INIT) { dlt_log(LOG_CRIT, "Failed to create socket\n"); @@ -286,12 +219,22 @@ return DLT_RETURN_ERROR; } - if (dlt_socket_set_nonblock_and_linger(sockfd) != DLT_RETURN_OK) { - close(sockfd); - DLT_SEM_FREE(); + status = fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK); + + if (status == -1) { + dlt_vlog(LOG_INFO, + "Socket %s/dlt cannot be changed to NON BLOCK\n", + DLT_USER_IPC_PATH); return DLT_RETURN_ERROR; } + /* Set SO_LINGER opt for the new client socket. */ + l_opt.l_onoff = 1; + l_opt.l_linger = 10; + + if (setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &l_opt, sizeof l_opt) < 0) + dlt_log(LOG_WARNING, "Failed to set linger option\n"); + remote.sun_family = AF_UNIX; snprintf(dltSockBaseDir, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH); strncpy(remote.sun_path, dltSockBaseDir, sizeof(remote.sun_path)); @@ -304,79 +247,21 @@ if (connect(sockfd, (struct sockaddr *)&remote, sizeof(remote)) == -1) { if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { dlt_vlog(LOG_INFO, - "Socket %s cannot be opened (errno=%d). Retrying later...\n", - dltSockBaseDir, errno); - dlt_user.connection_state = DLT_USER_RETRY_CONNECT; - } - - close(sockfd); - dlt_user.dlt_log_handle = -1; - } - else { - dlt_user.dlt_log_handle = sockfd; - dlt_user.connection_state = DLT_USER_CONNECTED; - - if (dlt_receiver_init(&(dlt_user.receiver), - sockfd, - DLT_RECEIVE_SOCKET, - DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { - dlt_user_init_state = INIT_UNITIALIZED; - close(sockfd); - DLT_SEM_FREE(); - return DLT_RETURN_ERROR; - } - } - - DLT_SEM_FREE(); - - return DLT_RETURN_OK; -} -#elif defined DLT_LIB_USE_VSOCK_IPC -static DltReturnValue dlt_initialize_vsock_connection() -{ - struct sockaddr_vm remote; - - DLT_SEM_LOCK(); - int sockfd = socket(AF_VSOCK, SOCK_STREAM, 0); - - if (sockfd == DLT_FD_INIT) { - dlt_log(LOG_CRIT, "Failed to create VSOCK socket\n"); - DLT_SEM_FREE(); - return DLT_RETURN_ERROR; - } - - memset(&remote, 0, sizeof(remote)); - remote.svm_family = AF_VSOCK; - remote.svm_port = DLT_VSOCK_PORT; - remote.svm_cid = VMADDR_CID_HOST; - - if (connect(sockfd, (struct sockaddr *)&remote, sizeof(remote)) == -1) { - if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { - dlt_vlog(LOG_INFO, "VSOCK socket cannot be opened. Retrying later...\n"); + "Socket %s cannot be opened. Retrying later...\n", + dltSockBaseDir); dlt_user.connection_state = DLT_USER_RETRY_CONNECT; } close(sockfd); - dlt_user.dlt_log_handle = -1; } else { - /* Set to non-blocking after connect() to avoid EINPROGRESS. DltUserConntextionState - needs "connecting" state if connect() should be non-blocking. */ - if (dlt_socket_set_nonblock_and_linger(sockfd) != DLT_RETURN_OK) { - close(sockfd); - DLT_SEM_FREE(); - return DLT_RETURN_ERROR; - } - dlt_user.dlt_log_handle = sockfd; dlt_user.connection_state = DLT_USER_CONNECTED; if (dlt_receiver_init(&(dlt_user.receiver), sockfd, - DLT_RECEIVE_SOCKET, DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { - dlt_user_init_state = INIT_UNITIALIZED; - close(sockfd); + dlt_user_initialised = false; DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -386,7 +271,7 @@ return DLT_RETURN_OK; } -#else /* DLT_LIB_USE_FIFO_IPC */ +#else /* setup fifo*/ static DltReturnValue dlt_initialize_fifo_connection(void) { char filename[DLT_PATH_MAX]; @@ -433,7 +318,7 @@ return DLT_RETURN_ERROR; } - dlt_user.dlt_user_handle = open(filename, O_RDWR | O_NONBLOCK | O_CLOEXEC); + dlt_user.dlt_user_handle = open(filename, O_RDWR | O_CLOEXEC); if (dlt_user.dlt_user_handle == DLT_FD_INIT) { dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Logging disabled, FIFO user %s cannot be opened!\n", filename); @@ -459,42 +344,28 @@ { /* process is exiting. Do not allocate new resources. */ if (dlt_user_freeing != 0) { - dlt_vlog(LOG_INFO, "%s logging disabled, process is exiting\n", __func__); + dlt_vlog(LOG_INFO, "%s logging disabled, process is exiting", __func__); /* return negative value, to stop the current log */ return DLT_RETURN_LOGGING_DISABLED; } - /* Compare dlt_user_init_state to INIT_UNITIALIZED. If equal it will be set to INIT_IN_PROGRESS. - * Call returns DLT_RETURN_OK init state != INIT_UNITIALIZED - * That way it's no problem, if two threads enter this function, because only the very first one will - * pass fully. The other one will immediately return, because when it executes the atomic function - * dlt_user_init_state won't be INIT_UNITIALIZED anymore. - * This is not handled via a simple boolean to prevent issues with shutting down while the init is still running. - * Furthermore, this makes sure we enter some function only when dlt_init is fully done. - * */ - enum InitState expectedInitState = INIT_UNITIALIZED; - if (!(atomic_compare_exchange_strong(&dlt_user_init_state, &expectedInitState, INIT_IN_PROGRESS))) { - return DLT_RETURN_OK; - } - - /* check environment variables */ - dlt_check_envvar(); - - /* Check logging mode and internal log file is opened or not*/ - if (logging_mode == DLT_LOG_TO_FILE && logging_handle == NULL) { - dlt_log_init(logging_mode); - } + /* WARNING: multithread unsafe ! */ + /* Another thread will check that dlt_user_initialised != 0, but the lib is not initialised ! */ + dlt_user_initialised = true; /* Initialize common part of dlt_init()/dlt_init_file() */ if (dlt_init_common() == DLT_RETURN_ERROR) { - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; return DLT_RETURN_ERROR; } - dlt_user.dlt_is_file = 0; - dlt_user.filesize_max = UINT_MAX; - dlt_user_file_reach_max = false; + strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, DLT_PATH_MAX); + dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; + /* check environment variables */ + dlt_check_envvar(); + + dlt_user.dlt_is_file = 0; dlt_user.overflow = 0; dlt_user.overflow_counter = 0; #ifdef DLT_SHM_ENABLE @@ -507,7 +378,7 @@ #endif -#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC if (dlt_initialize_socket_connection() != DLT_RETURN_OK) /* We could connect to the pipe, but not to the socket, which is normally */ @@ -515,122 +386,63 @@ /* in case application is started before daemon, it is expected behaviour */ return DLT_RETURN_ERROR; -#elif defined DLT_LIB_USE_VSOCK_IPC - - if (dlt_initialize_vsock_connection() != DLT_RETURN_OK) - return DLT_RETURN_ERROR; - -#else /* DLT_LIB_USE_FIFO_IPC */ +#else /* FIFO connection */ if (dlt_initialize_fifo_connection() != DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (dlt_receiver_init(&(dlt_user.receiver), - dlt_user.dlt_user_handle, - DLT_RECEIVE_FD, + if (dlt_receiver_init(&(dlt_user.receiver), dlt_user.dlt_user_handle, DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; return DLT_RETURN_ERROR; } #endif -#ifdef DLT_NETWORK_TRACE_ENABLE /* These will be lazy initialized only when needed */ dlt_user.dlt_segmented_queue_read_handle = -1; dlt_user.dlt_segmented_queue_write_handle = -1; pthread_cond_init(&mq_init_condition, NULL); -#endif if (dlt_start_threads() < 0) { - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; return DLT_RETURN_ERROR; } /* prepare for fork() call */ pthread_atfork(NULL, NULL, &dlt_fork_child_fork_handler); - expectedInitState = INIT_IN_PROGRESS; - if (!(atomic_compare_exchange_strong(&dlt_user_init_state, &expectedInitState, INIT_DONE))) { - return DLT_RETURN_ERROR; - } - return DLT_RETURN_OK; } -DltReturnValue dlt_get_appid(char *appid) -{ - if (appid != NULL) { - strncpy(appid, dlt_user.appID, 4); - return DLT_RETURN_OK; - } else { - dlt_log(LOG_ERR, "Invalid parameter.\n"); - return DLT_RETURN_WRONG_PARAMETER; - } -} - DltReturnValue dlt_init_file(const char *name) { /* check null pointer */ if (!name) return DLT_RETURN_WRONG_PARAMETER; - /* Compare dlt_user_init_state to INIT_UNITIALIZED. If equal it will be set to INIT_IN_PROGRESS. - * Call returns DLT_RETURN_OK init state != INIT_UNITIALIZED - * That way it's no problem, if two threads enter this function, because only the very first one will - * pass fully. The other one will immediately return, because when it executes the atomic function - * dlt_user_init_state won't be INIT_UNITIALIZED anymore. - * This is not handled via a simple boolean to prevent issues with shutting down while the init is still running. - * Furthermore, this makes sure we enter some function only when dlt_init is fully done. - * */ - enum InitState expectedInitState = INIT_UNITIALIZED; - if (!(atomic_compare_exchange_strong(&dlt_user_init_state, &expectedInitState, INIT_IN_PROGRESS))) - return DLT_RETURN_OK; + dlt_user_initialised = true; /* Initialize common part of dlt_init()/dlt_init_file() */ if (dlt_init_common() == DLT_RETURN_ERROR) { - expectedInitState = INIT_UNITIALIZED; + dlt_user_initialised = false; return DLT_RETURN_ERROR; } dlt_user.dlt_is_file = 1; /* open DLT output file */ - dlt_user.dlt_log_handle = open(name, O_WRONLY | O_CREAT, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + dlt_user.dlt_log_handle = open(name, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ if (dlt_user.dlt_log_handle == -1) { dlt_vnlog(LOG_ERR, DLT_USER_BUFFER_LENGTH, "Log file %s cannot be opened!\n", name); - dlt_user.dlt_is_file = 0; - return DLT_RETURN_ERROR; - } - - return DLT_RETURN_OK; -} - -DltReturnValue dlt_set_filesize_max(unsigned int filesize) -{ - if (dlt_user.dlt_is_file == 0) - { - dlt_vlog(LOG_ERR, "%s: Library is not configured to log to file\n", - __func__); return DLT_RETURN_ERROR; } - if (filesize == 0) { - dlt_user.filesize_max = UINT_MAX; - } - else { - dlt_user.filesize_max = filesize; - } - dlt_vlog(LOG_DEBUG, "%s: Defined filesize_max is [%d]\n", __func__, - dlt_user.filesize_max); - return DLT_RETURN_OK; } -#ifdef DLT_NETWORK_TRACE_ENABLE DltReturnValue dlt_init_message_queue(void) { dlt_lock_mutex(&mq_mutex); @@ -695,13 +507,6 @@ dlt_unlock_mutex(&mq_mutex); return DLT_RETURN_OK; } -#endif /* DLT_NETWORK_TRACE_ENABLE */ - -/* Return true if verbose mode is to be used for this DltContextData */ -static inline bool is_verbose_mode(int8_t dltuser_verbose_mode, const DltContextData* log) -{ - return (dltuser_verbose_mode == 1) || (log != NULL && log->verbose_mode); -} DltReturnValue dlt_init_common(void) { @@ -713,14 +518,12 @@ uint32_t buffer_max = DLT_USER_RINGBUFFER_MAX_SIZE; char *env_buffer_step; uint32_t buffer_step = DLT_USER_RINGBUFFER_STEP_SIZE; - char *env_disable_extended_header_for_nonverbose; char *env_log_buffer_len; uint32_t buffer_max_configured = 0; - uint32_t header_size = 0; /* Binary semaphore for threads */ if (sem_init(&dlt_mutex, 0, 1) == -1) { - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; return DLT_RETURN_ERROR; } @@ -738,31 +541,10 @@ /* Verbose mode is enabled by default */ dlt_user.verbose_mode = 1; - /* header_size is used for resend buffer - * so it won't include DltStorageHeader - */ - header_size = sizeof(DltUserHeader) + sizeof(DltStandardHeader) + - sizeof(DltStandardHeaderExtra); - /* Use extended header for non verbose is enabled by default */ - dlt_user.use_extended_header_for_non_verbose = - DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE; - - /* Use extended header for non verbose is modified as per environment variable */ - env_disable_extended_header_for_nonverbose = - getenv(DLT_USER_ENV_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE); - - if (env_disable_extended_header_for_nonverbose) { - if (strcmp(env_disable_extended_header_for_nonverbose, "1") == 0) - dlt_user.use_extended_header_for_non_verbose = - DLT_USER_NO_USE_EXTENDED_HEADER_FOR_NONVERBOSE; - } - - if (dlt_user.use_extended_header_for_non_verbose == - DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE) - header_size += (uint32_t) sizeof(DltExtendedHeader); + dlt_user.use_extende_header_for_non_verbose = DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE; - /* With session id is enabled by default */ + /* WIth session id is enabled by default */ dlt_user.with_session_id = DLT_USER_WITH_SESSION_ID; /* With timestamp is enabled by default */ @@ -855,36 +637,29 @@ "Configured size exceeds maximum allowed size,restricting to max [65535 bytes]\n"); } else { - dlt_user.log_buf_len = (uint16_t) buffer_max_configured; + dlt_user.log_buf_len = buffer_max_configured; dlt_vlog(LOG_INFO, - "Configured buffer size to [%u bytes]\n", + "Configured buffer size to [%d bytes]\n", buffer_max_configured); } } if (dlt_user.resend_buffer == NULL) { - dlt_user.resend_buffer = calloc(sizeof(unsigned char), - (dlt_user.log_buf_len + header_size)); + dlt_user.resend_buffer = calloc(sizeof(unsigned char), (dlt_user.log_buf_len + DLT_USER_EXTRA_BUFF_SIZE)); if (dlt_user.resend_buffer == NULL) { - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; DLT_SEM_FREE(); dlt_vlog(LOG_ERR, "cannot allocate memory for resend buffer\n"); return DLT_RETURN_ERROR; } } - dlt_user.disable_injection_msg = 0; - if (getenv(DLT_USER_ENV_DISABLE_INJECTION_MSG)) { - dlt_log(LOG_WARNING, "Injection message is disabled\n"); - dlt_user.disable_injection_msg = 1; - } - if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer), buffer_min, buffer_max, buffer_step) == DLT_RETURN_ERROR) { - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -913,8 +688,8 @@ if (g_dlt_is_child) return; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); /* close file */ dlt_log_free(); return; @@ -928,7 +703,7 @@ /* Unregister app (this also unregisters all contexts in daemon) */ /* Ignore return value */ - dlt_unregister_app_util(false); + dlt_unregister_app(); /* Cleanup */ /* Ignore return value */ @@ -1002,27 +777,27 @@ { uint32_t i; int ret = 0; - int expected = 0; -#ifdef DLT_LIB_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC char filename[DLT_PATH_MAX]; #endif - /* library is freeing its resources. Avoid to allocate it in dlt_init() */ - if (!(atomic_compare_exchange_strong(&dlt_user_freeing, &expected, 1))) { + if (dlt_user_freeing != 0) /* resources are already being freed. Do nothing and return. */ return DLT_RETURN_ERROR; - } - if (!DLT_USER_INITALIZED) { + /* library is freeing its resources. Avoid to allocate it in dlt_init() */ + dlt_user_freeing = 1; + + if (!dlt_user_initialised) { dlt_user_freeing = 0; return DLT_RETURN_ERROR; } - dlt_stop_threads(); + dlt_user_initialised = false; - dlt_user_init_state = INIT_UNITIALIZED; + dlt_stop_threads(); -#ifdef DLT_LIB_USE_FIFO_IPC +#ifndef DLT_USE_UNIX_SOCKET_IPC if (dlt_user.dlt_user_handle != DLT_FD_INIT) { close(dlt_user.dlt_user_handle); @@ -1040,61 +815,27 @@ if (dlt_user.dlt_log_handle != -1) { /* close log file/output fifo to daemon */ -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC ret = shutdown(dlt_user.dlt_log_handle, SHUT_WR); if (ret < 0) { dlt_vlog(LOG_WARNING, "%s: shutdown failed: %s\n", __func__, strerror(errno)); } else { - ssize_t bytes_read = 0; - int prev_errno = 0; - struct pollfd nfd[1]; - nfd[0].events = POLLIN; - nfd[0].fd = dlt_user.dlt_log_handle; - while (1) { - ret = poll(nfd, 1, DLT_USER_RECEIVE_MDELAY); + ssize_t bytes_read; - /* In case failure of polling or reaching timeout, - * continue to close socket anyway. - * */ - if (ret < 0) { - dlt_vlog(LOG_WARNING, "[%s] Failed to poll with error [%s]\n", - __func__, strerror(errno)); - break; - } - else if (ret == 0) { - dlt_vlog(LOG_DEBUG, "[%s] Polling timeout\n", __func__); + bytes_read = read(dlt_user.dlt_log_handle, dlt_user.resend_buffer, dlt_user.log_buf_len); + + if (bytes_read < 0) { + dlt_vlog(LOG_DEBUG, "%s - %d: Reading...\n", __func__, __LINE__); break; } else { - /* It could take some time to get the socket is shutdown - * So it means there could be some data available to read. - * Try to consume the data and poll the socket again. - * If read fails, time to close the socket then. - */ - dlt_vlog(LOG_DEBUG, "[%s] polling returns [%d] with revent [0x%x]." - "There are something to read\n", __func__, ret, (unsigned int)nfd[0].revents); - - bytes_read = read(dlt_user.dlt_log_handle, dlt_user.resend_buffer, dlt_user.log_buf_len); - prev_errno = errno; - - if (bytes_read < 0) { - dlt_vlog(LOG_WARNING, "[%s] Failed to read with error [%s]\n", - __func__, strerror(prev_errno)); - - if ((prev_errno == EAGAIN) || (EWOULDBLOCK != EAGAIN && prev_errno == EWOULDBLOCK)) - continue; - else - break; - } - if (bytes_read >= 0) { - if (!bytes_read) - break; - dlt_vlog(LOG_NOTICE, "[%s] data is still readable... [%zd] bytes read\n", - __func__, bytes_read); - } + dlt_vlog(LOG_DEBUG, "%s - %d: %d bytes read from resend buffer\n", __func__, __LINE__); + + if (!bytes_read) + break; } } } @@ -1118,11 +859,9 @@ dlt_user_free_buffer(&(dlt_user.resend_buffer)); dlt_buffer_free_dynamic(&(dlt_user.startup_buffer)); + DLT_SEM_FREE(); - /* Clear and free local stored application information */ - if (dlt_user.application_description != NULL) - free(dlt_user.application_description); - dlt_user.application_description = NULL; + DLT_SEM_LOCK(); if (dlt_user.dlt_ll_ts) { for (i = 0; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { @@ -1159,7 +898,6 @@ dlt_env_free_ll_set(&dlt_user.initial_ll_set); DLT_SEM_FREE(); -#ifdef DLT_NETWORK_TRACE_ENABLE char queue_name[NAME_MAX]; snprintf(queue_name, NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid()); @@ -1181,7 +919,6 @@ dlt_user.dlt_segmented_queue_read_handle = DLT_FD_INIT; pthread_cond_destroy(&mq_init_condition); -#endif /* DLT_NETWORK_TRACE_ENABLE */ sem_destroy(&dlt_mutex); /* allow the user app to do dlt_init() again. */ @@ -1205,7 +942,7 @@ if (g_dlt_is_child) return DLT_RETURN_ERROR; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -1257,8 +994,10 @@ dlt_user.application_description = malloc(desc_len + 1); if (dlt_user.application_description) { - strncpy(dlt_user.application_description, description, desc_len + 1); - } else { + strncpy(dlt_user.application_description, description, desc_len); + dlt_user.application_description[desc_len] = '\0'; + } + else { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -1284,7 +1023,7 @@ if (g_dlt_is_child) return DLT_RETURN_ERROR; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -1421,43 +1160,40 @@ } } - /* New context entry to be initialized */ - dlt_ll_ts_type *ctx_entry; - ctx_entry = &dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries]; - /* Store locally context id and context description */ - dlt_set_id(ctx_entry->contextID, contextid); + dlt_set_id(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].contextID, contextid); - if (ctx_entry->context_description != 0) - free(ctx_entry->context_description); + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description != 0) + free(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description); - ctx_entry->context_description = 0; + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = 0; if (description != 0) { size_t desc_len = strlen(description); - ctx_entry->context_description = malloc(desc_len + 1); + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = malloc(desc_len + 1); - if (ctx_entry->context_description == 0) { + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } - strncpy(ctx_entry->context_description, description, desc_len + 1); + strncpy(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description, description, desc_len); + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len] = '\0'; } - if (ctx_entry->log_level_ptr == 0) { - ctx_entry->log_level_ptr = malloc(sizeof(int8_t)); + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) { + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr = malloc(sizeof(int8_t)); - if (ctx_entry->log_level_ptr == 0) { + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } } - if (ctx_entry->trace_status_ptr == 0) { - ctx_entry->trace_status_ptr = malloc(sizeof(int8_t)); + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) { + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr = malloc(sizeof(int8_t)); - if (ctx_entry->trace_status_ptr == 0) { + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -1470,29 +1206,31 @@ DLT_USER_LOG_LEVEL_NOT_SET); if (envLogLevel != DLT_USER_LOG_LEVEL_NOT_SET) { - ctx_entry->log_level = (int8_t) envLogLevel; + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = envLogLevel; loglevel = envLogLevel; } else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET) { - ctx_entry->log_level = (int8_t) loglevel; + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel; } if (tracestatus != DLT_USER_TRACE_STATUS_NOT_SET) - ctx_entry->trace_status = (int8_t) tracestatus; + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus; /* Prepare transfer struct */ dlt_set_id(handle->contextID, contextid); - handle->log_level_pos = (int32_t) dlt_user.dlt_ll_ts_num_entries; + handle->log_level_pos = dlt_user.dlt_ll_ts_num_entries; - handle->log_level_ptr = ctx_entry->log_level_ptr; - handle->trace_status_ptr = ctx_entry->trace_status_ptr; + handle->log_level_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr; + handle->trace_status_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr; - log.context_description = ctx_entry->context_description; + log.context_description = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description; - *(ctx_entry->log_level_ptr) = ctx_entry->log_level; - *(ctx_entry->trace_status_ptr) = ctx_entry->trace_status = (int8_t) tracestatus; - ctx_entry->log_level_changed_callback = dlt_log_level_changed_callback; + *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) = + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level; + *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) = + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus; + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_changed_callback = dlt_log_level_changed_callback; log.log_level = loglevel; log.trace_status = tracestatus; @@ -1533,7 +1271,7 @@ if (g_dlt_is_child) return DLT_RETURN_ERROR; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -1548,9 +1286,7 @@ dlt_log_level_changed_callback); } -/* If force_sending_messages is set to true, do not clean appIDs when there are - * still data in startup_buffer. atexit_handler will free the appIDs */ -DltReturnValue dlt_unregister_app_util(bool force_sending_messages) +DltReturnValue dlt_unregister_app(void) { DltReturnValue ret = DLT_RETURN_OK; @@ -1558,8 +1294,8 @@ if (g_dlt_is_child) return DLT_RETURN_ERROR; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -1568,29 +1304,19 @@ DLT_SEM_LOCK(); - int count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); - if (!force_sending_messages || - (force_sending_messages && count == 0)) - { - /* Clear and free local stored application information */ - dlt_set_id(dlt_user.appID, ""); + /* Clear and free local stored application information */ + dlt_set_id(dlt_user.appID, ""); - if (dlt_user.application_description != NULL) - free(dlt_user.application_description); + if (dlt_user.application_description != NULL) + free(dlt_user.application_description); - dlt_user.application_description = NULL; - } + dlt_user.application_description = NULL; DLT_SEM_FREE(); return ret; } -DltReturnValue dlt_unregister_app(void) -{ - return dlt_unregister_app_util(false); -} - DltReturnValue dlt_unregister_app_flush_buffered_logs(void) { DltReturnValue ret = DLT_RETURN_OK; @@ -1599,8 +1325,8 @@ if (g_dlt_is_child) return DLT_RETURN_ERROR; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_ERR, "%s dlt_user_initialised false\n", __func__); return DLT_RETURN_ERROR; } @@ -1610,7 +1336,7 @@ while ((ret != DLT_RETURN_OK) && (dlt_user.dlt_log_handle != -1)); } - return dlt_unregister_app_util(true); + return dlt_unregister_app(); } DltReturnValue dlt_unregister_context(DltContext *handle) @@ -1690,7 +1416,7 @@ return DLT_RETURN_WRONG_PARAMETER; } - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -1729,8 +1455,6 @@ DltReturnValue dlt_set_log_mode(DltUserLogMode mode) { - DLT_UNUSED(mode); - /* forbid dlt usage in child after fork */ if (g_dlt_is_child) return DLT_RETURN_ERROR; @@ -1740,7 +1464,7 @@ return DLT_RETURN_WRONG_PARAMETER; } - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -1756,7 +1480,7 @@ if (g_dlt_is_child) return DLT_RETURN_ERROR; - if (DLT_USER_INITALIZED == 0) + if (dlt_user_initialised == 0) if (dlt_init() < 0) return -1; @@ -1766,35 +1490,9 @@ /* ********************************************************************************************* */ -DltReturnValue dlt_user_log_write_start_init(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - bool is_verbose) -{ - DLT_LOG_FATAL_RESET_TRAP(loglevel); - - /* initialize values */ - if ((dlt_user_log_init(handle, log) < DLT_RETURN_OK) || (dlt_user.dlt_ll_ts == NULL)) - return DLT_RETURN_ERROR; - - log->args_num = 0; - log->log_level = loglevel; - log->size = 0; - log->use_timestamp = DLT_AUTO_TIMESTAMP; - log->verbose_mode = is_verbose; - - return DLT_RETURN_TRUE; -} - -static DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - uint32_t messageid, - bool is_verbose); - inline DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel) { - return dlt_user_log_write_start_internal(handle, log, loglevel, DLT_USER_DEFAULT_MSGID, true); + return dlt_user_log_write_start_id(handle, log, loglevel, DLT_USER_DEFAULT_MSGID); } DltReturnValue dlt_user_log_write_start_id(DltContext *handle, @@ -1802,16 +1500,8 @@ DltLogLevelType loglevel, uint32_t messageid) { - return dlt_user_log_write_start_internal(handle, log, loglevel, messageid, false); -} - -DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - uint32_t messageid, - bool is_verbose) -{ - int ret = DLT_RETURN_TRUE; + DLT_LOG_FATAL_RESET_TRAP(loglevel); + DltReturnValue ret = DLT_RETURN_OK; /* check nullpointer */ if ((handle == NULL) || (log == NULL)) @@ -1824,84 +1514,46 @@ /* check log levels */ ret = dlt_user_is_logLevel_enabled(handle, loglevel); - if (ret == DLT_RETURN_WRONG_PARAMETER) { + if (ret == DLT_RETURN_WRONG_PARAMETER) return DLT_RETURN_WRONG_PARAMETER; - } else if (ret == DLT_RETURN_LOGGING_DISABLED) { - log->handle = NULL; + else if (ret == DLT_RETURN_LOGGING_DISABLED) return DLT_RETURN_OK; - } + else + /* Do nothing */ - ret = dlt_user_log_write_start_init(handle, log, loglevel, is_verbose); - if (ret == DLT_RETURN_TRUE) { - /* initialize values */ - if ((NULL != log->buffer)) - { - free(log->buffer); - log->buffer = NULL; - } - else - { - log->buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - } + /* initialize values */ + if ((dlt_user_log_init(handle, log) < DLT_RETURN_OK) || (dlt_user.dlt_ll_ts == NULL)) + return DLT_RETURN_ERROR; + + /* initialize values */ + if (log->buffer == NULL) { + log->buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); if (log->buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; } - else - { - /* In non-verbose mode, insert message id */ - if (!is_verbose_mode(dlt_user.verbose_mode, log)) { - if ((sizeof(uint32_t)) > dlt_user.log_buf_len) - return DLT_RETURN_USER_BUFFER_FULL; - - /* Write message id */ - memcpy(log->buffer, &(messageid), sizeof(uint32_t)); - log->size = sizeof(uint32_t); - - /* as the message id is part of each message in non-verbose mode, - * it doesn't increment the argument counter in extended header (if used) */ - } - } } - return ret; -} - -DltReturnValue dlt_user_log_write_start_w_given_buffer(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - char *buffer, - size_t size, - int32_t args_num) -{ - int ret = DLT_RETURN_TRUE; - - /* check nullpointer */ - if ((handle == NULL) || (log == NULL) || (buffer == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - /* discard unexpected parameters */ - if ((size <= 0) || (size > dlt_user.log_buf_len) || (args_num <= 0)) - return DLT_RETURN_WRONG_PARAMETER; + log->args_num = 0; + log->log_level = loglevel; + log->size = 0; - /* forbid dlt usage in child after fork */ - if (g_dlt_is_child) - return DLT_RETURN_ERROR; + /* In non-verbose mode, insert message id */ + if (dlt_user.verbose_mode == 0) { + if ((sizeof(uint32_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; - /* discard non-verbose mode */ - if (dlt_user.verbose_mode == 0) - return DLT_RETURN_ERROR; + /* Write message id */ + memcpy(log->buffer, &(messageid), sizeof(uint32_t)); + log->size = sizeof(uint32_t); - ret = dlt_user_log_write_start_init(handle, log, loglevel, true); - if (ret == DLT_RETURN_TRUE) { - log->buffer = (unsigned char *)buffer; - log->size = size; - log->args_num = args_num; + /* as the message id is part of each message in non-verbose mode, + * it doesn't increment the argument counter in extended header (if used) */ } - return ret; - } + return DLT_RETURN_TRUE; +} DltReturnValue dlt_user_log_write_finish(DltContextData *log) { @@ -1917,56 +1569,45 @@ return ret; } -DltReturnValue dlt_user_log_write_finish_w_given_buffer(DltContextData *log) +DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length) { - int ret = DLT_RETURN_ERROR; - - if (log == NULL) - return DLT_RETURN_WRONG_PARAMETER; - - ret = dlt_user_log_send_log(log, DLT_TYPE_LOG); - - return ret; + return dlt_user_log_write_raw_formatted(log, data, length, DLT_FORMAT_DEFAULT); } -static DltReturnValue dlt_user_log_write_raw_internal(DltContextData *log, const void *data, uint16_t length, DltFormatType type, const char *name, bool with_var_info) +DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type) { + size_t new_log_size = 0; + uint32_t type_info = 0; + /* check nullpointer */ if ((log == NULL) || ((data == NULL) && (length != 0))) return DLT_RETURN_WRONG_PARAMETER; /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { - dlt_vlog(LOG_ERR, "Format type %u is outside valid range", type); + dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - const uint16_t name_size = (name != NULL) ? strlen(name)+1 : 0; + new_log_size = log->size + length + sizeof(uint16_t); - size_t needed_size = length + sizeof(uint16_t); - if ((log->size + needed_size) > dlt_user.log_buf_len) + if (new_log_size > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (is_verbose_mode(dlt_user.verbose_mode, log)) { - uint32_t type_info = DLT_TYPE_INFO_RAWD; - - needed_size += sizeof(uint32_t); // Type Info field - if (with_var_info) { - needed_size += sizeof(uint16_t); // length of name - needed_size += name_size; // the name itself + if (dlt_user.verbose_mode) { + new_log_size = log->size + length + sizeof(uint32_t) + sizeof(uint16_t); - type_info |= DLT_TYPE_INFO_VARI; - } - if ((log->size + needed_size) > dlt_user.log_buf_len) + if (new_log_size > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - // Genivi extension: put formatting hints into the unused (for RAWD) TYLE + SCOD fields. - // The SCOD field holds the base (hex or bin); the TYLE field holds the column width (8bit..64bit). + /* Transmit type information */ + type_info = DLT_TYPE_INFO_RAWD; + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) { type_info |= DLT_SCOD_HEX; type_info += type; @@ -1977,31 +1618,15 @@ type_info += type - DLT_FORMAT_BIN8 + 1; } - memcpy(log->buffer + log->size, &type_info, sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy(log->buffer + log->size, &length, sizeof(uint16_t)); + /* First transmit length of raw data, then the raw data itself */ + memcpy((log->buffer) + log->size, &(length), sizeof(uint16_t)); log->size += sizeof(uint16_t); - if (is_verbose_mode(dlt_user.verbose_mode, log)) { - if (with_var_info) { - // Write length of "name" attribute. - // We assume that the protocol allows zero-sized strings here (which this code will create - // when the input pointer is NULL). - memcpy(log->buffer + log->size, &name_size, sizeof(uint16_t)); - log->size += sizeof(uint16_t); - - // Write name string itself. - // Must not use NULL as source pointer for memcpy. This check assures that. - if (name_size != 0) { - memcpy(log->buffer + log->size, name, name_size); - log->size += name_size; - } - } - } - - memcpy(log->buffer + log->size, data, length); + memcpy((log->buffer) + log->size, data, length); log->size += length; log->args_num++; @@ -2009,189 +1634,85 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length) -{ - return dlt_user_log_write_raw_internal(log, data, length, DLT_FORMAT_DEFAULT, NULL, false); -} - -DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type) -{ - return dlt_user_log_write_raw_internal(log, data, length, type, NULL, false); -} - -DltReturnValue dlt_user_log_write_raw_attr(DltContextData *log, const void *data, uint16_t length, const char *name) -{ - return dlt_user_log_write_raw_internal(log, data, length, DLT_FORMAT_DEFAULT, name, true); -} - -DltReturnValue dlt_user_log_write_raw_formatted_attr(DltContextData *log, const void *data, uint16_t length, DltFormatType type, const char *name) +DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data) { - return dlt_user_log_write_raw_internal(log, data, length, type, name, true); -} + uint32_t type_info; -// Generic implementation for all "simple" types, possibly with attributes -static DltReturnValue dlt_user_log_write_generic_attr(DltContextData *log, const void *datap, size_t datalen, uint32_t type_info, const VarInfo *varinfo) -{ if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - size_t needed_size = datalen; - if ((log->size + needed_size) > dlt_user.log_buf_len) - return DLT_RETURN_USER_BUFFER_FULL; - - if (is_verbose_mode(dlt_user.verbose_mode, log)) { - bool with_var_info = (varinfo != NULL); - - uint16_t name_size; - uint16_t unit_size; + if (sizeof(float32_t) != 4) + return DLT_RETURN_ERROR; - needed_size += sizeof(uint32_t); // Type Info field - if (with_var_info) { - name_size = (varinfo->name != NULL) ? strlen(varinfo->name)+1 : 0; - unit_size = (varinfo->unit != NULL) ? strlen(varinfo->unit)+1 : 0; - - needed_size += sizeof(uint16_t); // length of name - needed_size += name_size; // the name itself - if (varinfo->with_unit) { - needed_size += sizeof(uint16_t); // length of unit - needed_size += unit_size; // the unit itself - } + if ((log->size + sizeof(float32_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; - type_info |= DLT_TYPE_INFO_VARI; - } - if ((log->size + needed_size) > dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(float32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - memcpy(log->buffer + log->size, &type_info, sizeof(uint32_t)); - log->size += sizeof(uint32_t); - - if (with_var_info) { - // Write lengths of name/unit strings - // We assume here that the protocol allows zero-sized strings here (which occur - // when the input pointers are NULL). - memcpy(log->buffer + log->size, &name_size, sizeof(uint16_t)); - log->size += sizeof(uint16_t); - if (varinfo->with_unit) { - memcpy(log->buffer + log->size, &unit_size, sizeof(uint16_t)); - log->size += sizeof(uint16_t); - } + type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - // Write name/unit strings themselves - // Must not use NULL as source pointer for memcpy. - if (name_size != 0) { - memcpy(log->buffer + log->size, varinfo->name, name_size); - log->size += name_size; - } - if (unit_size != 0) { - memcpy(log->buffer + log->size, varinfo->unit, unit_size); - log->size += unit_size; - } - } + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); } - memcpy(log->buffer + log->size, datap, datalen); - log->size += datalen; + memcpy((log->buffer) + log->size, &data, sizeof(float32_t)); + log->size += sizeof(float32_t); log->args_num++; return DLT_RETURN_OK; } -// Generic implementation for all "simple" types -static DltReturnValue dlt_user_log_write_generic_formatted(DltContextData *log, const void *datap, size_t datalen, uint32_t type_info, DltFormatType type) +DltReturnValue dlt_user_log_write_float64(DltContextData *log, float64_t data) { + uint32_t type_info; + if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ - if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { - dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); - return DLT_RETURN_WRONG_PARAMETER; + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; } - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (sizeof(float64_t) != 8) return DLT_RETURN_ERROR; - } - size_t needed_size = datalen; - if ((log->size + needed_size) > dlt_user.log_buf_len) + if ((log->size + sizeof(float64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (is_verbose_mode(dlt_user.verbose_mode, log)) { - needed_size += sizeof(uint32_t); // Type Info field - if ((log->size + needed_size) > dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(float64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - // Genivi extension: put formatting hints into the unused (for SINT/UINT/FLOA) SCOD field. - if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) - type_info |= DLT_SCOD_HEX; + type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) - type_info |= DLT_SCOD_BIN; - - memcpy(log->buffer + log->size, &type_info, sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy(log->buffer + log->size, datap, datalen); - log->size += datalen; + memcpy((log->buffer) + log->size, &data, sizeof(float64_t)); + log->size += sizeof(float64_t); log->args_num++; return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data) -{ - if (sizeof(float32_t) != 4) - return DLT_RETURN_ERROR; - - uint32_t type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(float32_t), type_info, NULL); -} - -DltReturnValue dlt_user_log_write_float64(DltContextData *log, float64_t data) -{ - if (sizeof(float64_t) != 8) - return DLT_RETURN_ERROR; - - uint32_t type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(float64_t), type_info, NULL); -} - -DltReturnValue dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit) -{ - if (sizeof(float32_t) != 4) - return DLT_RETURN_ERROR; - - uint32_t type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(float32_t), type_info, &var_info); -} - -DltReturnValue dlt_user_log_write_float64_attr(DltContextData *log, float64_t data, const char *name, const char *unit) -{ - if (sizeof(float64_t) != 8) - return DLT_RETURN_ERROR; - - uint32_t type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(float64_t), type_info, &var_info); -} - DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -2228,119 +1749,314 @@ DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, NULL); + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } + + if ((log->size + sizeof(uint8_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint8_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(uint8_t)); + log->size += sizeof(uint8_t); + + log->args_num++; + + return DLT_RETURN_OK; } DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint16_t), type_info, NULL); + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } + + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(uint16_t)); + log->size += sizeof(uint16_t); + + log->args_num++; + + return DLT_RETURN_OK; } DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint32_t), type_info, NULL); + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } + + if ((log->size + sizeof(uint32_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint32_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(uint32_t)); + log->size += sizeof(uint32_t); + + log->args_num++; + + return DLT_RETURN_OK; } DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint64_t), type_info, NULL); -} + uint32_t type_info; -DltReturnValue dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit) -{ if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - switch (sizeof(unsigned int)) { - case 1: - { - return dlt_user_log_write_uint8_attr(log, (uint8_t)data, name, unit); - break; - } - case 2: - { - return dlt_user_log_write_uint16_attr(log, (uint16_t)data, name, unit); - break; - } - case 4: - { - return dlt_user_log_write_uint32_attr(log, (uint32_t)data, name, unit); - break; + if ((log->size + sizeof(uint64_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint64_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); } - case 8: - { - return dlt_user_log_write_uint64_attr(log, (uint64_t)data, name, unit); - break; + + memcpy((log->buffer) + log->size, &data, sizeof(uint64_t)); + log->size += sizeof(uint64_t); + + log->args_num++; + + return DLT_RETURN_OK; +} + +DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type) +{ + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { + dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); + return DLT_RETURN_WRONG_PARAMETER; } - default: - { + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; - break; } + + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; + + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) + type_info |= DLT_SCOD_HEX; + + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) + type_info |= DLT_SCOD_BIN; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); } + memcpy((log->buffer) + log->size, &data, sizeof(uint8_t)); + log->size += sizeof(uint8_t); + + log->args_num++; + return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, &var_info); -} + uint32_t type_info; -DltReturnValue dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit) -{ - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint16_t), type_info, &var_info); -} + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; -DltReturnValue dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit) -{ - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint32_t), type_info, &var_info); -} + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { + dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); + return DLT_RETURN_WRONG_PARAMETER; + } -DltReturnValue dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit) -{ - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint64_t), type_info, &var_info); -} + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } -DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type) -{ - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint8_t), type_info, type); -} + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; -DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type) -{ - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint16_t), type_info, type); + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; + + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) + type_info |= DLT_SCOD_HEX; + + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) + type_info |= DLT_SCOD_BIN; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(uint16_t)); + log->size += sizeof(uint16_t); + + log->args_num++; + + return DLT_RETURN_OK; } DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint32_t), type_info, type); + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { + dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); + return DLT_RETURN_WRONG_PARAMETER; + } + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } + + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; + + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) + type_info |= DLT_SCOD_HEX; + + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) + type_info |= DLT_SCOD_BIN; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(uint32_t)); + log->size += sizeof(uint32_t); + + log->args_num++; + + return DLT_RETURN_OK; } DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type) { - uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint64_t), type_info, type); + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { + dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); + return DLT_RETURN_WRONG_PARAMETER; + } + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } + + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; + + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) + type_info |= DLT_SCOD_HEX; + + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) + type_info |= DLT_SCOD_BIN; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(uint64_t)); + log->size += sizeof(uint64_t); + + log->args_num++; + + return DLT_RETURN_OK; } DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data) @@ -2348,7 +2064,7 @@ if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -2356,12 +2072,12 @@ switch (sizeof(void *)) { case 4: return dlt_user_log_write_uint32_formatted(log, - (uintptr_t) data, + (uintptr_t)data, DLT_FORMAT_HEX32); break; case 8: return dlt_user_log_write_uint64_formatted(log, - (uintptr_t) data, + (uintptr_t)data, DLT_FORMAT_HEX64); break; default: @@ -2376,8 +2092,8 @@ if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -2414,246 +2130,222 @@ DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data) { - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int8_t), type_info, NULL); -} + uint32_t type_info; -DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data) -{ - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int16_t), type_info, NULL); -} + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; -DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data) -{ - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int32_t), type_info, NULL); -} + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } -DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data) -{ - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int64_t), type_info, NULL); + if ((log->size + sizeof(int8_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int8_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(int8_t)); + log->size += sizeof(int8_t); + + log->args_num++; + + return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_int_attr(DltContextData *log, int data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data) { + uint32_t type_info; + if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - switch (sizeof(int)) { - case 1: - { - return dlt_user_log_write_int8_attr(log, (int8_t)data, name, unit); - break; - } - case 2: - { - return dlt_user_log_write_int16_attr(log, (int16_t)data, name, unit); - break; - } - case 4: - { - return dlt_user_log_write_int32_attr(log, (int32_t)data, name, unit); - break; - } - case 8: - { - return dlt_user_log_write_int64_attr(log, (int64_t)data, name, unit); - break; + if ((log->size + sizeof(int16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int16_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); } - default: - { + + memcpy((log->buffer) + log->size, &data, sizeof(int16_t)); + log->size += sizeof(int16_t); + + log->args_num++; + + return DLT_RETURN_OK; +} + +DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data) +{ + uint32_t type_info; + + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; + + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; - break; } + + if ((log->size + sizeof(int32_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int32_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; + + type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); } + memcpy((log->buffer) + log->size, &data, sizeof(int32_t)); + log->size += sizeof(int32_t); + + log->args_num++; + return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_int8_attr(DltContextData *log, int8_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data) { - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int8_t), type_info, &var_info); -} + uint32_t type_info; -DltReturnValue dlt_user_log_write_int16_attr(DltContextData *log, int16_t data, const char *name, const char *unit) -{ - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int16_t), type_info, &var_info); -} + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; -DltReturnValue dlt_user_log_write_int32_attr(DltContextData *log, int32_t data, const char *name, const char *unit) -{ - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int32_t), type_info, &var_info); -} + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } -DltReturnValue dlt_user_log_write_int64_attr(DltContextData *log, int64_t data, const char *name, const char *unit) -{ - uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; - const VarInfo var_info = { name, unit, true }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(int64_t), type_info, &var_info); -} + if ((log->size + sizeof(int64_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; -DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data) -{ - uint32_t type_info = DLT_TYPE_INFO_BOOL | DLT_TYLE_8BIT; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, NULL); -} + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int64_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; -DltReturnValue dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name) -{ - uint32_t type_info = DLT_TYPE_INFO_BOOL | DLT_TYLE_8BIT; - const VarInfo var_info = { name, NULL, false }; - return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, &var_info); -} + type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; + + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } + + memcpy((log->buffer) + log->size, &data, sizeof(int64_t)); + log->size += sizeof(int64_t); + + log->args_num++; -DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text) -{ - return dlt_user_log_write_string_utils_attr(log, text, ASCII_STRING, NULL, false); + return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_string_attr(DltContextData *log, const char *text, const char *name) +DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data) { - return dlt_user_log_write_string_utils_attr(log, text, ASCII_STRING, name, true); -} + uint32_t type_info; -DltReturnValue dlt_user_log_write_sized_string(DltContextData *log, const char *text, uint16_t length) -{ - return dlt_user_log_write_sized_string_utils_attr(log, text, length, ASCII_STRING, NULL, false); -} + if (log == NULL) + return DLT_RETURN_WRONG_PARAMETER; -DltReturnValue dlt_user_log_write_sized_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) -{ - return dlt_user_log_write_sized_string_utils_attr(log, text, length, ASCII_STRING, name, true); -} + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); + return DLT_RETURN_ERROR; + } -DltReturnValue dlt_user_log_write_constant_string(DltContextData *log, const char *text) -{ - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_string(log, text) : DLT_RETURN_OK; -} + if ((log->size + sizeof(uint8_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; -DltReturnValue dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name) -{ - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_string_attr(log, text, name) : DLT_RETURN_OK; -} + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint8_t)) > dlt_user.log_buf_len) + return DLT_RETURN_USER_BUFFER_FULL; -DltReturnValue dlt_user_log_write_sized_constant_string(DltContextData *log, const char *text, uint16_t length) -{ - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_string(log, text, length) : DLT_RETURN_OK; -} + type_info = DLT_TYPE_INFO_BOOL; -DltReturnValue dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) -{ - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_string_attr(log, text, length, name) : DLT_RETURN_OK; -} + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); + } -DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *text) -{ - return dlt_user_log_write_string_utils_attr(log, text, UTF8_STRING, NULL, false); -} + memcpy((log->buffer) + log->size, &data, sizeof(uint8_t)); + log->size += sizeof(uint8_t); -DltReturnValue dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name) -{ - return dlt_user_log_write_string_utils_attr(log, text, UTF8_STRING, name, true); -} + log->args_num++; -DltReturnValue dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length) -{ - return dlt_user_log_write_sized_string_utils_attr(log, text, length, UTF8_STRING, NULL, false); + return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) +DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text) { - return dlt_user_log_write_sized_string_utils_attr(log, text, length, UTF8_STRING, name, true); + return dlt_user_log_write_string_utils(log, text, ASCII_STRING); } -DltReturnValue dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text) +DltReturnValue dlt_user_log_write_constant_string(DltContextData *log, const char *text) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_utf8_string(log, text) : DLT_RETURN_OK; + return dlt_user.verbose_mode ? dlt_user_log_write_string(log, text) : DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name) +DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *text) { - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_utf8_string_attr(log, text, name) : DLT_RETURN_OK; + return dlt_user_log_write_string_utils(log, text, UTF8_STRING); } -DltReturnValue dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text, uint16_t length) +DltReturnValue dlt_user_log_write_string_utils(DltContextData *log, const char *text, const enum StringType type) { - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_utf8_string(log, text, length) : DLT_RETURN_OK; -} + uint16_t arg_size = 0; + uint32_t type_info = 0; + size_t new_log_size = 0; + DltReturnValue ret = DLT_RETURN_OK; -DltReturnValue dlt_user_log_write_sized_constant_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) -{ - /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_utf8_string_attr(log, text, length, name) : DLT_RETURN_OK; -} + size_t str_truncate_message_length = strlen(STR_TRUNCATED_MESSAGE) + 1; + size_t max_payload_str_msg; -static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData *log, const char *text, size_t length, const enum StringType type, const char *name, bool with_var_info) -{ if ((log == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - const uint16_t name_size = (name != NULL) ? strlen(name)+1 : 0; - - size_t arg_size = (size_t) (length + 1); - - size_t new_log_size = log->size + arg_size + sizeof(uint16_t); + arg_size = strlen(text) + 1; - uint32_t type_info = 0; + new_log_size = log->size + arg_size + sizeof(uint16_t); - if (is_verbose_mode(dlt_user.verbose_mode, log)) { + if (dlt_user.verbose_mode) new_log_size += sizeof(uint32_t); - if (with_var_info) { - new_log_size += sizeof(uint16_t); // length of "name" attribute - new_log_size += name_size; // the "name" attribute itself - - type_info |= DLT_TYPE_INFO_VARI; - } - } - - size_t str_truncate_message_length = strlen(STR_TRUNCATED_MESSAGE) + 1; - size_t max_payload_str_msg; - DltReturnValue ret = DLT_RETURN_OK; /* Check log size condition */ if (new_log_size > dlt_user.log_buf_len) { ret = DLT_RETURN_USER_BUFFER_FULL; /* Re-calculate arg_size */ - arg_size = (size_t) (dlt_user.log_buf_len - log->size - sizeof(uint16_t)); + arg_size = dlt_user.log_buf_len - log->size - sizeof(uint16_t); size_t min_payload_str_truncate_msg = log->size + str_truncate_message_length + sizeof(uint16_t); - if (is_verbose_mode(dlt_user.verbose_mode, log)) { + if (dlt_user.verbose_mode) { min_payload_str_truncate_msg += sizeof(uint32_t); - arg_size -= (size_t) sizeof(uint32_t); - if (with_var_info) { - min_payload_str_truncate_msg += sizeof(uint16_t) + name_size; - arg_size -= sizeof(uint16_t) + name_size; - } + arg_size -= sizeof(uint32_t); } /* Return when dlt_user.log_buf_len does not have enough space for min_payload_str_truncate_msg */ @@ -2687,65 +2379,52 @@ } max_payload_str_msg -= reduce_size; - arg_size -= (size_t) reduce_size; + arg_size -= reduce_size; } } - if (is_verbose_mode(dlt_user.verbose_mode, log)) { + if (dlt_user.verbose_mode) { switch (type) { case ASCII_STRING: - type_info |= DLT_TYPE_INFO_STRG | DLT_SCOD_ASCII; + { + type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_ASCII; break; + } case UTF8_STRING: - type_info |= DLT_TYPE_INFO_STRG | DLT_SCOD_UTF8; + { + type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_UTF8; break; + } default: + { /* Do nothing */ break; } + } - memcpy(log->buffer + log->size, &type_info, sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy(log->buffer + log->size, &arg_size, sizeof(uint16_t)); + memcpy((log->buffer) + log->size, &(arg_size), sizeof(uint16_t)); log->size += sizeof(uint16_t); - if (is_verbose_mode(dlt_user.verbose_mode, log)) { - if (with_var_info) { - // Write length of "name" attribute. - // We assume that the protocol allows zero-sized strings here (which this code will create - // when the input pointer is NULL). - memcpy(log->buffer + log->size, &name_size, sizeof(uint16_t)); - log->size += sizeof(uint16_t); - - // Write name string itself. - // Must not use NULL as source pointer for memcpy. This check assures that. - if (name_size != 0) { - memcpy(log->buffer + log->size, name, name_size); - log->size += name_size; - } - } - } - switch (ret) { case DLT_RETURN_OK: { /* Whole string will be copied */ - memcpy(log->buffer + log->size, text, length); - /* The input string might not be null-terminated, so we're doing that by ourselves */ - log->buffer[log->size + length] = '\0'; + memcpy((log->buffer) + log->size, text, arg_size); log->size += arg_size; break; } case DLT_RETURN_USER_BUFFER_FULL: { /* Only copy partial string */ - memcpy(log->buffer + log->size, text, max_payload_str_msg); + memcpy((log->buffer) + log->size, text, max_payload_str_msg); log->size += max_payload_str_msg; /* Append string truncate the input string */ - memcpy(log->buffer + log->size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); + memcpy((log->buffer) + log->size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); log->size += str_truncate_message_length; break; } @@ -2761,15 +2440,6 @@ return ret; } -static DltReturnValue dlt_user_log_write_string_utils_attr(DltContextData *log, const char *text, const enum StringType type, const char *name, bool with_var_info) -{ - if ((log == NULL) || (text == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - size_t length = strlen(text); - return dlt_user_log_write_sized_string_utils_attr(log, text, length, type, name, with_var_info); -} - DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint32_t service_id, dlt_injection_callback_id dlt_injection_cbk, void *priv) { @@ -2798,7 +2468,7 @@ } /* Insert callback in corresponding table */ - i = (uint32_t) handle->log_level_pos; + i = handle->log_level_pos; /* Insert each service_id only once */ for (k = 0; k < dlt_user.dlt_ll_ts[i].nrcallbacks; k++) @@ -2846,7 +2516,7 @@ dlt_user.dlt_ll_ts[i].injection_table[j].service_id = service_id; if (priv == NULL) { - dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = (dlt_injection_callback)(void*)dlt_injection_cbk; + dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = (dlt_injection_callback)dlt_injection_cbk; dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback_with_id = NULL; dlt_user.dlt_ll_ts[i].injection_table[j].data = NULL; } @@ -2868,7 +2538,7 @@ { return dlt_register_injection_callback_with_id(handle, service_id, - (dlt_injection_callback_id)(void*)dlt_injection_callback, + (dlt_injection_callback_id)dlt_injection_callback, NULL); } @@ -2897,7 +2567,7 @@ } /* Insert callback in corresponding table */ - i = (uint32_t) handle->log_level_pos; + i = handle->log_level_pos; /* Store new callback function */ dlt_user.dlt_ll_ts[i].log_level_changed_callback = dlt_log_level_changed_callback; @@ -2911,7 +2581,7 @@ * NW Trace related */ -#ifdef DLT_NETWORK_TRACE_ENABLE + int check_buffer(void) { int total_size, used_size; @@ -2931,7 +2601,7 @@ void *header, uint16_t payload_len) { - DltContextData log = { 0 }; + DltContextData log; struct timeval tv; int ret = DLT_RETURN_ERROR; @@ -2940,7 +2610,7 @@ return DLT_RETURN_WRONG_PARAMETER; if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { - dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type); + dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } @@ -2966,7 +2636,7 @@ log.size = 0; gettimeofday(&tv, NULL); - *id = (uint32_t) tv.tv_usec; + *id = tv.tv_usec; /* Write identifier */ if (dlt_user_log_write_string(&log, DLT_TRACE_NW_START) < 0) { @@ -2993,7 +2663,7 @@ } /* Write expected segment count */ - uint16_t segment_count = (uint16_t) (payload_len / DLT_MAX_TRACE_SEGMENT_SIZE + 1); + uint16_t segment_count = payload_len / DLT_MAX_TRACE_SEGMENT_SIZE + 1; /* If segments align perfectly with segment size, avoid sending empty segment */ if ((payload_len % DLT_MAX_TRACE_SEGMENT_SIZE) == 0) @@ -3032,7 +2702,7 @@ struct timespec ts; if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { - dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type); + dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } @@ -3048,7 +2718,7 @@ return DLT_RETURN_ERROR; if (handle->trace_status_ptr && (*(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)) { - DltContextData log = { 0 }; + DltContextData log; if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; @@ -3080,7 +2750,7 @@ } /* Write segment sequence number */ - if (dlt_user_log_write_uint16(&log, (uint16_t) sequence) < DLT_RETURN_OK) { + if (dlt_user_log_write_uint16(&log, sequence) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } @@ -3106,11 +2776,11 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *handle, DltNetworkTraceType nw_trace_type) { - DltContextData log = { 0 }; + DltContextData log; int ret = DLT_RETURN_ERROR; if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { - dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type); + dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } @@ -3160,16 +2830,13 @@ return DLT_RETURN_OK; } + void dlt_user_trace_network_segmented_thread(void *unused) { /* Unused on purpose. */ (void)unused; -#ifdef DLT_USE_PTHREAD_SETNAME_NP - if (pthread_setname_np(dlt_user.dlt_segmented_nwt_handle, "dlt_segmented")) - dlt_log(LOG_WARNING, "Failed to rename segmented thread!\n"); -#elif linux - if (prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0) < 0) - dlt_log(LOG_WARNING, "Failed to rename segmented thread!\n"); +#ifdef linux + prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0); #endif pthread_cleanup_push(dlt_user_cleanup_handler, NULL); @@ -3179,10 +2846,8 @@ /* Wait until message queue is initialized */ dlt_lock_mutex(&mq_mutex); - while (dlt_user.dlt_segmented_queue_read_handle < 0) - { + if (dlt_user.dlt_segmented_queue_read_handle < 0) pthread_cond_wait(&mq_init_condition, &mq_mutex); - } dlt_unlock_mutex(&mq_mutex); @@ -3210,6 +2875,26 @@ continue; } + /* Indicator just to try to flush the buffer */ + /* DLT_NW_TRACE_RESEND custom type is used to mark a resend */ + if (data->nw_trace_type == DLT_NW_TRACE_RESEND) { + struct timespec req; + /* Sleep 100ms, to allow other process to read FIFO */ + req.tv_sec = 0; + req.tv_nsec = 100 * 1000 * 1000; + nanosleep(&req, NULL); + + if (dlt_user_log_resend_buffer() < 0) { + /* Requeue if still not empty */ + if (dlt_user_queue_resend() < 0) { + /*dlt_log(LOG_WARNING, "Failed to queue resending in dlt_user_trace_network_segmented_thread.\n"); */ + } + } + + free(data); + continue; + } + dlt_user_trace_network_segmented_thread_segmenter(data); /* Send the end message */ @@ -3238,7 +2923,7 @@ uint16_t len = 0; if (offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len) - len = (uint16_t) (data->payload_len - offset); + len = data->payload_len - offset; else len = DLT_MAX_TRACE_SEGMENT_SIZE; @@ -3271,10 +2956,6 @@ uint16_t payload_len, void *payload) { - /* forbid dlt usage in child after fork */ - if (g_dlt_is_child) - return DLT_RETURN_ERROR; - /* Send as normal trace if possible */ if (header_len + payload_len + sizeof(uint16_t) < dlt_user.log_buf_len) return dlt_user_trace_network(handle, nw_trace_type, header_len, header, payload_len, payload); @@ -3310,11 +2991,9 @@ /* Send start message */ DltReturnValue err = dlt_user_trace_network_segmented_start(&(thread_data->id), - thread_data->handle, - thread_data->nw_trace_type, - (uint16_t) thread_data->header_len, - thread_data->header, - (uint16_t) thread_data->payload_len); + thread_data->handle, thread_data->nw_trace_type, + thread_data->header_len, thread_data->header, + thread_data->payload_len); if ((err == DLT_RETURN_BUFFER_FULL) || (err == DLT_RETURN_ERROR)) { dlt_log(LOG_ERR, "NWTSegmented: Could not send start segment. Aborting.\n"); @@ -3371,13 +3050,14 @@ int allow_truncate) { int ret = DLT_RETURN_ERROR; - DltContextData log = { 0 }; if ((payload == NULL) && (payload_len > 0)) return DLT_RETURN_WRONG_PARAMETER; + DltContextData log; + if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { - dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type); + dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } @@ -3408,7 +3088,7 @@ /* If truncation is allowed, check if we must do it */ if ((allow_truncate > 0) && ((header_len + payload_len + sizeof(uint16_t)) > dlt_user.log_buf_len)) { /* Identify as truncated */ - if (dlt_user_log_write_string(&log, DLT_TRACE_NW_TRUNCATED) < DLT_RETURN_OK) { + if (dlt_user_log_write_string(&log, DLT_TRACE_NW_END) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } @@ -3429,7 +3109,7 @@ * Calculate maximum available space in sending buffer after headers. */ - uint16_t truncated_payload_len = (uint16_t) (dlt_user.log_buf_len - log.size - sizeof(uint16_t) - sizeof(uint32_t)); + int truncated_payload_len = dlt_user.log_buf_len - log.size - sizeof(uint16_t) - sizeof(uint32_t); /* Write truncated payload */ if (dlt_user_log_write_raw(&log, payload, truncated_payload_len) < DLT_RETURN_OK) { @@ -3465,19 +3145,18 @@ return DLT_RETURN_OK; } -#endif /* DLT_NETWORK_TRACE_ENABLE */ DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text) { - if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) + DltReturnValue ret = DLT_RETURN_OK; + DltContextData log; + + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; if ((handle == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - DltReturnValue ret = DLT_RETURN_OK; - DltContextData log; - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { ret = dlt_user_log_write_string(&log, text); @@ -3490,15 +3169,15 @@ DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, const char *text, int data) { - if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) + DltReturnValue ret = DLT_RETURN_OK; + DltContextData log; + + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; if ((handle == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - DltReturnValue ret = DLT_RETURN_OK; - DltContextData log; - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { ret = dlt_user_log_write_string(&log, text); dlt_user_log_write_int(&log, data); @@ -3512,15 +3191,15 @@ DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data) { - if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) + DltReturnValue ret = DLT_RETURN_OK; + DltContextData log; + + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; if ((handle == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - DltReturnValue ret = DLT_RETURN_OK; - DltContextData log; - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { ret = dlt_user_log_write_string(&log, text); dlt_user_log_write_uint(&log, data); @@ -3534,14 +3213,14 @@ DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int data) { - if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) + DltContextData log; + + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; if (handle == NULL) return DLT_RETURN_ERROR; - DltContextData log; - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { dlt_user_log_write_int(&log, data); @@ -3554,14 +3233,14 @@ DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsigned int data) { - if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) + DltContextData log; + + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; if (handle == NULL) return DLT_RETURN_WRONG_PARAMETER; - DltContextData log; - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { dlt_user_log_write_uint(&log, data); @@ -3574,15 +3253,15 @@ DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *data, uint16_t length) { - if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) + DltContextData log; + DltReturnValue ret = DLT_RETURN_OK; + + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; if (handle == NULL) return DLT_RETURN_WRONG_PARAMETER; - DltContextData log; - DltReturnValue ret = DLT_RETURN_OK; - if (dlt_user_log_write_start(handle, &log, loglevel) > 0) { if ((ret = dlt_user_log_write_raw(&log, data, length)) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); @@ -3598,7 +3277,7 @@ DltReturnValue dlt_log_marker() { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3610,7 +3289,7 @@ DltReturnValue dlt_verbose_mode(void) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3625,7 +3304,7 @@ DltReturnValue dlt_nonverbose_mode(void) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3638,31 +3317,31 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extended_header_for_non_verbose) +DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extende_header_for_non_verbose) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } } - /* Set use_extended_header_for_non_verbose */ - dlt_user.use_extended_header_for_non_verbose = use_extended_header_for_non_verbose; + /* Set use_extende_header_for_non_verbose */ + dlt_user.use_extende_header_for_non_verbose = use_extende_header_for_non_verbose; return DLT_RETURN_OK; } DltReturnValue dlt_with_session_id(int8_t with_session_id) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } } - /* Set use_extended_header_for_non_verbose */ + /* Set use_extende_header_for_non_verbose */ dlt_user.with_session_id = with_session_id; return DLT_RETURN_OK; @@ -3670,7 +3349,7 @@ DltReturnValue dlt_with_timestamp(int8_t with_timestamp) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3685,7 +3364,7 @@ DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3700,7 +3379,7 @@ DltReturnValue dlt_enable_local_print(void) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3714,7 +3393,7 @@ DltReturnValue dlt_disable_local_print(void) { - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; @@ -3730,81 +3409,26 @@ static void dlt_user_cleanup_handler(void *arg) { DLT_UNUSED(arg); /* Satisfy compiler */ - -#ifdef DLT_NETWORK_TRACE_ENABLE /* unlock the message queue */ dlt_unlock_mutex(&mq_mutex); -#endif - /* unlock DLT (dlt_mutex) */ DLT_SEM_FREE(); } -void dlt_user_housekeeperthread_function(void *ptr) +void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr) { struct timespec ts; - bool in_loop = true; - int signal_status = 0; - atomic_bool* dlt_housekeeper_running = (atomic_bool*)ptr; - -#ifdef __ANDROID_API__ - sigset_t set; - sigset_t pset; - /* - * bionic is not supporting pthread_cancel so - * use SIGUSR1 to kill thread properly. - */ - sigemptyset(&set); - sigaddset(&set, SIGUSR1); - if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) { - dlt_vlog(LOG_ERR, "Failed to block signal with error [%s]\n", - strerror(errno)); - in_loop = false; - } -#endif - -#ifdef DLT_USE_PTHREAD_SETNAME_NP - if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper")) - dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n"); -#elif linux - if (prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0) < 0) - dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n"); +#ifdef linux + prctl(PR_SET_NAME, "dlt_receiver", 0, 0, 0); #endif pthread_cleanup_push(dlt_user_cleanup_handler, NULL); - // signal dlt thread to be running - *dlt_housekeeper_running = true; - signal_status = pthread_cond_signal(&dlt_housekeeper_running_cond); - if (signal_status != 0) { - dlt_log(LOG_CRIT, "Housekeeper thread failed to signal running state\n"); - } - - while (in_loop) { + while (1) { /* Check for new messages from DLT daemon */ - if (!dlt_user.disable_injection_msg) - if (dlt_user_log_check_user_message() < DLT_RETURN_OK) - /* Critical error */ - dlt_log(LOG_CRIT, "Housekeeper thread encountered error condition\n"); - - /* Reattach to daemon if neccesary */ - dlt_user_log_reattach_to_daemon(); - - /* flush buffer to DLT daemon if possible */ - if (dlt_user.dlt_log_handle != DLT_FD_INIT) - dlt_user_log_resend_buffer(); - -#ifdef __ANDROID_API__ - if (sigpending(&pset)) { - dlt_vlog(LOG_ERR, "sigpending failed with error [%s]!\n", strerror(errno)); - break; - } - - if (sigismember(&pset, SIGUSR1)) { - dlt_log(LOG_NOTICE, "Received SIGUSR1! Stop thread\n"); - break; - } -#endif + if (dlt_user_log_check_user_message() < DLT_RETURN_OK) + /* Critical error */ + dlt_log(LOG_CRIT, "Receiver thread encountered error condition\n"); /* delay */ ts.tv_sec = 0; @@ -3824,7 +3448,7 @@ if ((handle == NULL) || (log == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (!DLT_USER_INITALIZED) { + if (!dlt_user_initialised) { ret = dlt_init(); if (ret < DLT_RETURN_OK) { @@ -3840,6 +3464,54 @@ return ret; } +DltReturnValue dlt_user_queue_resend(void) +{ + static unsigned char dlt_user_queue_resend_error_counter = 0; + + if (dlt_user.dlt_log_handle < 0) + /* Fail silenty. FIFO is not open yet */ + return DLT_RETURN_ERROR; + + /** + * Ask segmented thread to try emptying the buffer soon. + * This will be freed in dlt_user_trace_network_segmented_thread + * */ + s_segmented_data *resend_data = malloc(sizeof(s_segmented_data)); + + if (resend_data == NULL) + return DLT_RETURN_ERROR; + + /* DLT_NW_TRACE_RESEND custom type is used to mark a resend */ + resend_data->nw_trace_type = DLT_NW_TRACE_RESEND; + + /* Open queue if it is not open */ + if (dlt_init_message_queue() < DLT_RETURN_OK) { + if (!dlt_user_queue_resend_error_counter) + /* log error only when problem occurred first time */ + dlt_log(LOG_WARNING, "NWTSegmented: Could not open queue.\n"); + + dlt_user_queue_resend_error_counter = 1; + free(resend_data); + return DLT_RETURN_ERROR; + } + + if (mq_send(dlt_user.dlt_segmented_queue_write_handle, (char *)&resend_data, sizeof(s_segmented_data *), 1) < 0) { + if (!dlt_user_queue_resend_error_counter) + /* log error only when problem occurred first time */ + dlt_vnlog(LOG_DEBUG, 256, "Could not request resending.: %s \n", strerror(errno)); + + dlt_user_queue_resend_error_counter = 1; + free(resend_data); + return DLT_RETURN_ERROR; + } + + dlt_user_queue_resend_error_counter = 0; + + /*thread_data will be freed by the receiver function */ + /*coverity[leaked_storage] */ + return DLT_RETURN_OK; +} + DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype) { DltMessage msg; @@ -3848,8 +3520,8 @@ DltReturnValue ret = DLT_RETURN_OK; - if (!DLT_USER_INITALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state != INIT_DONE\n", __FUNCTION__); + if (!dlt_user_initialised) { + dlt_vlog(LOG_ERR, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3861,7 +3533,14 @@ return DLT_RETURN_WRONG_PARAMETER; /* also for Trace messages */ +#ifdef DLT_SHM_ENABLE + + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_SHM) < DLT_RETURN_OK) +#else + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG) < DLT_RETURN_OK) +#endif + return DLT_RETURN_ERROR; if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) @@ -3886,15 +3565,15 @@ /* send session id */ if (dlt_user.with_session_id) { msg.standardheader->htyp |= DLT_HTYP_WSID; - msg.headerextra.seid = (uint32_t) getpid(); + msg.headerextra.seid = getpid(); } - if (is_verbose_mode(dlt_user.verbose_mode, log)) + if (dlt_user.verbose_mode) /* In verbose mode, send extended header */ msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH); else /* In non-verbose, send extended header if desired */ - if (dlt_user.use_extended_header_for_non_verbose) + if (dlt_user.use_extende_header_for_non_verbose) msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH); #if (BYTE_ORDER == BIG_ENDIAN) @@ -3905,14 +3584,8 @@ /* Set header extra parameters */ dlt_set_id(msg.headerextra.ecu, dlt_user.ecuID); - /*msg.headerextra.seid = 0; */ - if (log->use_timestamp == DLT_AUTO_TIMESTAMP) { - msg.headerextra.tmsp = dlt_uptime(); - } - else { - msg.headerextra.tmsp = log->user_timestamp; - } + msg.headerextra.tmsp = dlt_uptime(); if (dlt_message_set_extraparameters(&msg, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; @@ -3927,14 +3600,14 @@ switch (mtype) { case DLT_TYPE_LOG: { - msg.extendedheader->msin = (uint8_t) (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT | - ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + msg.extendedheader->msin = (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | + ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN); break; } case DLT_TYPE_NW_TRACE: { - msg.extendedheader->msin = (uint8_t) (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT | - ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + msg.extendedheader->msin = (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT) | + ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN); break; } default: @@ -3946,23 +3619,23 @@ } /* If in verbose mode, set flag in header for verbose mode */ - if (is_verbose_mode(dlt_user.verbose_mode, log)) + if (dlt_user.verbose_mode) msg.extendedheader->msin |= DLT_MSIN_VERB; - msg.extendedheader->noar = (uint8_t) log->args_num; /* number of arguments */ + msg.extendedheader->noar = log->args_num; /* number of arguments */ dlt_set_id(msg.extendedheader->apid, dlt_user.appID); /* application id */ dlt_set_id(msg.extendedheader->ctid, log->handle->contextID); /* context id */ - msg.headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); } else { /* without extended header */ - msg.headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE( - msg.standardheader->htyp)); + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE( + msg.standardheader->htyp); } - len = (int32_t) (msg.headersize - sizeof(DltStorageHeader) + log->size); + len = msg.headersize - sizeof(DltStorageHeader) + log->size; if (len > UINT16_MAX) { dlt_log(LOG_WARNING, "Huge message discarded!\n"); @@ -3980,36 +3653,14 @@ } if (dlt_user.dlt_is_file) { - if (dlt_user_file_reach_max) { - return DLT_RETURN_FILESZERR; - } - else { - /* Get file size */ - struct stat st; - fstat(dlt_user.dlt_log_handle, &st); - dlt_vlog(LOG_DEBUG, "%s: Current file size=[%jd]\n", __func__, - st.st_size); - - /* Check filesize */ - /* Return error if the file size has reached to maximum */ - unsigned int msg_size = st.st_size + (unsigned int) msg.headersize + - (unsigned int) log->size; - if (msg_size > dlt_user.filesize_max) { - dlt_user_file_reach_max = true; - dlt_vlog(LOG_ERR, - "%s: File size (%jd bytes) reached to defined maximum size (%d bytes)\n", - __func__, st.st_size, dlt_user.filesize_max); - return DLT_RETURN_FILESZERR; - } - else { - /* log to file */ - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - msg.headerbuffer, msg.headersize, - log->buffer, log->size); - return ret; - } - } - } else { + /* log to file */ + ret = dlt_user_log_out2(dlt_user.dlt_log_handle, msg.headerbuffer, msg.headersize, log->buffer, log->size); + return ret; + } + else { + /* Reattach to daemon if neccesary */ + dlt_user_log_reattach_to_daemon(); + if (dlt_user.overflow_counter) { if (dlt_user_log_send_overflow() == DLT_RETURN_OK) { dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "%u messages discarded!\n", dlt_user.overflow_counter); @@ -4040,10 +3691,10 @@ # ifdef DLT_TEST_ENABLE if (dlt_user.corrupt_user_header) { - userheader.pattern[0] = (char) 0xff; - userheader.pattern[1] = (char) 0xff; - userheader.pattern[2] = (char) 0xff; - userheader.pattern[3] = (char) 0xff; + userheader.pattern[0] = 0xff; + userheader.pattern[1] = 0xff; + userheader.pattern[2] = 0xff; + userheader.pattern[3] = 0xff; } if (dlt_user.corrupt_message_size) @@ -4059,37 +3710,33 @@ #endif } - DltReturnValue process_error_ret = DLT_RETURN_OK; /* store message in ringbuffer, if an error has occured */ if ((ret != DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) - process_error_ret = dlt_user_log_out_error_handling(&(userheader), + ret = dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), msg.headerbuffer + sizeof(DltStorageHeader), msg.headersize - sizeof(DltStorageHeader), log->buffer, log->size); - if (process_error_ret == DLT_RETURN_OK) - return DLT_RETURN_OK; - if (process_error_ret == DLT_RETURN_BUFFER_FULL) { + switch (ret) { + case DLT_RETURN_BUFFER_FULL: + { /* Buffer full */ dlt_user.overflow_counter += 1; return DLT_RETURN_BUFFER_FULL; } - - /* handle return value of function dlt_user_log_out3() when process_error_ret < 0*/ - switch (ret) { - case DLT_RETURN_PIPE_FULL: - { - /* data could not be written */ - return DLT_RETURN_PIPE_FULL; - } - case DLT_RETURN_PIPE_ERROR: - { - /* handle not open or pipe error */ - close(dlt_user.dlt_log_handle); - dlt_user.dlt_log_handle = -1; -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC + case DLT_RETURN_PIPE_FULL: + { + /* data could not be written */ + return DLT_RETURN_PIPE_FULL; + } + case DLT_RETURN_PIPE_ERROR: + { + /* handle not open or pipe error */ + close(dlt_user.dlt_log_handle); + dlt_user.dlt_log_handle = -1; +#ifdef DLT_USE_UNIX_SOCKET_IPC dlt_user.connection_state = DLT_USER_RETRY_CONNECT; #endif @@ -4142,7 +3789,7 @@ usercontext.pid = getpid(); if (dlt_user.application_description != NULL) - usercontext.description_length = (uint32_t) strlen(dlt_user.application_description); + usercontext.description_length = strlen(dlt_user.application_description); else usercontext.description_length = 0; @@ -4227,11 +3874,11 @@ usercontext.log_level_pos = log->handle->log_level_pos; usercontext.pid = getpid(); - usercontext.log_level = (int8_t) log->log_level; - usercontext.trace_status = (int8_t) log->trace_status; + usercontext.log_level = (int8_t)log->log_level; + usercontext.trace_status = (int8_t)log->trace_status; if (log->context_description != NULL) - usercontext.description_length = (uint32_t) strlen(log->context_description); + usercontext.description_length = strlen(log->context_description); else usercontext.description_length = 0; @@ -4421,8 +4068,8 @@ DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log) { uint8_t *databuffer_tmp; - uint32_t datasize_tmp; - uint32_t databuffersize_tmp; + int32_t datasize_tmp; + int32_t databuffersize_tmp; static char text[DLT_USER_TEXT_LENGTH]; if ((msg == NULL) || (log == NULL)) @@ -4438,8 +4085,8 @@ dlt_message_get_extraparameters(msg, 0); msg->databuffer = log->buffer; - msg->datasize = (uint32_t) log->size; - msg->databuffersize = (uint32_t) log->size; + msg->datasize = log->size; + msg->databuffersize = log->size; /* Print message as ASCII */ if (dlt_message_print_ascii(msg, text, DLT_USER_TEXT_LENGTH, 0) == DLT_RETURN_ERROR) @@ -4459,11 +4106,9 @@ { int offset = 0; int leave_while = 0; - int ret = 0; uint32_t i; int fd; - struct pollfd nfd[1]; DltUserHeader *userheader; DltReceiver *receiver = &(dlt_user.receiver); @@ -4486,29 +4131,21 @@ delayed_log_level_changed_callback.log_level_changed_callback = 0; delayed_injection_callback.data = 0; -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC fd = dlt_user.dlt_log_handle; -#else /* DLT_LIB_USE_FIFO_IPC */ +#else fd = dlt_user.dlt_user_handle; #endif - nfd[0].events = POLLIN; - nfd[0].fd = fd; - if (fd >= 0) { - ret = poll(nfd, 1, DLT_USER_RECEIVE_MDELAY); - if (ret) { - if (nfd[0].revents & (POLLHUP | POLLNVAL | POLLERR)) { - dlt_user.dlt_log_handle = DLT_FD_INIT; - return DLT_RETURN_ERROR; - } - - if (dlt_receiver_receive(receiver) <= 0) + if (fd != DLT_FD_INIT) { + while (1) { + if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD) <= 0) /* No new message available */ return DLT_RETURN_OK; /* look through buffer as long as data is in there */ while (1) { - if (receiver->bytesRcvd < (int32_t) sizeof(DltUserHeader)) + if (receiver->bytesRcvd < (int32_t)sizeof(DltUserHeader)) break; /* resync if necessary */ @@ -4523,7 +4160,7 @@ offset++; - } while (((int32_t) (sizeof(DltUserHeader)) + offset) <= receiver->bytesRcvd); + } while ((int32_t)(sizeof(DltUserHeader) + offset) <= receiver->bytesRcvd); /* Check for user header pattern */ if ((dlt_user_check_userheader(userheader) < 0) || @@ -4539,7 +4176,7 @@ switch (userheader->message) { case DLT_USER_MESSAGE_LOG_LEVEL: { - if (receiver->bytesRcvd < (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel))) { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel))) { leave_while = 1; break; } @@ -4552,25 +4189,26 @@ if ((usercontextll->log_level_pos >= 0) && (usercontextll->log_level_pos < (int32_t)dlt_user.dlt_ll_ts_num_entries)) { + /* printf("Store ll, ts\n"); */ if (dlt_user.dlt_ll_ts) { - dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = (int8_t) usercontextll->log_level; + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = usercontextll->log_level; dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = - (int8_t) usercontextll->trace_status; + usercontextll->trace_status; if (dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = - (int8_t) usercontextll->log_level; + usercontextll->log_level; if (dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = - (int8_t) usercontextll->trace_status; + usercontextll->trace_status; delayed_log_level_changed_callback.log_level_changed_callback = dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_changed_callback; memcpy(delayed_log_level_changed_callback.contextID, dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID, DLT_ID_SIZE); - delayed_log_level_changed_callback.log_level = (int8_t) usercontextll->log_level; - delayed_log_level_changed_callback.trace_status = (int8_t) usercontextll->trace_status; + delayed_log_level_changed_callback.log_level = usercontextll->log_level; + delayed_log_level_changed_callback.trace_status = usercontextll->trace_status; } } @@ -4581,8 +4219,8 @@ if (delayed_log_level_changed_callback.log_level_changed_callback != 0) delayed_log_level_changed_callback.log_level_changed_callback( delayed_log_level_changed_callback.contextID, - (uint8_t) delayed_log_level_changed_callback.log_level, - (uint8_t) delayed_log_level_changed_callback.trace_status); + delayed_log_level_changed_callback.log_level, + delayed_log_level_changed_callback.trace_status); /* keep not read data in buffer */ if (dlt_receiver_remove(receiver, @@ -4594,7 +4232,7 @@ case DLT_USER_MESSAGE_INJECTION: { /* At least, user header, user context, and service id and data_length of injected message is available */ - if (receiver->bytesRcvd < (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection))) { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection))) { leave_while = 1; break; } @@ -4606,7 +4244,7 @@ if (userbuffer != NULL) { if (receiver->bytesRcvd < - (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + + (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + usercontextinj->data_length_inject)) { leave_while = 1; break; @@ -4678,7 +4316,7 @@ /* keep not read data in buffer */ if (dlt_receiver_remove(receiver, - (int) (sizeof(DltUserHeader) + + (sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + usercontextinj->data_length_inject)) != DLT_RETURN_OK) return DLT_RETURN_ERROR; @@ -4688,7 +4326,7 @@ case DLT_USER_MESSAGE_LOG_STATE: { /* At least, user header, user context, and service id and data_length of injected message is available */ - if (receiver->bytesRcvd < (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) { leave_while = 1; break; } @@ -4796,7 +4434,7 @@ ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, sizeof(DltUserHeader), 0, 0, 0, 0); #else - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, (size_t) size, 0, 0, 0, 0); + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, size, 0, 0, 0, 0); #endif /* in case of error, keep message in ringbuffer */ @@ -4824,14 +4462,14 @@ void dlt_user_log_reattach_to_daemon(void) { - uint32_t num; + uint32_t num, reregistered = 0; DltContext handle; DltContextData log_new; if (dlt_user.dlt_log_handle < 0) { - dlt_user.dlt_log_handle = DLT_FD_INIT; + dlt_user.dlt_log_handle = -1; -#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC /* try to open connection to dlt daemon */ dlt_initialize_socket_connection(); @@ -4839,13 +4477,7 @@ /* return if not connected */ return; -#elif defined DLT_LIB_USE_VSOCK_IPC - dlt_initialize_vsock_connection(); - - if (dlt_user.connection_state != DLT_USER_CONNECTED) - return; - -#else /* DLT_LIB_USE_FIFO_IPC */ +#else /* try to open pipe to dlt daemon */ int fd = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK); @@ -4881,7 +4513,7 @@ if ((dlt_user.appID[0] != '\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0] != '\0')) { /*dlt_set_id(log_new.appID, dlt_user.appID); */ dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID); - handle.log_level_pos = (int32_t) num; + handle.log_level_pos = num; log_new.context_description = dlt_user.dlt_ll_ts[num].context_description; /* Release the mutex for sending context registration: */ @@ -4894,11 +4526,18 @@ if (dlt_user_log_send_register_context(&log_new) < DLT_RETURN_ERROR) return; + reregistered = 1; + /* Lock again the mutex */ /* it is necessary in the for(;;) test, in order to have coherent dlt_user data all over the critical section. */ DLT_SEM_LOCK(); + } + DLT_SEM_FREE(); + + if (reregistered == 1) + dlt_user_log_resend_buffer(); } } @@ -4934,7 +4573,7 @@ *total_size = dlt_shm_get_total_size(&(dlt_user.dlt_shm)); *used_size = dlt_shm_get_used_size(&(dlt_user.dlt_shm)); #else - *total_size = (int) dlt_buffer_get_total_size(&(dlt_user.startup_buffer)); + *total_size = dlt_buffer_get_total_size(&(dlt_user.startup_buffer)); *used_size = dlt_buffer_get_used_size(&(dlt_user.startup_buffer)); #endif @@ -4957,107 +4596,40 @@ int dlt_start_threads() { - struct timespec time_to_wait; - struct timespec now; - int signal_status; - atomic_bool dlt_housekeeper_running = false; - - /* - * Configure the condition varibale to use CLOCK_MONOTONIC. - * This makes sure we're protected against changes in the system clock - */ - pthread_condattr_t attr; - pthread_condattr_init(&attr); - pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); - pthread_cond_init(&dlt_housekeeper_running_cond, &attr); - - if (pthread_create(&(dlt_housekeeperthread_handle), + /* Start receiver thread */ + if (pthread_create(&(dlt_receiverthread_handle), 0, - (void *)&dlt_user_housekeeperthread_function, - &dlt_housekeeper_running) != 0) { - dlt_log(LOG_CRIT, "Can't create housekeeper thread!\n"); + (void *)&dlt_user_receiverthread_function, + 0) != 0) { + dlt_log(LOG_CRIT, "Can't create receiver thread!\n"); return -1; } - clock_gettime(CLOCK_MONOTONIC, &now); - /* wait at most 10s */ - time_to_wait.tv_sec = now.tv_sec + 10; - time_to_wait.tv_nsec = 0; - - /* - * wait until the house keeper is up and running - * Even though the condition variable and the while are - * using the same time out the while loop is not a no op. - * This is due to the fact that the pthread_cond_timedwait - * can be woken before time is up and dlt_housekeeper_running is not true yet. - * (spurious wakeup) - * To protect against this, a while loop with a timeout is added - * */ - while (!dlt_housekeeper_running - && now.tv_sec <= time_to_wait.tv_sec) { - signal_status = pthread_cond_timedwait( - &dlt_housekeeper_running_cond, - &dlt_housekeeper_running_mutex, - &time_to_wait); - - /* otherwise it might be a spurious wakeup, try again until the time is over */ - if (signal_status == 0) { - break; - } - - clock_gettime(CLOCK_MONOTONIC, &now); - } - - if (signal_status != 0 && !dlt_housekeeper_running) { - dlt_log(LOG_CRIT, "Failed to wait for house keeper thread!\n"); - dlt_stop_threads(); - return -1; - } - -#ifdef DLT_NETWORK_TRACE_ENABLE /* Start the segmented thread */ if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL, (void *)dlt_user_trace_network_segmented_thread, NULL)) { dlt_log(LOG_CRIT, "Can't start segmented thread!\n"); return -1; } -#endif + return 0; } void dlt_stop_threads() { - int dlt_housekeeperthread_result = 0; - int joined = 0; + int dlt_receiverthread_result = 0; + int dlt_segmented_nwt_result = 0; - if (dlt_housekeeperthread_handle) { + if (dlt_receiverthread_handle) { /* do not ignore return value */ -#ifndef __ANDROID_API__ - dlt_housekeeperthread_result = pthread_cancel(dlt_housekeeperthread_handle); -#else - -#ifdef DLT_NETWORK_TRACE_ENABLE - dlt_lock_mutex(&mq_mutex); -#endif /* DLT_NETWORK_TRACE_ENABLE */ - dlt_housekeeperthread_result = pthread_kill(dlt_housekeeperthread_handle, SIGUSR1); - dlt_user_cleanup_handler(NULL); -#endif + dlt_receiverthread_result = pthread_cancel(dlt_receiverthread_handle); - - if (dlt_housekeeperthread_result != 0) + if (dlt_receiverthread_result != 0) dlt_vlog(LOG_ERR, - "ERROR %s(dlt_housekeeperthread_handle): %s\n", -#ifndef __ANDROID_API__ - "pthread_cancel", -#else - "pthread_kill", -#endif - strerror(dlt_housekeeperthread_result)); + "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n", + strerror(errno)); } -#ifdef DLT_NETWORK_TRACE_ENABLE - int dlt_segmented_nwt_result = 0; - if (dlt_user.dlt_segmented_nwt_handle) { dlt_lock_mutex(&mq_mutex); pthread_cond_signal(&mq_init_condition); @@ -5068,58 +4640,56 @@ if (dlt_segmented_nwt_result != 0) dlt_vlog(LOG_ERR, "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", - strerror(dlt_segmented_nwt_result)); + strerror(errno)); } -#endif /* DLT_NETWORK_TRACE_ENABLE */ + /* make sure that the threads really finished working */ - if ((dlt_housekeeperthread_result == 0) && dlt_housekeeperthread_handle) { - joined = pthread_join(dlt_housekeeperthread_handle, NULL); + if ((dlt_receiverthread_result == 0) && dlt_receiverthread_handle) { + int joined = pthread_join(dlt_receiverthread_handle, NULL); - if (joined != 0) + if (joined < 0) dlt_vlog(LOG_ERR, - "ERROR pthread_join(dlt_housekeeperthread_handle, NULL): %s\n", - strerror(joined)); + "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n", + strerror(errno)); - dlt_housekeeperthread_handle = 0; /* set to invalid */ + dlt_receiverthread_handle = 0; /* set to invalid */ } -#ifdef DLT_NETWORK_TRACE_ENABLE if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle) { - joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); + int joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); - if (joined != 0) + if (joined < 0) dlt_vlog(LOG_ERR, "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", - strerror(joined)); + strerror(errno)); dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */ } -#endif /* DLT_NETWORK_TRACE_ENABLE */ } static void dlt_fork_child_fork_handler() { g_dlt_is_child = 1; - dlt_user_init_state = INIT_UNITIALIZED; + dlt_user_initialised = false; dlt_user.dlt_log_handle = -1; } DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3) { - DltReturnValue ret = DLT_RETURN_ERROR; - size_t msg_size = len1 + len2 + len3; + int ret = DLT_RETURN_ERROR; + int msg_size = len1 + len2 + len3; DLT_SEM_LOCK(); - ret = dlt_buffer_check_size(&(dlt_user.startup_buffer), (int)msg_size); + ret = dlt_buffer_check_size(&(dlt_user.startup_buffer), msg_size); DLT_SEM_FREE(); DLT_SEM_LOCK(); if (dlt_buffer_push3(&(dlt_user.startup_buffer), - ptr1, (unsigned int)len1, - ptr2, (unsigned int)len2, - ptr3, (unsigned int)len3) == DLT_RETURN_ERROR) { + ptr1, len1, + ptr2, len2, + ptr3, len3) == DLT_RETURN_ERROR) { if (dlt_user.overflow_counter == 0) dlt_log(LOG_WARNING, "Buffer full! Messages will be discarded.\n"); diff -Nru dlt-daemon-2.18.9/src/lib/dlt_user_cfg.h dlt-daemon-2.18.4/src/lib/dlt_user_cfg.h --- dlt-daemon-2.18.9/src/lib/dlt_user_cfg.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/lib/dlt_user_cfg.h 2019-09-03 08:28:13.000000000 +0000 @@ -111,6 +111,9 @@ /* Initial trace status */ #define DLT_USER_INITIAL_TRACE_STATUS DLT_TRACE_STATUS_OFF +/* use extended header for non-verbose mode: 0 - don't use, 1 - use */ +#define DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE 1 + /* send always session id: 0 - don't use, 1 - use */ #define DLT_USER_WITH_SESSION_ID 1 @@ -123,11 +126,8 @@ /* default message id for non-verbose mode, if no message id was provided */ #define DLT_USER_DEFAULT_MSGID 0xffff -/* timeout for poll operations in milliseconds*/ -#define DLT_USER_RECEIVE_MDELAY (500) - -/* delay for housekeeper thread (nsec) while receiving messages*/ -#define DLT_USER_RECEIVE_NDELAY (DLT_USER_RECEIVE_MDELAY * 1000 * 1000) +/* delay for receiver thread (nsec) */ +#define DLT_USER_RECEIVE_NDELAY (100000000) /* Name of environment variable for local print mode */ #define DLT_USER_ENV_LOCAL_PRINT_MODE "DLT_LOCAL_PRINT_MODE" @@ -138,16 +138,6 @@ /* Sleeps between resending user buffer at exit in nsec (1000000 nsec = 1ms)*/ #define DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP 100000000 -/* Name of environment variable to disable extended header in non verbose mode */ -#define DLT_USER_ENV_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE \ - "DLT_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE" - -typedef enum -{ - DLT_USER_NO_USE_EXTENDED_HEADER_FOR_NONVERBOSE = 0, - DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE -} DltExtHeaderNonVer; - /* Retry interval for mq error in usec */ #define DLT_USER_MQ_ERROR_RETRY_INTERVAL 100000 @@ -158,9 +148,6 @@ /* Maximum msg size as per autosar standard */ #define DLT_LOG_MSG_BUF_MAX_SIZE 65535 -/* Name of environment variable for disabling the injection message at libdlt */ -#define DLT_USER_ENV_DISABLE_INJECTION_MSG "DLT_DISABLE_INJECTION_MSG_AT_USER" - /************************/ /* Don't change please! */ /************************/ diff -Nru dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage_behavior.c dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage_behavior.c --- dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage_behavior.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage_behavior.c 2019-09-03 08:28:13.000000000 +0000 @@ -32,7 +32,6 @@ #include "dlt_offline_logstorage_behavior.h" #include "dlt_offline_logstorage_behavior_internal.h" -unsigned int g_logstorage_cache_size; /** * dlt_logstorage_log_file_name * @@ -89,23 +88,16 @@ char stamp[DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1] = { 0 }; time_t t = time(NULL); struct tm tm_info; - ssize_t n = 0; - tzset(); localtime_r(&t, &tm_info); - n = snprintf(stamp, - DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1, - "%c%04d%02d%02d-%02d%02d%02d", - file_config->logfile_delimiter, - 1900 + tm_info.tm_year, - 1 + tm_info.tm_mon, - tm_info.tm_mday, - tm_info.tm_hour, - tm_info.tm_min, - tm_info.tm_sec); - if (n < 0 || (size_t)n > (DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1)) { - dlt_vlog(LOG_WARNING, "%s: snprintf truncation %s\n", __func__, - stamp); - } + sprintf(stamp, + "%c%04d%02d%02d-%02d%02d%02d", + file_config->logfile_delimiter, + 1900 + tm_info.tm_year, + 1 + tm_info.tm_mon, + tm_info.tm_mday, + tm_info.tm_hour, + tm_info.tm_min, + tm_info.tm_sec); strcat(log_file_name, stamp); } @@ -118,15 +110,14 @@ * Sort the filenames with index based ascending order (bubble sort) * * @param head Log filename list - * @ return The last (biggest) index + * @ return None */ -unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList **head) +void dlt_logstorage_sort_file_name(DltLogStorageFileList **head) { int done = 0; - unsigned int max_idx = 0; if ((head == NULL) || (*head == NULL) || ((*head)->next == NULL)) - return 0; + return; while (!done) { /* "source" of the pointer to the current node in the list struct */ @@ -137,9 +128,7 @@ done = 1; while (nx) { - max_idx = nx->idx; if (nd->idx > nx->idx) { - max_idx = nd->idx; nd->next = nx->next; nx->next = nd; *pv = nx; @@ -152,8 +141,6 @@ nx = nx->next; } } - - return max_idx; } /** @@ -175,17 +162,8 @@ if ((head == NULL) || (*head == NULL) || ((*head)->next == NULL)) return; - if ((*head)->idx != 1) - { - /* Do not sort */ - return; - } - for (n = *head; n != NULL; n = n->next) { - /* Compare the diff between n->idx and n_prev->idx only if - * wrap_post and wrap_pre are not set yet. Otherwise continue the loop - * until the tail */ - if (n && n_prev && !wrap_post && !wrap_pre) { + if (n && n_prev) { if ((n->idx - n_prev->idx) != 1) { wrap_post = n; wrap_pre = n_prev; @@ -281,15 +259,11 @@ char *path, DltLogStorageFilterConfig *config) { - int check = 0; int i = 0; int cnt = 0; int ret = 0; - unsigned int max_idx = 0; struct dirent **files = { 0 }; unsigned int current_idx = 0; - DltLogStorageFileList *n = NULL; - DltLogStorageFileList *n1 = NULL; if ((config == NULL) || (file_config == NULL) || @@ -300,33 +274,18 @@ cnt = scandir(path, &files, 0, alphasort); if (cnt < 0) { - dlt_vlog(LOG_ERR, "%s: Failed to scan directory\n", __func__); + dlt_log(LOG_ERR, + "dlt_logstorage_storage_dir_info: Failed to scan directory\n"); return -1; } - dlt_vlog(LOG_DEBUG, "%s: Scanned [%d] files from %s\n", __func__, cnt, path); - - /* In order to have a latest status of file list, - * the existing records must be deleted before updating - */ - n = config->records; - if (config->records) { - while (n) { - n1 = n; - n = n->next; - free(n1->name); - n1->name = NULL; - free(n1); - n1 = NULL; - } - config->records = NULL; - } - for (i = 0; i < cnt; i++) { int len = 0; len = strlen(config->file_name); - if ((strncmp(files[i]->d_name, config->file_name, len) == 0) && + if ((strncmp(files[i]->d_name, + config->file_name, + len) == 0) && (files[i]->d_name[len] == file_config->logfile_delimiter)) { DltLogStorageFileList **tmp = NULL; current_idx = dlt_logstorage_get_idx_of_log_file(file_config, @@ -337,7 +296,8 @@ if (config->records == NULL) { ret = -1; - dlt_log(LOG_ERR, "Memory allocation failed\n"); + dlt_log(LOG_ERR, + "Memory allocation failed\n"); break; } @@ -353,7 +313,8 @@ if (*tmp == NULL) { ret = -1; - dlt_log(LOG_ERR, "Memory allocation failed\n"); + dlt_log(LOG_ERR, + "Memory allocation failed\n"); break; } } @@ -361,25 +322,12 @@ (*tmp)->name = strdup(files[i]->d_name); (*tmp)->idx = current_idx; (*tmp)->next = NULL; - check++; } } - dlt_vlog(LOG_DEBUG, "%s: After dir scan: [%d] files of [%s]\n", __func__, - check, config->file_name); - if (ret == 0) { - max_idx = dlt_logstorage_sort_file_name(&config->records); - - /* Fault tolerance: - * In case there are some log files are removed but - * the index is still not reaching maxcounter, no need - * to perform rearrangement of filename. - * This would help the log keeps growing until maxcounter is reached and - * the maximum number of log files could be obtained. - */ - if (max_idx == file_config->logfile_maxcounter) - dlt_logstorage_rearrange_file_name(&config->records); + dlt_logstorage_sort_file_name(&config->records); + dlt_logstorage_rearrange_file_name(&config->records); } /* free scandir result */ @@ -403,14 +351,12 @@ * @param file_config User configurations for log file * @param dev_path Storage device path * @param msg_size Size of incoming message - * @param is_update_required The file list needs to be updated * @return 0 on succes, -1 on error */ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int msg_size, - bool is_update_required) + int msg_size) { int ret = 0; char absolute_file_path[DLT_MOUNT_PATH_MAX + DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN + 1] = { '\0' }; @@ -432,8 +378,9 @@ snprintf(storage_path, DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN, "%s/", dev_path); /* check if there are already files stored */ - if (config->records == NULL || is_update_required) { - if (dlt_logstorage_storage_dir_info(file_config, storage_path, config) != 0) + if (config->records == NULL) { + if (dlt_logstorage_storage_dir_info(file_config, storage_path, config) + != 0) return -1; } @@ -459,14 +406,14 @@ /* concatenate path and file and open absolute path */ strcat(absolute_file_path, storage_path); strcat(absolute_file_path, file_name); - config->working_file_name = strdup(file_name); config->log = fopen(absolute_file_path, "a+"); /* Add file to file list */ *tmp = malloc(sizeof(DltLogStorageFileList)); if (*tmp == NULL) { - dlt_log(LOG_ERR, "Memory allocation for file name failed\n"); + dlt_log(LOG_ERR, + "Memory allocation for file name failed\n"); return -1; } @@ -474,49 +421,28 @@ (*tmp)->idx = 1; (*tmp)->next = NULL; } - else { + else { /* newest file available*/ strcat(absolute_file_path, storage_path); - - /* newest file available - * Since the working file is already updated from newest file info - * So if there is already wrap-up, the newest file will be the working file - */ - if ((config->wrap_id == 0) || (config->working_file_name == NULL)) { - if (config->working_file_name != NULL) { - free(config->working_file_name); - config->working_file_name = NULL; - } - config->working_file_name = strdup((*newest)->name); - } - strcat(absolute_file_path, config->working_file_name); - - dlt_vlog(LOG_DEBUG, - "%s: Number of log files-newest file-wrap_id [%u]-[%s]-[%u]\n", - __func__, num_log_files, config->working_file_name, - config->wrap_id); + strcat(absolute_file_path, (*newest)->name); ret = stat(absolute_file_path, &s); /* if size is enough, open it */ - if ((ret == 0) && (s.st_size + msg_size <= (int) config->file_size)) { + if ((ret == 0) && (s.st_size + msg_size < (int)config->file_size)) { config->log = fopen(absolute_file_path, "a+"); - config->current_write_file_offset = s.st_size; } - else { - /* no space in file or file stats cannot be read */ + else { /* no space in file or file stats cannot be read */ unsigned int idx = 0; /* get index of newest log file */ idx = dlt_logstorage_get_idx_of_log_file(file_config, - config->working_file_name); + (*newest)->name); idx += 1; /* wrap around if max index is reached or an error occurred * while calculating index from file name */ - if ((idx > file_config->logfile_maxcounter) || (idx == 0)) { + if ((idx > file_config->logfile_maxcounter) || (idx == 0)) idx = 1; - config->wrap_id += 1; - } dlt_logstorage_log_file_name(file_name, file_config, @@ -529,34 +455,14 @@ sizeof(absolute_file_path) / sizeof(char)); strcat(absolute_file_path, storage_path); strcat(absolute_file_path, file_name); - - if(config->working_file_name) { - free(config->working_file_name); - config->working_file_name = strdup(file_name); - } - - /* If there is already wrap-up, check the existence of file - * remove it and reopen it. - * In this case number of log file won't be increased*/ - if (config->wrap_id && stat(absolute_file_path, &s) == 0) { - remove(absolute_file_path); - num_log_files -= 1; - dlt_vlog(LOG_DEBUG, - "%s: Remove '%s' (num_log_files: %u, config->num_files:%u)\n", - __func__, absolute_file_path, num_log_files, config->num_files); - } - config->log = fopen(absolute_file_path, "a+"); - dlt_vlog(LOG_DEBUG, - "%s: Filename and Index after updating [%s]-[%u]\n", - __func__, file_name, idx); - /* Add file to file list */ *tmp = malloc(sizeof(DltLogStorageFileList)); if (*tmp == NULL) { - dlt_log(LOG_ERR, "Memory allocation for file name failed\n"); + dlt_log(LOG_ERR, + "Memory allocation for file name failed\n"); return -1; } @@ -576,13 +482,8 @@ sizeof(absolute_file_path) / sizeof(char)); strcat(absolute_file_path, storage_path); strcat(absolute_file_path, (*head)->name); - dlt_vlog(LOG_DEBUG, - "%s: Remove '%s' (num_log_files: %u, config->num_files:%u)\n", - __func__, absolute_file_path, num_log_files, - config->num_files); remove(absolute_file_path); free((*head)->name); - (*head)->name = NULL; *head = n->next; n->next = NULL; free(n); @@ -591,21 +492,8 @@ } if (config->log == NULL) { - if (*tmp != NULL) { - if ((*tmp)->name != NULL) { - free((*tmp)->name); - (*tmp)->name = NULL; - } - free(*tmp); - *tmp = NULL; - } - - if (config->working_file_name != NULL) { - free(config->working_file_name); - config->working_file_name = NULL; - } - - dlt_vlog(LOG_ERR, "%s: Unable to open log file.\n", __func__); + dlt_log(LOG_ERR, + "dlt_logstorage_create_log_file: Unable to open log file.\n"); return -1; } @@ -626,13 +514,17 @@ unsigned int offset, unsigned int cnt) { - const char magic[] = { 'D', 'L', 'T', 0x01 }; - const char *cache = (char*)ptr + offset; + int index = 0; + char substring[] = { 'D', 'L', 'T', 0x01 }; - unsigned int i; - for (i = 0; i < cnt; i++) { - if ((cache[i] == 'D') && (strncmp(&cache[i], magic, 4) == 0)) - return i; + while (cnt > 0) { + if (*((char *)(ptr + offset + index)) == 'D') { + if (strncmp(ptr + offset + index, substring, 4) == 0) + return index; + } + + cnt--; + index++; } return -1; @@ -652,15 +544,18 @@ unsigned int offset, unsigned int cnt) { - const char magic[] = {'D', 'L', 'T', 0x01}; - const char *cache = (char*)ptr + offset; - - unsigned int i; - for (i = cnt; i > 0; i--) { - if ((cache[i] == 'D') && (strncmp(&cache[i], magic, 4) == 0)) - return i; + char substring[] = {'D', 'L', 'T', 0x01}; + while(cnt > 0) + { + if (*((char *)(ptr + offset + cnt)) == 'D') + { + if (strncmp(ptr + offset + cnt, substring, 4) == 0) + { + return cnt; + } + } + cnt--; } - return -1; } @@ -719,8 +614,8 @@ int ret = 0; int start_index = 0; int end_index = 0; - int count = 0; - int remain_file_size = 0; + int count; + int remain_file_size; if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || (footer == NULL)) @@ -730,22 +625,6 @@ } count = end_offset - start_offset; - - /* In case of cached-based strategy, the newest file information - * must be updated everytime of synchronization. - */ - if (config->log) { - fclose(config->log); - config->log = NULL; - config->current_write_file_offset = 0; - } - - if (dlt_logstorage_open_log_file(config, file_config, - dev_path, count, true) != 0) { - dlt_vlog(LOG_ERR, "%s: failed to open log file\n", __func__); - return -1; - } - remain_file_size = config->file_size - config->current_write_file_offset; if (count > remain_file_size) @@ -761,8 +640,20 @@ if ((start_index >= 0) && (end_index > start_index) && (count > 0) && (count <= remain_file_size)) { - ret = fwrite((uint8_t*)config->cache + start_offset + start_index, - count, 1, config->log); + /* Prepare log file */ + if (config->log == NULL) + { + if (dlt_logstorage_prepare_on_msg(config, file_config, dev_path, + config->file_size) != 0) + { + dlt_vlog(LOG_ERR, "%s: failed to prepare log file\n", + __func__); + return -1; + } + } + + ret = fwrite(config->cache + start_offset + start_index, count, 1, + config->log); dlt_logstorage_check_write_ret(config, ret); /* Close log file */ @@ -782,7 +673,8 @@ } } - start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, count); + start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, + count); count = end_offset - start_offset - start_index; if ((start_index >= 0) && (count > 0)) @@ -791,14 +683,14 @@ if (config->log == NULL) { if (dlt_logstorage_prepare_on_msg(config, file_config, dev_path, - count, NULL) != 0) + config->file_size) != 0) { dlt_vlog(LOG_ERR, "%s: failed to prepare log file\n", __func__); return -1; } } - ret = fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, + ret = fwrite(config->cache + start_offset + start_index, count, 1, config->log); dlt_logstorage_check_write_ret(config, ret); @@ -821,71 +713,37 @@ * @param file_config User configurations for log file * @param dev_path Storage device path * @param log_msg_size Size of log message - * @param newest_file_info Info of newest file for corresponding filename * @return 0 on success, -1 on error */ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info) + int log_msg_size) { int ret = 0; struct stat s; - if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || - (newest_file_info == NULL)) { - dlt_vlog(LOG_INFO, "Wrong paratemters\n"); + if ((config == NULL) || (file_config == NULL) || (dev_path == NULL)) return -1; - } - - /* This is for ON_MSG/UNSET strategy */ - if (config->log == NULL) { - /* Sync the wrap id and working file name before opening log file */ - if (config->wrap_id < newest_file_info->wrap_id) { - config->wrap_id = newest_file_info->wrap_id; - if (config->working_file_name) { - free(config->working_file_name); - config->working_file_name = NULL; - } - config->working_file_name = strdup(newest_file_info->newest_file); - } - /* open a new log file */ + if (config->log == NULL) { /* open a new log file */ ret = dlt_logstorage_open_log_file(config, file_config, dev_path, - log_msg_size, - true); + log_msg_size); } else { /* already open, check size and create a new file if needed */ ret = fstat(fileno(config->log), &s); if (ret == 0) { /* check if adding new data do not exceed max file size */ - /* Check if wrap id needs to be updated*/ - if ((s.st_size + log_msg_size > (int)config->file_size) || - (strcmp(config->working_file_name, newest_file_info->newest_file) != 0) || - (config->wrap_id < newest_file_info->wrap_id)) { - + if (s.st_size + log_msg_size > (int)config->file_size) { fclose(config->log); config->log = NULL; - - /* Sync the wrap id and working file name before opening log file */ - if (config->wrap_id <= newest_file_info->wrap_id) { - config->wrap_id = newest_file_info->wrap_id; - if (config->working_file_name) { - free(config->working_file_name); - config->working_file_name = NULL; - } - config->working_file_name = strdup(newest_file_info->newest_file); - } - ret = dlt_logstorage_open_log_file(config, file_config, dev_path, - log_msg_size, - true); + log_msg_size); } else { /*everything is prepared */ ret = 0; @@ -998,38 +856,16 @@ * @param file_config User configurations for log file * @param dev_path Storage device path * @param log_msg_size Size of log message - * @param newest_file_info Info of newest files for corresponding filename * @return 0 on success, -1 on error */ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info ) + int log_msg_size) { - if ((config == NULL) || (file_config == NULL) || - (dev_path == NULL) || (newest_file_info == NULL)) + if ((config == NULL) || (file_config == NULL) || (dev_path == NULL)) return -1; - /* check if newest file info is available - * + working file name is NULL => update directly to newest file - * + working file name is not NULL: check if - * ++ wrap_ids are different from each other or - * ++ newest file name <> working file name - */ - if (newest_file_info->newest_file) { - if (config->working_file_name && - ((config->wrap_id != newest_file_info->wrap_id) || - (strcmp(newest_file_info->newest_file, config->working_file_name) != 0))) { - free(config->working_file_name); - config->working_file_name = NULL; - } - if (config->working_file_name == NULL) { - config->working_file_name = strdup(newest_file_info->newest_file); - config->wrap_id = newest_file_info->wrap_id; - } - } - /* Combinations allowed: on Daemon_Exit with on Demand,File_Size with Daemon_Exit * File_Size with on Demand, Specific_Size with Daemon_Exit,Specific_Size with on Demand * Combination not allowed : File_Size with Specific_Size @@ -1125,7 +961,7 @@ DltLogStorageCacheFooter *footer = NULL; int msg_size; int remain_cache_size; - uint8_t *curr_write_addr = NULL; + void *curr_write_addr = NULL; int ret = 0; unsigned int cache_size; @@ -1146,7 +982,7 @@ cache_size = config->file_size; } - footer = (DltLogStorageCacheFooter *)((uint8_t*)config->cache + cache_size); + footer = (DltLogStorageCacheFooter *)(config->cache + cache_size); if (footer == NULL) { dlt_log(LOG_ERR, "Cannot retrieve cache footer. Address is NULL\n"); @@ -1157,7 +993,7 @@ if (msg_size <= remain_cache_size) /* add at current position */ { - curr_write_addr = (uint8_t*)config->cache + footer->offset; + curr_write_addr = (void *)(config->cache + footer->offset); footer->offset += msg_size; if (footer->wrap_around_cnt < 1) { footer->end_sync_offset = footer->offset; @@ -1286,7 +1122,7 @@ cache_size = config->file_size; } - footer = (DltLogStorageCacheFooter *)((uint8_t*)config->cache + cache_size); + footer = (DltLogStorageCacheFooter *)(config->cache + cache_size); if (footer == NULL) { dlt_log(LOG_ERR, "Cannot retrieve cache information\n"); diff -Nru dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage_behavior.h dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage_behavior.h --- dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage_behavior.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage_behavior.h 2019-09-03 08:28:13.000000000 +0000 @@ -54,8 +54,7 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info); + int log_msg_size); int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, @@ -77,8 +76,7 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info); + int log_msg_size); int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, diff -Nru dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h --- dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h 2019-09-03 08:28:13.000000000 +0000 @@ -54,7 +54,7 @@ char *name, int idx); -unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList **head); +void dlt_logstorage_sort_file_name(DltLogStorageFileList **head); void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head); @@ -68,8 +68,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int msg_size, - bool is_update_required); + int msg_size); DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, diff -Nru dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage.c dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage.c --- dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage.c 2019-09-03 08:28:13.000000000 +0000 @@ -45,25 +45,12 @@ DltLogStorageFileList *n = NULL; DltLogStorageFileList *n1 = NULL; - if (data->apids) { - free(data->apids); - data->apids = NULL; - } - - if (data->ctids) { - free(data->ctids); - data->ctids = NULL; - } - - if (data->file_name) { - free(data->file_name); - data->file_name = NULL; - } - - if (data->working_file_name) { - free(data->working_file_name); - data->working_file_name = NULL; - } + free(data->apids); + data->apids = NULL; + free(data->ctids); + data->ctids = NULL; + free(data->file_name); + data->file_name = NULL; if (data->ecuid != NULL) { free(data->ecuid); @@ -83,11 +70,8 @@ while (n) { n1 = n; n = n->next; - if (n1->name) { - free(n1->name); - n1->name = NULL; - } - + free(n1->name); + n1->name = NULL; free(n1); n1 = NULL; } @@ -147,6 +131,14 @@ if (*(listdata) == NULL) return -1; + (*listdata)->apids = NULL; + (*listdata)->ctids = NULL; + (*listdata)->file_name = NULL; + (*listdata)->ecuid = NULL; + (*listdata)->records = NULL; + (*listdata)->log = NULL; + (*listdata)->cache = NULL; + /* copy the data to list */ memcpy(*listdata, data, sizeof(DltLogStorageFilterConfig)); @@ -498,7 +490,7 @@ int curr_len = 0; if (ecuid != NULL) { - strncpy(curr_str, ecuid, DLT_ID_SIZE); + strncpy(curr_str, ecuid, strlen(ecuid)); strncat(curr_str, "::", 2); } else { @@ -530,7 +522,7 @@ int curr_len = 0; if (ecuid != NULL) { - strncpy(curr_str, ecuid, DLT_ID_SIZE); + strncpy(curr_str, ecuid, strlen(ecuid)); strncat(curr_str, ":", 1); } else { @@ -564,7 +556,7 @@ int curr_len = 0; if (ecuid != NULL) { - strncpy(curr_str, ecuid, DLT_ID_SIZE); + strncpy(curr_str, ecuid, strlen(ecuid)); strncat(curr_str, ":", 1); } else { @@ -595,7 +587,7 @@ { char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - strncpy(curr_str, ecuid, DLT_ID_SIZE); + strncpy(curr_str, ecuid, strlen(ecuid)); strncat(curr_str, "::", 2); strncpy(key, curr_str, strlen(curr_str)); @@ -613,9 +605,8 @@ * - a comma separated list of ids * - a wildcard: .* * - * If both application and context id are set to wildcard, this will be treated - * in the same way of the case application and context id are not present: - * - EcuID must be specified + * Not allowed is the combination of application id and context id set to + * wildcard. This will be rejected. * * If lists given for application and/or context id, all possible combinations * are returned as keys in a form "[apid][ctid], e.g. "APP1\:CTX1". @@ -646,9 +637,7 @@ int num_currkey = 0; /* Handle ecuid alone case here */ - if (((apids == NULL) && (ctids == NULL) && (ecuid != NULL)) || - ((apids != NULL) && (strncmp(apids, ".*", 2) == 0) && - (ctids != NULL) && (strncmp(ctids, ".*", 2) == 0) && (ecuid != NULL)) ) { + if ((apids == NULL) && (ctids == NULL) && (ecuid != NULL)) { dlt_logstorage_create_keys_only_ecu(ecuid, curr_key); *(num_keys) = 1; *(keys) = (char *)calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, @@ -732,11 +721,7 @@ { int ret = 0; int num_keys = 0; - int found = 0; char *keys = NULL; - DltNewestFileName *tmp = NULL; - DltNewestFileName *prev_tmp = NULL; - DltNewestFileName *new_tmp = NULL; if ((handle == NULL) || (data == NULL)) { dlt_vlog(LOG_ERR, "Invalid parameters in %s\n", __func__); @@ -767,43 +752,6 @@ return -1; } - if (data->file_name) { - if (handle->newest_file_list != NULL) { - tmp = handle->newest_file_list; - while (tmp) { - if (strcmp(tmp->file_name, data->file_name) == 0) { - found = 1; - break; - } - else { - prev_tmp = tmp; - tmp = tmp->next; - } - } - } - - if (!found) { - new_tmp = calloc(1, sizeof(DltNewestFileName)); - if (new_tmp == NULL) { - /* In this case, the existing list does not need to be freed.*/ - dlt_vlog(LOG_ERR, - "Failed to allocate memory for new file name [%s]\n", - data->file_name); - free(keys); - keys = NULL; - return -1; - } - new_tmp->file_name = strdup(data->file_name); - new_tmp->newest_file = NULL; - new_tmp->next = NULL; - - if (handle->newest_file_list == NULL) - handle->newest_file_list = new_tmp; - else - prev_tmp->next = new_tmp; - } - } - free(keys); keys = NULL; return 0; @@ -1327,41 +1275,6 @@ return -1; } -DLT_STATIC int dlt_logstorage_get_filter_section_value(DltConfigFile *config_file, - char *sec_name, - DltLogstorageFilterConf entry, - char *value) -{ - int ret = 0; - - if ((config_file == NULL) || (sec_name == NULL)) - return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; - - if (entry.key != NULL) { - ret = dlt_config_file_get_value(config_file, sec_name, - entry.key, - value); - - if ((ret != 0) && (entry.is_opt == 0)) { - dlt_vlog(LOG_WARNING, - "Invalid configuration in section: %s -> %s : %s\n", - sec_name, entry.key, value); - return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; - } - - if ((ret != 0) && (entry.is_opt == 1)) { - dlt_vlog(LOG_DEBUG, "Optional parameter %s not specified\n", - entry.key); - return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; - } - } - else { - return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; - } - - return 0; -} - DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file, char *sec_name, int index, @@ -1379,30 +1292,70 @@ if (strncmp(sec_name, DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, config_sec_len) == 0) { - ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, - filter_cfg_entries[index], - value); + if (filter_cfg_entries[index].key != NULL) { + ret = dlt_config_file_get_value(config_file, sec_name, + filter_cfg_entries[index].key, + value); + + if ((ret != 0) && (filter_cfg_entries[index].is_opt == 0)) { + dlt_vlog(LOG_WARNING, + "Invalid configuration in section: %s -> %s : %s\n", + sec_name, filter_cfg_entries[index].key, value); + return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; + } + + if ((ret != 0) && (filter_cfg_entries[index].is_opt == 1)) { + dlt_vlog(LOG_DEBUG, "Optional parameter %s not specified\n", + filter_cfg_entries[index].key); + return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; + } + } + else { + return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; + } } else if (strncmp(sec_name, DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION, - storage_sec_len) == 0) { - ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, - filter_nonverbose_storage_entries[index], - value); + storage_sec_len) == 0) + { + if (filter_nonverbose_storage_entries[index].key != NULL) { + if (dlt_config_file_get_value(config_file, sec_name, + filter_nonverbose_storage_entries[index].key, value) != 0) { + dlt_vlog(LOG_WARNING, + "Invalid configuration in section: %s -> %s : %s\n", + sec_name, filter_nonverbose_storage_entries[index].key, + value); + return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; + } + } + else { + return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; + } } else if ((strncmp(sec_name, DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION, - control_sec_len) == 0)) { - ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, - filter_nonverbose_control_entries[index], - value); + control_sec_len) == 0)) + { + if (filter_nonverbose_control_entries[index].key != NULL) { + if (dlt_config_file_get_value(config_file, sec_name, + filter_nonverbose_control_entries[index].key, value) != 0) { + dlt_vlog(LOG_WARNING, + "Invalid configuration in section: %s -> %s : %s\n", + sec_name, filter_nonverbose_control_entries[index].key, + value); + return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; + } + } + else { + return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; + } } else { dlt_log(LOG_ERR, "Error: Section name not valid \n"); - ret = DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; + return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; } - return ret; + return 0; } DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage *handle, @@ -1441,8 +1394,15 @@ return DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR; memset(&tmp_data, 0, sizeof(DltLogStorageFilterConfig)); + tmp_data.apids = NULL; + tmp_data.ctids = NULL; + tmp_data.file_name = NULL; + tmp_data.ecuid = NULL; tmp_data.log_level = DLT_LOG_VERBOSE; tmp_data.reset_log_level = DLT_LOG_OFF; + tmp_data.records = NULL; + tmp_data.log = NULL; + tmp_data.cache = NULL; for (i = 0; i < DLT_LOGSTORAGE_FILTER_CONF_COUNT; i++) { ret = dlt_logstorage_get_filter_value(config_file, sec_name, i, value); @@ -1472,11 +1432,6 @@ tmp_data.file_name = NULL; } - if (tmp_data.working_file_name != NULL) { - free(tmp_data.working_file_name); - tmp_data.working_file_name = NULL; - } - if (tmp_data.ecuid != NULL) { free(tmp_data.ecuid); tmp_data.ecuid = NULL; @@ -1504,126 +1459,6 @@ } /** - * dlt_logstorage_check_maintain_logstorage_loglevel - * - * Evaluate to maintain the logstorage loglevel setting. This is an optional - * configuration parameter - * If the given value cannot be associated with an overwrite, the default value - * will be assigned. - * - * @param config DltLogStorage - * @param value string given in config file - * @return 0 on success, -1 on error - */ -DLT_STATIC int dlt_logstorage_check_maintain_logstorage_loglevel(DltLogStorage *handle, - char *value) -{ - if ((handle == NULL) || (value == NULL)) - { - return -1; - } - - if ((strncmp(value, "OFF", 3) == 0) || (strncmp(value, "0", 1) == 0)) - { - handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF; - } - else if ((strncmp(value, "ON", 2) == 0) || (strncmp(value, "1", 1) == 0)) - { - handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; - } - else - { - dlt_vlog(LOG_ERR, - "Wrong value for Maintain logstorage loglevel section name: %s\n", value); - handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; - return -1; - } - - return 0; -} - -DLT_STATIC DltLogstorageGeneralConf - general_cfg_entries[DLT_LOGSTORAGE_GENERAL_CONF_COUNT] = { - [DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL] = { - .key = "MaintainLogstorageLogLevel", - .func = dlt_logstorage_check_maintain_logstorage_loglevel, - .is_opt = 1 - } -}; - -/** - * Check if DltLogstorage General configuration parameter is valid. - * - * @param handle pointer to DltLogstorage structure - * @param ctype Logstorage general configuration type - * @param value specified property value from configuration file - * @return 0 on success, -1 otherwise - */ -DLT_STATIC int dlt_logstorage_check_general_param(DltLogStorage *handle, - DltLogstorageGeneralConfType ctype, - char *value) -{ - if ((handle == NULL) || (value == NULL)) - { - return -1; - } - - if (ctype < DLT_LOGSTORAGE_GENERAL_CONF_COUNT) - { - return general_cfg_entries[ctype].func(handle, value); - } - - return -1; -} - -DLT_STATIC int dlt_daemon_setup_general_properties(DltLogStorage *handle, - DltConfigFile *config_file, - char *sec_name) -{ - DltLogstorageGeneralConfType type = DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL; - char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {0}; - - if ((handle == NULL) || (config_file == NULL) || (sec_name == NULL)) - { - return -1; - } - - for ( ; type < DLT_LOGSTORAGE_GENERAL_CONF_COUNT ; type++) - { - if (dlt_config_file_get_value(config_file, - sec_name, - general_cfg_entries[type].key, - value) == 0) - { - if (dlt_logstorage_check_general_param(handle, type, value) != 0) - { - dlt_vlog(LOG_WARNING, - "General parameter %s [%s] is invalid\n", - general_cfg_entries[type].key, value); - } - } - else - { - if (general_cfg_entries[type].is_opt == 1) - { - dlt_vlog(LOG_DEBUG, - "Optional General parameter %s not given\n", - general_cfg_entries[type].key); - } - else - { - dlt_vlog(LOG_ERR, - "General parameter %s not given\n", - general_cfg_entries[type].key); - return -1; - } - } - } - - return 0; -} - -/** * dlt_logstorage_store_filters * * This function reads the filter keys and values @@ -1657,7 +1492,6 @@ return -1; } - handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF; dlt_config_file_get_num_sections(config, &num_sec); for (sec = 0; sec < num_sec; sec++) { @@ -1670,11 +1504,8 @@ } if (strstr(sec_name, GENERAL_BASE_NAME) != NULL) { - if (dlt_daemon_setup_general_properties(handle, config, sec_name) == -1) - { - dlt_log(LOG_CRIT, "General configuration is invalid\n"); - continue; - } + dlt_log(LOG_CRIT, "General configuration not supported \n"); + continue; } else if (dlt_logstorage_validate_filter_name(sec_name) == 0) { @@ -1716,7 +1547,7 @@ * key consists of none wildcard value, e.g. apid=.*, cxid=CTX1 * results in "CTX1". * - * Combination of two wildcards is not allowed if ECUID is not specified. + * Combination of two wildcards is not allowed. * * @param handle DLT Logstorage handle * @return 0 on success, -1 on error, 1 on warning @@ -1798,7 +1629,6 @@ handle->config_status = 0; handle->write_errors = 0; handle->num_configs = 0; - handle->newest_file_list = NULL; /* Setup logstorage with config file settings */ return dlt_logstorage_load_config(handle); @@ -1816,7 +1646,6 @@ */ int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason) { - DltNewestFileName *tmp = NULL; if (handle == NULL) return -1; @@ -1831,21 +1660,6 @@ handle->write_errors = 0; handle->num_configs = 0; - while (handle->newest_file_list) { - tmp = handle->newest_file_list; - handle->newest_file_list = tmp->next; - if (tmp->file_name) { - free(tmp->file_name); - tmp->file_name = NULL; - } - if (tmp->newest_file) { - free(tmp->newest_file); - tmp->newest_file = NULL; - } - free(tmp); - tmp = NULL; - } - return 0; } @@ -2103,7 +1917,7 @@ * configuration. * * @param handle DltLogStorage handle - * @param uconfig User configurations for log file + * @param uconfig User configurations for log file * @param data1 Data buffer of message header * @param size1 Size of message header buffer * @param data2 Data buffer of extended message body @@ -2134,8 +1948,6 @@ DltStandardHeader *standardHeader = NULL; unsigned int standardHeaderExtraLen = sizeof(DltStandardHeaderExtra); unsigned int header_len = 0; - DltNewestFileName *tmp = NULL; - int found = 0; int log_level = -1; @@ -2217,56 +2029,11 @@ if (config[i]->file_name == NULL) continue; - tmp = handle->newest_file_list; - while (tmp) { - if (strcmp(tmp->file_name, config[i]->file_name) == 0) { - found = 1; - break; - } - else { - tmp = tmp->next; - } - } - if (!found) { - dlt_vlog(LOG_ERR, "Cannot find out record for filename [%s]\n", - config[i]->file_name); - return -1; - } - /* prepare log file (create and/or open)*/ - if (config[i]->ecuid == NULL) - dlt_vlog(LOG_DEBUG, "%s: ApId-CtId-EcuId [%s]-[%s]-[]\n", __func__, - config[i]->apids, config[i]->ctids); - else - dlt_vlog(LOG_DEBUG, "%s: ApId-CtId-EcuId [%s]-[%s]-[%s]\n", __func__, - config[i]->apids, config[i]->ctids, config[i]->ecuid); - ret = config[i]->dlt_logstorage_prepare(config[i], uconfig, handle->device_mount_point, - size1 + size2 + size3, - tmp); - - if (config[i]->sync == DLT_LOGSTORAGE_SYNC_UNSET || - config[i]->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) { - /* It is abnormal if working file is still NULL after preparation. */ - if (!config[i]->working_file_name) { - dlt_vlog(LOG_ERR, "Failed to prepare working file for %s\n", - config[i]->file_name); - return -1; - } - else { - /* After preparation phase, update newest file info - * it means there is new file created, newest file info must be updated. - */ - if (tmp->newest_file) { - free(tmp->newest_file); - tmp->newest_file = NULL; - } - tmp->newest_file = strdup(config[i]->working_file_name); - tmp->wrap_id = config[i]->wrap_id; - } - } + size1 + size2 + size3); if (ret == 0) { /* log data (write) */ ret = config[i]->dlt_logstorage_write(config[i], @@ -2280,25 +2047,6 @@ size3); if (ret == 0) { - /* In case of behavior CACHED_BASED, the newest file info - * must be updated right after writing phase. - * That is because in writing phase, it could also perform - * sync to file which actions could impact to the log file info. - * If both working file name and newest file name are unavailable, - * it means the sync to file is not performed yet, wait for next times. - */ - if (config[i]->sync != DLT_LOGSTORAGE_SYNC_ON_MSG && - config[i]->sync != DLT_LOGSTORAGE_SYNC_UNSET) { - if (config[i]->working_file_name) { - if (tmp->newest_file) { - free(tmp->newest_file); - tmp->newest_file = NULL; - } - tmp->newest_file = strdup(config[i]->working_file_name); - tmp->wrap_id = config[i]->wrap_id; - } - } - /* flush to be sure log is stored on device */ ret = config[i]->dlt_logstorage_sync(config[i], uconfig, diff -Nru dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage.h dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage.h --- dlt-daemon-2.18.9/src/offlinelogstorage/dlt_offline_logstorage.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/offlinelogstorage/dlt_offline_logstorage.h 2019-09-03 08:28:13.000000000 +0000 @@ -52,7 +52,6 @@ #define DLT_OFFLINE_LOGSTORAGE_H #include -#include #include "dlt_common.h" #include "dlt-daemon_cfg.h" #include "dlt_config_file_parser.h" @@ -114,9 +113,9 @@ #define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S)&(s)) /* logstorage max cache */ -extern unsigned int g_logstorage_cache_max; +unsigned int g_logstorage_cache_max; /* current logstorage cache size */ -extern unsigned int g_logstorage_cache_size; +unsigned int g_logstorage_cache_size; typedef struct { @@ -140,19 +139,9 @@ /* List for filenames */ char *name; /* Filename */ unsigned int idx; /* File index */ - struct DltLogStorageFileList *next; /* Pointer to next */ + struct DltLogStorageFileList *next; } DltLogStorageFileList; -typedef struct DltNewestFileName DltNewestFileName; - -struct DltNewestFileName -{ - char *file_name; /* The unique name of file in whole a dlt_logstorage.conf */ - char *newest_file; /* The real newest name of file which is associated with filename.*/ - unsigned int wrap_id; /* Identifier of wrap around happened for this file_name */ - DltNewestFileName *next; /* Pointer to next */ -}; - typedef struct DltLogStorageFilterConfig DltLogStorageFilterConfig; struct DltLogStorageFilterConfig @@ -163,8 +152,6 @@ int log_level; /* Log level number configured for filter */ int reset_log_level; /* reset Log level to be sent on disconnect */ char *file_name; /* File name for log storage configured for filter */ - char *working_file_name; /* Current open log file name */ - unsigned int wrap_id; /* Identifier of wrap around happened for this filter */ unsigned int file_size; /* MAX File size of storage file configured for filter */ unsigned int num_files; /* MAX number of storage files configured for filters */ int sync; /* Sync strategy */ @@ -173,8 +160,7 @@ int (*dlt_logstorage_prepare)(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info); + int log_msg_size); int (*dlt_logstorage_write)(DltLogStorageFilterConfig *config, DltLogStorageUserConfig *file_config, char *dev_path, @@ -216,8 +202,6 @@ unsigned int connection_type; /* Type of connection */ unsigned int config_status; /* Status of configuration */ int write_errors; /* number of write errors */ - DltNewestFileName *newest_file_list; /* List of newest file name */ - int maintain_logstorage_loglevel; /* Permission to maintain the logstorage loglevel*/ } DltLogStorage; typedef struct { @@ -227,7 +211,7 @@ } DltLogstorageGeneralConf; typedef enum { - DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL = 1, + DLT_LOGSTORAGE_GENERAL_CONF_BLOCKMODE = 0, DLT_LOGSTORAGE_GENERAL_CONF_COUNT } DltLogstorageGeneralConfType; diff -Nru dlt-daemon-2.18.9/src/shared/dlt_common.c dlt-daemon-2.18.4/src/shared/dlt_common.c --- dlt-daemon-2.18.9/src/shared/dlt_common.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_common.c 2019-09-03 08:28:13.000000000 +0000 @@ -31,18 +31,14 @@ #include /* for localtime_r(), strftime() */ #include /* for NAME_MAX */ #include /* for PRI formatting macro */ -#include /* dirname */ #include -#include #include #include /* for mkdir() */ -#include #include "dlt_user_shared.h" #include "dlt_common.h" #include "dlt_common_cfg.h" -#include "dlt_multiple_files.h" #include "dlt_version.h" @@ -58,7 +54,6 @@ # include #else # include /* for read(), close() */ -# include # include /* for gettimeofday() */ #endif @@ -70,32 +65,17 @@ const char dltSerialHeader[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 }; char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 }; - -#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC char dltFifoBaseDir[DLT_PATH_MAX] = "/tmp"; -#endif #ifdef DLT_SHM_ENABLE char dltShmName[NAME_MAX + 1] = "/dlt-shm"; #endif /* internal logging parameters */ +static int logging_mode = DLT_LOG_TO_CONSOLE; static int logging_level = LOG_INFO; static char logging_filename[NAME_MAX + 1] = ""; -static bool print_with_attributes = false; -int logging_mode = DLT_LOG_TO_STDERR; -FILE *logging_handle = NULL; - -//use ohandle as an indicator that multiple files logging is active -MultipleFilesRingBuffer multiple_files_ring_buffer = { - .directory={0}, - .filename={0}, - .fileSize=0, - .maxSize=0, - .filenameTimestampBased=false, - .filenameBase={0}, - .filenameExt={0}, - .ohandle=-1}; +static FILE *logging_handle = NULL; char *message_type[] = { "log", "app_trace", "nw_trace", "control", "", "", "", "" }; char *log_info[] = { "", "fatal", "error", "warn", "info", "debug", "verbose", "", "", "", "", "", "", "", "", "" }; @@ -130,17 +110,17 @@ for (num = 0; num < size; num++) { if (num > 0) - dlt_user_printf(" "); + printf(" "); - dlt_user_printf("%.2x", ((uint8_t *)ptr)[num]); + printf("%.2x", ((uint8_t *)ptr)[num]); } } -static DltReturnValue dlt_print_hex_string_delim(char *text, int textlength, uint8_t *ptr, int size, char delim) +DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size) { int num; - if ((ptr == NULL) || (text == NULL) || (textlength <= 0) || (size < 0) || (delim == '\0')) + if ((ptr == NULL) || (text == NULL) || (textlength <= 0) || (size < 0)) return DLT_RETURN_WRONG_PARAMETER; /* Length 3: AB_ , A is first digit of hex number, B is second digit of hex number, _ is space */ @@ -153,7 +133,7 @@ for (num = 0; num < size; num++) { if (num > 0) { - snprintf(text, 2, "%c", delim); + snprintf(text, 2, " "); text++; } @@ -164,11 +144,6 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size) -{ - return dlt_print_hex_string_delim(text, textlength, ptr, size, ' '); -} - DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, int size, int html) { int required_size = 0; @@ -183,16 +158,15 @@ (DLT_COMMON_HEX_LINELEN + (2 * DLT_COMMON_HEX_CHARS + (DLT_COMMON_HEX_CHARS - 1)) + DLT_COMMON_CHARLEN + DLT_COMMON_HEX_CHARS + DLT_COMMON_CHARLEN) * ((size / DLT_COMMON_HEX_CHARS) + 1); - /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + CR) * - * ((size/16) lines + extra line for the rest) */ + /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + CR) * + * ((size/16) lines + extra line for the rest) */ else required_size = (DLT_COMMON_HEX_LINELEN + (2 * DLT_COMMON_HEX_CHARS + (DLT_COMMON_HEX_CHARS - 1)) + DLT_COMMON_CHARLEN + DLT_COMMON_HEX_CHARS + 4 * DLT_COMMON_CHARLEN) * ((size / DLT_COMMON_HEX_CHARS) + 1); - - /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + 4 [HTML CR:
]) * - * ((size/16) lines + extra line for the rest) */ + /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + 4 [HTML CR:
]) * + * ((size/16) lines + extra line for the rest) */ if (textlength < required_size) { dlt_vlog(LOG_WARNING, @@ -205,7 +179,7 @@ for (lines = 0; lines < (size / DLT_COMMON_HEX_CHARS); lines++) { int ret = 0; /* Line number */ - ret = snprintf(text, DLT_COMMON_HEX_LINELEN + 1, "%.6x: ", (uint32_t)lines * DLT_COMMON_HEX_CHARS); + ret = snprintf(text, DLT_COMMON_HEX_LINELEN + 1, "%.6x: ", lines * DLT_COMMON_HEX_CHARS); if ((ret < 0) || (ret >= (DLT_COMMON_HEX_LINELEN + 1))) dlt_log(LOG_WARNING, "line was truncated\n"); @@ -215,10 +189,7 @@ /* Hex-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_hex_string(text, textlength, - (uint8_t *)(ptr + (lines * DLT_COMMON_HEX_CHARS)), - DLT_COMMON_HEX_CHARS) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; + dlt_print_hex_string(text, textlength, (uint8_t *)(ptr + (lines * DLT_COMMON_HEX_CHARS)), DLT_COMMON_HEX_CHARS); text += ((2 * DLT_COMMON_HEX_CHARS) + (DLT_COMMON_HEX_CHARS - 1)); /* 32 characters + 15 spaces */ snprintf(text, 2, " "); @@ -227,10 +198,8 @@ /* Char-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_char_string(&text, textlength, - (uint8_t *)(ptr + (lines * DLT_COMMON_HEX_CHARS)), - DLT_COMMON_HEX_CHARS) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; + dlt_print_char_string(&text, textlength, (uint8_t *)(ptr + (lines * DLT_COMMON_HEX_CHARS)), + DLT_COMMON_HEX_CHARS); if (html == 0) { snprintf(text, 2, "\n"); @@ -248,7 +217,7 @@ if (rest > 0) { /* Line number */ int ret = 0; - ret = snprintf(text, 9, "%.6x: ", (uint32_t)(size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS); + ret = snprintf(text, 9, "%.6x: ", (size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS); if ((ret < 0) || (ret >= 9)) dlt_log(LOG_WARNING, "line number was truncated"); @@ -258,11 +227,10 @@ /* Hex-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_hex_string(text, + dlt_print_hex_string(text, textlength, (uint8_t *)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), - rest) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; + rest); text += 2 * rest + (rest - 1); for (i = 0; i < (DLT_COMMON_HEX_CHARS - rest); i++) { @@ -276,10 +244,8 @@ /* Char-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_char_string(&text, textlength, - (uint8_t *)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), - rest) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; + dlt_print_char_string(&text, textlength, + (uint8_t *)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), rest); } return DLT_RETURN_OK; @@ -317,32 +283,25 @@ return DLT_RETURN_OK; } -size_t dlt_strnlen_s(const char* str, size_t maxsize) -{ - if (str == NULL) - return 0; - - for (size_t i = 0; i < maxsize; ++i) { - if (str[i] == '\0') - return i; - } - return maxsize; -} - void dlt_print_id(char *text, const char *id) { /* check nullpointer */ if ((text == NULL) || (id == NULL)) return; + int i, len; + /* Initialize text */ - memset(text, '-', DLT_ID_SIZE); + for (i = 0; i < DLT_ID_SIZE; i++) + text[i] = '-'; text[DLT_ID_SIZE] = 0; - size_t len = dlt_strnlen_s(id, DLT_ID_SIZE); + len = ((strlen(id) <= DLT_ID_SIZE) ? strlen(id) : DLT_ID_SIZE); - memcpy(text, id, len); + /* Check id*/ + for (i = 0; i < len; i++) + text[i] = id[i]; } void dlt_set_id(char *id, const char *text) @@ -417,7 +376,7 @@ return DLT_RETURN_WRONG_PARAMETER; FILE *handle; - char str1[DLT_COMMON_BUFFER_LENGTH + 1]; + char str1[DLT_COMMON_BUFFER_LENGTH]; char apid[DLT_ID_SIZE], ctid[DLT_ID_SIZE]; PRINT_FUNCTION_VERBOSE(verbose); @@ -429,16 +388,13 @@ return DLT_RETURN_ERROR; } - #define FORMAT_STRING_(x) "%" #x "s" - #define FORMAT_STRING(x) FORMAT_STRING_(x) - /* Reset filters */ filter->counter = 0; while (!feof(handle)) { str1[0] = 0; - if (fscanf(handle, FORMAT_STRING(DLT_COMMON_BUFFER_LENGTH), str1) != 1) + if (fscanf(handle, "%s", str1) != 1) break; if (str1[0] == 0) @@ -453,7 +409,7 @@ str1[0] = 0; - if (fscanf(handle, FORMAT_STRING(DLT_COMMON_BUFFER_LENGTH), str1) != 1) + if (fscanf(handle, "%s", str1) != 1) break; if (str1[0] == 0) @@ -466,12 +422,14 @@ else dlt_set_id(ctid, str1); - if (filter->counter < DLT_FILTER_MAX) - dlt_filter_add(filter, apid, ctid, 0, 0, INT32_MAX, verbose); - else + if (filter->counter < DLT_FILTER_MAX) { + dlt_filter_add(filter, apid, ctid, verbose); + } + else { dlt_vlog(LOG_WARNING, "Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", DLT_FILTER_MAX); + } } fclose(handle); @@ -520,8 +478,7 @@ return DLT_RETURN_OK; } -int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, int verbose) { int num; @@ -539,25 +496,16 @@ char empty_ctid[DLT_ID_SIZE] = ""; if (memcmp(filter->ctid[num], empty_ctid, DLT_ID_SIZE) == 0) - if ((filter->log_level[num] == log_level) || (filter->log_level[num] == 0)) - if (filter->payload_min[num] <= payload_min) - if (filter->payload_max[num] >= payload_max) - return num; + return num; } else if (memcmp(filter->ctid[num], ctid, DLT_ID_SIZE) == 0) - { - if ((filter->log_level[num] == log_level) || (filter->log_level[num] == 0)) - if (filter->payload_min[num] <= payload_min) - if (filter->payload_max[num] >= payload_max) - return num; - } + return num; } return -1; /* Not found */ } -DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -571,25 +519,23 @@ return DLT_RETURN_ERROR; } - /* add each filter (apid, ctid, log_level, payload_min, payload_max) only once to filter array */ - if (dlt_filter_find(filter, apid, ctid, log_level, payload_min, payload_max, verbose) < 0) { + /* add each filter (apid, ctid) only once to filter array */ + if (dlt_filter_find(filter, apid, ctid, verbose) < 0) { /* filter not found, so add it to filter array */ - dlt_set_id(filter->apid[filter->counter], apid); - dlt_set_id(filter->ctid[filter->counter], (ctid ? ctid : "")); - filter->log_level[filter->counter] = log_level; - filter->payload_min[filter->counter] = payload_min; - filter->payload_max[filter->counter] = payload_max; + if (filter->counter < DLT_FILTER_MAX) { + dlt_set_id(filter->apid[filter->counter], apid); + dlt_set_id(filter->ctid[filter->counter], (ctid ? ctid : "")); - filter->counter++; + filter->counter++; - return DLT_RETURN_OK; + return DLT_RETURN_OK; + } } return DLT_RETURN_ERROR; } -DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, int verbose) { int j, k; int found = 0; @@ -603,31 +549,24 @@ /* Get first occurence of apid and ctid in filter array */ for (j = 0; j < filter->counter; j++) if ((memcmp(filter->apid[j], apid, DLT_ID_SIZE) == 0) && - (memcmp(filter->ctid[j], ctid, DLT_ID_SIZE) == 0) && - ((filter->log_level[j] == log_level) || (filter->log_level[j] == 0)) && - (filter->payload_min[j] == payload_min) && - (filter->payload_max[j] == payload_max) + (memcmp(filter->ctid[j], ctid, DLT_ID_SIZE) == 0) ) { found = 1; break; } + + if (found) { /* j is index */ /* Copy from j+1 til end to j til end-1 */ dlt_set_id(filter->apid[j], ""); dlt_set_id(filter->ctid[j], ""); - filter->log_level[j] = 0; - filter->payload_min[j] = 0; - filter->payload_max[j] = INT32_MAX; for (k = j; k < (filter->counter - 1); k++) { dlt_set_id(filter->apid[k], filter->apid[k + 1]); dlt_set_id(filter->ctid[k], filter->ctid[k + 1]); - filter->log_level[k] = filter->log_level[k + 1]; - filter->payload_min[k] = filter->payload_min[k + 1]; - filter->payload_max[k] = filter->payload_max[k + 1]; } filter->counter--; @@ -678,12 +617,12 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_message_header(DltMessage *msg, char *text, size_t textlength, int verbose) +DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose) { return dlt_message_header_flags(msg, text, textlength, DLT_HEADER_SHOW_ALL, verbose); } -DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t textlength, int flags, int verbose) +DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, int textlength, int flags, int verbose) { struct tm timeinfo; char buffer [DLT_COMMON_BUFFER_LENGTH]; @@ -693,9 +632,6 @@ if ((msg == NULL) || (text == NULL) || (textlength <= 0)) return DLT_RETURN_WRONG_PARAMETER; - if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) && (msg->extendedheader == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - if ((flags < DLT_HEADER_SHOW_NONE) || (flags > DLT_HEADER_SHOW_ALL)) return DLT_RETURN_WRONG_PARAMETER; @@ -704,7 +640,6 @@ if ((flags & DLT_HEADER_SHOW_TIME) == DLT_HEADER_SHOW_TIME) { /* print received time */ time_t tt = msg->storageheader->seconds; - tzset(); localtime_r(&tt, &timeinfo); strftime (buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", &timeinfo); snprintf(text, textlength, "%s.%.6d ", buffer, msg->storageheader->microseconds); @@ -811,7 +746,7 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlength, int type, int verbose) +DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose) { uint32_t id = 0, id_tmp = 0; uint8_t retval = 0; @@ -827,12 +762,10 @@ int num; uint32_t type_info = 0, type_info_tmp = 0; - int text_offset = 0; PRINT_FUNCTION_VERBOSE(verbose); - if ((msg == NULL) || (msg->databuffer == NULL) || (text == NULL) || - (type < DLT_OUTPUT_HEX) || (type > DLT_OUTPUT_ASCII_LIMITED)) + if ((msg == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; if (textlength <= 0) { @@ -845,17 +778,17 @@ /* print payload only as hex */ if (type == DLT_OUTPUT_HEX) - return dlt_print_hex_string(text, (int)textlength, msg->databuffer, (int)msg->datasize); + return dlt_print_hex_string(text, textlength, msg->databuffer, msg->datasize); /* print payload as mixed */ if (type == DLT_OUTPUT_MIXED_FOR_PLAIN) - return dlt_print_mixed_string(text, (int)textlength, msg->databuffer, (int)msg->datasize, 0); + return dlt_print_mixed_string(text, textlength, msg->databuffer, msg->datasize, 0); if (type == DLT_OUTPUT_MIXED_FOR_HTML) - return dlt_print_mixed_string(text, (int)textlength, msg->databuffer, (int)msg->datasize, 1); + return dlt_print_mixed_string(text, textlength, msg->databuffer, msg->datasize, 1); ptr = msg->databuffer; - datalength = (int32_t)msg->datasize; + datalength = msg->datasize; /* Pointer to ptr and datalength */ pptr = &ptr; @@ -869,18 +802,19 @@ DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); - if (textlength < (((unsigned int)datalength * 3) + 20)) { + if (textlength < ((datalength * 3) + 20)) { dlt_vlog(LOG_WARNING, "String does not fit binary data (available=%d, required=%d) !\n", - (int) textlength, (datalength * 3) + 20); + textlength, (datalength * 3) + 20); return DLT_RETURN_ERROR; } /* process message id / service id */ if (DLT_MSG_IS_CONTROL(msg)) { - if ((id > 0) && (id < DLT_SERVICE_ID_LAST_ENTRY)) + if ((id > 0) && (id < DLT_SERVICE_ID_LAST_ENTRY)) { snprintf(text + strlen(text), textlength - strlen(text), "%s", service_id_name[id]); /* service id */ + } else if (!(DLT_MSG_IS_CONTROL_TIME(msg))) snprintf(text + strlen(text), textlength - strlen(text), "service(%u)", id); /* service id */ @@ -896,7 +830,7 @@ if (datalength > 0) { DLT_MSG_READ_VALUE(retval, ptr, datalength, uint8_t); /* No endian conversion necessary */ - if ((retval < DLT_SERVICE_RESPONSE_LAST) || (retval == 8)) + if ((retval < 3) || (retval == 8)) snprintf(text + strlen(text), textlength - strlen(text), "%s", return_type[retval]); else snprintf(text + strlen(text), textlength - strlen(text), "%.2x", retval); @@ -908,8 +842,8 @@ if (type == DLT_OUTPUT_ASCII_LIMITED) { ret = dlt_print_hex_string(text + strlen(text), - (int)(textlength - strlen( - text)), + textlength - strlen( + text), ptr, (datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); @@ -919,7 +853,7 @@ snprintf(text + strlen(text), textlength - strlen(text), " ..."); } else { - ret = dlt_print_hex_string(text + strlen(text), (int)(textlength - strlen(text)), ptr, datalength); + ret = dlt_print_hex_string(text + strlen(text), textlength - strlen(text), ptr, datalength); } return ret; @@ -932,21 +866,15 @@ type_info_tmp = 0; for (num = 0; num < (int)(msg->extendedheader->noar); num++) { - if (num != 0) { - text_offset = (int)strlen(text); - snprintf(text + text_offset, textlength - (size_t)text_offset, " "); - } + if (num != 0) + snprintf(text + strlen(text), textlength - strlen(text), " "); /* first read the type info of the argument */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); type_info = DLT_ENDIAN_GET_32(msg->standardheader->htyp, type_info_tmp); /* print out argument */ - text_offset = (int)strlen(text); - - if (dlt_message_argument_print(msg, type_info, pptr, pdatalength, - (text + text_offset), (textlength - (size_t)text_offset), -1, - 0) == DLT_RETURN_ERROR) + if (dlt_message_argument_print(msg, type_info, pptr, pdatalength, text, textlength, -1, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; } @@ -972,11 +900,7 @@ /* check each filter if it matches */ if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) && ((filter->apid[num][0] == 0) || (memcmp(filter->apid[num], msg->extendedheader->apid, DLT_ID_SIZE) == 0)) && - ((filter->ctid[num][0] == 0) || (memcmp(filter->ctid[num], msg->extendedheader->ctid, DLT_ID_SIZE) == 0)) && - ((filter->log_level[num] == 0) || - (filter->log_level[num] == DLT_GET_MSIN_MTIN(msg->extendedheader->msin))) && - ((filter->payload_min[num] == 0) || (filter->payload_min[num] <= msg->datasize)) && - ((filter->payload_max[num] == 0) || (filter->payload_max[num] >= msg->datasize))) { + ((filter->ctid[num][0] == 0) || (memcmp(filter->ctid[num], msg->extendedheader->ctid, DLT_ID_SIZE) == 0))) { found = DLT_RETURN_TRUE; break; } @@ -986,7 +910,7 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose) { - uint32_t extra_size = 0; + int extra_size = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -1005,7 +929,7 @@ /* serial header found */ msg->found_serialheader = 1; buffer += sizeof(dltSerialHeader); - length -= (unsigned int)sizeof(dltSerialHeader); + length -= sizeof(dltSerialHeader); } else { /* serial header not found */ @@ -1020,18 +944,18 @@ /* serial header found */ msg->found_serialheader = 1; buffer += sizeof(dltSerialHeader); - length -= (unsigned int)sizeof(dltSerialHeader); + length -= sizeof(dltSerialHeader); break; } msg->resync_offset++; - } while ((sizeof(dltSerialHeader) + (size_t)msg->resync_offset) <= length); + } while ((sizeof(dltSerialHeader) + msg->resync_offset) <= length); /* Set new start offset */ if (msg->resync_offset > 0) { /* Resyncing connection */ buffer += msg->resync_offset; - length -= (unsigned int)msg->resync_offset; + length -= msg->resync_offset; } } } @@ -1048,31 +972,23 @@ msg->standardheader = (DltStandardHeader *)(msg->headerbuffer + sizeof(DltStorageHeader)); /* calculate complete size of headers */ - extra_size = (uint32_t) (DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp) + - (DLT_IS_HTYP_UEH(msg->standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); - msg->headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + extra_size); - msg->datasize = (uint32_t) DLT_BETOH_16(msg->standardheader->len) - msg->headersize + (uint32_t) sizeof(DltStorageHeader); - - /* calculate complete size of payload */ - int32_t temp_datasize; - temp_datasize = DLT_BETOH_16(msg->standardheader->len) - (int32_t) msg->headersize + (int32_t) sizeof(DltStorageHeader); + extra_size = DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp) + + (DLT_IS_HTYP_UEH(msg->standardheader->htyp) ? sizeof(DltExtendedHeader) : 0); + msg->headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + extra_size; + msg->datasize = DLT_BETOH_16(msg->standardheader->len) - (msg->headersize - sizeof(DltStorageHeader)); + + if (verbose) { + dlt_vlog(LOG_DEBUG, "BufferLength=%d, HeaderSize=%d, DataSize=%d\n", + length, msg->headersize, msg->datasize); + } /* check data size */ - if (temp_datasize < 0) { + if (msg->datasize < 0) { dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short (%d)!\n", - temp_datasize); + msg->datasize); return DLT_MESSAGE_ERROR_CONTENT; } - else { - msg->datasize = (uint32_t) temp_datasize; - } - - /* check if verbose mode is on*/ - if (verbose) { - dlt_vlog(LOG_DEBUG, "BufferLength=%u, HeaderSize=%u, DataSize=%u\n", - length, msg->headersize, msg->datasize); - } /* load standard header extra parameters and Extended header if used */ if (extra_size > 0) { @@ -1080,7 +996,7 @@ return DLT_MESSAGE_ERROR_SIZE; memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), - buffer + sizeof(DltStandardHeader), (size_t)extra_size); + buffer + sizeof(DltStandardHeader), extra_size); /* set extended header ptr and get standard header extra parameters */ if (DLT_IS_HTYP_UEH(msg->standardheader->htyp)) @@ -1114,7 +1030,7 @@ if (msg->databuffer == NULL) { dlt_vlog(LOG_WARNING, - "Cannot allocate memory for payload buffer of size %u!\n", + "Cannot allocate memory for payload buffer of size %d!\n", msg->datasize); return DLT_MESSAGE_ERROR_UNKNOWN; } @@ -1229,64 +1145,41 @@ if (file == NULL) return DLT_RETURN_WRONG_PARAMETER; - /* Loop until storage header is found */ - while (1) { - /* load header from file */ - if (fread(file->msg.headerbuffer, - sizeof(DltStorageHeader) + sizeof(DltStandardHeader), 1, - file->handle) != 1) { - if (!feof(file->handle)) - dlt_log(LOG_WARNING, "Cannot read header from file!\n"); - else - dlt_log(LOG_DEBUG, "Reached end of file\n"); + /* load header from file */ + if (fread(file->msg.headerbuffer, sizeof(DltStorageHeader) + sizeof(DltStandardHeader), 1, file->handle) != 1) { + if (!feof(file->handle)) + dlt_log(LOG_WARNING, "Cannot read header from file!\n"); - return DLT_RETURN_ERROR; - } + return DLT_RETURN_ERROR; + } - /* set ptrs to structures */ - file->msg.storageheader = (DltStorageHeader *)file->msg.headerbuffer; - file->msg.standardheader = (DltStandardHeader *)(file->msg.headerbuffer + - sizeof(DltStorageHeader)); - - /* check id of storage header */ - if (dlt_check_storageheader(file->msg.storageheader) != DLT_RETURN_TRUE) { - /* Shift the position back to the place where it stared to read + 1 */ - if (fseek(file->handle, - (long) (1 - (sizeof(DltStorageHeader) + sizeof(DltStandardHeader))), - SEEK_CUR) < 0) { - dlt_log(LOG_WARNING, "DLT storage header pattern not found!\n"); - return DLT_RETURN_ERROR; - } - } - else { - /* storage header is found */ - break; - } + /* set ptrs to structures */ + file->msg.storageheader = (DltStorageHeader *)file->msg.headerbuffer; + file->msg.standardheader = (DltStandardHeader *)(file->msg.headerbuffer + sizeof(DltStorageHeader)); + + /* check id of storage header */ + if (dlt_check_storageheader(file->msg.storageheader) != DLT_RETURN_TRUE) { + dlt_log(LOG_WARNING, "DLT storage header pattern not found!\n"); + return DLT_RETURN_ERROR; } /* calculate complete size of headers */ - file->msg.headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + file->msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + - (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0); + file->msg.datasize = DLT_BETOH_16(file->msg.standardheader->len) + sizeof(DltStorageHeader) - file->msg.headersize; - /* calculate complete size of payload */ - int32_t temp_datasize; - temp_datasize = DLT_BETOH_16(file->msg.standardheader->len) + (int32_t) sizeof(DltStorageHeader) - (int32_t) file->msg.headersize; + if (verbose) { + dlt_vlog(LOG_DEBUG, "HeaderSize=%d, DataSize=%d\n", + file->msg.headersize, file->msg.datasize); + } /* check data size */ - if (temp_datasize < 0) { + if (file->msg.datasize < 0) { dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short! (%d)\n", - temp_datasize); + file->msg.datasize); return DLT_RETURN_ERROR; - } else { - file->msg.datasize = (uint32_t) temp_datasize; - } - - /* check if verbose mode is on */ - if (verbose) { - dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n", - file->msg.headersize, file->msg.datasize); } return DLT_RETURN_OK; @@ -1337,9 +1230,7 @@ else /* go back to last file position */ if (0 != fseek(file->handle, file->file_position, SEEK_SET)) - { return DLT_RETURN_ERROR; - } } /* load header from file */ @@ -1363,30 +1254,23 @@ /* no check for storage header id*/ /* calculate complete size of headers */ - file->msg.headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + file->msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + - (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0); + file->msg.datasize = DLT_BETOH_16(file->msg.standardheader->len) + sizeof(DltStorageHeader) - file->msg.headersize; - /* calculate complete size of payload */ - int32_t temp_datasize; - temp_datasize = DLT_BETOH_16(file->msg.standardheader->len) + (int32_t) sizeof(DltStorageHeader) - (int32_t) file->msg.headersize; + if (verbose) { + dlt_vlog(LOG_DEBUG, "HeaderSize=%d, DataSize=%d\n", + file->msg.headersize, file->msg.datasize); + } /* check data size */ - if (temp_datasize < 0) { + if (file->msg.datasize < 0) { dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short! (%d)\n", - temp_datasize); + file->msg.datasize); return DLT_RETURN_ERROR; } - else { - file->msg.datasize = (uint32_t) temp_datasize; - } - - /* check if verbose mode is on */ - if (verbose) { - dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n", - file->msg.headersize, file->msg.datasize); - } return DLT_RETURN_OK; } @@ -1455,7 +1339,7 @@ if (file->msg.databuffer == NULL) { dlt_vlog(LOG_WARNING, - "Cannot allocate memory for payload buffer of size %u!\n", + "Cannot allocate memory for payload buffer of size %d!\n", file->msg.datasize); return DLT_RETURN_ERROR; } @@ -1464,7 +1348,7 @@ if (fread(file->msg.databuffer, file->msg.datasize, 1, file->handle) != 1) { if (file->msg.datasize != 0) { dlt_vlog(LOG_WARNING, - "Cannot read payload data from file of size %u!\n", + "Cannot read payload data from file of size %d!\n", file->msg.datasize); return DLT_RETURN_ERROR; } @@ -1511,9 +1395,10 @@ return DLT_RETURN_ERROR; } - if (verbose) + if (verbose) { /* print file length */ - dlt_vlog(LOG_DEBUG, "File is %" PRIu64 "bytes long\n", file->file_length); + dlt_vlog(LOG_DEBUG, "File is %lu bytes long\n", file->file_length); + } return DLT_RETURN_OK; } @@ -1523,12 +1408,13 @@ long *ptr; int found = DLT_RETURN_OK; + if (verbose) { + dlt_vlog(LOG_DEBUG, "%s: Message %d:\n", __func__, file->counter_total); + } + if (file == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (verbose) - dlt_vlog(LOG_DEBUG, "%s: Message %d:\n", __func__, file->counter_total); - /* allocate new memory for index if number of messages exceeds a multiple of DLT_COMMON_INDEX_ALLOC (e.g.: 1000) */ if (file->counter % DLT_COMMON_INDEX_ALLOC == 0) { ptr = (long *)malloc(((file->counter / DLT_COMMON_INDEX_ALLOC) + 1) * DLT_COMMON_INDEX_ALLOC * sizeof(long)); @@ -1537,7 +1423,7 @@ return DLT_RETURN_ERROR; if (file->index) { - memcpy(ptr, file->index, (size_t)(file->counter) * sizeof(long)); + memcpy(ptr, file->index, file->counter * sizeof(long)); free(file->index); } @@ -1546,14 +1432,15 @@ /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */ if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { - dlt_vlog(LOG_WARNING, "Seek failed to file_position %" PRIu64 "\n", + dlt_vlog(LOG_WARNING, "Seek failed to file_position %ld \n", file->file_position); return DLT_RETURN_ERROR; } /* get file position at start of DLT message */ - if (verbose) - dlt_vlog(LOG_INFO, "Position in file: %" PRIu64 "\n", file->file_position); + if (verbose) { + dlt_vlog(LOG_INFO, "Position in file: %ld\n", file->file_position); + } /* read header */ if (dlt_file_read_header(file, verbose) < DLT_RETURN_OK) { @@ -1566,8 +1453,9 @@ /* read the extended header if filter is enabled and extended header exists */ if (dlt_file_read_header_extended(file, verbose) < DLT_RETURN_OK) { /* go back to last position in file */ - if (0 != fseek(file->handle, file->file_position, SEEK_SET)) + if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { dlt_vlog(LOG_WARNING, "Seek to last file pos failed!\n"); + } return DLT_RETURN_ERROR; } @@ -1587,11 +1475,12 @@ if (fseek(file->handle, file->msg.datasize, SEEK_CUR) != 0) { /* go back to last position in file */ dlt_vlog(LOG_WARNING, - "Seek failed to skip payload data of size %u!\n", + "Seek failed to skip payload data of size %d!\n", file->msg.datasize); - if (0 != fseek(file->handle, file->file_position, SEEK_SET)) + if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { dlt_log(LOG_WARNING, "Seek back also failed!\n"); + } return DLT_RETURN_ERROR; } @@ -1600,17 +1489,18 @@ /* filter is disabled */ /* skip additional header parameters and payload data */ if (fseek(file->handle, - (long) (file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize), + file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize, SEEK_CUR)) { dlt_vlog(LOG_WARNING, - "Seek failed to skip extra header and payload data from file of size %u!\n", + "Seek failed to skip extra header and payload data from file of size %d!\n", file->msg.headersize - (int32_t)sizeof(DltStorageHeader) - (int32_t)sizeof(DltStandardHeader) + file->msg.datasize); /* go back to last position in file */ - if (fseek(file->handle, file->file_position, SEEK_SET)) + if (fseek(file->handle, file->file_position, SEEK_SET)) { dlt_log(LOG_WARNING, "Seek back also failed!\n"); + } return DLT_RETURN_ERROR; } @@ -1637,8 +1527,9 @@ int found = DLT_RETURN_OK; long *ptr; - if (verbose) + if (verbose) { dlt_vlog(LOG_DEBUG, "%s: Message %d:\n", __func__, file->counter_total); + } if (file == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -1651,7 +1542,7 @@ return DLT_RETURN_ERROR; if (file->index) { - memcpy(ptr, file->index, (size_t)(file->counter) * sizeof(long)); + memcpy(ptr, file->index, file->counter * sizeof(long)); free(file->index); } @@ -1663,14 +1554,16 @@ return DLT_RETURN_ERROR; /* get file position at start of DLT message */ - if (verbose) - dlt_vlog(LOG_DEBUG, "Position in file: %" PRIu64 "\n", file->file_position); + if (verbose) { + dlt_vlog(LOG_DEBUG, "Position in file: %ld\n", file->file_position); + } /* read header */ if (dlt_file_read_header_raw(file, resync, verbose) < DLT_RETURN_OK) { /* go back to last position in file */ - if (0 != fseek(file->handle, file->file_position, SEEK_SET)) + if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { dlt_log(LOG_WARNING, "dlt_file_read_raw, fseek failed 1\n"); + } return DLT_RETURN_ERROR; } @@ -1678,16 +1571,18 @@ /* read the extended header if filter is enabled and extended header exists */ if (dlt_file_read_header_extended(file, verbose) < DLT_RETURN_OK) { /* go back to last position in file */ - if (0 != fseek(file->handle, file->file_position, SEEK_SET)) + if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { dlt_log(LOG_WARNING, "dlt_file_read_raw, fseek failed 2\n"); + } return DLT_RETURN_ERROR; } if (dlt_file_read_data(file, verbose) < DLT_RETURN_OK) { /* go back to last position in file */ - if (0 != fseek(file->handle, file->file_position, SEEK_SET)) + if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { dlt_log(LOG_WARNING, "dlt_file_read_raw, fseek failed 3\n"); + } return DLT_RETURN_ERROR; } @@ -1731,7 +1626,7 @@ return DLT_RETURN_WRONG_PARAMETER; /* check if message is in range */ - if (index < 0 || index >= file->counter) { + if (index >= file->counter) { dlt_vlog(LOG_WARNING, "Message %d out of range!\r\n", index); return DLT_RETURN_WRONG_PARAMETER; } @@ -1806,167 +1701,53 @@ logging_filename[NAME_MAX] = 0; } -#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC -void dlt_log_set_fifo_basedir(const char *pipe_dir) +void dlt_log_set_fifo_basedir(const char *env_pipe_dir) { - strncpy(dltFifoBaseDir, pipe_dir, DLT_PATH_MAX); + strncpy(dltFifoBaseDir, env_pipe_dir, DLT_PATH_MAX); dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; } -#endif #ifdef DLT_SHM_ENABLE -void dlt_log_set_shm_name(const char *env_shm_name) +void dlt_log_set_shm_name(const char * env_shm_name) { strncpy(dltShmName, env_shm_name, NAME_MAX); dltShmName[NAME_MAX] = 0; } #endif -void dlt_print_with_attributes(bool state) -{ - print_with_attributes = state; -} - -DltReturnValue dlt_log_init(int mode) -{ - return dlt_log_init_multiple_logfiles_support((DltLoggingMode)mode, false, 0, 0); -} - -DltReturnValue dlt_log_init_multiple_logfiles_support(const DltLoggingMode mode, const bool enable_multiple_logfiles, - const int logging_file_size, const int logging_files_max_size) +void 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 DLT_RETURN_WRONG_PARAMETER; + return; } logging_mode = mode; - if (logging_mode != DLT_LOG_TO_FILE) { - return DLT_RETURN_OK; - } + if (logging_mode == DLT_LOG_TO_FILE) { + /* internal logging to file */ + logging_handle = fopen(logging_filename, "a"); - if (enable_multiple_logfiles) { - dlt_user_printf("configure dlt logging using file limits\n"); - int result = dlt_log_init_multiple_logfiles(logging_file_size, logging_files_max_size); - if (result == DLT_RETURN_OK) { - return DLT_RETURN_OK; + if (logging_handle == NULL) { + printf("Internal log file %s cannot be opened!\n", logging_filename); + return; } - dlt_user_printf("dlt logging for limits fails with error code=%d, use logging without limits as fallback\n", result); - return dlt_log_init_single_logfile(); - } else { - dlt_user_printf("configure dlt logging without file limits\n"); - return dlt_log_init_single_logfile(); - } -} - -DltReturnValue dlt_log_init_single_logfile() -{ - /* internal logging to file */ - errno = 0; - logging_handle = fopen(logging_filename, "a"); - - if (logging_handle == NULL) { - dlt_user_printf("Internal log file %s cannot be opened, error: %s\n", logging_filename, strerror(errno)); - return DLT_RETURN_ERROR; - } - return DLT_RETURN_OK; -} - -DltReturnValue dlt_log_init_multiple_logfiles(const int logging_file_size, const int logging_files_max_size) -{ - char path_logging_filename[PATH_MAX + 1]; - strncpy(path_logging_filename, logging_filename, PATH_MAX); - path_logging_filename[PATH_MAX] = 0; - - const char *directory = dirname(path_logging_filename); - if (directory[0]) { - char basename_logging_filename[NAME_MAX + 1]; - strncpy(basename_logging_filename, logging_filename, NAME_MAX); - basename_logging_filename[NAME_MAX] = 0; - - const char *file_name = basename(basename_logging_filename); - char filename_base[NAME_MAX]; - if (!dlt_extract_base_name_without_ext(file_name, filename_base, sizeof(filename_base))) return DLT_RETURN_ERROR; - - const char *filename_ext = get_filename_ext(file_name); - if (!filename_ext) return DLT_RETURN_ERROR; - - DltReturnValue result = multiple_files_buffer_init( - &multiple_files_ring_buffer, - directory, - logging_file_size, - logging_files_max_size, - false, - true, - filename_base, - filename_ext); - - return result; } - - return DLT_RETURN_ERROR; } void dlt_log_free(void) { - if (logging_mode == DLT_LOG_TO_FILE) { - if (dlt_is_log_in_multiple_files_active()) { - dlt_log_free_multiple_logfiles(); - } else { - dlt_log_free_single_logfile(); - } - } -} - -void dlt_log_free_single_logfile() -{ - if (logging_handle) + if (logging_mode == DLT_LOG_TO_FILE) fclose(logging_handle); } -void dlt_log_free_multiple_logfiles() -{ - if (DLT_RETURN_ERROR == multiple_files_buffer_free(&multiple_files_ring_buffer)) return; - - // reset indicator of multiple files usage - multiple_files_ring_buffer.ohandle = -1; -} - -int dlt_user_printf(const char *format, ...) -{ - if (format == NULL) return -1; - - va_list args; - va_start(args, format); - - int ret = 0; - - switch (logging_mode) { - case DLT_LOG_TO_CONSOLE: - case DLT_LOG_TO_SYSLOG: - case DLT_LOG_TO_FILE: - case DLT_LOG_DROPPED: - default: - ret = vfprintf(stdout, format, args); - break; - case DLT_LOG_TO_STDERR: - ret = vfprintf(stderr, format, args); - break; - } - - va_end(args); - - return ret; -} - DltReturnValue dlt_log(int prio, char *s) { static const char asSeverity[LOG_DEBUG + 2][11] = { "EMERGENCY", "ALERT ", "CRITICAL ", "ERROR ", "WARNING ", "NOTICE ", "INFO ", "DEBUG ", " " }; - static const char sFormatString[] = "[%5u.%06u]~DLT~%5d~%s~%s"; + static const char sFormatString[] = "[%5d.%06d]~DLT~%5d~%s~%s"; struct timespec sTimeSpec; if (s == NULL) @@ -1983,23 +1764,14 @@ switch (logging_mode) { case DLT_LOG_TO_CONSOLE: /* log to stdout */ - fprintf(stdout, sFormatString, - (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), - getpid(), - asSeverity[prio], - s); + printf(sFormatString, + (unsigned int)sTimeSpec.tv_sec, + (unsigned int)(sTimeSpec.tv_nsec / 1000), + getpid(), + asSeverity[prio], + s); fflush(stdout); break; - case DLT_LOG_TO_STDERR: - /* log to stderr */ - fprintf(stderr, sFormatString, - (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), - getpid(), - asSeverity[prio], - s); - break; case DLT_LOG_TO_SYSLOG: /* log to syslog */ #if !defined (__WIN32__) && !defined(_MSC_VER) @@ -2015,13 +1787,9 @@ #endif break; case DLT_LOG_TO_FILE: - /* log to file */ - if (dlt_is_log_in_multiple_files_active()) { - dlt_log_multiple_files_write(sFormatString, (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), asSeverity[prio], s); - } - else if (logging_handle) { + /* log to file */ + if (logging_handle) { fprintf(logging_handle, sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), asSeverity[prio], s); fflush(logging_handle); @@ -2084,34 +1852,21 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, DltReceiverType type, int buffersize) +DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize) { - if (NULL == receiver) + if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; + receiver->lastBytesRcvd = 0; + receiver->bytesRcvd = 0; + receiver->totalBytesRcvd = 0; + receiver->buffersize = buffersize; receiver->fd = fd; - receiver->type = type; - - /** Reuse the receiver buffer if it exists and the buffer size - * is not changed. If not, free the old one and allocate a new buffer. - */ - if ((NULL != receiver->buffer) && ( buffersize != receiver->buffersize)) { - free(receiver->buffer); - receiver->buffer = NULL; - } + receiver->buffer = (char *)malloc(receiver->buffersize); + receiver->backup_buf = NULL; - if (NULL == receiver->buffer) { - receiver->lastBytesRcvd = 0; - receiver->bytesRcvd = 0; - receiver->totalBytesRcvd = 0; + if (receiver->buffer == NULL) { receiver->buf = NULL; - receiver->backup_buf = NULL; - receiver->buffer = (char *)calloc(1, (size_t)buffersize); - receiver->buffersize = (uint32_t)buffersize; - } - - if (NULL == receiver->buffer) { - dlt_log(LOG_ERR, "allocate memory for receiver buffer failed.\n"); return DLT_RETURN_ERROR; } else { @@ -2121,7 +1876,7 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, DltReceiverType type, char **buffer) +DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char **buffer) { if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -2141,7 +1896,6 @@ receiver->totalBytesRcvd = 0; receiver->buffersize = DLT_RECEIVE_BUFSIZE; receiver->fd = fd; - receiver->type = type; receiver->buffer = *buffer; receiver->backup_buf = NULL; receiver->buf = receiver->buffer; @@ -2168,7 +1922,7 @@ return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_free_global_buffer(DltReceiver *receiver) +DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver) { if (receiver == NULL) @@ -2184,10 +1938,8 @@ return DLT_RETURN_OK; } -int dlt_receiver_receive(DltReceiver *receiver) +int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src) { - socklen_t addrlen; - if (receiver == NULL) return -1; @@ -2198,36 +1950,26 @@ receiver->lastBytesRcvd = receiver->bytesRcvd; if ((receiver->lastBytesRcvd) && (receiver->backup_buf != NULL)) { - memcpy(receiver->buf, receiver->backup_buf, (size_t)receiver->lastBytesRcvd); + memcpy(receiver->buf, receiver->backup_buf, receiver->lastBytesRcvd); free(receiver->backup_buf); receiver->backup_buf = NULL; } - if (receiver->type == DLT_RECEIVE_SOCKET) + if (from_src == DLT_RECEIVE_SOCKET) /* wait for data from socket */ receiver->bytesRcvd = recv(receiver->fd, receiver->buf + receiver->lastBytesRcvd, - receiver->buffersize - (uint32_t) receiver->lastBytesRcvd, + receiver->buffersize - receiver->lastBytesRcvd, 0); - else if (receiver->type == DLT_RECEIVE_FD) + else /* wait for data from fd */ receiver->bytesRcvd = read(receiver->fd, receiver->buf + receiver->lastBytesRcvd, - receiver->buffersize - (uint32_t) receiver->lastBytesRcvd); - - else { /* receiver->type == DLT_RECEIVE_UDP_SOCKET */ - /* wait for data from UDP socket */ - addrlen = sizeof(receiver->addr); - receiver->bytesRcvd = recvfrom(receiver->fd, - receiver->buf + receiver->lastBytesRcvd, - receiver->buffersize - receiver->lastBytesRcvd, - 0, - (struct sockaddr *)&(receiver->addr), - &addrlen); - } + receiver->buffersize - receiver->lastBytesRcvd); if (receiver->bytesRcvd <= 0) { receiver->bytesRcvd = 0; + return receiver->bytesRcvd; } /* if */ @@ -2266,14 +2008,14 @@ return DLT_RETURN_ERROR; if ((receiver->buffer != receiver->buf) && (receiver->bytesRcvd != 0)) { - receiver->backup_buf = calloc((size_t)(receiver->bytesRcvd + 1), sizeof(char)); + receiver->backup_buf = calloc(receiver->bytesRcvd + 1, sizeof(char)); if (receiver->backup_buf == NULL) dlt_vlog(LOG_WARNING, "Can't allocate memory for backup buf, there will be atleast" "one corrupted message for fd[%d] \n", receiver->fd); else - memcpy(receiver->backup_buf, receiver->buf, (size_t)receiver->bytesRcvd); + memcpy(receiver->backup_buf, receiver->buf, receiver->bytesRcvd); } return DLT_RETURN_OK; @@ -2284,19 +2026,19 @@ unsigned int to_get, unsigned int flags) { - size_t min_size = (size_t)to_get; - uint8_t *src = NULL; + unsigned int min_size = to_get; + void *src = NULL; if (flags & DLT_RCV_SKIP_HEADER) min_size += sizeof(DltUserHeader); if (!receiver || - (receiver->bytesRcvd < (int32_t) min_size) || + (receiver->bytesRcvd < (int32_t)min_size) || !receiver->buf || !dest) return DLT_RETURN_WRONG_PARAMETER; - src = (uint8_t *)receiver->buf; + src = (void *)receiver->buf; if (flags & DLT_RCV_SKIP_HEADER) src += sizeof(DltUserHeader); @@ -2304,7 +2046,7 @@ memcpy(dest, src, to_get); if (flags & DLT_RCV_REMOVE) { - if (dlt_receiver_remove(receiver, (int)min_size) != DLT_RETURN_OK) { + if (dlt_receiver_remove(receiver, min_size) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return DLT_RETURN_ERROR; } @@ -2342,24 +2084,13 @@ #if defined(_MSC_VER) storageheader->microseconds = 0; #else - storageheader->seconds = (uint32_t) tv.tv_sec; /* value is long */ - storageheader->microseconds = (int32_t) tv.tv_usec; /* value is long */ + storageheader->seconds = (time_t)tv.tv_sec; /* value is long */ + storageheader->microseconds = (int32_t)tv.tv_usec; /* value is long */ #endif return DLT_RETURN_OK; } -DltReturnValue dlt_check_rcv_data_size(int received, int required) -{ - int _ret = DLT_RETURN_OK; - if (received < required) { - dlt_vlog(LOG_WARNING, "%s: Received data not complete\n", __func__); - _ret = DLT_RETURN_ERROR; - } - - return _ret; -} - DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader) { if (storageheader == NULL) @@ -2372,6 +2103,17 @@ ? DLT_RETURN_TRUE : DLT_RETURN_OK; } + + + + + + + + + + + DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size) { if ((buf == NULL) || (ptr == NULL)) @@ -2391,13 +2133,13 @@ head->write = 0; head->count = 0; buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); - buf->size = (unsigned int) buf->min_size - (unsigned int) sizeof(DltBufferHead); + buf->size = buf->min_size - sizeof(DltBufferHead); /* clear memory */ memset(buf->mem, 0, buf->size); dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size %u, Start address %lX\n", + "%s: Buffer: Size %d, Start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); return DLT_RETURN_OK; /* OK */ @@ -2416,10 +2158,10 @@ /* Init pointers */ buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); - buf->size = (uint32_t)(buf->min_size - sizeof(DltBufferHead)); + buf->size = buf->min_size - sizeof(DltBufferHead); dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size %u, Start address %lX\n", + "%s: Buffer: Size %d, Start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); return DLT_RETURN_OK; /* OK */ @@ -2454,7 +2196,7 @@ if (buf->shm == NULL) { dlt_vlog(LOG_EMERG, - "%s: Buffer: Cannot allocate %u bytes\n", + "%s: Buffer: Cannot allocate %d bytes\n", __func__, buf->min_size); return DLT_RETURN_ERROR; } @@ -2465,22 +2207,14 @@ head->write = 0; head->count = 0; buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); - - if (buf->min_size < (uint32_t)sizeof(DltBufferHead)) { - dlt_vlog(LOG_ERR, - "%s: min_size is too small [%u]\n", - __func__, buf->min_size); - return DLT_RETURN_WRONG_PARAMETER; - } - - buf->size = (uint32_t) (buf->min_size - sizeof(DltBufferHead)); + buf->size = buf->min_size - sizeof(DltBufferHead); dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size %u, Start address %lX\n", + "%s: Buffer: Size %d, Start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); /* clear memory */ - memset(buf->mem, 0, (size_t)buf->size); + memset(buf->mem, 0, buf->size); return DLT_RETURN_OK; /* OK */ } @@ -2523,27 +2257,17 @@ { /* catch null pointer */ if ((buf != NULL) && (write != NULL) && (data != NULL)) { - if (size <= buf->size){ - if (( (unsigned int) (*write ) + size) <= buf->size) { - /* write one block */ - memcpy(buf->mem + *write, data, size); - *write += (int) size; - } - else { - /* when (*write) = buf->size, write only the second block - * and update write position correspondingly. - */ - if((unsigned int) (*write) <= buf->size) { - /* write two blocks */ - memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write)); - memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write)); - *write += (int) (size - buf->size); - } - } - } - else { - dlt_vlog(LOG_WARNING, "%s: Write error: ring buffer to small\n", __func__); - } + if ((int)(*write + size) <= buf->size) { + /* write one block */ + memcpy(buf->mem + *write, data, size); + *write += size; + } + else { + /* write two blocks */ + memcpy(buf->mem + *write, data, buf->size - *write); + memcpy(buf->mem, data + buf->size - *write, size - buf->size + *write); + *write += size - buf->size; + } } else { dlt_vlog(LOG_WARNING, "%s: Wrong parameter: Null pointer\n", __func__); @@ -2554,21 +2278,16 @@ { /* catch nullpointer */ if ((buf != NULL) && (read != NULL) && (data != NULL)) { - if (((unsigned int)(*read) + size) <= buf->size) { + if ((int)(*read + size) <= buf->size) { /* read one block */ memcpy(data, buf->mem + *read, size); - *read += (int)size; + *read += size; } else { - /* when (*read) = buf->size, read only the second block - * and update read position correspondingly. - */ - if ((unsigned int)(*read) <= buf->size) { - /* read two blocks */ - memcpy(data, buf->mem + *read, buf->size - (unsigned int)(*read)); - memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int)(*read)); - *read += (int) (size - buf->size); - } + /* read two blocks */ + memcpy(data, buf->mem + *read, buf->size - *read); + memcpy(data + buf->size - *read, buf->mem, size - buf->size + *read); + *read += size - buf->size; } } else { @@ -2581,7 +2300,7 @@ if (buf == NULL) return DLT_RETURN_WRONG_PARAMETER; - if ((buf->size + sizeof(DltBufferHead) + (size_t) needed) > buf->max_size) + if ((buf->size + sizeof(DltBufferHead) + needed) > buf->max_size) return DLT_RETURN_ERROR; return DLT_RETURN_OK; @@ -2613,7 +2332,7 @@ if (new_ptr == NULL) { dlt_vlog(LOG_WARNING, - "%s: Buffer: Cannot increase size because allocate %u bytes failed\n", + "%s: Buffer: Cannot increase size because allocate %d bytes failed\n", __func__, buf->min_size); return DLT_RETURN_ERROR; } @@ -2623,16 +2342,16 @@ new_head = (DltBufferHead *)new_ptr; if (head->read < head->write) { - memcpy(new_ptr + sizeof(DltBufferHead), buf->mem + head->read, (size_t)(head->write - head->read)); + memcpy(new_ptr + sizeof(DltBufferHead), buf->mem + head->read, head->write - head->read); new_head->read = 0; new_head->write = head->write - head->read; new_head->count = head->count; } else { - memcpy(new_ptr + sizeof(DltBufferHead), buf->mem + head->read, buf->size - (uint32_t)(head->read)); - memcpy(new_ptr + sizeof(DltBufferHead) + buf->size - head->read, buf->mem, (size_t)head->write); + memcpy(new_ptr + sizeof(DltBufferHead), buf->mem + head->read, buf->size - head->read); + memcpy(new_ptr + sizeof(DltBufferHead) + buf->size - head->read, buf->mem, head->write); new_head->read = 0; - new_head->write = (int)(buf->size) + head->write - head->read; + new_head->write = buf->size - head->read + head->write; new_head->count = head->count; } @@ -2645,7 +2364,7 @@ buf->size += buf->step_size; dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size increased to %u bytes with start address %lX\n", + "%s: Buffer: Size increased to %d bytes with start address %lX\n", __func__, buf->size + (int32_t)sizeof(DltBufferHead), (unsigned long)buf->mem); @@ -2672,7 +2391,7 @@ if (new_ptr == NULL) { dlt_vlog(LOG_WARNING, - "%s: Buffer: Cannot set to min size of %u bytes\n", + "%s: Buffer: Cannot set to min size of %d bytes\n", __func__, buf->min_size); return DLT_RETURN_ERROR; } @@ -2683,7 +2402,7 @@ /* update data */ buf->shm = new_ptr; buf->mem = new_ptr + sizeof(DltBufferHead); - buf->size = (uint32_t)(buf->min_size - sizeof(DltBufferHead)); + buf->size = buf->min_size - sizeof(DltBufferHead); /* reset pointers and counters */ ((int *)(buf->shm))[0] = 0; /* pointer to write memory */ @@ -2691,7 +2410,7 @@ ((int *)(buf->shm))[2] = 0; /* number of packets */ dlt_vlog(LOG_DEBUG, - "%s: Buffer: Buffer minimized to Size %u bytes with start address %lX\n", + "%s: Buffer: Buffer minimized to Size %d bytes with start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); /* clear memory */ @@ -2709,7 +2428,7 @@ } dlt_vlog(LOG_WARNING, - "%s: Buffer: Buffer reset triggered. Size: %u, Start address: %lX\n", + "%s: Buffer: Buffer reset triggered. Size: %d, Start address: %lX\n", __func__, buf->size, (unsigned long)buf->mem); /* reset pointers and counters */ @@ -2756,9 +2475,9 @@ count = ((int *)(buf->shm))[2]; /* check pointers */ - if (((unsigned int)read > buf->size) || ((unsigned int)write > buf->size)) { + if ((read > buf->size) || (write > buf->size)) { dlt_vlog(LOG_ERR, - "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Size: %u\n", + "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Size: %d\n", __func__, read, write, buf->size); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ @@ -2770,10 +2489,10 @@ else if (count && (write == read)) free_size = 0; else - free_size = (int)buf->size - write + read; + free_size = buf->size - write + read; /* check size */ - while (free_size < (int) (sizeof(DltBufferBlockHead) + size1 + size2 + size3)) { + if (free_size < (int)(sizeof(DltBufferBlockHead) + size1 + size2 + size3)) { /* try to increase size if possible */ if (dlt_buffer_increase_size(buf)) /* increase size is not possible */ @@ -2783,21 +2502,13 @@ /* update pointers */ write = ((int *)(buf->shm))[0]; read = ((int *)(buf->shm))[1]; - - /* update free size */ - if (read > write) - free_size = read - write; - else if (count && (write == read)) - free_size = 0; - else - free_size = buf->size - write + read; } /* set header */ strncpy(head.head, DLT_BUFFER_HEAD, 4); head.head[3] = 0; head.status = 2; - head.size = (int)(size1 + size2 + size3); + head.size = size1 + size2 + size3; /* write data */ dlt_buffer_write_block(buf, &write, (unsigned char *)&head, sizeof(DltBufferBlockHead)); @@ -2842,9 +2553,9 @@ count = ((int *)(buf->shm))[2]; /* check pointers */ - if (((unsigned int)read > buf->size) || ((unsigned int)write > buf->size) || (count < 0)) { + if ((read > buf->size) || (write > buf->size) || (count < 0)) { dlt_vlog(LOG_ERR, - "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Count: %d, Size: %u\n", + "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Count: %d, Size: %d\n", __func__, read, write, count, buf->size); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ @@ -2866,7 +2577,7 @@ if (write > read) used_size = write - read; else - used_size = (int)buf->size - read + write; + used_size = buf->size - read + write; /* first check size */ if (used_size < (int)(sizeof(DltBufferBlockHead))) { @@ -2894,7 +2605,7 @@ } /* second check size */ - if (used_size < ((int)sizeof(DltBufferBlockHead) + head.size)) { + if (used_size < (int)(sizeof(DltBufferBlockHead) + head.size)) { dlt_vlog(LOG_ERR, "%s: Buffer: Used size is smaller than buffer block header size And read header size. Used size: %d\n", __func__, used_size); @@ -2907,24 +2618,22 @@ dlt_vlog(LOG_WARNING, "%s: Buffer: Max size is smaller than read header size. Max size: %d\n", __func__, max_size); + /* nothing to do but data does not fit provided buffer */ - /* nothing to do but data does not fit provided buffer */ if ((data != NULL) && max_size) { /* read data */ - dlt_buffer_read_block(buf, &read, data, (unsigned int)head.size); + dlt_buffer_read_block(buf, &read, data, head.size); if (delete) /* update buffer pointers */ ((int *)(buf->shm))[1] = read; /* set new read pointer */ - } - else if (delete) - { - if ((unsigned int)(read + head.size) <= buf->size) + else if (delete) { + if ((read + head.size) <= buf->size) ((int *)(buf->shm))[1] = read + head.size; /* set new read pointer */ else - ((int *)(buf->shm))[1] = read + head.size - (int)buf->size; /* set new read pointer */ + ((int *)(buf->shm))[1] = read + head.size - buf->size; /* set new read pointer */ } @@ -2963,7 +2672,7 @@ } dlt_vlog(LOG_DEBUG, - "Buffer: Available size: %u, Buffer: Buffer full start address: %lX, Buffer: Buffer start address: %lX\n", + "Buffer: Available size: %d, Buffer: Buffer full start address: %lX, Buffer: Buffer start address: %lX\n", buf->size, (unsigned long)buf->shm, (unsigned long)buf->mem); } @@ -3021,7 +2730,7 @@ if (write > read) return write - read; - return (int)buf->size - read + write; + return buf->size - read + write; } int dlt_buffer_get_message_count(DltBuffer *buf) @@ -3286,9 +2995,6 @@ return; } -/* Clang does not like these macros, because they are not reproducable */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdate-time" snprintf(buf, size, "DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n", @@ -3301,7 +3007,6 @@ _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, _DLT_SHM_ENABLE); -#pragma GCC diagnostic pop } void dlt_get_major_version(char *buf, size_t size) @@ -3336,7 +3041,7 @@ struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) - return (uint32_t)ts.tv_sec * 10000 + (uint32_t)ts.tv_nsec / 100000; /* in 0.1 ms = 100 us */ + return (uint32_t)ts.tv_sec * 10000 + (uint32_t)ts.tv_nsec / 100000;/* in 0.1 ms = 100 us */ else return 0; @@ -3349,9 +3054,8 @@ if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (dlt_message_header(message, text, size, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("%s\n", text); + dlt_message_header(message, text, size, verbose); + printf("%s\n", text); return DLT_RETURN_OK; } @@ -3361,13 +3065,10 @@ if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (dlt_message_header(message, text, size, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("%s ", text); - - if (dlt_message_payload(message, text, size, DLT_OUTPUT_HEX, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("[%s]\n", text); + dlt_message_header(message, text, size, verbose); + printf("%s ", text); + dlt_message_payload(message, text, size, DLT_OUTPUT_HEX, verbose); + printf("[%s]\n", text); return DLT_RETURN_OK; } @@ -3377,13 +3078,10 @@ if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (dlt_message_header(message, text, size, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("%s ", text); - - if (dlt_message_payload(message, text, size, DLT_OUTPUT_ASCII, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("[%s]\n", text); + dlt_message_header(message, text, size, verbose); + printf("%s ", text); + dlt_message_payload(message, text, size, DLT_OUTPUT_ASCII, verbose); + printf("[%s]\n", text); return DLT_RETURN_OK; } @@ -3393,13 +3091,10 @@ if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (dlt_message_header(message, text, size, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("%s \n", text); - - if (dlt_message_payload(message, text, size, DLT_OUTPUT_MIXED_FOR_PLAIN, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("[%s]\n", text); + dlt_message_header(message, text, size, verbose); + printf("%s \n", text); + dlt_message_payload(message, text, size, DLT_OUTPUT_MIXED_FOR_PLAIN, verbose); + printf("[%s]\n", text); return DLT_RETURN_OK; } @@ -3409,14 +3104,10 @@ if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (dlt_message_header(message, text, size, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - dlt_user_printf("%s \n", text); - - if (dlt_message_payload(message, text, size, DLT_OUTPUT_MIXED_FOR_HTML, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; - - dlt_user_printf("[%s]\n", text); + dlt_message_header(message, text, size, verbose); + printf("%s \n", text); + dlt_message_payload(message, text, size, DLT_OUTPUT_MIXED_FOR_HTML, verbose); + printf("[%s]\n", text); return DLT_RETURN_OK; } @@ -3426,7 +3117,7 @@ uint8_t **ptr, int32_t *datalength, char *text, - size_t textlength, + int textlength, int byteLength, int __attribute__((unused)) verbose) { @@ -3434,7 +3125,8 @@ if ((msg == NULL) || (ptr == NULL) || (datalength == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - uint16_t length = 0, length2 = 0, length3 = 0; + int16_t length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ + uint16_t length2 = 0, length2_tmp = 0, length3 = 0, length3_tmp = 0; uint8_t value8u = 0; uint16_t value16u = 0, value16u_tmp = 0; @@ -3453,13 +3145,6 @@ uint32_t quantisation_tmp = 0; - // pointer to the value string - char* value_text = text; - // pointer to the "unit" attribute string, if there is one (only for *INT and FLOAT*) - const uint8_t* unit_text_src = NULL; - // length of the "unit" attribute string, if there is one (only for *INT and FLOAT*) - size_t unit_text_len = 0; - /* apparently this makes no sense but needs to be done to prevent compiler warning. * This variable is only written by DLT_MSG_READ_VALUE macro in if (type_info & DLT_TYPE_INFO_FIXP) * case but never read anywhere */ @@ -3469,42 +3154,33 @@ (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8))) { /* string type or utf8-encoded string type */ if (byteLength < 0) { - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length_tmp); } else { - length = (uint16_t)byteLength; + length = (int16_t)byteLength; } if (type_info & DLT_TYPE_INFO_VARI) { - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length2_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; - if (print_with_attributes) { - // Print "name" attribute, if we have one with non-zero size. - if (length2 > 1) { - snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= length2+1-1; - } - } - *ptr += length2; *datalength -= length2; } - DLT_MSG_READ_STRING(value_text, *ptr, *datalength, textlength, length); + DLT_MSG_READ_STRING((text + strlen(text)), *ptr, *datalength, length); if ((*datalength) < 0) return DLT_RETURN_ERROR; @@ -3513,25 +3189,16 @@ { /* Boolean type */ if (type_info & DLT_TYPE_INFO_VARI) { - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length2_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; - if (print_with_attributes) { - // Print "name" attribute, if we have one with non-zero size. - if (length2 > 1) { - snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= length2+1-2; - } - } - *ptr += length2; *datalength -= length2; } @@ -3542,7 +3209,7 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "%d", value8u); + snprintf(text + strlen(text), textlength - strlen(text), "%d", value8u); } else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD))) { @@ -3562,7 +3229,7 @@ strcat(binary, (i == (value8u & i)) ? "1" : "0"); } - snprintf(value_text, textlength, "0b%s", binary); + snprintf(text + strlen(text), textlength - strlen(text), "0b%s", binary); } if (DLT_TYLE_16BIT == (type_info & DLT_TYPE_INFO_TYLE)) { @@ -3581,7 +3248,7 @@ strcat(binary, (i == (value16u & i)) ? "1" : "0"); } - snprintf(value_text, textlength, "0b%s", binary); + snprintf(text + strlen(text), textlength - strlen(text), "0b%s", binary); } } else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD))) @@ -3592,7 +3259,7 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "0x%02x", value8u); + snprintf(text + strlen(text), textlength - strlen(text), "0x%02x", value8u); } if (DLT_TYLE_16BIT == (type_info & DLT_TYPE_INFO_TYLE)) { @@ -3601,7 +3268,7 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "0x%04x", value16u); + snprintf(text + strlen(text), textlength - strlen(text), "0x%04x", value16u); } if (DLT_TYLE_32BIT == (type_info & DLT_TYPE_INFO_TYLE)) { @@ -3610,7 +3277,7 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "0x%08x", value32u); + snprintf(text + strlen(text), textlength - strlen(text), "0x%08x", value32u); } if (DLT_TYLE_64BIT == (type_info & DLT_TYPE_INFO_TYLE)) { @@ -3620,14 +3287,14 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "0x%08x", value32u); + snprintf(text + strlen(text), textlength - strlen(text), "0x%08x", value32u); *ptr -= 8; DLT_MSG_READ_VALUE(value32u, *ptr, *datalength, uint32_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text + strlen(value_text), textlength - strlen(value_text), "%08x", value32u); + snprintf(text + strlen(text), textlength - strlen(text), "%08x", value32u); *ptr += 4; } } @@ -3635,41 +3302,28 @@ { /* signed or unsigned argument received */ if (type_info & DLT_TYPE_INFO_VARI) { - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length2_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp); + DLT_MSG_READ_VALUE(length3_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length3 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length3 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length3_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; - if (print_with_attributes) { - // Print "name" attribute, if we have one with non-zero size. - if (length2 > 1) { - snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for the ":", and -1 for nul - textlength -= length2+1-1; - } - } - *ptr += length2; *datalength -= length2; if ((*datalength) < length3) return DLT_RETURN_ERROR; - // We want to add the "unit" attribute only after the value, so remember its pointer and length here. - unit_text_src = *ptr; - unit_text_len = length3; - *ptr += length3; *datalength -= length3; } @@ -3727,7 +3381,7 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "%d", value8i); + snprintf(text + strlen(text), textlength - strlen(text), "%d", value8i); } else { value8u = 0; @@ -3736,7 +3390,7 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - snprintf(value_text, textlength, "%d", value8u); + snprintf(text + strlen(text), textlength - strlen(text), "%d", value8u); } break; @@ -3751,8 +3405,8 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - value16i = (int16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16i_tmp); - snprintf(value_text, textlength, "%hd", value16i); + value16i = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16i_tmp); + snprintf(text + strlen(text), textlength - strlen(text), "%hd", value16i); } else { value16u = 0; @@ -3762,8 +3416,8 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - value16u = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); - snprintf(value_text, textlength, "%hu", value16u); + value16u = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + snprintf(text + strlen(text), textlength - strlen(text), "%hu", value16u); } break; @@ -3778,8 +3432,8 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - value32i = (int32_t) DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32i_tmp); - snprintf(value_text, textlength, "%d", value32i); + value32i = DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32i_tmp); + snprintf(text + strlen(text), textlength - strlen(text), "%d", value32i); } else { value32u = 0; @@ -3790,7 +3444,7 @@ return DLT_RETURN_ERROR; value32u = DLT_ENDIAN_GET_32(msg->standardheader->htyp, value32u_tmp); - snprintf(value_text, textlength, "%u", value32u); + snprintf(text + strlen(text), textlength - strlen(text), "%u", value32u); } break; @@ -3805,11 +3459,11 @@ if ((*datalength) < 0) return DLT_RETURN_ERROR; - value64i = (int64_t) DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64i_tmp); + value64i = DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64i_tmp); #if defined (__WIN32__) && !defined(_MSC_VER) - snprintf(value_text, textlength, "%I64d", value64i); + snprintf(text + strlen(text), textlength - strlen(text), "%I64d", value64i); #else - snprintf(value_text, textlength, "%" PRId64, value64i); + snprintf(text + strlen(text), textlength - strlen(text), "%" PRId64, value64i); #endif } else { @@ -3822,9 +3476,9 @@ value64u = DLT_ENDIAN_GET_64(msg->standardheader->htyp, value64u_tmp); #if defined (__WIN32__) && !defined(_MSC_VER) - snprintf(value_text, textlength, "%I64u", value64u); + snprintf(text + strlen(text), textlength - strlen(text), "%I64u", value64u); #else - snprintf(value_text, textlength, "%" PRIu64, value64u); + snprintf(text + strlen(text), textlength - strlen(text), "%" PRId64, value64u); #endif } @@ -3833,7 +3487,7 @@ case DLT_TYLE_128BIT: { if (*datalength >= 16) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 16); + dlt_print_hex_string(text + strlen(text), textlength, *ptr, 16); if ((*datalength) < 16) return DLT_RETURN_ERROR; @@ -3852,41 +3506,28 @@ { /* float data argument */ if (type_info & DLT_TYPE_INFO_VARI) { - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length2_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp); + DLT_MSG_READ_VALUE(length3_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length3 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length3 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length3_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; - if (print_with_attributes) { - // Print "name" attribute, if we have one with non-zero size. - if (length2 > 1) { - snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= length2+1-1; - } - } - *ptr += length2; *datalength -= length2; if ((*datalength) < length3) return DLT_RETURN_ERROR; - // We want to add the "unit" attribute only after the value, so remember its pointer and length here. - unit_text_src = *ptr; - unit_text_len = length3; - *ptr += length3; *datalength -= length3; } @@ -3895,7 +3536,7 @@ case DLT_TYLE_8BIT: { if (*datalength >= 1) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 1); + dlt_print_hex_string(text + strlen(text), textlength, *ptr, 1); if ((*datalength) < 1) return DLT_RETURN_ERROR; @@ -3907,7 +3548,7 @@ case DLT_TYLE_16BIT: { if (*datalength >= 2) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 2); + dlt_print_hex_string(text + strlen(text), textlength, *ptr, 2); if ((*datalength) < 2) return DLT_RETURN_ERROR; @@ -3930,9 +3571,9 @@ memcpy(&value32f_tmp_int32i, &value32f_tmp, sizeof(float32_t)); value32f_tmp_int32i_swaped = - (int32_t) DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32f_tmp_int32i); + DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32f_tmp_int32i); memcpy(&value32f, &value32f_tmp_int32i_swaped, sizeof(float32_t)); - snprintf(value_text, textlength, "%g", value32f); + snprintf(text + strlen(text), textlength - strlen(text), "%g", value32f); } else { dlt_log(LOG_ERR, "Invalid size of float32_t\n"); @@ -3955,12 +3596,12 @@ memcpy(&value64f_tmp_int64i, &value64f_tmp, sizeof(float64_t)); value64f_tmp_int64i_swaped = - (int64_t) DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64f_tmp_int64i); + DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64f_tmp_int64i); memcpy(&value64f, &value64f_tmp_int64i_swaped, sizeof(float64_t)); #ifdef __arm__ - snprintf(value_text, textlength, "ILLEGAL"); + snprintf(text + strlen(text), textlength - strlen(text), "ILLEGAL"); #else - snprintf(value_text, textlength, "%g", value64f); + snprintf(text + strlen(text), textlength - strlen(text), "%g", value64f); #endif } else { @@ -3973,7 +3614,7 @@ case DLT_TYLE_128BIT: { if (*datalength >= 16) - dlt_print_hex_string(value_text, textlength, *ptr, 16); + dlt_print_hex_string(text + strlen(text), textlength, *ptr, 16); if ((*datalength) < 16) return DLT_RETURN_ERROR; @@ -3991,33 +3632,24 @@ else if (type_info & DLT_TYPE_INFO_RAWD) { /* raw data argument */ - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length_tmp); if (type_info & DLT_TYPE_INFO_VARI) { - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length2_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length2 = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; - if (print_with_attributes) { - // Print "name" attribute, if we have one with non-zero size. - if (length2 > 1) { - snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= length2+1-1; - } - } - *ptr += length2; *datalength -= length2; } @@ -4025,22 +3657,20 @@ if ((*datalength) < length) return DLT_RETURN_ERROR; - if (dlt_print_hex_string_delim(value_text, (int) textlength, *ptr, length, '\'') < DLT_RETURN_OK) - return DLT_RETURN_ERROR; + dlt_print_hex_string(text + strlen(text), textlength, *ptr, length); *ptr += length; *datalength -= length; } else if (type_info & DLT_TYPE_INFO_TRAI) { /* trace info argument */ - DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); + DLT_MSG_READ_VALUE(length_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length = DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); - - DLT_MSG_READ_STRING(value_text, *ptr, *datalength, textlength, length); + length = DLT_ENDIAN_GET_16(msg->standardheader->htyp, length_tmp); + DLT_MSG_READ_STRING((text + strlen(text)), *ptr, *datalength, length); if ((*datalength) < 0) return DLT_RETURN_ERROR; @@ -4054,18 +3684,6 @@ return DLT_RETURN_ERROR; } - // Now write "unit" attribute, but only if it has more than only a nul-termination char. - if (print_with_attributes) { - if (unit_text_len > 1) { - // 'value_text' still points to the +start+ of the value text - size_t currLen = strlen(value_text); - - char* unitText = value_text + currLen; - textlength -= currLen; - snprintf(unitText, textlength, ":%s", unit_text_src); - } - } - return DLT_RETURN_OK; } @@ -4094,22 +3712,17 @@ dlt_log_init(mode); } -#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC char *env_pipe_dir = getenv("DLT_PIPE_DIR"); if (env_pipe_dir != NULL) dlt_log_set_fifo_basedir(env_pipe_dir); - else - dlt_log_set_fifo_basedir(DLT_USER_IPC_PATH); - -#endif #ifdef DLT_SHM_ENABLE - char *env_shm_name = getenv("DLT_SHM_NAME"); - + char* env_shm_name = getenv("DLT_SHM_NAME"); if (env_shm_name != NULL) + { dlt_log_set_shm_name(env_shm_name); - + } #endif } @@ -4126,7 +3739,7 @@ /* ascii type, syntax is 'get_log_info, ..' */ /* check target id */ - strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info") + 1); + strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info")); ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag) - 1); if (ret == 0) { @@ -4135,7 +3748,7 @@ service_opt_str[0] = *(resp_text + GET_LOG_INFO_LENGTH + 1); service_opt_str[1] = *(resp_text + GET_LOG_INFO_LENGTH + 2); service_opt_str[2] = 0; - *service_opt = (uint8_t) atoi(service_opt_str); + *service_opt = atoi(service_opt_str); } return ret; @@ -4150,8 +3763,8 @@ return -1; /* ------------------------------------------------------ - * from: [89 13 ] -> to: ['+0x'1389\0] -> to num - * ------------------------------------------------------ */ + * from: [89 13 ] -> to: ['+0x'1389\0] -> to num + * ------------------------------------------------------ */ num_work[0] = *(rp + *rp_count + 3); num_work[1] = *(rp + *rp_count + 4); num_work[2] = *(rp + *rp_count + 0); @@ -4159,7 +3772,7 @@ num_work[4] = 0; *rp_count += 6; - return (uint16_t)strtol(num_work, &endptr, 16); + return (unsigned char)strtol(num_work, &endptr, 16); } int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count) @@ -4171,8 +3784,8 @@ return -1; /* ------------------------------------------------------ - * from: [89 ] -> to: ['0x'89\0] -> to num - * ------------------------------------------------------ */ + * from: [89 ] -> to: ['0x'89\0] -> to num + * ------------------------------------------------------ */ num_work[0] = *(rp + *rp_count + 0); num_work[1] = *(rp + *rp_count + 1); num_work[2] = 0; @@ -4181,40 +3794,27 @@ return (signed char)strtol(num_work, &endptr, 16); } -void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int len) +void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len) { - if ((rp == NULL ) || (rp_count == NULL ) || (wp == NULL )) - return; - /* ------------------------------------------------------ - * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00] - * ------------------------------------------------------ */ - - int count = dlt_getloginfo_conv_ascii_to_id(rp, rp_count, wp, len); - *(wp + count) = '\0'; - - return; -} - -int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len) -{ - char number16[3] = { 0 }; + char number16[3] = {0}; char *endptr; int count; if ((rp == NULL) || (rp_count == NULL) || (wp == NULL)) - return 0; + return; /* ------------------------------------------------------ - * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f] - * ------------------------------------------------------ */ + * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00] + * ------------------------------------------------------ */ for (count = 0; count < len; count++) { number16[0] = *(rp + *rp_count + 0); number16[1] = *(rp + *rp_count + 1); - *(wp + count) = (char) strtol(number16, &endptr, 16); + *(wp + count) = strtol(number16, &endptr, 16); *rp_count += 3; } - return count; + *(wp + count) = 0; + return; } void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size) @@ -4234,17 +3834,17 @@ found = 0; if ((ch >= '0') && (ch <= '9')) { - binary[pos] = (uint8_t) ((binary[pos] << 4) + (ch - '0')); + binary[pos] = (binary[pos] << 4) + (ch - '0'); found = 1; } else if ((ch >= 'A') && (ch <= 'F')) { - binary[pos] = (uint8_t) ((binary[pos] << 4) + (ch - 'A' + 10)); + binary[pos] = (binary[pos] << 4) + (ch - 'A' + 10); found = 1; } else if ((ch >= 'a') && (ch <= 'f')) { - binary[pos] = (uint8_t) ((binary[pos] << 4) + (ch - 'a' + 10)); + binary[pos] = (binary[pos] << 4) + (ch - 'a' + 10); found = 1; } @@ -4267,180 +3867,38 @@ } } -DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, - int type, int verbose) -{ - PRINT_FUNCTION_VERBOSE(verbose); - int ret = DLT_RETURN_OK; - char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 }; - - if ((file == NULL) || (filename == NULL)) - return DLT_RETURN_WRONG_PARAMETER; - - FILE *output = fopen(filename, "w+"); - - if (output == NULL) { - dlt_vlog(LOG_ERR, "Cannot open output file %s for parsing\n", filename); - return DLT_RETURN_ERROR; - } - - while (ret >= DLT_RETURN_OK && file->file_position < file->file_length) { - /* get file position at start of DLT message */ - if (verbose) - dlt_vlog(LOG_DEBUG, "Position in file: %" PRIu64 "\n", file->file_position); - - /* read all header and payload */ - ret = dlt_file_read_header(file, verbose); - - if (ret < DLT_RETURN_OK) - break; - - ret = dlt_file_read_header_extended(file, verbose); - - if (ret < DLT_RETURN_OK) - break; - - ret = dlt_file_read_data(file, verbose); - - if (ret < DLT_RETURN_OK) - break; - - if (file->filter) { - /* check the filters if message is used */ - ret = dlt_message_filter_check(&(file->msg), file->filter, verbose); - - if (ret != DLT_RETURN_TRUE) - continue; - } - - ret = dlt_message_header(&(file->msg), text, - DLT_CONVERT_TEXTBUFSIZE, verbose); - - if (ret < DLT_RETURN_OK) - break; - - fprintf(output, "%s", text); - - ret = dlt_message_payload(&(file->msg), text, - DLT_CONVERT_TEXTBUFSIZE, type, verbose); - - if (ret < DLT_RETURN_OK) - break; - - fprintf(output, "[%s]\n", text); - - /* store index pointer to message position in DLT file */ - file->counter++; - file->position = file->counter_total - 1; - /* increase total message counter */ - file->counter_total++; - /* store position to next message */ - file->file_position = ftell(file->handle); - } /* while() */ - - fclose(output); - return ret; -} - - -int dlt_execute_command(char *filename, char *command, ...) +#ifndef DLT_USE_UNIX_SOCKET_IPC +int dlt_mkdir_recursive(const char *dir) { - va_list val; - int argc; - char **args = NULL; int ret = 0; + char tmp[PATH_MAX + 1]; + char *p = NULL; + char *end = NULL; + size_t len; - if (command == NULL) - return -1; - - /* Determine number of variadic arguments */ - va_start(val, command); - - for (argc = 2; va_arg(val, char *) != NULL; argc++); - - va_end(val); - - /* Allocate args, put references to command */ - args = (char **) malloc( (uint32_t) argc * sizeof(char*)); - args[0] = command; - - va_start(val, command); + strncpy(tmp, dir, PATH_MAX); + len = strlen(tmp); - for (int i = 0; args[i] != NULL; i++) - args[i + 1] = va_arg(val, char *); + if (tmp[len - 1] == '/') + tmp[len - 1] = 0; - va_end(val); + end = tmp + len; - /* Run command in child process */ - pid_t pid = fork(); - - if (pid == 0) { /* child process */ - - /* Redirect output if required */ - if (filename != NULL) { - int fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - - if (fd < 0) - err(-1, "%s failed on open()", __func__); - - if (dup2(fd, STDOUT_FILENO) == -1) { - close(fd); - err(-1, "%s failed on dup2()", __func__); - } - - close(fd); + for (p = tmp + 1; ((*p) && (ret == 0)) || ((ret == -1 && errno == EEXIST) && (p != end)); p++) + if (*p == '/') { + *p = 0; + ret = mkdir(tmp, S_IRWXU); + *p = '/'; } - /* Run command */ - execvp(command, (char **)args); - } - else if (pid == -1) /* error in fork */ - { - ret = -1; - } - else { /* parent */ - wait(&ret); - } - - free(args); - return ret; -} - -char *get_filename_ext(const char *filename) -{ - if (filename == NULL) { - fprintf(stderr, "ERROR: %s: invalid arguments\n", __FUNCTION__); - return NULL; - } - - char *dot = strrchr(filename, '.'); - return (!dot || dot == filename) ? NULL : dot; -} -bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len) { - if (abs_file_name == NULL || base_name == NULL) return false; - const char* last_separator = strrchr(abs_file_name, '.'); - if (!last_separator) return false; - long length = last_separator - abs_file_name; - length = length > base_name_len ? base_name_len : length; + if ((ret == 0) || ((ret == -1) && (errno == EEXIST))) + ret = mkdir(tmp, S_IRWXU); - strncpy(base_name, abs_file_name, length); - base_name[length] = '\0'; - return true; -} + if ((ret == -1) && (errno == EEXIST)) + ret = 0; -void dlt_log_multiple_files_write(const char* format, ...) -{ - char output_string[2048] = { 0 }; - va_list args; - va_start (args, format); - vsnprintf(output_string, 2047, format, args); - va_end (args); - multiple_files_buffer_write(&multiple_files_ring_buffer, (unsigned char*)output_string, strlen(output_string)); -} - -bool dlt_is_log_in_multiple_files_active() -{ - return multiple_files_ring_buffer.ohandle > -1; + return ret; } +#endif diff -Nru dlt-daemon-2.18.9/src/shared/dlt_config_file_parser.c dlt-daemon-2.18.4/src/shared/dlt_config_file_parser.c --- dlt-daemon-2.18.9/src/shared/dlt_config_file_parser.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_config_file_parser.c 2019-09-03 08:28:13.000000000 +0000 @@ -123,7 +123,7 @@ int section = file->num_sections; /* check if adding another section would exceed max number of sections */ - if (section >= DLT_CONFIG_FILE_SECTIONS_MAX) { + if (section + 1 >= DLT_CONFIG_FILE_SECTIONS_MAX) { dlt_log(LOG_WARNING, "Cannot store more sections\n"); return -1; /* reached max number of sections */ } @@ -148,7 +148,6 @@ if (s->keys == NULL) { free(s->name); - s->name = NULL; dlt_log(LOG_ERR, "Cannot allocate memory for internal data structure\n"); return -1; } @@ -289,21 +288,17 @@ ptr = strtok_r(line, delimiter, &save_ptr); - if (ptr != NULL) { /* get key */ - strncpy(str1, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1); - str1[DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1] = '\0'; - } else { + if (ptr != NULL) /* get key */ + strncpy(str1, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN); + else return -1; - } ptr = strtok_r(NULL, delimiter, &save_ptr); - if (ptr != NULL) { - strncpy(str2, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1); - str2[DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1] = '\0'; - } else { + if (ptr != NULL) + strncpy(str2, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN); + else return -1; - } return 0; } @@ -496,7 +491,6 @@ return -1; strncpy(name, (file->sections + num)->name, DLT_CONFIG_FILE_ENTRY_MAX_LEN); - name[DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1] = '\0'; return 0; } @@ -506,10 +500,6 @@ if ((file == NULL) || (file->num_sections < 0)) return -1; - /* - * Note: Since General section could be used in configuration file, - * this number could be also containing General section. - */ *num = file->num_sections; return 0; @@ -548,21 +538,6 @@ } } - dlt_vlog(LOG_WARNING, "Entry does not exist in section: %s\n", key); + dlt_log(LOG_WARNING, "Entry does not exist in section \n"); return -1; } - -int dlt_config_file_check_section_name_exists(const DltConfigFile *file, - const char *name) -{ - int ret = 0; - - if ((file == NULL) || (file->num_sections <= 0) || (name == NULL)) - return -1; - - ret = dlt_config_file_find_section(file, name); - if (ret == -1) - return ret; - - return 0; -} diff -Nru dlt-daemon-2.18.9/src/shared/dlt_config_file_parser.h dlt-daemon-2.18.4/src/shared/dlt_config_file_parser.h --- dlt-daemon-2.18.9/src/shared/dlt_config_file_parser.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_config_file_parser.h 2019-09-03 08:28:13.000000000 +0000 @@ -62,7 +62,7 @@ #define DLT_CONFIG_FILE_PATH_MAX_LEN 100 /* absolute path including filename */ #define DLT_CONFIG_FILE_ENTRY_MAX_LEN 100 /* Entry for section, key and value */ #define DLT_CONFIG_FILE_LINE_MAX_LEN 210 -#define DLT_CONFIG_FILE_SECTIONS_MAX 125 +#define DLT_CONFIG_FILE_SECTIONS_MAX 100 #define DLT_CONFIG_FILE_KEYS_MAX 25 /* Maximal keys per section */ typedef struct DltConfigKeyData @@ -148,16 +148,4 @@ const char *section, const char *key, char *value); - -/** - * dlt_config_file_check_section_name_exists - * - * Get name of section number. - * - * @param[in] file DltConfigFile - * @param[in] name Section name - * @return 0 on success/exist, else -1 - */ -int dlt_config_file_check_section_name_exists(const DltConfigFile *file, - const char *name); #endif diff -Nru dlt-daemon-2.18.9/src/shared/dlt_multiple_files.c dlt-daemon-2.18.4/src/shared/dlt_multiple_files.c --- dlt-daemon-2.18.9/src/shared/dlt_multiple_files.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_multiple_files.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,498 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2022, Daimler TSS GmbH - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see https://www.covesa.global/. - */ - -/*! - * \author - * Oleg Tropmann - * Daniel Weber - * - * \copyright Copyright © 2022 Daimler TSS GmbH. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - * \file dlt_daemon_log.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dlt_multiple_files.h" -#include "dlt_common.h" - -unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char *file_name, - char *newest, char *oldest) -{ - int i = 0; - unsigned int num_log_files = 0; - struct dirent **files = { 0 }; - char *tmp_old = NULL; - char *tmp_new = NULL; - - if ((path == NULL) || (file_name == NULL) || (newest == NULL) || (oldest == NULL)) { - fprintf(stderr, "multiple_files_buffer_storage_dir_info: Invalid parameter(s)"); - return 0; - } - - const int file_cnt = scandir(path, &files, NULL, alphasort); - if (file_cnt <= 0) return 0; - - for (i = 0; i < file_cnt; i++) { - int len = 0; - len = strlen(file_name); - - if ((strncmp(files[i]->d_name, file_name, len) == 0) && - (files[i]->d_name[len] == MULTIPLE_FILES_FILENAME_INDEX_DELIM[0])) { - num_log_files++; - - if ((tmp_old == NULL) || (strlen(tmp_old) >= strlen(files[i]->d_name))) { - if (tmp_old == NULL) { - tmp_old = files[i]->d_name; - } else if (strlen(tmp_old) > strlen(files[i]->d_name)) { - /* when file name is smaller, it is older */ - tmp_old = files[i]->d_name; - } else if (strcmp(tmp_old, files[i]->d_name) > 0) { - /* filename length is equal, do a string compare */ - tmp_old = files[i]->d_name; - } - } - - if ((tmp_new == NULL) || (strlen(tmp_new) <= strlen(files[i]->d_name))) { - if (tmp_new == NULL) { - tmp_new = files[i]->d_name; - } else if (strlen(tmp_new) < strlen(files[i]->d_name)) { - /* when file name is longer, it is younger */ - tmp_new = files[i]->d_name; - } else if (strcmp(tmp_new, files[i]->d_name) < 0) { - tmp_new = files[i]->d_name; - } - } - } - } - - if (num_log_files > 0) { - if ((tmp_old != NULL) && (strlen(tmp_old) < NAME_MAX)) { - strncpy(oldest, tmp_old, NAME_MAX); - oldest[NAME_MAX] = '\0'; - } else if ((tmp_old != NULL) && (strlen(tmp_old) >= NAME_MAX)) { - printf("length mismatch of file %s\n", tmp_old); - } - - if ((tmp_new != NULL) && (strlen(tmp_new) < NAME_MAX)) { - strncpy(newest, tmp_new, NAME_MAX); - oldest[NAME_MAX] = '\0'; - } else if ((tmp_new != NULL) && (strlen(tmp_new) >= NAME_MAX)) { - printf("length mismatch of file %s\n", tmp_new); - } - } - - /* free scandir result */ - for (i = 0; i < file_cnt; i++) free(files[i]); - - free(files); - - return num_log_files; -} - -void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, const size_t length, const unsigned int idx) -{ - char file_index[11]; /* UINT_MAX = 4294967295 -> 10 digits */ - snprintf(file_index, sizeof(file_index), "%010u", idx); - - /* create log file name */ - char* file_name = files_buffer->filename; - memset(file_name, 0, length * sizeof(char)); - - const size_t size = length - strlen(file_name) - 1; - strncat(file_name, files_buffer->filenameBase, size); - strncat(file_name, MULTIPLE_FILES_FILENAME_INDEX_DELIM, size); - strncat(file_name, file_index, size); - strncat(file_name, files_buffer->filenameExt, size); -} - -unsigned int multiple_files_buffer_get_idx_of_log_file(char *file) -{ - if ((file == NULL) || (file[0] == '\0')) return 0; - - const char d[2] = MULTIPLE_FILES_FILENAME_INDEX_DELIM; - char *token; - - token = strtok(file, d); - /* we are interested in 2. token because of log file name */ - token = strtok(NULL, d); - - return token != NULL ? strtol(token, NULL, 10) : 0; -} - -DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer *files_buffer) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return DLT_RETURN_ERROR; - } - - time_t t; - struct tm tmp; - char file_path[PATH_MAX + 1]; - unsigned int idx = 0; - int ret = 0; - - /* set filename */ - if (files_buffer->filenameTimestampBased) { - /* timestamp format: "yyyymmdd_hhmmss" */ - char timestamp[16]; - t = time(NULL); - tzset(); - localtime_r(&t, &tmp); - - strftime(timestamp, sizeof(timestamp), "%Y%m%d_%H%M%S", &tmp); - - ret = snprintf(files_buffer->filename, sizeof(files_buffer->filename), "%s%s%s%s", - files_buffer->filenameBase, - MULTIPLE_FILES_FILENAME_TIMESTAMP_DELIM, timestamp, - files_buffer->filenameExt); - - if ((ret < 0) || ((size_t)ret >= (int)sizeof(files_buffer->filename))) { - fprintf(stderr, "filename cannot be concatenated\n"); - return DLT_RETURN_ERROR; - } - - ret = snprintf(file_path, sizeof(file_path), "%s/%s", - files_buffer->directory, files_buffer->filename); - - if ((ret < 0) || ((size_t)ret >= (int)sizeof(file_path))) { - fprintf(stderr, "file path cannot be concatenated\n"); - return DLT_RETURN_ERROR; - } - } - else { - char newest[NAME_MAX + 1] = { 0 }; - char oldest[NAME_MAX + 1] = { 0 }; - /* targeting newest file, ignoring number of files in dir returned */ - if (0 == multiple_files_buffer_storage_dir_info(files_buffer->directory, - files_buffer->filenameBase, - newest, - oldest)) { - printf("No multiple files found\n"); - } - - idx = multiple_files_buffer_get_idx_of_log_file(newest) + 1; - - multiple_files_buffer_file_name(files_buffer, sizeof(files_buffer->filename), idx); - ret = snprintf(file_path, sizeof(file_path), "%s/%s", - files_buffer->directory, files_buffer->filename); - - if ((ret < 0) || (ret >= NAME_MAX)) { - fprintf(stderr, "filename cannot be concatenated\n"); - return DLT_RETURN_ERROR; - } - } - - /* open DLT output file */ - errno = 0; - files_buffer->ohandle = open(file_path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | - S_IRGRP | S_IROTH); /* mode: wb */ - - if (files_buffer->ohandle == -1) { - /* file cannot be opened */ - fprintf(stderr, "file %s cannot be created, error: %s\n", file_path, strerror(errno)); - return DLT_RETURN_ERROR; - } - - return DLT_RETURN_OK; -} - -ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer *files_buffer) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return -1; - } - - struct dirent *dp; - char filename[PATH_MAX + 1]; - ssize_t size = 0; - struct stat status; - - /* go through all dlt files in directory */ - DIR *dir = opendir(files_buffer->directory); - if (!dir) { - fprintf(stderr, "directory %s cannot be opened, error=%s\n", files_buffer->directory, strerror(errno)); - return -1; - } - - while ((dp = readdir(dir)) != NULL) { - // consider files matching with a specific base name and a particular extension - if (strstr(dp->d_name, files_buffer->filenameBase) && strstr(dp->d_name, files_buffer->filenameExt)) { - int res = snprintf(filename, sizeof(filename), "%s/%s", files_buffer->directory, dp->d_name); - - /* if the total length of the string is greater than the buffer, silently forget it. */ - /* snprintf: a return value of size or more means that the output was truncated */ - /* if an output error is encountered, a negative value is returned. */ - if (((unsigned int)res < sizeof(filename)) && (res > 0)) { - errno = 0; - if (0 == stat(filename, &status)) - size += status.st_size; - else - fprintf(stderr, "file %s cannot be stat-ed, error=%s\n", filename, strerror(errno)); - } - } - } - - closedir(dir); - - /* return size */ - return size; -} - -int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer *files_buffer) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return -1; /* ERROR */ - } - - struct dirent *dp; - char filename[PATH_MAX + 1]; - char filename_oldest[PATH_MAX + 1]; - unsigned long size_oldest = 0; - struct stat status; - time_t time_oldest = 0; - int index_oldest = INT_MAX; - - filename[0] = 0; - filename_oldest[0] = 0; - - /* go through all dlt files in directory */ - DIR *dir = opendir(files_buffer->directory); - - if(!dir) - return -1; - - while ((dp = readdir(dir)) != NULL) { - if (strstr(dp->d_name, files_buffer->filenameBase) && strstr(dp->d_name, files_buffer->filenameExt)) { - int res = snprintf(filename, sizeof(filename), "%s/%s", files_buffer->directory, dp->d_name); - - /* if the total length of the string is greater than the buffer, silently forget it. */ - /* snprintf: a return value of size or more means that the output was truncated */ - /* if an output error is encountered, a negative value is returned. */ - if (((unsigned int) res >= sizeof(filename)) || (res <= 0)) { - printf("Filename for delete oldest too long. Skip file.\n"); - continue; - } - - if (files_buffer->filenameTimestampBased) { - errno = 0; - if (0 == stat(filename, &status)) { - if ((time_oldest == 0) || (status.st_mtime < time_oldest)) { - time_oldest = status.st_mtime; - size_oldest = status.st_size; - strncpy(filename_oldest, filename, PATH_MAX); - filename_oldest[PATH_MAX] = 0; - } - } else { - printf("Old file %s cannot be stat-ed, error=%s\n", filename, strerror(errno)); - } - } else { - //index based - const int index = multiple_files_buffer_get_idx_of_log_file(filename); - if (index < index_oldest) { - index_oldest = index; - snprintf(filename, sizeof(filename), "%s/%s", files_buffer->directory, dp->d_name); - strncpy(filename_oldest, filename, PATH_MAX); - filename_oldest[PATH_MAX] = 0; - } - } - } - } - - closedir(dir); - - /* delete file */ - if (filename_oldest[0]) { - if (remove(filename_oldest)) { - fprintf(stderr, "Remove file %s failed! error=%s\n", filename_oldest, strerror(errno)); - return -1; /* ERROR */ - } - } else { - fprintf(stderr, "No file to be removed!\n"); - return -1; /* ERROR */ - } - - /* return size of deleted file*/ - return size_oldest; -} - -DltReturnValue multiple_files_buffer_check_size(MultipleFilesRingBuffer *files_buffer) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return DLT_RETURN_ERROR; - } - - struct stat status; - - /* check for existence of buffer files directory */ - errno = 0; - if (stat(files_buffer->directory, &status) == -1) { - fprintf(stderr, "Buffer files directory: %s doesn't exist, error=%s\n", files_buffer->directory, strerror(errno)); - return DLT_RETURN_ERROR; - } - /* check for accessibility of buffer files directory */ - else if (access(files_buffer->directory, W_OK) != 0) { - fprintf(stderr, "Buffer files directory: %s doesn't have the write access \n", files_buffer->directory); - return DLT_RETURN_ERROR; - } - - ssize_t total_size = 0; - /* check size of complete buffer file */ - while ((total_size = multiple_files_buffer_get_total_size(files_buffer)) > (files_buffer->maxSize - files_buffer->fileSize)) { - /* remove the oldest files as long as new file will not fit in completely into complete multiple files buffer */ - if (multiple_files_buffer_delete_oldest_file(files_buffer) < 0) return DLT_RETURN_ERROR; - } - - return total_size == -1 ? DLT_RETURN_ERROR : DLT_RETURN_OK; -} - -DltReturnValue multiple_files_buffer_open_file_for_append(MultipleFilesRingBuffer *files_buffer) { - if (files_buffer == NULL || files_buffer->filenameTimestampBased) return DLT_RETURN_ERROR; - - char newest[NAME_MAX + 1] = {0}; - char oldest[NAME_MAX + 1] = {0}; - /* targeting the newest file, ignoring number of files in dir returned */ - - if (0 == multiple_files_buffer_storage_dir_info(files_buffer->directory, - files_buffer->filenameBase, newest, oldest) ) { - // no file for appending found. Create a new one - printf("No multiple files for appending found. Create a new one\n"); - return multiple_files_buffer_create_new_file(files_buffer); - } - - char file_path[PATH_MAX + 1]; - int ret = snprintf(file_path, sizeof(file_path), "%s/%s", - files_buffer->directory, newest); - - if ((ret < 0) || (ret >= NAME_MAX)) { - fprintf(stderr, "filename cannot be concatenated\n"); - return DLT_RETURN_ERROR; - } - - /* open DLT output file */ - errno = 0; - files_buffer->ohandle = open(file_path, O_WRONLY | O_APPEND); /* mode: wb */ - - return files_buffer->ohandle == -1 ? DLT_RETURN_ERROR : DLT_RETURN_OK; -} - -DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer, - const char *directory, - const int file_size, - const int max_size, - const bool filename_timestamp_based, - const bool append, - const char *filename_base, - const char *filename_ext) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return DLT_RETURN_ERROR; - } - - /* init parameters */ - strncpy(files_buffer->directory, directory, NAME_MAX); - files_buffer->directory[NAME_MAX] = 0; - files_buffer->fileSize = file_size; - files_buffer->maxSize = max_size; - files_buffer->filenameTimestampBased = filename_timestamp_based; - strncpy(files_buffer->filenameBase, filename_base, NAME_MAX); - files_buffer->filenameBase[NAME_MAX] = 0; - strncpy(files_buffer->filenameExt, filename_ext, NAME_MAX); - files_buffer->filenameExt[NAME_MAX] = 0; - - if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) return DLT_RETURN_ERROR; - - return (!files_buffer->filenameTimestampBased && append) - ? multiple_files_buffer_open_file_for_append(files_buffer) - : multiple_files_buffer_create_new_file(files_buffer); -} - -void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer *files_buffer, const int size) -{ - /* check file size here */ - if ((lseek(files_buffer->ohandle, 0, SEEK_CUR) + size) < files_buffer->fileSize) return; - - /* close old file */ - close(files_buffer->ohandle); - files_buffer->ohandle = -1; - - /* check complete files size, remove old logs if needed */ - if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) return; - - /* create new file */ - multiple_files_buffer_create_new_file(files_buffer); -} - -DltReturnValue multiple_files_buffer_write_chunk(const MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - const int size) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return DLT_RETURN_ERROR; - } - - if (data && (files_buffer->ohandle >= 0)) { - if (write(files_buffer->ohandle, data, size) != size) { - fprintf(stderr, "file write failed!\n"); - return DLT_RETURN_ERROR; - } - } - return DLT_RETURN_OK; -} - -DltReturnValue multiple_files_buffer_write(MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - const int size) -{ - if (files_buffer->ohandle < 0) return DLT_RETURN_ERROR; - - multiple_files_buffer_rotate_file(files_buffer, size); - - /* write data into log file */ - return multiple_files_buffer_write_chunk(files_buffer, data, size); -} - -DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer *files_buffer) -{ - if (files_buffer == NULL) { - fprintf(stderr, "multiple files buffer not set\n"); - return DLT_RETURN_ERROR; - } - - if (files_buffer->ohandle < 0) return DLT_RETURN_ERROR; - - /* close last used log file */ - close(files_buffer->ohandle); - - return DLT_RETURN_OK; -} diff -Nru dlt-daemon-2.18.9/src/shared/dlt_offline_trace.c dlt-daemon-2.18.4/src/shared/dlt_offline_trace.c --- dlt-daemon-2.18.9/src/shared/dlt_offline_trace.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_offline_trace.c 2019-09-03 08:28:13.000000000 +0000 @@ -61,28 +61,364 @@ #include #include #include -#include #include -#include +#include "dlt_common.h" -DltReturnValue dlt_offline_trace_write(MultipleFilesRingBuffer *trace, - const unsigned char *data1, - const int size1, - const unsigned char *data2, - const int size2, - const unsigned char *data3, - const int size3) +unsigned int dlt_offline_trace_storage_dir_info(char *path, char *file_name, char *newest, char *oldest) { + int i = 0; + unsigned int num = 0; + int cnt = 0; + struct dirent **files = { 0 }; + char *tmp_old = NULL; + char *tmp_new = NULL; - if (trace->ohandle < 0) return DLT_RETURN_ERROR; + if ((path == NULL) || (file_name == NULL) || (newest == NULL) || (oldest == NULL)) { + printf("dlt_offline_trace_storage_dir_info: Invalid parameter(s)"); + return 0; + } - multiple_files_buffer_rotate_file(trace, size1 + size2 + size3); + cnt = scandir(path, &files, NULL, alphasort); + + if (cnt < 0) + return 0; + + for (i = 0; i < cnt; i++) { + int len = 0; + len = strlen(file_name); + + if ((strncmp(files[i]->d_name, file_name, len) == 0) && (files[i]->d_name[len] == '.')) { + num++; + + if ((tmp_old == NULL) || (strlen(tmp_old) >= strlen(files[i]->d_name))) { + if (tmp_old == NULL) + tmp_old = files[i]->d_name; + /* when file name is smaller, it is older */ + else if (strlen(tmp_old) > strlen(files[i]->d_name)) + tmp_old = files[i]->d_name; + else /* filename is equal, do a string compare */ + if (strcmp(tmp_old, files[i]->d_name) > 0) + tmp_old = files[i]->d_name; + } + + if ((tmp_new == NULL) || (strlen(tmp_new) <= strlen(files[i]->d_name))) { + if (tmp_new == NULL) { + tmp_new = files[i]->d_name; + } + /* when file name is longer, it is younger */ + else if (strlen(tmp_new) < strlen(files[i]->d_name)) + { + tmp_new = files[i]->d_name; + } + else if (strcmp(tmp_new, files[i]->d_name) < 0) + tmp_new = files[i]->d_name; + } + } + } + + if (num > 0) { + if (tmp_old != NULL) { + if (strlen(tmp_old) < DLT_OFFLINETRACE_FILENAME_MAX_SIZE) + strncpy(oldest, tmp_old, DLT_OFFLINETRACE_FILENAME_MAX_SIZE); + } + + if (tmp_new != NULL) { + if (strlen(tmp_old) < DLT_OFFLINETRACE_FILENAME_MAX_SIZE) + strncpy(newest, tmp_new, DLT_OFFLINETRACE_FILENAME_MAX_SIZE); + } + } + + /* free scandir result */ + for (i = 0; i < cnt; i++) + free(files[i]); + + free(files); + + return num; +} + +void dlt_offline_trace_file_name(char *log_file_name, char *name, unsigned int idx) +{ + char file_index[11]; /* UINT_MAX = 4294967295 -> 10 digits */ + snprintf(file_index, sizeof(file_index), "%010u", idx); + + /* create log file name */ + memset(log_file_name, 0, DLT_OFFLINETRACE_FILENAME_MAX_SIZE * sizeof(char)); + strncat(log_file_name, name, sizeof(log_file_name) - strlen(log_file_name) - 1); + strncat(log_file_name, DLT_OFFLINETRACE_FILENAME_DELI, sizeof(log_file_name) - strlen(log_file_name) - 1); + strncat(log_file_name, file_index, sizeof(log_file_name) - strlen(log_file_name) - 1); + strncat(log_file_name, DLT_OFFLINETRACE_FILENAME_EXT, sizeof(log_file_name) - strlen(log_file_name) - 1); +} + +unsigned int dlt_offline_trace_get_idx_of_log_file(char *file) +{ + const char d[2] = "."; + char *token; + unsigned int idx = 0; + + if (file[0] == '\0') + return 0; + + token = strtok(file, d); + /* we are interested in 2. token because of log file name */ + token = strtok(NULL, d); + + if (token != NULL) + idx = strtol(token, NULL, 10); + else + idx = 0; + + return idx; +} + + +DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace) +{ + time_t t; + struct tm tmp; + char outstr[200]; + char newest[DLT_OFFLINETRACE_FILENAME_MAX_SIZE] = { 0 }; + char oldest[DLT_OFFLINETRACE_FILENAME_MAX_SIZE] = { 0 }; + unsigned int idx = 0; + + /* set filename */ + if (trace->filenameTimestampBased) { + int ret = 0; + t = time(NULL); + localtime_r(&t, &tmp); + + strftime(outstr, sizeof(outstr), "%Y%m%d_%H%M%S", &tmp); + + ret = snprintf(trace->filename, NAME_MAX, "%s/dlt_offlinetrace_%s.dlt", trace->directory, outstr); + + if ((ret < 0) || (ret >= NAME_MAX)) { + printf("dlt_offlinetrace filename cannot be concatenated\n"); + return DLT_RETURN_ERROR; + } + } + else { + int ret = 0; + /* targeting newest file, ignoring number of files in dir returned */ + dlt_offline_trace_storage_dir_info(trace->directory, DLT_OFFLINETRACE_FILENAME_BASE, newest, oldest); + idx = dlt_offline_trace_get_idx_of_log_file(newest) + 1; + + dlt_offline_trace_file_name(outstr, DLT_OFFLINETRACE_FILENAME_BASE, idx); + ret = snprintf(trace->filename, NAME_MAX, "%s/%s", trace->directory, outstr); + + if ((ret < 0) || (ret >= NAME_MAX)) { + printf("filename cannot be concatenated\n"); + return DLT_RETURN_ERROR; + } + } + + /* open DLT output file */ + trace->ohandle = open(trace->filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + + if (trace->ohandle == -1) { + /* trace file cannot be opened */ + printf("Offline trace file %s cannot be created\n", trace->filename); + return DLT_RETURN_ERROR; + } /* if */ + + return DLT_RETURN_OK; /* OK */ +} + +unsigned long dlt_offline_trace_get_total_size(DltOfflineTrace *trace) +{ + struct dirent *dp; + char filename[256]; + unsigned long size = 0; + struct stat status; + + /* go through all dlt files in directory */ + DIR *dir = opendir(trace->directory); + + while ((dp = readdir(dir)) != NULL) + if (strstr(dp->d_name, DLT_OFFLINETRACE_FILENAME_BASE)) { + int res = snprintf(filename, sizeof(filename), "%s/%s", trace->directory, dp->d_name); + + /* if the total length of the string is greater than the buffer, silently forget it. */ + /* snprintf: a return value of size or more means that the output was truncated */ + /* if an output error is encountered, a negative value is returned. */ + if (((unsigned int)res < sizeof(filename)) && (res > 0)) { + if (0 == stat(filename, &status)) + size += status.st_size; + else + printf("Offline trace file %s cannot be stat-ed", filename); + } + + /*else */ + /*{ */ + /* dlt_log(3, "dlt_offline_trace_get_total_size: long filename ignored"); */ + /*} */ + } + + closedir(dir); + + /* return size */ + return size; +} + +int dlt_offline_trace_delete_oldest_file(DltOfflineTrace *trace) +{ + struct dirent *dp; + char filename[PATH_MAX + 1]; + char filename_oldest[PATH_MAX + 1]; + unsigned long size_oldest = 0; + struct stat status; + time_t time_oldest = 0; + + filename[0] = 0; + filename_oldest[0] = 0; + + /* go through all dlt files in directory */ + DIR *dir = opendir(trace->directory); + + while ((dp = readdir(dir)) != NULL) + if (strstr(dp->d_name, DLT_OFFLINETRACE_FILENAME_TO_COMPARE)) { + int res = snprintf(filename, sizeof(filename), "%s/%s", trace->directory, dp->d_name); + + /* if the total length of the string is greater than the buffer, silently forget it. */ + /* snprintf: a return value of size or more means that the output was truncated */ + /* if an output error is encountered, a negative value is returned. */ + if (((unsigned int)res < sizeof(filename)) && (res > 0)) { + if (0 == stat(filename, &status)) { + if ((time_oldest == 0) || (status.st_mtime < time_oldest)) { + time_oldest = status.st_mtime; + size_oldest = status.st_size; + strncpy(filename_oldest, filename, PATH_MAX); + filename_oldest[PATH_MAX] = 0; + } + } + else { + printf("Old offline trace file %s cannot be stat-ed", filename); + } + } + } + + closedir(dir); + + /* delete file */ + if (filename_oldest[0]) { + if (remove(filename_oldest)) { + printf("Remove file %s failed!\n", filename_oldest); + return -1; /* ERROR */ + } + } + else { + printf("No file to be removed!\n"); + return -1; /* ERROR */ + } + + /* return size of deleted file*/ + return size_oldest; +} + +DltReturnValue dlt_offline_trace_check_size(DltOfflineTrace *trace) +{ + + struct stat status; + + /* check for existence of offline trace directory */ + if (stat(trace->directory, &status) == -1) { + dlt_vlog(LOG_ERR, "Offline trace directory: %s doesn't exist \n", trace->directory); + return DLT_RETURN_ERROR; + } + + /* check for accesibilty of offline trace directory */ + else if (access(trace->directory, W_OK) != 0) + { + dlt_vlog(LOG_ERR, "Offline trace directory: %s doesn't have the write access \n", trace->directory); + return DLT_RETURN_ERROR; + } + + /* check size of complete offline trace */ + while ((int)dlt_offline_trace_get_total_size(trace) > (trace->maxSize - trace->fileSize)) + /* remove oldest files as long as new file will not fit in completely into complete offline trace */ + if (dlt_offline_trace_delete_oldest_file(trace) < 0) + return DLT_RETURN_ERROR; + + return DLT_RETURN_OK; /* OK */ +} + +DltReturnValue dlt_offline_trace_init(DltOfflineTrace *trace, + const char *directory, + int fileSize, + int maxSize, + int filenameTimestampBased) +{ + + /* init parameters */ + strncpy(trace->directory, directory, NAME_MAX); + trace->directory[NAME_MAX] = 0; + trace->fileSize = fileSize; + trace->maxSize = maxSize; + trace->filenameTimestampBased = filenameTimestampBased; + /* check complete offlien trace size, remove old logs if needed */ + dlt_offline_trace_check_size(trace); + + return dlt_offline_trace_create_new_file(trace); +} + +DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace, + unsigned char *data1, + int size1, + unsigned char *data2, + int size2, + unsigned char *data3, + int size3) +{ + + if (trace->ohandle <= 0) + return DLT_RETURN_ERROR; + + /* check file size here */ + if ((lseek(trace->ohandle, 0, SEEK_CUR) + size1 + size2 + size3) >= trace->fileSize) { + /* close old file */ + close(trace->ohandle); + trace->ohandle = -1; + + /* check complete offline trace size, remove old logs if needed */ + dlt_offline_trace_check_size(trace); + + /* create new file */ + dlt_offline_trace_create_new_file(trace); + } /* write data into log file */ - if (multiple_files_buffer_write_chunk(trace, data1, size1) != DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (multiple_files_buffer_write_chunk(trace, data2, size2) != DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (multiple_files_buffer_write_chunk(trace, data3, size3) != DLT_RETURN_OK) return DLT_RETURN_ERROR; + if (data1 && (trace->ohandle >= 0)) { + if (write(trace->ohandle, data1, size1) != size1) { + printf("Offline trace write failed!\n"); + return DLT_RETURN_ERROR; + } + } + + if (data2 && (trace->ohandle >= 0)) { + if (write(trace->ohandle, data2, size2) != size2) { + printf("Offline trace write failed!\n"); + return DLT_RETURN_ERROR; + } + } + + if (data3 && (trace->ohandle >= 0)) { + if (write(trace->ohandle, data3, size3) != size3) { + printf("Offline trace write failed!\n"); + return DLT_RETURN_ERROR; + } + } + + return DLT_RETURN_OK; /* OK */ +} + +DltReturnValue dlt_offline_trace_free(DltOfflineTrace *trace) +{ + + if (trace->ohandle <= 0) + return DLT_RETURN_ERROR; + + /* close last used log file */ + close(trace->ohandle); - return DLT_RETURN_OK; + return DLT_RETURN_OK; /* OK */ } diff -Nru dlt-daemon-2.18.9/src/shared/dlt_user_shared.c dlt-daemon-2.18.4/src/shared/dlt_user_shared.c --- dlt-daemon-2.18.9/src/shared/dlt_user_shared.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_user_shared.c 2019-09-03 08:28:13.000000000 +0000 @@ -108,7 +108,7 @@ struct iovec iov[2]; uint32_t bytes_written; - if (handle < 0) + if (handle <= 0) /* Invalid handle */ return DLT_RETURN_ERROR; @@ -117,7 +117,7 @@ iov[1].iov_base = ptr2; iov[1].iov_len = len2; - bytes_written = (uint32_t) writev(handle, iov, 2); + bytes_written = writev(handle, iov, 2); if (bytes_written != (len1 + len2)) return DLT_RETURN_ERROR; @@ -130,7 +130,7 @@ struct iovec iov[3]; uint32_t bytes_written; - if (handle < 0) + if (handle <= 0) /* Invalid handle */ return DLT_RETURN_ERROR; @@ -141,15 +141,10 @@ iov[2].iov_base = ptr3; iov[2].iov_len = len3; - bytes_written = (uint32_t) writev(handle, iov, 3); + bytes_written = writev(handle, iov, 3); if (bytes_written != (len1 + len2 + len3)) { switch (errno) { - case ETIMEDOUT: - { - return DLT_RETURN_PIPE_ERROR; /* ETIMEDOUT - connect timeout */ - break; - } case EBADF: { return DLT_RETURN_PIPE_ERROR; /* EBADF - handle not open */ @@ -175,4 +170,4 @@ } return DLT_RETURN_OK; -} \ No newline at end of file +} diff -Nru dlt-daemon-2.18.9/src/shared/dlt_user_shared.h dlt-daemon-2.18.4/src/shared/dlt_user_shared.h --- dlt-daemon-2.18.9/src/shared/dlt_user_shared.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/shared/dlt_user_shared.h 2019-09-03 08:28:13.000000000 +0000 @@ -80,7 +80,7 @@ { char pattern[DLT_ID_SIZE]; /**< This pattern should be DUH0x01 */ uint32_t message; /**< messsage info */ -} DLT_PACKED DltUserHeader; +} PACKED DltUserHeader; /** * This is the internal message content to exchange control msg register app information between application and daemon. @@ -90,7 +90,7 @@ char apid[DLT_ID_SIZE]; /**< application id */ pid_t pid; /**< process id of user application */ uint32_t description_length; /**< length of description */ -} DLT_PACKED DltUserControlMsgRegisterApplication; +} PACKED DltUserControlMsgRegisterApplication; /** * This is the internal message content to exchange control msg unregister app information between application and daemon. @@ -99,7 +99,7 @@ { char apid[DLT_ID_SIZE]; /**< application id */ pid_t pid; /**< process id of user application */ -} DLT_PACKED DltUserControlMsgUnregisterApplication; +} PACKED DltUserControlMsgUnregisterApplication; /** * This is the internal message content to exchange control msg register information between application and daemon. @@ -113,7 +113,7 @@ int8_t trace_status; /**< trace status */ pid_t pid; /**< process id of user application */ uint32_t description_length; /**< length of description */ -} DLT_PACKED DltUserControlMsgRegisterContext; +} PACKED DltUserControlMsgRegisterContext; /** * This is the internal message content to exchange control msg unregister information between application and daemon. @@ -123,7 +123,7 @@ char apid[DLT_ID_SIZE]; /**< application id */ char ctid[DLT_ID_SIZE]; /**< context id */ pid_t pid; /**< process id of user application */ -} DLT_PACKED DltUserControlMsgUnregisterContext; +} PACKED DltUserControlMsgUnregisterContext; /** * This is the internal message content to exchange control msg log level information between application and daemon. @@ -133,7 +133,7 @@ uint8_t log_level; /**< log level */ uint8_t trace_status; /**< trace status */ int32_t log_level_pos; /**< offset in management structure on user-application side */ -} DLT_PACKED DltUserControlMsgLogLevel; +} PACKED DltUserControlMsgLogLevel; /** * This is the internal message content to exchange control msg injection information between application and daemon. @@ -143,7 +143,7 @@ int32_t log_level_pos; /**< offset in management structure on user-application side */ uint32_t service_id; /**< service id of injection */ uint32_t data_length_inject; /**< length of injection message data field */ -} DLT_PACKED DltUserControlMsgInjection; +} PACKED DltUserControlMsgInjection; /** * This is the internal message content to exchange information about application log level and trace stats between @@ -154,7 +154,7 @@ char apid[DLT_ID_SIZE]; /**< application id */ uint8_t log_level; /**< log level */ uint8_t trace_status; /**< trace status */ -} DLT_PACKED DltUserControlMsgAppLogLevelTraceStatus; +} PACKED DltUserControlMsgAppLogLevelTraceStatus; /** * This is the internal message content to set the logging mode: off, external, internal, both. @@ -162,7 +162,7 @@ typedef struct { int8_t log_mode; /**< the mode to be used for logging: off, external, internal, both */ -} DLT_PACKED DltUserControlMsgLogMode; +} PACKED DltUserControlMsgLogMode; /** * This is the internal message content to get the logging state: 0 = off, 1 = external client connected. @@ -170,7 +170,7 @@ typedef struct { int8_t log_state; /**< the state to be used for logging state: 0 = off, 1 = external client connected */ -} DLT_PACKED DltUserControlMsgLogState; +} PACKED DltUserControlMsgLogState; /** * This is the internal message content to get the number of lost messages reported to the daemon. @@ -179,7 +179,7 @@ { uint32_t overflow_counter; /**< counts the number of lost messages */ char apid[4]; /**< application which lost messages */ -} DLT_PACKED DltUserControlMsgBufferOverflow; +} PACKED DltUserControlMsgBufferOverflow; /************************************************************************************************** * The folowing functions are used shared between the user lib and the daemon implementation diff -Nru dlt-daemon-2.18.9/src/system/CMakeLists.txt dlt-daemon-2.18.4/src/system/CMakeLists.txt --- dlt-daemon-2.18.9/src/system/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -18,30 +18,20 @@ endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD OR WITH_SYSTEMD_JOURNAL) set(dlt_system_SRCS dlt-system.c dlt-system-options.c dlt-system-process-handling.c - dlt-system-logfile.c dlt-system-processes.c dlt-system-shell.c - dlt-system-syslog.c dlt-system-watchdog.c dlt-system-journal.c) - -if(WITH_DLT_FILETRANSFER) - set(dlt_system_SRCS ${dlt_system_SRCS} dlt-system-filetransfer.c) - add_definitions(-DDLT_FILETRANSFER_ENABLE) -endif(WITH_DLT_FILETRANSFER) - + dlt-system-filetransfer.c dlt-system-logfile.c dlt-system-processes.c dlt-system-shell.c + dlt-system-syslog.c dlt-system-watchdog.c dlt-system-journal.c) add_executable(dlt-system ${dlt_system_SRCS} ${systemd_SRCS}) -target_link_libraries(dlt-system dlt) - if(WITH_SYSTEMD_JOURNAL) - if(SYSTEMD_VERSION LESS 209) - target_link_libraries(dlt-system systemd-journal systemd-id128) - else(SYSTEMD_VERSION LESS 209) - target_link_libraries(dlt-system systemd) - endif(SYSTEMD_VERSION LESS 209) + if(SYSTEMD_VERSION LESS 209) + target_link_libraries(dlt-system dlt ${ZLIB_LIBRARIES} systemd-journal systemd-id128) + else(SYSTEMD_VERSION LESS 209) + target_link_libraries(dlt-system dlt ${ZLIB_LIBRARIES} systemd) + endif(SYSTEMD_VERSION LESS 209) +else(WITH_SYSTEMD_JOURNAL) + target_link_libraries(dlt-system dlt ${ZLIB_LIBRARIES}) endif(WITH_SYSTEMD_JOURNAL) -if(WITH_DLT_FILETRANSFER) - target_link_libraries(dlt-system ${ZLIB_LIBRARY}) -endif(WITH_DLT_FILETRANSFER) - set_target_properties(dlt-system PROPERTIES LINKER_LANGUAGE C) diff -Nru dlt-daemon-2.18.9/src/system/dlt-system.c dlt-daemon-2.18.4/src/system/dlt-system.c --- dlt-daemon-2.18.9/src/system/dlt-system.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system.c 2019-09-03 08:28:13.000000000 +0000 @@ -49,7 +49,6 @@ #include #include #include -#include #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE) # include "sd-daemon.h" @@ -113,12 +112,12 @@ signal(SIGQUIT, dlt_system_signal_handler); signal(SIGINT, dlt_system_signal_handler); - DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Initializing all processes and starting poll for events.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Launching threads.")); - start_dlt_system_processes(&config); - cleanup_config(&config, &options); - exit(0); + start_threads(&config); + join_threads(); + return 0; } diff -Nru dlt-daemon-2.18.9/src/system/dlt-system.conf dlt-daemon-2.18.4/src/system/dlt-system.conf --- dlt-daemon-2.18.9/src/system/dlt-system.conf 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system.conf 2019-09-03 08:28:13.000000000 +0000 @@ -74,9 +74,6 @@ # 7 Debug DLT_LOG_DEBUG JournalMapLogLevels = 1 -# Use the original timestamp (uptime when the event actually occured) as DLT timestamp (Default: 1) -JournalUseOriginalTimestamp = 1 - ######################################################################## # Filetransfer Manager ######################################################################## @@ -90,6 +87,10 @@ # Time in seconds after startup of dlt-system when first file is transfered (Default: 0) FiletransferTimeStartup = 0 +# Time to wait when transfered file is deleted and next file transfer starts (Default: 10) +# Time in seconds +FiletransferTimeDelay = 10 + # Time in ms seconds to wait between two file transfer logs of a single file to DLT. (Default: 10) FiletransferTimeoutBetweenLogs = 5 @@ -198,3 +199,4 @@ # LogProcessFilename = stat # LogProcessMode = 2 # LogProcessTimeDelay = 1 + diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-filetransfer.c dlt-daemon-2.18.4/src/system/dlt-system-filetransfer.c --- dlt-daemon-2.18.9/src/system/dlt-system-filetransfer.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-filetransfer.c 2019-09-03 08:28:13.000000000 +0000 @@ -49,6 +49,7 @@ *******************************************************************************/ +#include #include #ifdef linux # include @@ -60,7 +61,6 @@ #include #include #include -#include #include "dlt-system.h" #include "dlt.h" @@ -76,6 +76,8 @@ #define SUBDIR_TOSEND ".tosend" + +extern DltSystemThreads threads; /* From dlt_filetransfer */ extern uint32_t getFileSerialNumber(const char *file, int *ok); @@ -83,6 +85,11 @@ DLT_DECLARE_CONTEXT(filetransferContext) #ifdef linux +typedef struct { + int handle; + int fd[DLT_SYSTEM_LOG_DIRS_MAX]; +} s_ft_inotify; + s_ft_inotify ino; #endif @@ -253,6 +260,7 @@ { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sending a file.")); + sleep(opts->TimeDelay); /* Prepare all needed file names */ char *fn = basename(src); @@ -264,13 +272,9 @@ return -1; } - char *src_copy = strndup(src, PATH_MAX); - MALLOC_ASSERT(src_copy); - - /*dirname overwrites its argument anyway, */ - /*but depending on argument returned address might change */ - char *fdir = dirname(src_copy); - + char *fdir = strndup(src, PATH_MAX); + MALLOC_ASSERT(fdir); + fdir = dirname(fdir);/*dirname overwrites its argument anyway */ char *dst_tosend;/*file which is going to be sent */ char *rn = unique_name(src);/*new unique filename based on inode */ @@ -304,7 +308,7 @@ DLT_STRING(dst_tocompress)); free(rn); free(dst_tocompress); - free(src_copy); + free(fdir); return -1; } @@ -317,7 +321,7 @@ free(rn); free(dst_tosend); free(dst_tocompress); - free(src_copy); + free(fdir); return -1; } @@ -345,7 +349,7 @@ DLT_STRING(dst_tosend)); free(rn); free(dst_tosend); - free(src_copy); + free(fdir); return -1; } } @@ -358,7 +362,7 @@ free(rn); free(dst_tosend); - free(src_copy); + free(fdir); return 0; } @@ -366,6 +370,7 @@ int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, const char *send_dir) { + struct dirent *dp; DIR *dir; dir = opendir(send_dir); @@ -559,6 +564,8 @@ */ int flush_dir(FiletransferOptions const *opts, int which) { + + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, flush directory of old files.")); @@ -600,13 +607,11 @@ /*!Initializes the surveyed directories */ /**On startup, the inotifiy handlers are created, and existing files shall be sent into DLT stream - * @param config DltSystemConfiguration + * @param opts FiletransferOptions * @return Returns 0 if everything was okay. If there was a failure a value < 0 will be returned. */ -int init_filetransfer_dirs(DltSystemConfiguration *config) +int init_filetransfer_dirs(FiletransferOptions const *opts) { - FiletransferOptions const *opts = &(config->Filetransfer); - DLT_REGISTER_CONTEXT(filetransferContext, config->Filetransfer.ContextId, "Filetransfer Adapter"); DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, initializing inotify on directories.")); int i; @@ -681,19 +686,20 @@ flush_dir(opts, i); } + return 0; } -int process_files(FiletransferOptions const *opts) +int wait_for_files(FiletransferOptions const *opts) { #ifdef linux - DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, processing files.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, waiting for files.")); static char buf[INOTIFY_LEN]; ssize_t len = read(ino.handle, buf, INOTIFY_LEN); if (len < 0) { DLT_LOG(filetransferContext, DLT_LOG_ERROR, - DLT_STRING("Error while reading events for files in dlt-system file transfer.")); + DLT_STRING("Error while waiting for files in dlt-system file transfer.")); return -1; } @@ -738,7 +744,33 @@ return 0; } -void filetransfer_fd_handler(DltSystemConfiguration *config) +void filetransfer_thread(void *v_conf) { - process_files(&(config->Filetransfer)); -} \ No newline at end of file + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, in thread.")); + DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DLT_REGISTER_CONTEXT(filetransferContext, conf->Filetransfer.ContextId, + "File transfer manager."); + + sleep(conf->Filetransfer.TimeStartup); + + if (init_filetransfer_dirs(&(conf->Filetransfer)) < 0) + return; + + while (!threads.shutdown) { + if (wait_for_files(&(conf->Filetransfer)) < 0) { + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while waiting files. File transfer shutdown.")); + return; + } + + sleep(conf->Filetransfer.TimeDelay); + } +} + +void start_filetransfer(DltSystemConfiguration *conf) +{ + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, start.")); + static pthread_attr_t t_attr; + static pthread_t pt; + pthread_create(&pt, &t_attr, (void *)filetransfer_thread, conf); + threads.threads[threads.count++] = pt; +} diff -Nru dlt-daemon-2.18.9/src/system/dlt-system.h dlt-daemon-2.18.4/src/system/dlt-system.h --- dlt-daemon-2.18.9/src/system/dlt-system.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system.h 2019-09-03 08:28:13.000000000 +0000 @@ -54,9 +54,6 @@ #ifndef DLT_SYSTEM_H_ #define DLT_SYSTEM_H_ -#include -#include - /* DLT related includes. */ #include "dlt.h" #include "dlt_common.h" @@ -73,29 +70,13 @@ #define MAX_LINE 1024 -/** Total number of file descriptors needed for processing all features: -* - Journal file descriptor -* - Syslog file descriptor -* - Timer file descriptor for processing LogFile and LogProcesses every second -* - Inotify file descriptor for FileTransfer -* - Timer file descriptor for Watchdog -*/ -#define MAX_FD_NUMBER 5 +#define MAX_THREADS 8 /* Macros */ #define MALLOC_ASSERT(x) if (x == NULL) { \ fprintf(stderr, "Out of memory\n"); \ abort(); } -/* enum for classification of FD */ -enum fdType { - fdType_journal = 0, - fdType_syslog, - fdType_filetransfer, - fdType_timer, - fdType_watchdog, -}; - /** * Configuration structures. * Please see dlt-system.conf for explanation of all the options. @@ -115,25 +96,26 @@ /* Configuration syslog options */ typedef struct { int Enable; - char ContextId[DLT_ID_SIZE]; + char *ContextId; int Port; } SyslogOptions; /* Configuration journal options */ typedef struct { int Enable; - char ContextId[DLT_ID_SIZE]; + char *ContextId; int CurrentBoot; int Follow; int MapLogLevels; - int UseOriginalTimestamp; } JournalOptions; typedef struct { int Enable; - char ContextId[DLT_ID_SIZE]; + char *ContextId; int TimeStartup; + int TimeDelay; int TimeoutBetweenLogs; + char *TempDir; /* Variable number of file transfer dirs */ int Count; @@ -143,16 +125,11 @@ } FiletransferOptions; typedef struct { - int handle; - int fd[DLT_SYSTEM_LOG_DIRS_MAX]; -} s_ft_inotify; - -typedef struct { int Enable; /* Variable number of files to transfer */ int Count; - char ContextId[DLT_SYSTEM_LOG_FILE_MAX][DLT_ID_SIZE]; + char *ContextId[DLT_SYSTEM_LOG_FILE_MAX]; char *Filename[DLT_SYSTEM_LOG_FILE_MAX]; int Mode[DLT_SYSTEM_LOG_FILE_MAX]; int TimeDelay[DLT_SYSTEM_LOG_FILE_MAX]; @@ -160,7 +137,7 @@ typedef struct { int Enable; - char ContextId[DLT_ID_SIZE]; + char *ContextId; /* Variable number of processes */ int Count; @@ -171,7 +148,7 @@ } LogProcessOptions; typedef struct { - char ApplicationId[DLT_ID_SIZE]; + char *ApplicationId; ShellOptions Shell; SyslogOptions Syslog; JournalOptions Journal; @@ -180,6 +157,12 @@ LogProcessOptions LogProcesses; } DltSystemConfiguration; +typedef struct { + pthread_t threads[MAX_THREADS]; + int count; + int shutdown; +} DltSystemThreads; + /** * Forward declarations for the whole application */ @@ -187,30 +170,27 @@ /* In dlt-system-options.c */ int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]); int read_configuration_file(DltSystemConfiguration *config, char *file_name); -void cleanup_config(DltSystemConfiguration *config, DltSystemCliOptions *options); -/* For dlt-process-handling.c */ +/* In dlt-process-handling.c */ int daemonize(); -void init_shell(); +void start_threads(DltSystemConfiguration *config); +void join_threads(); void dlt_system_signal_handler(int sig); +void register_with_dlt(DltSystemConfiguration *config); -/* Main function for creating/registering all needed file descriptors and starting the poll for all of them. */ -void start_dlt_system_processes(DltSystemConfiguration *config); - -/* Init process, create file descriptors and register them into main pollfd. */ -int register_watchdog_fd(struct pollfd *pollfd, int fdcnt); -int init_filetransfer_dirs(DltSystemConfiguration *config); -void logfile_init(void *v_conf); -void logprocess_init(void *v_conf); -void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSystemConfiguration *config); -int register_syslog_fd(struct pollfd *pollfd, int i, DltSystemConfiguration *config); - -/* Routines that are called, when a fd event was raised. */ -void logfile_fd_handler(void *v_conf); -void logprocess_fd_handler(void *v_conf); -void filetransfer_fd_handler(DltSystemConfiguration *config); -void watchdog_fd_handler(int fd); -void journal_fd_handler(sd_journal *j, DltSystemConfiguration *config); -void syslog_fd_handler(int syslogSock); +/* Thread initiators: */ +void init_shell(); +void start_syslog(); +void start_filetransfer(DltSystemConfiguration *conf); +void start_logfile(DltSystemConfiguration *conf); +void start_logprocess(DltSystemConfiguration *conf); + +#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) +void start_systemd_watchdog(DltSystemConfiguration *conf); +#endif + +#if defined(DLT_SYSTEMD_JOURNAL_ENABLE) +void start_systemd_journal(DltSystemConfiguration *conf); +#endif #endif /* DLT_SYSTEM_H_ */ diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-journal.c dlt-daemon-2.18.4/src/system/dlt-system-journal.c --- dlt-daemon-2.18.9/src/system/dlt-system-journal.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-journal.c 2019-09-03 08:28:13.000000000 +0000 @@ -43,7 +43,7 @@ *******************************************************************************/ #if defined(DLT_SYSTEMD_JOURNAL_ENABLE) -#include +#include #include #include #include @@ -56,6 +56,7 @@ #include #include /* for PRI formatting macro */ +extern DltSystemThreads threads; #define DLT_SYSTEM_JOURNAL_BUFFER_SIZE 256 #define DLT_SYSTEM_JOURNAL_BUFFER_SIZE_BIG 2048 @@ -135,9 +136,9 @@ void dlt_system_journal_get_timestamp(sd_journal *journal, MessageTimestamp *timestamp) { int ret = 0; - time_t time_secs = 0; + uint64_t time_secs = 0; uint64_t time_usecs = 0; - struct tm timeinfo; + struct tm *timeinfo = NULL; char buffer_realtime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }; char buffer_realtime_formatted[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }; @@ -153,8 +154,7 @@ if (errno != 0) time_usecs = 0; } - else if ((ret = sd_journal_get_realtime_usec(journal, &time_usecs)) < 0) - { + else if ((ret = sd_journal_get_realtime_usec(journal, &time_usecs)) < 0) { DLT_LOG(dltsystem, DLT_LOG_WARN, DLT_STRING("dlt-system-journal failed to get realtime: "), DLT_STRING(strerror(-ret))); @@ -163,10 +163,9 @@ time_usecs = 0; } - time_secs = (time_t)(time_usecs / 1000000); - tzset(); - localtime_r(&time_secs, &timeinfo); - strftime(buffer_realtime_formatted, sizeof(buffer_realtime_formatted), "%Y/%m/%d %H:%M:%S", &timeinfo); + time_secs = time_usecs / 1000000; + localtime_r((const time_t *)(&time_secs), timeinfo); + strftime(buffer_realtime_formatted, sizeof(buffer_realtime_formatted), "%Y/%m/%d %H:%M:%S", timeinfo); snprintf(timestamp->real, sizeof(timestamp->real), "%s.%06" PRIu64, buffer_realtime_formatted, time_usecs % 1000000); @@ -181,8 +180,7 @@ if (errno != 0) time_usecs = 0; } - else if ((ret = sd_journal_get_monotonic_usec(journal, &time_usecs, NULL)) < 0) - { + else if ((ret = sd_journal_get_monotonic_usec(journal, &time_usecs, NULL)) < 0) { DLT_LOG(dltsystem, DLT_LOG_WARN, DLT_STRING("dlt-system-journal failed to get monotonic time: "), DLT_STRING(strerror(-ret))); @@ -198,10 +196,12 @@ time_usecs % 1000000); } -void get_journal_msg(sd_journal *j, DltSystemConfiguration *config) -{ - uint32_t ts; +void journal_thread(void *v_conf) +{ int r; + sd_journal *j; + char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID="; + sd_id128_t boot_id; char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, @@ -216,178 +216,180 @@ char *systemd_log_levels[] = { "Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug" }; - for(;;) - { - r = sd_journal_next(j); - if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal failed to get next entry:"), DLT_STRING(strerror(-r))); - sd_journal_close(j); - return; - } - else if (r == 0) { - return; - } - - /* get all data from current journal entry */ - dlt_system_journal_get_timestamp(j, ×tamp); - - /* get data from journal entry, empty string if invalid fields */ - dlt_system_journal_get(j, buffer_comm, "_COMM", sizeof(buffer_comm)); - dlt_system_journal_get(j, buffer_pid, "_PID", sizeof(buffer_pid)); - dlt_system_journal_get(j, buffer_priority, "PRIORITY", sizeof(buffer_priority)); - dlt_system_journal_get(j, buffer_message, "MESSAGE", sizeof(buffer_message)); - dlt_system_journal_get(j, buffer_transport, "_TRANSPORT", sizeof(buffer_transport)); - - /* prepare process string */ - if (strcmp(buffer_transport, "kernel") == 0) - snprintf(buffer_process, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "kernel:"); - else - snprintf(buffer_process, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "%s[%s]:", buffer_comm, buffer_pid); - - /* map log level on demand */ - loglevel = DLT_LOG_INFO; - systemd_loglevel = atoi(buffer_priority); - - if (config->Journal.MapLogLevels) { - /* Map log levels from journal to DLT */ - switch (systemd_loglevel) { - case 0: /* Emergency */ - case 1: /* Alert */ - case 2: /* Critical */ - loglevel = DLT_LOG_FATAL; - break; - case 3: /* Error */ - loglevel = DLT_LOG_ERROR; - break; - case 4: /* Warning */ - loglevel = DLT_LOG_WARN; - break; - case 5: /* Notice */ - case 6: /* Informational */ - loglevel = DLT_LOG_INFO; - break; - case 7: /* Debug */ - loglevel = DLT_LOG_DEBUG; - break; - default: - loglevel = DLT_LOG_INFO; - break; - } - } - - if ((systemd_loglevel >= 0) && (systemd_loglevel <= 7)) - snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "%s:", systemd_log_levels[systemd_loglevel]); - else - snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "prio_unknown:"); - - /* write log entry */ - if (config->Journal.UseOriginalTimestamp == 0) { - DLT_LOG(journalContext, loglevel, - DLT_STRING(timestamp.real), - DLT_STRING(timestamp.monotonic), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); - - } - else { - /* since we are talking about points in time, I'd prefer truncating over arithmetic rounding */ - ts = (uint32_t)(atof(timestamp.monotonic) * 10000); - DLT_LOG_TS(journalContext, loglevel, ts, - DLT_STRING(timestamp.real), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); - } + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-journal, in thread.")); - if (journal_checkUserBufferForFreeSpace() == -1) { - /* buffer is nearly full */ - /* wait 500ms for writing next entry */ - struct timespec t; - t.tv_sec = 0; - t.tv_nsec = 1000000ul * 500; - nanosleep(&t, NULL); - } - } -} - -void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSystemConfiguration *config) -{ - DLT_REGISTER_CONTEXT(journalContext, config->Journal.ContextId, "Journal Adapter"); - sd_journal *j_tmp; - char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID="; - sd_id128_t boot_id; - int r; + DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DLT_REGISTER_CONTEXT(journalContext, conf->Journal.ContextId, "Journal Adapter"); - r = sd_journal_open(&j_tmp, SD_JOURNAL_LOCAL_ONLY /*SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY*/); + r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY /*SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY*/); printf("journal open return %d\n", r); + if (r < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal, cannot open journal:"), DLT_STRING(strerror(-r))); printf("journal open failed: %s\n", strerror(-r)); - j_tmp = NULL; + return; } - if (config->Journal.CurrentBoot) { + if (conf->Journal.CurrentBoot) { /* show only current boot entries */ r = sd_id128_get_boot(&boot_id); + if (r < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to get boot id:"), DLT_STRING(strerror(-r))); - sd_journal_close(j_tmp); - j_tmp = NULL; + sd_journal_close(j); + return; + } sd_id128_to_string(boot_id, match + 9); - r = sd_journal_add_match(j_tmp, match, strlen(match)); + r = sd_journal_add_match(j, match, strlen(match)); + if (r < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to get match:"), DLT_STRING(strerror(-r))); - sd_journal_close(j_tmp); - j_tmp = NULL; + sd_journal_close(j); + return; + } } - if (config->Journal.Follow) { + if (conf->Journal.Follow) { /* show only last 10 entries and follow */ - r = sd_journal_seek_tail(j_tmp); + r = sd_journal_seek_tail(j); + if (r < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to seek to tail:"), DLT_STRING(strerror(-r))); - sd_journal_close(j_tmp); - j_tmp = NULL; + sd_journal_close(j); + return; + } - r = sd_journal_previous_skip(j_tmp, 10); + r = sd_journal_previous_skip(j, 10); + if (r < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to seek back 10 entries:"), DLT_STRING(strerror(-r))); - sd_journal_close(j_tmp); - j_tmp = NULL; + sd_journal_close(j); + return; + } } - pollfd[i].fd = sd_journal_get_fd(j_tmp); - if(pollfd[i].fd < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal fd: "), - DLT_STRING(strerror(pollfd[i].fd))); - j_tmp = NULL; - } - pollfd[i].events = sd_journal_get_events(j_tmp); - if(pollfd[i].events < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal events: "), - DLT_STRING(strerror(pollfd[i].events))); - j_tmp = NULL; + while (!threads.shutdown) { + + r = sd_journal_next(j); + + if (r < 0) { + DLT_LOG(dltsystem, DLT_LOG_ERROR, + DLT_STRING("dlt-system-journal failed to get next entry:"), DLT_STRING(strerror(-r))); + sd_journal_close(j); + return; + + } + else if (r > 0) + { + /* get all data from current journal entry */ + dlt_system_journal_get_timestamp(j, ×tamp); + + /* get data from journal entry, empty string if invalid fields */ + dlt_system_journal_get(j, buffer_comm, "_COMM", sizeof(buffer_comm)); + dlt_system_journal_get(j, buffer_pid, "_PID", sizeof(buffer_pid)); + dlt_system_journal_get(j, buffer_priority, "PRIORITY", sizeof(buffer_priority)); + dlt_system_journal_get(j, buffer_message, "MESSAGE", sizeof(buffer_message)); + dlt_system_journal_get(j, buffer_transport, "_TRANSPORT", sizeof(buffer_transport)); + + /* prepare process string */ + if (strcmp(buffer_transport, "kernel") == 0) + snprintf(buffer_process, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "kernel:"); + else + snprintf(buffer_process, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "%s[%s]:", buffer_comm, buffer_pid); + + /* map log level on demand */ + loglevel = DLT_LOG_INFO; + systemd_loglevel = atoi(buffer_priority); + + if (conf->Journal.MapLogLevels) { + /* Map log levels from journal to DLT */ + switch (systemd_loglevel) { + case 0: /* Emergency */ + case 1: /* Alert */ + case 2: /* Critical */ + loglevel = DLT_LOG_FATAL; + break; + case 3: /* Error */ + loglevel = DLT_LOG_ERROR; + break; + case 4: /* Warning */ + loglevel = DLT_LOG_WARN; + break; + case 5: /* Notice */ + case 6: /* Informational */ + loglevel = DLT_LOG_INFO; + break; + case 7: /* Debug */ + loglevel = DLT_LOG_DEBUG; + break; + default: + loglevel = DLT_LOG_INFO; + break; + } + } + + if ((systemd_loglevel >= 0) && (systemd_loglevel <= 7)) + snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "%s:", systemd_log_levels[systemd_loglevel]); + else + snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "prio_unknown:"); + + /* write log entry */ + DLT_LOG(journalContext, loglevel, + DLT_STRING(timestamp.real), + DLT_STRING(timestamp.monotonic), + DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), + DLT_STRING(buffer_message) + ); + } + else { + r = sd_journal_wait(j, 1000000); + + if (r < 0) { + DLT_LOG(dltsystem, DLT_LOG_ERROR, + DLT_STRING("dlt-system-journal failed to call sd_journal_get_realtime_usec(): "), + DLT_STRING(strerror(-r))); + sd_journal_close(j); + return; + + } + } + + if (journal_checkUserBufferForFreeSpace() == -1) { + /* buffer is nearly full */ + /* wait 500ms for writing next entry */ + struct timespec t; + t.tv_sec = 0; + t.tv_nsec = 1000000ul * 500; + nanosleep(&t, NULL); + } } - *j = j_tmp; + + sd_journal_close(j); + + DLT_UNREGISTER_CONTEXT(journalContext); + } -void journal_fd_handler(sd_journal *j, DltSystemConfiguration *config) +void start_systemd_journal(DltSystemConfiguration *conf) { - get_journal_msg(j, config); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-journal, start journal")); + static pthread_attr_t t_attr; + static pthread_t pt; + pthread_create(&pt, &t_attr, (void *)journal_thread, conf); + threads.threads[threads.count++] = pt; } -#endif /* DLT_SYSTEMD_JOURNAL_ENABLE */ \ No newline at end of file +#endif /* DLT_SYSTEMD_JOURNAL_ENABLE */ diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-logfile.c dlt-daemon-2.18.4/src/system/dlt-system-logfile.c --- dlt-daemon-2.18.9/src/system/dlt-system-logfile.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-logfile.c 2019-09-03 08:28:13.000000000 +0000 @@ -44,6 +44,7 @@ *******************************************************************************/ +#include #include #include "dlt-system.h" @@ -54,8 +55,8 @@ DLT_IMPORT_CONTEXT(dltsystem) +extern DltSystemThreads threads; DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX]; -int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX]; void send_file(LogFileOptions const *fileopt, int n) { @@ -107,7 +108,7 @@ (*fileopts).Filename[i]); } -void logfile_init(void *v_conf) +void logfile_thread(void *v_conf) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, in thread.")); @@ -115,27 +116,40 @@ register_contexts(&(conf->LogFile)); - for (int i = 0; i < conf->LogFile.Count; i++) + int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX]; + int i; + + for (i = 0; i < conf->LogFile.Count; i++) logfile_delays[i] = conf->LogFile.TimeDelay[i]; -} -void logfile_fd_handler(void *v_conf) -{ - DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; - for (int i = 0; i < conf->LogFile.Count; i++) { - if (conf->LogFile.Mode[i] == SEND_MODE_OFF) - continue; - - if (logfile_delays[i] <= 0) { - send_file(&(conf->LogFile), i); - logfile_delays[i] = conf->LogFile.TimeDelay[i]; + while (!threads.shutdown) { + sleep(1); - if (conf->LogFile.Mode[i] == SEND_MODE_ONCE) - conf->LogFile.Mode[i] = SEND_MODE_OFF; - } - else { - logfile_delays[i]--; + for (i = 0; i < conf->LogFile.Count; i++) { + if (conf->LogFile.Mode[i] == SEND_MODE_OFF) + continue; + + if (logfile_delays[i] <= 0) { + send_file(&(conf->LogFile), i); + logfile_delays[i] = conf->LogFile.TimeDelay[i]; + + if (conf->LogFile.Mode[i] == SEND_MODE_ONCE) + conf->LogFile.Mode[i] = SEND_MODE_OFF; + } + else { + logfile_delays[i]--; + } } } } +void start_logfile(DltSystemConfiguration *conf) +{ + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-logfile, starting.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Starting thread for logfile")); + static pthread_attr_t t_attr; + static pthread_t pt; + pthread_create(&pt, &t_attr, (void *)logfile_thread, conf); + threads.threads[threads.count++] = pt; +} diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-options.c dlt-daemon-2.18.4/src/system/dlt-system-options.c --- dlt-daemon-2.18.9/src/system/dlt-system-options.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-options.c 2019-09-03 08:28:13.000000000 +0000 @@ -81,7 +81,7 @@ */ void init_cli_options(DltSystemCliOptions *options) { - options->ConfigurationFileName = strdup(DEFAULT_CONF_FILE); + options->ConfigurationFileName = DEFAULT_CONF_FILE; options->Daemonize = 0; } @@ -132,27 +132,27 @@ int i = 0; /* Common */ - strncpy(config->ApplicationId, "SYS", DLT_ID_SIZE); + config->ApplicationId = "SYS"; /* Shell */ config->Shell.Enable = 0; /* Syslog */ config->Syslog.Enable = 0; - strncpy(config->Syslog.ContextId, "SYSL", DLT_ID_SIZE); + config->Syslog.ContextId = "SYSL"; config->Syslog.Port = 47111; /* Journal */ config->Journal.Enable = 0; - strncpy(config->Journal.ContextId, "JOUR", DLT_ID_SIZE); + config->Journal.ContextId = "JOUR"; config->Journal.CurrentBoot = 1; config->Journal.Follow = 0; config->Journal.MapLogLevels = 1; - config->Journal.UseOriginalTimestamp = 1; /* File transfer */ config->Filetransfer.Enable = 0; - strncpy(config->Filetransfer.ContextId, "FILE", DLT_ID_SIZE); + config->Filetransfer.ContextId = "FILE"; + config->Filetransfer.TimeDelay = 10; config->Filetransfer.TimeStartup = 30; config->Filetransfer.TimeoutBetweenLogs = 10; config->Filetransfer.Count = 0; @@ -168,7 +168,7 @@ config->LogFile.Count = 0; for (i = 0; i < DLT_SYSTEM_LOG_FILE_MAX; i++) { - strncpy(config->LogFile.ContextId[i], "\0", DLT_ID_SIZE); + config->LogFile.ContextId[i] = NULL; config->LogFile.Filename[i] = NULL; config->LogFile.Mode[i] = 0; config->LogFile.TimeDelay[i] = 0; @@ -176,7 +176,7 @@ /* Log process */ config->LogProcesses.Enable = 0; - strncpy(config->LogProcesses.ContextId, "PROC", DLT_ID_SIZE); + config->LogProcesses.ContextId = "PROC"; config->LogProcesses.Count = 0; for (i = 0; i < DLT_SYSTEM_LOG_PROCESSES_MAX; i++) { @@ -239,7 +239,9 @@ if (token[0] && value[0]) { /* Common */ if (strcmp(token, "ApplicationId") == 0) { - strncpy(config->ApplicationId, value, DLT_ID_SIZE); + config->ApplicationId = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->ApplicationId); + strcpy(config->ApplicationId, value); /* strcpy unritical here, because size matches exactly the size to be copied */ } /* Shell */ @@ -255,7 +257,9 @@ } else if (strcmp(token, "SyslogContextId") == 0) { - strncpy(config->Syslog.ContextId, value, DLT_ID_SIZE); + config->Syslog.ContextId = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->Syslog.ContextId); + strcpy(config->Syslog.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */ } else if (strcmp(token, "SyslogPort") == 0) { @@ -269,7 +273,9 @@ } else if (strcmp(token, "JournalContextId") == 0) { - strncpy(config->Journal.ContextId, value, DLT_ID_SIZE); + config->Journal.ContextId = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->Journal.ContextId); + strcpy(config->Journal.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */ } else if (strcmp(token, "JournalCurrentBoot") == 0) { @@ -283,10 +289,6 @@ { config->Journal.MapLogLevels = atoi(value); } - else if (strcmp(token, "JournalUseOriginalTimestamp") == 0) - { - config->Journal.UseOriginalTimestamp = atoi(value); - } /* File transfer */ else if (strcmp(token, "FiletransferEnable") == 0) @@ -295,16 +297,28 @@ } else if (strcmp(token, "FiletransferContextId") == 0) { - strncpy(config->Filetransfer.ContextId, value, DLT_ID_SIZE); + config->Filetransfer.ContextId = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->Filetransfer.ContextId); + strcpy(config->Filetransfer.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */ } else if (strcmp(token, "FiletransferTimeStartup") == 0) { config->Filetransfer.TimeStartup = atoi(value); } + else if (strcmp(token, "FiletransferTimeDelay") == 0) + { + config->Filetransfer.TimeDelay = atoi(value); + } else if (strcmp(token, "FiletransferTimeoutBetweenLogs") == 0) { config->Filetransfer.TimeoutBetweenLogs = atoi(value); } + else if (strcmp(token, "FiletransferTempDir") == 0) + { + config->Filetransfer.TempDir = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->Filetransfer.TempDir); + strcpy(config->Filetransfer.TempDir, value); /* strcpy unritical here, because size matches exactly the size to be copied */ + } else if (strcmp(token, "FiletransferDirectory") == 0) { config->Filetransfer.Directory[config->Filetransfer.Count] = malloc(strlen(value) + 1); @@ -352,7 +366,9 @@ } else if (strcmp(token, "LogFileContextId") == 0) { - strncpy(config->LogFile.ContextId[config->LogFile.Count], value, DLT_ID_SIZE); + config->LogFile.ContextId[config->LogFile.Count] = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->LogFile.ContextId[config->LogFile.Count]); + strcpy(config->LogFile.ContextId[config->LogFile.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */ if (config->LogFile.Count < (DLT_SYSTEM_LOG_FILE_MAX - 1)) { config->LogFile.Count++; @@ -373,7 +389,9 @@ } else if (strcmp(token, "LogProcessesContextId") == 0) { - strncpy(config->LogProcesses.ContextId, value, DLT_ID_SIZE); + config->LogProcesses.ContextId = malloc(strlen(value) + 1); + MALLOC_ASSERT(config->LogProcesses.ContextId); + strcpy(config->LogProcesses.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */ } else if (strcmp(token, "LogProcessName") == 0) { @@ -415,48 +433,3 @@ free(line); return ret; } - -void cleanup_config(DltSystemConfiguration *config, DltSystemCliOptions *options) -{ - /* command line options */ - if ((options->ConfigurationFileName) != NULL) - { - free(options->ConfigurationFileName); - options->ConfigurationFileName = NULL; - } - - /* File transfer */ - for(int i = 0 ; i < DLT_SYSTEM_LOG_DIRS_MAX ; i++) - { - if ((config->Filetransfer.Directory[i]) != NULL) - { - free(config->Filetransfer.Directory[i]); - config->Filetransfer.Directory[i] = NULL; - } - } - - /* Log files */ - for(int i = 0 ; i < DLT_SYSTEM_LOG_FILE_MAX ; i++) - { - if ((config->LogFile.Filename[i]) != NULL) - { - free(config->LogFile.Filename[i]); - config->LogFile.Filename[i] = NULL; - } - } - - /* Log Processes */ - for(int i = 0 ; i < DLT_SYSTEM_LOG_PROCESSES_MAX ; i++) - { - if ((config->LogProcesses.Filename[i]) != NULL) - { - free(config->LogProcesses.Filename[i]); - config->LogProcesses.Filename[i] = NULL; - } - if ((config->LogProcesses.Name[i]) != NULL) - { - free(config->LogProcesses.Name[i]); - config->LogProcesses.Name[i] = NULL; - } - } -} diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-processes.c dlt-daemon-2.18.4/src/system/dlt-system-processes.c --- dlt-daemon-2.18.9/src/system/dlt-system-processes.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-processes.c 2019-09-03 08:28:13.000000000 +0000 @@ -44,6 +44,7 @@ *******************************************************************************/ +#include #include #include #include @@ -59,7 +60,7 @@ #define SEND_MODE_ONCE 1 #define SEND_MODE_ON 2 -int process_delays[DLT_SYSTEM_LOG_PROCESSES_MAX]; +extern DltSystemThreads threads; DLT_IMPORT_CONTEXT(dltsystem) DLT_DECLARE_CONTEXT(procContext) @@ -124,7 +125,7 @@ DLT_STRING("not running!")); } -void logprocess_init(void *v_conf) +void logprocess_thread(void *v_conf) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-processes, in thread.")); @@ -132,26 +133,39 @@ DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; DLT_REGISTER_CONTEXT(procContext, conf->LogProcesses.ContextId, "Log Processes"); - for (int i = 0; i < conf->LogProcesses.Count; i++) + int process_delays[DLT_SYSTEM_LOG_PROCESSES_MAX]; + int i; + + for (i = 0; i < conf->LogProcesses.Count; i++) process_delays[i] = conf->LogProcesses.TimeDelay[i]; -} -void logprocess_fd_handler(void *v_conf) -{ - DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; - for (int i = 0; i < conf->LogProcesses.Count; i++) { - if (conf->LogProcesses.Mode[i] == SEND_MODE_OFF) - continue; - - if (process_delays[i] <= 0) { - send_process(&(conf->LogProcesses), i); - process_delays[i] = conf->LogProcesses.TimeDelay[i]; + while (!threads.shutdown) { + sleep(1); - if (conf->LogProcesses.Mode[i] == SEND_MODE_ONCE) - conf->LogProcesses.Mode[i] = SEND_MODE_OFF; - } - else { - process_delays[i]--; + for (i = 0; i < conf->LogProcesses.Count; i++) { + if (conf->LogProcesses.Mode[i] == SEND_MODE_OFF) + continue; + + if (process_delays[i] <= 0) { + send_process(&(conf->LogProcesses), i); + process_delays[i] = conf->LogProcesses.TimeDelay[i]; + + if (conf->LogProcesses.Mode[i] == SEND_MODE_ONCE) + conf->LogProcesses.Mode[i] = SEND_MODE_OFF; + } + else { + process_delays[i]--; + } } } } + +void start_logprocess(DltSystemConfiguration *conf) +{ + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-processes, starting process log.")); + static pthread_attr_t t_attr; + static pthread_t pt; + pthread_create(&pt, &t_attr, (void *)logprocess_thread, conf); + threads.threads[threads.count++] = pt; +} diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-process-handling.c dlt-daemon-2.18.4/src/system/dlt-system-process-handling.c --- dlt-daemon-2.18.9/src/system/dlt-system-process-handling.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-process-handling.c 2019-09-03 08:28:13.000000000 +0000 @@ -50,26 +50,12 @@ #include #include #include +#include #include -#include -#include -#include -#include +volatile DltSystemThreads threads; DLT_IMPORT_CONTEXT(dltsystem) -DLT_IMPORT_CONTEXT(syslogContext) -DLT_IMPORT_CONTEXT(journalContext) -DLT_IMPORT_CONTEXT(watchdogContext) -DLT_IMPORT_CONTEXT(procContext) -DLT_IMPORT_CONTEXT(filetransferContext) -extern DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX]; - -volatile uint8_t quit = 0; - -#if defined(DLT_FILETRANSFER_ENABLE) -extern s_ft_inotify ino; -#endif int daemonize() { @@ -120,194 +106,73 @@ return 0; } -/* Unregisters all DLT Contexts and closes all file descriptors */ -void cleanup_processes(struct pollfd *pollfd, sd_journal *j, DltSystemConfiguration *config) +void start_threads(DltSystemConfiguration *config) { - //Syslog cleanup - if (config->Syslog.Enable) - DLT_UNREGISTER_CONTEXT(syslogContext); - - //Journal cleanup -#if defined(DLT_SYSTEMD_JOURNAL_ENABLE) - if (config->Journal.Enable) - DLT_UNREGISTER_CONTEXT(journalContext); - if(j != NULL) - sd_journal_close(j); -#endif + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-process-handling, start threads")); - //Logfile cleanup - if (config->LogFile.Enable) { - for (int i = 0; i < config->LogFile.Count; i++) - DLT_UNREGISTER_CONTEXT(logfileContext[i]); - } + int i; + threads.count = 0; + threads.shutdown = 0; - //LogProcess cleanup - if (config->LogProcesses.Enable) { - DLT_UNREGISTER_CONTEXT(procContext); - } + for (i = 0; i < MAX_THREADS; i++) + threads.threads[i] = 0; - //Watchdog cleanup #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) - DLT_UNREGISTER_CONTEXT(watchdogContext); -#endif - - //FileTransfer cleanup -#if defined(DLT_FILETRANSFER_ENABLE) - if (config->Filetransfer.Enable) { - DLT_UNREGISTER_CONTEXT(filetransferContext); - } + start_systemd_watchdog(config); #endif - for (int i = 0; i < MAX_FD_NUMBER; i++) { - if(pollfd[i].fd > 0) - close(pollfd[i].fd); - } -} - -/* Creates timer for LogFile and LogProcess, that need to be called every second. */ -int register_timer_fd(struct pollfd *pollfd, int fdcnt) -{ - struct itimerspec timerValue; - memset(&timerValue, '\0', sizeof(timerValue)); - timerValue.it_value.tv_sec = 1; - timerValue.it_value.tv_nsec = 0; - timerValue.it_interval.tv_sec = 1; - timerValue.it_interval.tv_nsec = 0; - - int timerfd = timerfd_create(CLOCK_MONOTONIC, 0); - if (timerfd < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Failed to create timer fd")); - return -1; - } - pollfd[fdcnt].fd = timerfd; - pollfd[fdcnt].events = POLLIN; - - if (timerfd_settime(timerfd, 0, &timerValue, NULL) < 0) { // init timer with 1 second - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not start timer")); - return -1; - } - return 0; -} - -/* Routine for executing LogProcess and LogFile, when timer expires */ -void timer_fd_handler(int fd, DltSystemConfiguration *config) -{ - uint64_t timersElapsed = 0ULL; - int r = read(fd, &timersElapsed, 8U); // only needed to reset fd event - if (r < 0) - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while reading timer fd: "), - DLT_STRING(strerror(r))); - - if(config->LogProcesses.Enable) - logprocess_fd_handler(config); - if(config->LogFile.Enable) - logfile_fd_handler(config); -} - -void start_dlt_system_processes(DltSystemConfiguration *config) -{ - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-process-handling, start threads")); - if (config->Shell.Enable) init_shell(); - int fdcnt = 0; + if (config->LogFile.Enable) + start_logfile(config); - /* Init FDs for all activated processes*/ - struct pollfd pollfd[MAX_FD_NUMBER]; // Holds all FDs and events - uint8_t fdType[MAX_FD_NUMBER]; // Holds corresponding enum for process identification - - for(int cnt = 0 ; cnt < MAX_FD_NUMBER ; cnt++) { - pollfd[cnt].fd = 0; - pollfd[cnt].events = 0; - } + if (config->Filetransfer.Enable) + start_filetransfer(config); - //init FD for LogFile and LogProcesses - if (config->LogProcesses.Enable || config->LogFile.Enable) { - fdType[fdcnt] = fdType_timer; - if (register_timer_fd(pollfd, fdcnt) == 0) { - if(config->LogProcesses.Enable) - logprocess_init(config); - if(config->LogFile.Enable) - logfile_init(config); - fdcnt++; - } - } + if (config->LogProcesses.Enable) + start_logprocess(config); - //init FD for Syslog - int syslogSock = 0; - if (config->Syslog.Enable) { - fdType[fdcnt] = fdType_syslog; - syslogSock = register_syslog_fd(pollfd, fdcnt, config); - fdcnt++; - } + if (config->Syslog.Enable) + start_syslog(config); - //init FD for Journal - sd_journal *j = NULL; #if defined(DLT_SYSTEMD_JOURNAL_ENABLE) - if (config->Journal.Enable) { - register_journal_fd(&j, pollfd, fdcnt, config); - fdType[fdcnt] = fdType_journal; - fdcnt++; - } -#endif - //init FD for FileTransfer -#if defined(DLT_FILETRANSFER_ENABLE) - if (config->Filetransfer.Enable) { - init_filetransfer_dirs(config); - pollfd[fdcnt].fd = ino.handle; - pollfd[fdcnt].events = POLLIN; - fdType[fdcnt] = fdType_filetransfer; - fdcnt++; - } -#endif + if (config->Journal.Enable) + start_systemd_journal(config); - //init FD for Watchdog -#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) - fdType[fdcnt] = fdType_watchdog; - register_watchdog_fd(pollfd, fdcnt); #endif +} - while (quit == 0) - { - int ready; - ready = poll(pollfd, MAX_FD_NUMBER, -1); - if (ready == -1 && quit == 0) - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while poll. Exit with: "), - DLT_STRING(strerror(ready))); - - for (int i = 0; i < MAX_FD_NUMBER; i++) { - if(pollfd[i].revents & POLLIN){ - if (fdType[i] == fdType_syslog && syslogSock > 0) { - syslog_fd_handler(syslogSock); - } - else if (fdType[i] == fdType_timer) { - timer_fd_handler(pollfd[i].fd, config); - } - #if defined(DLT_SYSTEMD_JOURNAL_ENABLE) - else if((fdType[i] == fdType_journal) && (j != NULL)) { - if(sd_journal_process(j) == SD_JOURNAL_APPEND) { - journal_fd_handler(j, config); - } - } - #endif - #if defined(DLT_FILETRANSFER_ENABLE) - else if (fdType[i] == fdType_filetransfer) { - filetransfer_fd_handler(config); - } - #endif - #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) - else if (fdType[i] == fdType_watchdog) { - watchdog_fd_handler(pollfd[i].fd); - } - #endif - } - } +/** + * Wait for threads to exit. + * There's not actually a condition currently + * to bail out of file transfer without a signal. + */ +void join_threads() +{ + int i; + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-process-handling, waiting for threads to exit.")); + + if (threads.count < 1) { + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-process-handling, no threads, waiting for signal.")); + sleep(UINT_MAX); } + else { + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-process-handling, thread count: "), + DLT_INT(threads.count)); - cleanup_processes(pollfd, j, config); + for (i = 0; i < threads.count; i++) { + pthread_join(threads.threads[i], NULL); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-process-handling, thread exit: "), + DLT_INT(threads.threads[i])); + } + } } void dlt_system_signal_handler(int sig) @@ -323,11 +188,12 @@ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-process-handling, exit, signal: "), DLT_INT(sig)); - quit = 1; + exit(0); break; default: DLT_LOG(dltsystem, DLT_LOG_WARN, DLT_STRING("dlt-system-process-handling, unknown signal!")); break; } -} \ No newline at end of file +} + diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-syslog.c dlt-daemon-2.18.4/src/system/dlt-system-syslog.c --- dlt-daemon-2.18.9/src/system/dlt-system-syslog.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-syslog.c 2019-09-03 08:28:13.000000000 +0000 @@ -44,17 +44,17 @@ *******************************************************************************/ +#include #include #include #include #include #include -#include -#include - #include "dlt-system.h" +extern DltSystemThreads threads; + DLT_IMPORT_CONTEXT(dltsystem) DLT_DECLARE_CONTEXT(syslogContext) #define RECV_BUF_SZ 1024 @@ -66,14 +66,11 @@ DLT_INT(opts.Port)); int sock = -1; + struct sockaddr_in syslog_addr; #ifdef DLT_USE_IPv6 - /* declare struct for IPv6 socket address*/ - struct sockaddr_in6 syslog_addr; sock = socket(AF_INET6, SOCK_DGRAM, 0); #else - /* declare struct for IPv4 socket address*/ - struct sockaddr_in syslog_addr; sock = socket(AF_INET, SOCK_DGRAM, 0); #endif @@ -83,25 +80,19 @@ return -1; } - /* initialize struct syslog_addr */ - memset(&syslog_addr, 0, sizeof(syslog_addr)); #ifdef DLT_USE_IPv6 - syslog_addr.sin6_family = AF_INET6; - syslog_addr.sin6_addr = in6addr_any; - syslog_addr.sin6_port = htons(opts.Port); + syslog_addr.sin_family = AF_INET6; #else syslog_addr.sin_family = AF_INET; - syslog_addr.sin_addr.s_addr = INADDR_ANY; +#endif syslog_addr.sin_port = htons(opts.Port); + syslog_addr.sin_addr.s_addr = INADDR_ANY; memset(&(syslog_addr.sin_zero), 0, 8); -#endif - /* bind the socket address to local interface */ if (bind(sock, (struct sockaddr *)&syslog_addr, - sizeof(syslog_addr)) == -1) { + sizeof(struct sockaddr)) == -1) { DLT_LOG(syslogContext, DLT_LOG_FATAL, - DLT_STRING("Unable to bind socket for SYSLOG, error description: "), - DLT_STRING(strerror(errno))); + DLT_STRING("Unable to bind socket for SYSLOG.")); close(sock); return -1; } @@ -134,27 +125,39 @@ recv_data[bytes_read] = '\0'; if (bytes_read != 0) - { DLT_LOG(syslogContext, DLT_LOG_INFO, DLT_STRING(recv_data)); - } return bytes_read; } -int register_syslog_fd(struct pollfd *pollfd, int i, DltSystemConfiguration *config) +void syslog_thread(void *v_conf) { - DLT_REGISTER_CONTEXT(syslogContext, config->Syslog.ContextId, "SYSLOG Adapter"); - int syslogSock = init_socket(config->Syslog); - if (syslogSock < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not init syslog socket\n")); - return -1; - } - pollfd[i].fd = syslogSock; - pollfd[i].events = POLLIN; - return syslogSock; + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-syslog, in thread.")); + + DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DLT_REGISTER_CONTEXT(syslogContext, conf->Syslog.ContextId, "SYSLOG Adapter"); + + int sock = init_socket(conf->Syslog); + + if (sock < 0) + return; + + while (!threads.shutdown) + if (read_socket(sock) < 0) { + close(sock); + return; + } + + close (sock); } -void syslog_fd_handler(int syslogSock) +void start_syslog(DltSystemConfiguration *conf) { - read_socket(syslogSock); -} \ No newline at end of file + DLT_LOG(dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-syslog, start syslog")); + static pthread_attr_t t_attr; + static pthread_t pt; + pthread_create(&pt, &t_attr, (void *)syslog_thread, conf); + threads.threads[threads.count++] = pt; +} diff -Nru dlt-daemon-2.18.9/src/system/dlt-system-watchdog.c dlt-daemon-2.18.4/src/system/dlt-system-watchdog.c --- dlt-daemon-2.18.9/src/system/dlt-system-watchdog.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/system/dlt-system-watchdog.c 2019-09-03 08:28:13.000000000 +0000 @@ -29,96 +29,148 @@ #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) #include #include -#include +#include #include #include "dlt.h" #include "dlt-system.h" -#include -#include + +#include "sd-daemon.h" + DLT_DECLARE_CONTEXT(watchdogContext) DLT_IMPORT_CONTEXT(dltsystem) -int calculate_period(struct itimerspec *itval) +extern DltSystemThreads threads; + +typedef struct +{ + int timer_fd; + unsigned long long wakeups_missed; +} PeriodicData; + +void wait_period (PeriodicData *info) +{ + unsigned long long missed; + + if (read (info->timer_fd, &missed, sizeof (missed)) < 0) + DLT_LOG(watchdogContext, DLT_LOG_ERROR, + DLT_STRING("Could not read from timer file descriptor in watchdog.\n")); + + if (missed > 0) + info->wakeups_missed += (missed - 1); +} + +int make_periodic(unsigned int period, PeriodicData *info) { unsigned int ns; unsigned int sec; - char str[512]; - char *watchdogUSec; - unsigned int watchdogTimeoutSeconds; - unsigned int notifiyPeriodNSec; - - watchdogUSec = getenv("WATCHDOG_USEC"); + int fd; + struct itimerspec itval; - if (watchdogUSec == NULL) { - DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("systemd watchdog timeout (WATCHDOG_USEC) is null\n")); - return -1; - } - - DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("watchdogusec: "), DLT_STRING(watchdogUSec)); - watchdogTimeoutSeconds = atoi(watchdogUSec); - - if (watchdogTimeoutSeconds <= 0) { - snprintf(str, 512, "systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds); - DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING(str)); + if (info == 0) { + DLT_LOG(watchdogContext, DLT_LOG_ERROR, + DLT_STRING("Invalid function parameters used for function make_periodic.\n")); return -1; } - /* Calculate half of WATCHDOG_USEC in ns for timer tick */ - notifiyPeriodNSec = watchdogTimeoutSeconds / 2; + /* Create the timer */ + fd = timerfd_create (CLOCK_MONOTONIC, 0); - snprintf(str, - 512, - "systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", - watchdogTimeoutSeconds, - notifiyPeriodNSec); - DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING(str)); + info->wakeups_missed = 0; + info->timer_fd = fd; + + if (fd == -1) { + DLT_LOG(watchdogContext, DLT_LOG_ERROR, + DLT_STRING("Can't create timer filedescriptor.\n")); + return -1; + } /* Make the timer periodic */ - sec = notifiyPeriodNSec / 1000000; - ns = (notifiyPeriodNSec - (sec * 1000000)) * 1000; - itval->it_interval.tv_sec = sec; - itval->it_interval.tv_nsec = ns; - itval->it_value.tv_sec = sec; - itval->it_value.tv_nsec = ns; + sec = period / 1000000; + ns = (period - (sec * 1000000)) * 1000; + itval.it_interval.tv_sec = sec; + itval.it_interval.tv_nsec = ns; + itval.it_value.tv_sec = sec; + itval.it_value.tv_nsec = ns; - return 0; + return timerfd_settime (fd, 0, &itval, NULL); } -int register_watchdog_fd(struct pollfd *pollfd, int fdcnt) + +void watchdog_thread(void *v_conf) { + char str[512]; + char *watchdogUSec; + unsigned int watchdogTimeoutSeconds; + unsigned int notifiyPeriodNSec; + PeriodicData info; + DLT_REGISTER_CONTEXT(watchdogContext, "DOG", "dlt system watchdog context."); - struct itimerspec timerValue; - if (calculate_period(&timerValue) != 0) - return -1; - int timerfd = timerfd_create(CLOCK_MONOTONIC, 0); - if (timerfd < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Failed to create timer fd\n")); - return -1; + sleep(1); + + DLT_LOG(watchdogContext, DLT_LOG_INFO, DLT_STRING("Watchdog thread started.\n")); + + if (v_conf == 0) { + DLT_LOG(watchdogContext, DLT_LOG_ERROR, + DLT_STRING("Invalid function parameters used for function watchdog_thread.\n")); + return; } - pollfd[fdcnt].fd = timerfd; - pollfd[fdcnt].events = POLLIN; - if (timerfd_settime(timerfd, 0, &timerValue, NULL) < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not start timer\n")); - return -1; + watchdogUSec = getenv("WATCHDOG_USEC"); + + if (watchdogUSec) { + DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("watchdogusec: "), DLT_STRING(watchdogUSec)); + + watchdogTimeoutSeconds = atoi(watchdogUSec); + + if (watchdogTimeoutSeconds > 0) { + + /* Calculate half of WATCHDOG_USEC in ns for timer tick */ + notifiyPeriodNSec = watchdogTimeoutSeconds / 2; + + snprintf(str, + 512, + "systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", + watchdogTimeoutSeconds, + notifiyPeriodNSec); + DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING(str)); + + if (make_periodic (notifiyPeriodNSec, &info) < 0) { + DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not initialize systemd watchdog timer\n")); + return; + } + + while (1) { + if (sd_notify(0, "WATCHDOG=1") < 0) + DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog\n")); + + DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("systemd watchdog waited periodic\n")); + + /* Wait for next period */ + wait_period(&info); + } + } + else { + snprintf(str, 512, "systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds); + DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING(str)); + } + } + else { + DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("systemd watchdog timeout (WATCHDOG_USEC) is null\n")); } - return 0; } -void watchdog_fd_handler(int fd) +void start_systemd_watchdog(DltSystemConfiguration *conf) { - uint64_t timersElapsed = 0ULL; - int r = read(fd, &timersElapsed, 8U); // only needed to reset fd event - if(r < 0) - DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog. Exit with: "), - DLT_STRING(strerror(r))); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Creating thread for systemd watchdog\n")); - if (sd_notify(0, "WATCHDOG=1") < 0) - DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog\n")); + static pthread_attr_t t_attr; + static pthread_t pt; - DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("systemd watchdog waited periodic\n")); + if (pthread_create(&pt, &t_attr, (void *)watchdog_thread, conf) == 0) + threads.threads[threads.count++] = pt; + else + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not create thread for systemd watchdog\n")); } #endif - diff -Nru dlt-daemon-2.18.9/src/tests/CMakeLists.txt dlt-daemon-2.18.4/src/tests/CMakeLists.txt --- dlt-daemon-2.18.9/src/tests/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -13,42 +13,36 @@ # For further information see http://www.genivi.org/. ####### -set(TARGET_LIST ${TARGET_LIST} dlt-test-multi-process) -set(TARGET_LIST ${TARGET_LIST} dlt-test-multi-process-client) -set(TARGET_LIST ${TARGET_LIST} dlt-test-user) -set(TARGET_LIST ${TARGET_LIST} dlt-test-client) -set(TARGET_LIST ${TARGET_LIST} dlt-test-stress-user) -set(TARGET_LIST ${TARGET_LIST} dlt-test-stress-client) -set(TARGET_LIST ${TARGET_LIST} dlt-test-stress) -set(TARGET_LIST ${TARGET_LIST} dlt-test-fork-handler) -set(TARGET_LIST ${TARGET_LIST} dlt-test-init-free) -set(TARGET_LIST ${TARGET_LIST} dlt-test-preregister-context) -set(TARGET_LIST ${TARGET_LIST} dlt-test-filetransfer) -install(FILES dlt-test-filetransfer-file dlt-test-filetransfer-image.png - DESTINATION share/dlt-filetransfer) - -if(WITH_DLT_CXX11_EXT) - set(TARGET_LIST ${TARGET_LIST} dlt-test-cpp-extension) -endif() - -#TODO: Enable again once dlt-test-non-verbose is adapted to non-macro usage -if (NOT WITH_DLT_DISABLE_MACRO) - set(TARGET_LIST ${TARGET_LIST} dlt-test-non-verbose) - if(WITH_DLT_CXX11_EXT) - set(TARGET_LIST ${TARGET_LIST} dlt-test-cpp-extension) - endif() -endif() +set(dlt-test-multi-process_SRCS dlt-test-multi-process.c) +set(dlt-test-multi-process-client_SRCS dlt-test-multi-process-client.c) +set(dlt-test-user_SRCS dlt-test-user.c) +set(dlt-test-client_SRCS dlt-test-client.c) +set(dlt-test-stress-user_SRCS dlt-test-stress-user.c) +set(dlt-test-stress-client_SRCS dlt-test-stress-client.c) +set(dlt-test-stress_SRCS dlt-test-stress.c) +set(dlt-test-filetransfer_SRCS dlt-test-filetransfer.c) +set(dlt-test-fork-handler_SRCS dlt-test-fork-handler.c) +set(dlt-test-init-free_SRCS dlt-test-init-free.c) -if(WITH_DLT_QNX_SYSTEM) - set(TARGET_LIST ${TARGET_LIST} dlt-test-qnx-slogger) -endif() - -foreach(TARGET IN LISTS TARGET_LIST) - set(TARGET_SRCS ${TARGET}) - add_executable(${TARGET} ${TARGET_SRCS}) - target_link_libraries(${TARGET} dlt) - set_target_properties(${TARGET} PROPERTIES LINKER_LANGUAGE C) - install(TARGETS ${TARGET} +foreach(target + dlt-test-multi-process + dlt-test-multi-process-client + dlt-test-user + dlt-test-client + dlt-test-stress-user + dlt-test-stress-client + dlt-test-stress + dlt-test-filetransfer + dlt-test-fork-handler + dlt-test-init-free + ) + add_executable(${target} ${${target}_SRCS}) + target_link_libraries(${target} dlt) + set_target_properties(${target} PROPERTIES LINKER_LANGUAGE C) + install(TARGETS ${target} RUNTIME DESTINATION bin COMPONENT base) endforeach() + +install(FILES dlt-test-filetransfer-file dlt-test-filetransfer-image.png + DESTINATION share/dlt-filetransfer) diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-client.c dlt-daemon-2.18.4/src/tests/dlt-test-client.c --- dlt-daemon-2.18.9/src/tests/dlt-test-client.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-client.c 2019-09-03 08:28:13.000000000 +0000 @@ -68,11 +68,10 @@ #include /* for isprint() */ #include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ #include /* for strcmp() */ #include /* for writev() */ -#include -#include -#include #include "dlt_client.h" #include "dlt_protocol.h" @@ -87,7 +86,6 @@ DltClient g_dltclient; /* Function prototypes */ int dlt_testclient_message_callback(DltMessage *message, void *data); -bool dlt_testclient_fetch_next_message_callback(void *data); typedef struct { @@ -102,8 +100,6 @@ char *tvalue; char *evalue; int bvalue; - int sendSerialHeaderFlag; - int resyncSerialHeaderFlag; char ecuid[4]; int ohandle; @@ -120,7 +116,6 @@ int tests_failed; int sock; - int max_messages; } DltTestclientData; /** @@ -142,14 +137,11 @@ printf(" -s Print DLT messages; only headers\n"); printf(" -v Verbose mode\n"); printf(" -h Usage\n"); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode\n"); printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); printf(" -e ecuid Set ECU ID (Default: ECU1)\n"); printf(" -o filename Output messages in new DLT file\n"); printf(" -f filename Enable filtering of messages\n"); - printf(" -z max msgs Print z DLT messages\n"); } /** @@ -172,12 +164,9 @@ dltdata.fvalue = 0; dltdata.evalue = 0; dltdata.bvalue = 0; - dltdata.sendSerialHeaderFlag = 0; - dltdata.resyncSerialHeaderFlag = 0; dltdata.ohandle = -1; dltdata.running_test = 0; - dltdata.max_messages = INT_MIN; for (i = 0; i < DLT_TESTCLIENT_NUM_TESTS; i++) { dltdata.test_counter_macro[i] = 0; @@ -192,7 +181,7 @@ /* Fetch command line arguments */ opterr = 0; - while ((c = getopt (argc, argv, "vashSRyxmf:o:e:b:z:")) != -1) + while ((c = getopt (argc, argv, "vashyxmf:o:e:b:")) != -1) switch (c) { case 'v': { @@ -224,16 +213,6 @@ usage(); return -1; } - case 'S': - { - dltdata.sendSerialHeaderFlag = 1; - break; - } - case 'R': - { - dltdata.resyncSerialHeaderFlag = 1; - break; - } case 'y': { dltdata.yflag = 1; @@ -259,11 +238,6 @@ dltdata.bvalue = atoi(optarg); break; } - case 'z': - { - dltdata.max_messages = atoi(optarg); - break; - } case '?': { if ((optopt == 'o') || (optopt == 'f') || (optopt == 't')) @@ -290,9 +264,6 @@ /* Register callback to be called when message was received */ dlt_client_register_message_callback(dlt_testclient_message_callback); - /* Register callback to be called if next message needs to be fetched */ - dlt_client_register_fetch_next_message_callback(dlt_testclient_fetch_next_message_callback); - /* Setup DLT Client structure */ g_dltclient.mode = dltdata.yflag; @@ -332,10 +303,6 @@ dlt_client_setbaudrate(&g_dltclient, dltdata.bvalue); } - /* Update the send and resync serial header flags based on command line option */ - g_dltclient.send_serial_header = dltdata.sendSerialHeaderFlag; - g_dltclient.resync_serial_header = dltdata.resyncSerialHeaderFlag; - /* initialise structure to use DLT file */ dlt_file_init(&(dltdata.file), dltdata.vflag); @@ -389,21 +356,6 @@ return g_testsFailed == 0 ? 0 : 1; } -bool dlt_testclient_fetch_next_message_callback(void *data) -{ - if (data == 0) - return true; - - DltTestclientData *dltdata = (DltTestclientData *)data; - if (dltdata->max_messages > INT_MIN) - { - dltdata->max_messages--; - if (dltdata->max_messages <= 0) - return false; - } - return true; -} - int dlt_testclient_message_callback(DltMessage *message, void *data) { static char text[DLT_TESTCLIENT_TEXTBUFSIZE]; @@ -526,7 +478,7 @@ length = 0; /* the macro can set this variable to -1 */ length_tmp = 0; ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* Log message */ if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin)) == DLT_TYPE_LOG) { @@ -714,7 +666,7 @@ id = 0; id_tmp = 0; ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; slen = -1; tc_old = dltdata->test_counter_macro[2]; @@ -724,7 +676,7 @@ id = DLT_ENDIAN_GET_32(message->standardheader->htyp, id_tmp); /* Length of string */ - datalength -= (int32_t) sizeof(uint16_t); + datalength -= sizeof(uint16_t); ptr += sizeof(uint16_t); switch (id) { @@ -900,7 +852,7 @@ slen = strlen("raw") + 1; datalength -= slen; ptr += slen; - datalength -= (int32_t) sizeof(uint16_t); + datalength -= sizeof(uint16_t); ptr += sizeof(uint16_t); if (datalength == 10) @@ -951,7 +903,7 @@ length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* first read the type info of the first argument: must be string */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -1030,7 +982,7 @@ if (strcmp(text, "Next line: DLT_LOG_RAW") == 0) dltdata->test_counter_macro[4]++; - if (strcmp(text, "00\'01\'02\'03\'04\'05\'06\'07\'08\'09\'0a\'0b\'0c\'0d\'0e\'0f") == 0) + if (strcmp(text, "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f") == 0) dltdata->test_counter_macro[4]++; if (strcmp(text, "Next line: DLT_LOG_STRING_INT") == 0) @@ -1126,7 +1078,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* first read the type info of the first argument: must be string */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -1209,7 +1161,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); type_info = DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp); @@ -1219,7 +1171,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_TRUNCATED) == 0) dltdata->test_counter_macro[7]++; @@ -1231,7 +1183,7 @@ char hdr[2048]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(hdr, ptr, datalength, (int)sizeof(hdr), length); + DLT_MSG_READ_STRING(hdr, ptr, datalength, length); if ((length == 16) && (hdr[15] == 15)) dltdata->test_counter_macro[7]++; @@ -1314,7 +1266,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* NWST */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -1324,7 +1276,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_START) == 0) dltdata->test_counter_macro[8]++; @@ -1411,7 +1363,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* NWCH */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -1421,7 +1373,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_SEGMENT) == 0) dltdata->test_counter_macro[8]++; @@ -1473,7 +1425,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* NWEN */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -1483,7 +1435,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_END) == 0) dltdata->test_counter_macro[8]++; @@ -1581,7 +1533,7 @@ length = 0; length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* Log message */ if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin)) == DLT_TYPE_LOG) { @@ -1759,7 +1711,7 @@ id = 0; id_tmp = 0; ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; slen = -1; tc_old = dltdata->test_counter_function[2]; @@ -1974,7 +1926,7 @@ length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* first read the type info of the first argument: should be string */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -2053,7 +2005,7 @@ if (strcmp(text, "Next line: dlt_log_raw()") == 0) dltdata->test_counter_function[4]++; - if (strcmp(text, "00\'01\'02\'03\'04\'05\'06\'07\'08\'09\'0a\'0b\'0c\'0d\'0e\'0f") == 0) + if (strcmp(text, "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f") == 0) dltdata->test_counter_function[4]++; if (strcmp(text, "Next line: dlt_log_string_int()") == 0) @@ -2150,7 +2102,7 @@ length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* first read the type info of the first argument: should be string */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -2233,7 +2185,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); type_info = DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp); @@ -2243,7 +2195,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_TRUNCATED) == 0) dltdata->test_counter_function[7]++; @@ -2255,7 +2207,7 @@ char hdr[2048]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(hdr, ptr, datalength, (int)sizeof(hdr), length); + DLT_MSG_READ_STRING(hdr, ptr, datalength, length); if ((length == 16) && (hdr[15] == 15)) dltdata->test_counter_function[7]++; @@ -2338,7 +2290,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* NWST */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -2348,7 +2300,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_START) == 0) dltdata->test_counter_function[8]++; @@ -2435,7 +2387,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* NWCH */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -2445,7 +2397,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_SEGMENT) == 0) dltdata->test_counter_function[8]++; @@ -2497,7 +2449,7 @@ length = 0, length_tmp = 0; /* the macro can set this variable to -1 */ ptr = message->databuffer; - datalength = (int32_t) message->datasize; + datalength = message->datasize; /* NWEN */ DLT_MSG_READ_VALUE(type_info_tmp, ptr, datalength, uint32_t); @@ -2507,7 +2459,7 @@ char chdr[10]; DLT_MSG_READ_VALUE(length_tmp, ptr, datalength, uint16_t); length = DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - DLT_MSG_READ_STRING(chdr, ptr, datalength, (int)sizeof(chdr), length); + DLT_MSG_READ_STRING(chdr, ptr, datalength, length); if (strcmp((char *)chdr, DLT_TRACE_NW_END) == 0) dltdata->test_counter_function[8]++; @@ -2560,7 +2512,7 @@ iov[1].iov_base = message->databuffer; iov[1].iov_len = message->datasize; - bytes_written = (int) writev(dltdata->ohandle, iov, 2); + bytes_written = writev(dltdata->ohandle, iov, 2); if (0 > bytes_written) { printf("dlt_testclient_message_callback, error in: writev(dltdata->ohandle, iov, 2)\n"); diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-cpp-extension.cpp dlt-daemon-2.18.4/src/tests/dlt-test-cpp-extension.cpp --- dlt-daemon-2.18.9/src/tests/dlt-test-cpp-extension.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-cpp-extension.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,119 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2015 Intel Corporation - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -/*! - * \author Stefan Vacek Intel Corporation - * - * \copyright Copyright © 2015 Intel Corporation. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - * \file dlt-test-cpp-extension.cpp - */ - -#include "dlt_cpp_extension.hpp" -#include -#include -#include -#include "dlt_user_macros.h" - -struct MyStruct -{ - int64_t uuid; - int32_t interfaceId; - int32_t registrationState; -}; - -template<> -inline int logToDlt(DltContextData &log, MyStruct const &value) -{ - int result = 0; - - result += dlt_user_log_write_string(&log, "("); - result += logToDlt(log, value.uuid); - result += dlt_user_log_write_string(&log, ","); - result += logToDlt(log, value.interfaceId); - result += dlt_user_log_write_string(&log, ","); - result += logToDlt(log, value.registrationState); - result += dlt_user_log_write_string(&log, ")"); - - if (result != 0) - result = -1; - - return result; -} - -/** - * Sample code to show usage of the cpp-extension - * mainly the variadic templates - */ -int main() -{ - if (dlt_register_app("TCPP", "Test cpp extension") < 0) { - printf("Failed to register application\n"); - return -1; - } - - DltContext ctx; - - if (dlt_register_context_ll_ts(&ctx, "TCPP", "Test cpp extension", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF) < 0) { - printf("Failed to register context\n"); - return -1; - } - - dlt_enable_local_print(); - dlt_verbose_mode(); - - DLT_LOG(ctx, DLT_LOG_WARN, DLT_STRING("a message")); /* the classic way to go */ - - int an_int = 42; - float a_float = 22.7; - DLT_LOG_FCN_CXX(ctx, DLT_LOG_WARN, "Testing DLT_LOG_CXX_FCN", an_int, a_float); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, 1.0, 65); - - /* Example for logging user-defined types */ - MyStruct myData = { 1u, 2u, 3u }; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "MyStruct myData", myData); - - char *non_const_string = (char *)malloc(17); - memcpy(non_const_string, "non_const_string", 16); - non_const_string[16] = 0; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "char *", non_const_string); - - std::string aString = "std::string"; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "std::string", aString); - - std::vector intVector; - intVector.push_back(0); - intVector.push_back(1); - intVector.push_back(2); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector); - - std::vector doubleList; - doubleList.push_back(10.); - doubleList.push_back(11.); - doubleList.push_back(12.); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList); - - std::map testMap; - testMap["apple"] = 100; - testMap["plum"] = 200; - testMap["orange"] = 300; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "map", testMap); - - dlt_unregister_context(&ctx); - dlt_unregister_app(); - - return 0; -} diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-fork-handler.c dlt-daemon-2.18.4/src/tests/dlt-test-fork-handler.c --- dlt-daemon-2.18.9/src/tests/dlt-test-fork-handler.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-fork-handler.c 2019-09-03 08:28:13.000000000 +0000 @@ -28,24 +28,6 @@ #include "dlt.h" -void dlt_log_message(DltContext *context, DltLogLevelType ll, char *text, int32_t num) -{ - DltContextData contextData; - - if (text == NULL) - return; - - if (dlt_user_log_write_start(context, &contextData, ll) > 0) { - dlt_user_log_write_string(&contextData, text); - if (num > 0) { - dlt_user_log_write_int32(&contextData, num); - } - dlt_user_log_write_finish(&contextData); - } - - return; -} - /** * @brief sample code for using at_fork-handler */ @@ -57,22 +39,22 @@ timeout.tv_sec = 0; timeout.tv_nsec = 200000000L; - dlt_register_app("PRNT", "Parent application"); - dlt_register_context(&mainContext, "CTXP", "Parent context"); - dlt_log_message(&mainContext, DLT_LOG_WARN, "First message before fork", 0); + DLT_REGISTER_APP("PRNT", "Parent application"); + DLT_REGISTER_CONTEXT(mainContext, "CTXP", "Parent context"); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before fork")); nanosleep(&timeout, &r); pid_t pid = fork(); if (pid == 0) { /* child process */ /* this message should not be visible */ - dlt_log_message(&mainContext, DLT_LOG_WARN, "Child's first message after fork, pid: ", getpid()); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's first message after fork, pid: "), DLT_INT32(getpid())); /* this will not register CHLD application */ - dlt_register_app("CHLD", "Child application"); + DLT_REGISTER_APP("CHLD", "Child application"); /* this will not register CTXC context */ - dlt_register_context(&mainContext, "CTXC", "Child context"); + DLT_REGISTER_CONTEXT(mainContext, "CTXC", "Child context"); /* this will not log a message */ - dlt_log_message(&mainContext, DLT_LOG_WARN, "Child's second message after fork, pid: ", getpid()); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's second message after fork, pid: "), DLT_INT32(getpid())); nanosleep(&timeout, &r); if (execlp("dlt-example-user", "dlt-example-user", "-n 1", "you should see this message", NULL)) @@ -83,11 +65,12 @@ return -1; } else { /* parent */ - dlt_log_message(&mainContext, DLT_LOG_WARN, "Parent's first message after fork, pid: ", getpid()); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Parent's first message after fork, pid: "), DLT_INT32(getpid())); nanosleep(&timeout, &r); } - dlt_unregister_app(); + DLT_UNREGISTER_APP() + ; return 0; } diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-init-free.c dlt-daemon-2.18.4/src/tests/dlt-test-init-free.c --- dlt-daemon-2.18.9/src/tests/dlt-test-init-free.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-init-free.c 2019-09-03 08:28:13.000000000 +0000 @@ -32,7 +32,7 @@ void exec(const char *cmd, char *buffer, size_t length); void printMemoryUsage(); -char *occupyMemory(int size); +char *occupyMemory(uint size); void do_example_test(); void do_dlt_test(); @@ -41,7 +41,7 @@ int main(int argc, char **argv) { if (argc > 1) - num_repetitions = (int) strtol(argv[1], 0, 10); + num_repetitions = strtol(argv[1], 0, 10); else num_repetitions = 1000; @@ -113,7 +113,7 @@ if ((pipe = popen(cmd, "r")) == NULL) return; - while (fgets(buffer, (int) length, pipe) != NULL); + while (fgets(buffer, length, pipe) != NULL); if (pipe != NULL) pclose(pipe); @@ -131,7 +131,7 @@ printf("%s", result); } -char *occupyMemory(int size) +char *occupyMemory(uint size) { char *buf = (char *)malloc(size * sizeof(char)); diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-multi-process.c dlt-daemon-2.18.4/src/tests/dlt-test-multi-process.c --- dlt-daemon-2.18.9/src/tests/dlt-test-multi-process.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-multi-process.c 2019-09-03 08:28:13.000000000 +0000 @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -53,7 +52,6 @@ #include #include #include -#include #include "dlt.h" #include "dlt_common.h" @@ -62,7 +60,6 @@ /* Constants */ #define MAX_PROCS 100 #define MAX_THREADS 100 -#define MAX_LOG_LENGTH 1024 #ifndef WAIT_ANY # define WAIT_ANY -1 @@ -73,7 +70,6 @@ int nmsgs; /* Number of messages to send */ int nprocs; /* Number of processes to start */ int nthreads; /* Number of threads to start */ - int nloglength; /* Length of Log message */ int delay; /* Delay between logs messages for each process */ int delay_fudge; /* Fudge the delay by 0-n to cause desynchronization */ bool generate_ctid; /* true: To generate context Id from App Id + Thread Number */ @@ -119,7 +115,6 @@ printf(" -m number Number of messages per thread to send. (%d)\n", defaults.nmsgs); printf(" -p number Number of processes to start. (%d), Max %d.\n", defaults.nprocs, MAX_PROCS); printf(" -t number Number of threads per process. (%d), Max %d.\n", defaults.nthreads, MAX_THREADS); - printf(" -l number Length of log message. (%d)\n", defaults.nloglength); printf(" -d delay Delay in milliseconds to wait between log messages. (%d)\n", defaults.delay); printf(" -f delay Random fudge in milliseconds to add to delay. (%d)\n", defaults.delay_fudge); printf(" -g Generate Context IDs from Application ID and thread number \n"); @@ -133,7 +128,6 @@ params->nmsgs = 100; params->nprocs = 10; params->nthreads = 2; - params->nloglength = 40; params->delay = 1000; params->delay_fudge = 100; params->generate_ctid = false; @@ -147,7 +141,7 @@ int c; opterr = 0; - while ((c = getopt (argc, argv, "m:p:t:l:d:f:g")) != -1) + while ((c = getopt (argc, argv, "m:p:t:d:f:g")) != -1) switch (c) { case 'm': params->nmsgs = atoi(optarg); @@ -164,21 +158,12 @@ case 't': params->nthreads = atoi(optarg); - if (params->nthreads > MAX_THREADS) { + if (params->nprocs > MAX_PROCS) { fprintf(stderr, "Too many threads selected.\n"); return -1; } break; - case 'l': - params->nloglength = atoi(optarg); - - if(params->nloglength > MAX_LOG_LENGTH) { - fprintf(stderr, "Too long log message selected.\n"); - return -1; - } - - break; case 'd': params->delay = atoi(optarg); break; @@ -190,7 +175,7 @@ break; case '?': - if ((optopt == 'l') || (optopt == 'd') || (optopt == 'f')) + if ((optopt == 'n') || (optopt == 'd') || (optopt == 'f')) fprintf(stderr, "Option -%c requires an argument.\n", optopt); else if (isprint(optopt)) fprintf(stderr, "Unknown option '-%c'.\n", optopt); @@ -325,14 +310,10 @@ void do_logging(s_thread_data *data) { DltContext mycontext; - DltContextData mycontextdata; char ctid[5]; char ctid_name[256]; struct timespec ts; time_t sleep_time; - int i = 0; - int n = 0; - char *logmsg = NULL; if(data->params.generate_ctid) snprintf(ctid, 5, "%02u%02u", data->pidcount, data->tidcount); @@ -341,44 +322,18 @@ snprintf(ctid_name, 256, "Child %s in dlt-test-multi-process", ctid); - dlt_register_context(&mycontext, ctid, ctid_name); + DLT_REGISTER_CONTEXT(mycontext, ctid, ctid_name); int msgs_left = data->params.nmsgs; - logmsg = calloc(1, (size_t) (data->params.nloglength + 1)); - if (logmsg == NULL) { - printf("Error allocate memory for message.\n"); - dlt_unregister_context(&mycontext); - abort(); - } - - for(i = 0; i < data->params.nloglength; i++) { - n = 'A' + i; - if(n > 90) - { - n = 'A' + (n - 91) % 26; - } - logmsg[i] = (char) n; - } - while (msgs_left-- > 0) { - if (dlt_user_log_write_start(&mycontext, &mycontextdata, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&mycontextdata, logmsg); - dlt_user_log_write_finish(&mycontextdata); - } - + DLT_LOG(mycontext, DLT_LOG_INFO, DLT_STRING(PAYLOAD_DATA)); sleep_time = mksleep_time(data->params.delay, data->params.delay_fudge); ts.tv_sec = sleep_time / 1000000000; ts.tv_nsec = sleep_time % 1000000000; nanosleep(&ts, NULL); } - - if (logmsg) { - free(logmsg); - logmsg = NULL; - } - - dlt_unregister_context(&mycontext); + DLT_UNREGISTER_CONTEXT(mycontext); } /** @@ -392,21 +347,21 @@ char apid_name[256]; int i; - srand((unsigned int) getpid()); + srand(getpid()); snprintf(apid, 5, "MT%02u", pidcount); snprintf(apid_name, 256, "Apps %s.", apid); - dlt_register_app(apid, apid_name); + DLT_REGISTER_APP(apid, apid_name); - thread_data = calloc( (size_t) params.nthreads, sizeof(s_thread_data)); + thread_data = calloc(params.nthreads, sizeof(s_thread_data)); if (thread_data == NULL) { printf("Error allocate memory for thread data.\n"); abort(); } for (i = 0; i < params.nthreads; i++) { - thread_data[i].tidcount = (unsigned int) i; + thread_data[i].tidcount = i; thread_data[i].params = params; thread_data[i].pidcount = pidcount; @@ -422,7 +377,7 @@ if(thread_data) free(thread_data); - dlt_unregister_app(); + DLT_UNREGISTER_APP(); /* We can exit now */ exit(0); } @@ -432,7 +387,7 @@ */ int wait_for_death() { - int pids_left = (int) pidcount; + int pids_left = pidcount; while (pids_left > 0) { int status; diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-multi-process-client.c dlt-daemon-2.18.4/src/tests/dlt-test-multi-process-client.c --- dlt-daemon-2.18.9/src/tests/dlt-test-multi-process-client.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-multi-process-client.c 2019-09-03 08:28:13.000000000 +0000 @@ -45,11 +45,12 @@ #include #include #include -#include #include #include #include +#include #include +#include /* DLT Library includes */ #include "dlt_client.h" @@ -67,8 +68,6 @@ char *output; int output_handle; int messages_left; - int sendSerialHeaderFlag; - int resyncSerialHeaderFlag; DltClient *client_ref; } s_parameters; @@ -96,8 +95,6 @@ printf("%s", version); printf("Options:\n"); printf(" -m Total messages to receive. (Default: 10000)\n"); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode.\n"); printf(" -b baudrate Serial device baudrate. (Default: 115200)\n"); printf(" -v Verbose. Increases the verbosity level of dlt client library.\n"); @@ -115,8 +112,6 @@ params->output = NULL; params->output_handle = -1; params->baudrate = 115200; - params->sendSerialHeaderFlag = 0; - params->resyncSerialHeaderFlag = 0; } /** @@ -128,21 +123,11 @@ int c; opterr = 0; - while ((c = getopt(argc, argv, "m:yb:vo:SR")) != -1) + while ((c = getopt(argc, argv, "m:yb:vo:")) != -1) switch (c) { case 'm': params->max_messages = atoi(optarg); break; - case 'S': - { - params->sendSerialHeaderFlag = 1; - break; - } - case 'R': - { - params->resyncSerialHeaderFlag = 1; - break; - } case 'y': params->serial = 1; break; @@ -221,10 +206,6 @@ dlt_client_init(&client, params.verbose); dlt_client_register_message_callback(receive); - /* Update the send and resync serial header flags based on command line option */ - client.send_serial_header = params.sendSerialHeaderFlag; - client.resync_serial_header = params.resyncSerialHeaderFlag; - err = init_dlt_connect(&client, ¶ms, argc, argv); if (err != 0) { @@ -289,7 +270,7 @@ } fflush(stdout); - last_print_time = (int) time(NULL); + last_print_time = time(NULL); } /** * Callback for dlt client @@ -312,15 +293,15 @@ if (stats.first_message_time == 0) stats.first_message_time = time(NULL); - int buflen = (int) msg->datasize + 1; - char *buf = malloc((size_t) buflen); + int buflen = msg->datasize + 1; + char *buf = malloc(buflen); if (buf == 0) { printf("Out of memory\n"); return -1; } - memset(buf, 0, (size_t) buflen); + memset(buf, 0, buflen); dlt_message_payload(msg, buf, buflen - 1, DLT_OUTPUT_ASCII, 0); @@ -341,7 +322,7 @@ iov[1].iov_base = msg->databuffer; iov[1].iov_len = msg->datasize; - stats.output_bytes += (int) writev(params->output_handle, iov, 2); + stats.output_bytes += writev(params->output_handle, iov, 2); } if (params->messages_left < 1) diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-multi-process.h dlt-daemon-2.18.4/src/tests/dlt-test-multi-process.h --- dlt-daemon-2.18.9/src/tests/dlt-test-multi-process.h 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-multi-process.h 2019-09-03 08:28:13.000000000 +0000 @@ -27,7 +27,7 @@ #define DLT_TEST_MULTI_PROCESS_H_ #define DMPT_NAME "DMPT" -#define PAYLOAD_DATA "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN" +#define PAYLOAD_DATA "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBM1234567890" #define ECUID "ECU1" #endif /* DLT_TEST_MULTI_PROCESS_H_ */ diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-non-verbose.c dlt-daemon-2.18.4/src/tests/dlt-test-non-verbose.c --- dlt-daemon-2.18.9/src/tests/dlt-test-non-verbose.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-non-verbose.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,501 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2015 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -/*! - *author - * Onkar Palkar - * - *copyright Copyright © 2015 Advanced Driver Information Technology. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - *file dlt-test-non-verbose.c - */ - -#include -#include -#include -#include -#include - -#include "dlt.h" - -/* data for real life message test */ -#define DLT_COMMON_BUFFER_LENGTH 255 -#define MAXSTRLEN 1024 -#define DLT_MODULE_ID 0x0154 -#define DLT_MSG_ID_1 0x0032 -#define DLT_MSG_ID_2 0x0033 -#define DLT_MSG_ID_3 0x0009 -#define DLT_MSG_ID_4 0x000c -#define DLT_MSG_ID_5 0x0004 -#define DLT_MSG_ID_6 0x0009 - -#define LOG_DELAY 200 * 1000 -#define NUM_LOG_MSGS 10 - -#define DEFAULT_WAIT_TIMEOUT 1000 - -DLT_DECLARE_CONTEXT(context_info) -DLT_DECLARE_CONTEXT(context_log); -DLT_DECLARE_CONTEXT(context_macro_test) -DltContext context_function_test; - -DltContextData context_data; - -void dlt_user_log_level_changed_callback(char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status); - -void usage() -{ - char version[DLT_COMMON_BUFFER_LENGTH]; - - dlt_get_version(version, DLT_COMMON_BUFFER_LENGTH); - - printf("Usage: dlt-test-non-verbose [options]\n"); - printf("Test user application providing several Tests.\n"); - printf("%s\n", version); - printf("Options:\n"); - printf(" -a run all tests \n"); - printf(" -i test all types (macro interface and functional interface)\n"); - printf(" -l message for log storage test\n"); - printf(" -r real data\n"); - printf(" -o Log level test \n"); - printf(" -h this help\n"); - printf("\nTests:\n"); - printf(" 01: (Macro IF) Test all variable types (non-verbose)\n"); - printf(" 02: (Function IF) Test all variable types (non-verbose)\n"); - printf(" 03: Test Logstorage messages (non-verbose)\n"); - printf(" 04: Test real life messages (non-verbose)\n"); -} - -/******************/ -/* The test cases */ -/******************/ -int test_logstorage() -{ - int delay = LOG_DELAY; - int i; - - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test Logstorage messages")); - - printf("Test01: Sending log messages with level :\n"); - printf(" FATAL\n"); - printf(" ERROR\n"); - printf(" WARN\n"); - - printf("Test01: Check DLT viewer\n"); - printf("Test01: Log messages with FATAL," - "ERROR should be seen\n"); - printf("Test01: Connect USB to TARGET\n"); - - for(i = 1 ; i <= NUM_LOG_MSGS ; i++) - { - printf("Send log message %d\n", i); - DLT_LOG_ID(context_log,DLT_LOG_FATAL, 1000, - DLT_CSTRING("DLT Log Storage Test"), DLT_INT(i)); - DLT_LOG_ID(context_log,DLT_LOG_ERROR, 1001, - DLT_CSTRING("DLT Log Storage Test"), DLT_INT(i)); - DLT_LOG_ID(context_log,DLT_LOG_WARN, 1002, - DLT_CSTRING("DLT Log Storage Test"), DLT_INT(i)); - - usleep(delay); - } - - printf("Test01: Remove USB from TARGET\n"); - printf("Test01: Open log file stored in USB using DLT viewer\n"); - - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test Logstorage messages finished")); - - return 0; -} - -int test_loglevel(int wait_duration) -{ - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test log level")); - - sleep(wait_duration); - return 0; -} - -int test_macro_interface(void) -{ - char buffer[10]; - int num2; - - printf("Test02: (Macro IF) Test all variable types (non-verbose)\n"); - - DLT_LOG(context_info, DLT_LOG_INFO,DLT_STRING - ("Test02: (Macro IF) Test all variable types (non-verbose)")); - - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 1, - DLT_STRING("string"), DLT_STRING("Hello world")); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 2, - DLT_STRING("utf8"), DLT_UTF8("Hello world")); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 3, - DLT_STRING("bool"), DLT_BOOL(1)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 4, - DLT_STRING("int"), DLT_INT(INT32_MIN)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 5, - DLT_STRING("int8"), DLT_INT8(INT8_MIN)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 6, - DLT_STRING("int16"), DLT_INT16(INT16_MIN)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 7, - DLT_STRING("int32"), DLT_INT32(INT32_MIN)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 8, - DLT_STRING("int64"), DLT_INT64(INT64_MIN)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 9, - DLT_STRING("uint"), DLT_UINT(UINT32_MAX)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 10, - DLT_STRING("uint8"), DLT_UINT8(UINT8_MAX)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 11, - DLT_STRING("uint16"), DLT_UINT16(UINT16_MAX)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 12, - DLT_STRING("uint32"), DLT_UINT32(UINT32_MAX)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 13, - DLT_STRING("uint64"), DLT_UINT64(UINT64_MAX)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 14, DLT_STRING("float32"), - DLT_FLOAT32(FLT_MIN), DLT_FLOAT32(FLT_MAX)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 15, DLT_STRING("float64"), - DLT_FLOAT64(DBL_MIN), DLT_FLOAT64(DBL_MAX)); - - for(num2 = 0 ; num2 < 10 ; num2++) - { - buffer[num2] = (char) num2; - } - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, 14, - DLT_STRING("raw"), DLT_RAW(buffer, 10)); - - sleep(2); - DLT_LOG(context_info, DLT_LOG_INFO, - DLT_STRING("Test02: (Macro IF) finished")); - - return 0; -} - -int test_function_interface(void) -{ - char buffer[10]; - int num2; - - printf("Test03: (Function IF) Test all variable types (non-verbose)\n"); - if (dlt_user_log_write_start(&context_info, - &context_data,DLT_LOG_INFO) > 0) - { - dlt_user_log_write_string(&context_data, - "Test03: (Function IF) Test all variable types (non-verbose)"); - dlt_user_log_write_finish(&context_data); - } - - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data,DLT_LOG_INFO, 1) > 0) - { - dlt_user_log_write_string(&context_data, "bool"); - dlt_user_log_write_bool(&context_data, 1); - dlt_user_log_write_finish(&context_data); - } - - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 2) > 0) - { - dlt_user_log_write_string(&context_data, "int"); - dlt_user_log_write_int(&context_data, INT32_MIN);/* (-2147483647-1) */ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 3) > 0) - { - dlt_user_log_write_string(&context_data, "int8"); - dlt_user_log_write_int8(&context_data, INT8_MIN); /* (-128) */ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO,4) > 0) - { - dlt_user_log_write_string(&context_data, "int16"); - dlt_user_log_write_int16(&context_data, INT16_MIN);/* (-32767-1) */ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 5) > 0) - { - dlt_user_log_write_string(&context_data, "int32"); - dlt_user_log_write_int32(&context_data, INT32_MIN);/*(-2147483647-1)*/ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 6) > 0) - { - dlt_user_log_write_string(&context_data, "int64"); - dlt_user_log_write_int64(&context_data, INT64_MIN); - /* (-__INT64_C(9223372036854775807)-1) */ - dlt_user_log_write_finish(&context_data); - } - - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 7) > 0) - { - dlt_user_log_write_string(&context_data, "uint"); - dlt_user_log_write_uint(&context_data, UINT32_MAX);/* (4294967295U)*/ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 8) > 0) - { - dlt_user_log_write_string(&context_data, "uint8"); - dlt_user_log_write_uint8(&context_data, UINT8_MAX);/* (255) */ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 9) > 0) - { - dlt_user_log_write_string(&context_data, "uint16"); - dlt_user_log_write_uint16(&context_data, UINT16_MAX);/* (65535) */ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 10) > 0) - { - dlt_user_log_write_string(&context_data,"uint32"); - dlt_user_log_write_uint32(&context_data,UINT32_MAX);/* (4294967295U)*/ - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 11) > 0) - { - dlt_user_log_write_string(&context_data,"uint64"); - dlt_user_log_write_uint64(&context_data,UINT64_MAX); - /* (__UINT64_C(18446744073709551615)) */ - dlt_user_log_write_finish(&context_data); - } - - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 12) > 0) - { - dlt_user_log_write_string(&context_data,"float32"); - dlt_user_log_write_float32(&context_data,FLT_MIN); - dlt_user_log_write_float32(&context_data,FLT_MAX); - dlt_user_log_write_finish(&context_data); - } - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 13) > 0) - { - dlt_user_log_write_string(&context_data,"float64"); - dlt_user_log_write_float64(&context_data,DBL_MIN); - dlt_user_log_write_float64(&context_data,DBL_MAX); - dlt_user_log_write_finish(&context_data); - } - - for(num2 = 0 ; num2 < 10 ; num2++) - { - buffer[num2] = (char) num2; - } - - if (dlt_user_log_write_start_id(&(context_function_test), - &context_data, DLT_LOG_INFO, 14) > 0) - { - dlt_user_log_write_string(&context_data, "raw"); - dlt_user_log_write_raw(&context_data,buffer, 10); - dlt_user_log_write_finish(&context_data); - } - - sleep(2); - if (dlt_user_log_write_start(&context_info, - &context_data, DLT_LOG_INFO) > 0) - { - dlt_user_log_write_string(&context_data, - "Test03: (Function IF) finished"); - dlt_user_log_write_finish(&context_data); - } - - return 0; -} - -int test_real_data(void) -{ - printf("Test04: Real data test (non-verbose)\n"); - DLT_LOG(context_info, DLT_LOG_INFO,DLT_STRING("Test04: real life mesages" - " (non-verbose)")); - - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, DLT_MSG_ID_1, - DLT_UINT16(DLT_MODULE_ID), DLT_UINT8(0x98), DLT_UINT8(0x01)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, DLT_MSG_ID_2, - DLT_UINT16(DLT_MODULE_ID), DLT_UINT8(0x64), DLT_UINT8(0x0)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, DLT_MSG_ID_3, - DLT_UINT16(DLT_MODULE_ID), DLT_UINT8(0x31), DLT_UINT8(0x28)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, DLT_MSG_ID_4, - DLT_UINT16(DLT_MODULE_ID), DLT_UINT8(0x30)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, DLT_MSG_ID_5, - DLT_UINT16(DLT_MODULE_ID), DLT_UINT8(0x31), - DLT_UINT8(0x02), DLT_UINT8(0x2c), DLT_UINT8(0x0f), - DLT_UINT8(0x08), DLT_UINT8(0x01), DLT_UINT8(0x11)); - DLT_LOG_ID(context_macro_test, DLT_LOG_INFO, DLT_MSG_ID_6, - DLT_UINT16(DLT_MODULE_ID), DLT_UINT8(0x31), DLT_UINT8(0x28)); - - sleep(2); - - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING - (" Test04: real life mesages (non-verbose) finished")); - - return 0; -} - -void dlt_user_log_level_changed_callback(char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status) -{ - char text[5]; - text[4]=0; - - memcpy(text,context_id,DLT_ID_SIZE); - - printf("Log level changed of context %s, LogLevel=%u, TraceState=%u \n",text,log_level,trace_status); -} -/** - * Main function of tool. - */ -int main(int argc, char* argv[]) -{ - int avalue = 0; - int ivalue = 0; - int lvalue = 0; - int rvalue = 0; - int ovalue = 0; - int wait_timeout = DEFAULT_WAIT_TIMEOUT; - int c; - - if(argc < 2) - { - printf("\nPlease enter valid option\n\n"); - usage(); - return -1; - } - - while ((c = getopt (argc, argv, "ailrho:")) != -1) - { - switch (c) - { - case 'a': - { - avalue = 1; - break; - } - case 'i': - { - ivalue = 1; - break; - } - case 'l': - { - lvalue = 1; - break; - } - case 'r': - { - rvalue = 1; - break; - } - case 'h': - { - usage(); - return 0; - } - case 'o': - { - ovalue = 1; - wait_timeout = atoi(optarg); - break; - } - case '?': - { - if (isprint (optopt)) - { - fprintf (stderr, "\nUnknown option `-%c'.\n\n", optopt); - } - else - { - fprintf (stderr, "\nUnknown option character `\\x%x'.\n\n", - optopt); - } - usage(); - return -1; - } - default: - { - abort (); - return -1; - } - } - } - - DLT_REGISTER_APP("DINT", "DLT Non-Verbose Interface Test"); - DLT_REGISTER_CONTEXT(context_info, "INFO","Information context"); - DLT_REGISTER_CONTEXT(context_log, "LOG", "Log Context"); - DLT_REGISTER_CONTEXT(context_macro_test, "MACR", "Macro Test Context"); - dlt_register_context(&(context_function_test), "FUNC", "Function Test Context"); - - DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(context_log, dlt_user_log_level_changed_callback); - DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(context_macro_test, dlt_user_log_level_changed_callback); - - DLT_NONVERBOSE_MODE(); - - printf("Tests starting\n"); - - DLT_LOG(context_info, DLT_LOG_INFO,DLT_STRING("Tests starting")); - - if(avalue) - { - printf("Execute all tests\n"); - test_logstorage(); - sleep(1); - test_macro_interface(); - sleep(1); - test_function_interface(); - sleep(1); - test_real_data(); - } - else if(ivalue) - { - printf("Test all different log interface types\n"); - test_macro_interface(); - sleep(1); - test_function_interface(); - } - else if(lvalue) - { - printf("Log storage test\n"); - test_logstorage(); - } - else if(rvalue) - { - printf("Real data test\n"); - test_real_data(); - } - else if(ovalue) - { - printf("Log level test\n"); - test_loglevel(wait_timeout); - } - - printf("Tests finished\n"); - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Tests finished")); - - DLT_UNREGISTER_CONTEXT(context_info); - DLT_UNREGISTER_CONTEXT(context_log); - DLT_UNREGISTER_CONTEXT(context_macro_test); - dlt_unregister_context(&(context_function_test)); - - DLT_UNREGISTER_APP(); - - return 0; -} diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-preregister-context.c dlt-daemon-2.18.4/src/tests/dlt-test-preregister-context.c --- dlt-daemon-2.18.9/src/tests/dlt-test-preregister-context.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-preregister-context.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2015 Intel Corporation - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -/*! - * \author Stefan Vacek Intel Corporation - * - * \copyright Copyright © 2015 Intel Corporation. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - * \file dlt-test-preregister-context.c - */ - -#include /* for fork() */ - -#include "dlt.h" -#include "dlt_user_macros.h" - -/** - * @brief sample code for using pre-registered contexts - */ -int main() -{ - DltContext mainContext; - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = 200000 * 1000; - - DLT_REGISTER_CONTEXT(mainContext, "CTXP", "main context"); - - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before app registered")); - nanosleep(&ts, NULL); - - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Second message before app registered")); - nanosleep(&ts, NULL); - - DLT_REGISTER_APP("PRNT", "Sample pre-register application"); - - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message after app registered")); - nanosleep(&ts, NULL); - - DLT_UNREGISTER_APP() - ; - - return 0; -} diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-qnx-slogger.c dlt-daemon-2.18.4/src/tests/dlt-test-qnx-slogger.c --- dlt-daemon-2.18.9/src/tests/dlt-test-qnx-slogger.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-qnx-slogger.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,135 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2021 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -#include -#include -#include -#include -#include - -#include "dlt.h" -#include "dlt_common.h" /* for dlt_get_version() */ - -#define COUNT 10 -#define DELAY 500 -#define LENGTH 100 - -void usage() -{ - char version[255]; - - dlt_get_version(version, 255); - - printf("Usage: dlt-test-qnx-slogger [options]\n"); - printf("Generate messages and send them to slogger2\n"); - printf("%s\n", version); - printf("Options:\n"); - printf(" -h Usage\n"); - printf(" -n count Number of messages to be generated (Default: %d)\n", COUNT); - printf(" -d delay Milliseconds to wait between sending messages (Default: %d)\n", DELAY); - printf(" -l length Message payload length (Default: %d bytes)\n", LENGTH); -} - -int main(int argc, char *argv[]) { - int i = 0; - int count = COUNT; - int delay = DELAY; - int length = LENGTH; - char *str = NULL; - struct timespec ts; - - int c; - - while ((c = getopt(argc, argv, "hn:d:l:")) != -1) - { - switch(c) - { - case 'n': - { - count = atoi(optarg); - break; - } - case 'd': - { - delay = atoi(optarg); - break; - } - case 'l': - { - length = atoi(optarg); - break; - } - case 'h': - { - usage(); - return -1; - } - case '?': - { - if ((optopt == 'n') || (optopt == 'd') || (optopt == 'l')) - fprintf(stderr, "Option -%c requires an argument\n", optopt); - else if (isprint(optopt)) - fprintf(stderr, "Unknown option `-%c`\n", optopt); - else - fprintf(stderr, "Unknown option character `\\x%x`\n", optopt); - - /* unknown or wrong option used, show usage information and terminate */ - usage(); - return -1; - } - default: - { - usage(); - return -1; - } - } - } - - /* Generate string */ - if (length > 0) - { - str = (char *) malloc((size_t) length + 1); - if (str == NULL) - { - fprintf(stderr, "Cannot allocate memory\n"); - return -1; - } - memset(str, 'X', (size_t) length); - str[length] = '\n'; - } - - /* Calculate delay */ - if (delay > 0) { - ts.tv_sec = delay / 1000; - ts.tv_nsec = (delay % 1000) * 1000000; - } - - - for (i = 0; i < count; i++) - { - slogf(_SLOG_SETCODE(_SLOGC_TEST, 0), _SLOG_INFO, "%s", str); - nanosleep(&ts, NULL); - } - - if (str != NULL) - { - free(str); - str = NULL; - } - - return 0; -} diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-stress.c dlt-daemon-2.18.4/src/tests/dlt-test-stress.c --- dlt-daemon-2.18.9/src/tests/dlt-test-stress.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-stress.c 2019-09-03 08:28:13.000000000 +0000 @@ -211,7 +211,7 @@ return -1; } - dlt_register_app("DSTS", "DLT daemon stress tests"); + DLT_REGISTER_APP("DSTS", "DLT daemon stress tests"); if (test[0]) stress1(); @@ -222,7 +222,7 @@ if (test[2]) stress3(); - dlt_unregister_app(); + DLT_UNREGISTER_APP(); sleep(1); @@ -269,7 +269,7 @@ printf("* Unregister %d contexts...\n", STRESS1_NUM_CONTEXTS); for (i = 0; i < STRESS1_NUM_CONTEXTS; i++) { - dlt_unregister_context(&(mycontext[i])); + DLT_UNREGISTER_CONTEXT(mycontext[i]); ts.tv_sec = 0; ts.tv_nsec = 500 * 1000; nanosleep(&ts, NULL); @@ -288,7 +288,7 @@ printf("Starting stress test2... \n"); - srand((unsigned int) time(NULL)); + srand(time(NULL)); printf("* Creating %d Threads, each of them registers one context,\n", STRESS2_MAX_NUM_THREADS); printf(" sending one log message, then unregisters the context\n"); @@ -314,8 +314,7 @@ void thread_function(void) { /*thread_data_t *data; */ - DltContext context_thread1; - DltContextData context_thread1_data; + DLT_DECLARE_CONTEXT(context_thread1); char ctid[5]; struct timespec ts; @@ -330,37 +329,29 @@ ts.tv_nsec = rand(); nanosleep(&ts, NULL); - dlt_register_context(&context_thread1, ctid, ctid); + DLT_REGISTER_CONTEXT(context_thread1, ctid, ctid); - if (dlt_user_log_write_start(&context_thread1, &context_thread1_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_thread1_data, ctid); - dlt_user_log_write_finish(&context_thread1_data); - } + DLT_LOG(context_thread1, DLT_LOG_INFO, DLT_STRING(ctid)); - dlt_unregister_context(&context_thread1); + DLT_UNREGISTER_CONTEXT(context_thread1); } void stress3(void) { - DltContext context_stress3; - DltContextData context_stress3_data; + DLT_DECLARE_CONTEXT(context_stress3); char buffer[STRESS3_MAX_NUM_MESSAGES]; int num; struct timespec ts; /* Performance test */ - dlt_register_context(&context_stress3, "TST3", "Stress Test 3 - Performance"); + DLT_REGISTER_CONTEXT(context_stress3, "TST3", "Stress Test 3 - Performance"); printf("Starting stress test3... \n"); printf("* Logging raw data, up to a size of %d\n", STRESS3_MAX_NUM_MESSAGES); for (num = 0; num < STRESS3_MAX_NUM_MESSAGES; num++) { - buffer[num] = (char) num; - if (dlt_user_log_write_start(&context_stress3, &context_stress3_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_int(&context_stress3_data, num); - dlt_user_log_write_raw(&context_stress3_data, buffer, (uint16_t) num); - dlt_user_log_write_finish(&context_stress3_data); - } + buffer[num] = num; + DLT_LOG(context_stress3, DLT_LOG_INFO, DLT_INT(num), DLT_RAW(buffer, num)); ts.tv_sec = 0; ts.tv_nsec = 10000 * 1000; nanosleep(&ts, NULL); diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-stress-client.c dlt-daemon-2.18.4/src/tests/dlt-test-stress-client.c --- dlt-daemon-2.18.9/src/tests/dlt-test-stress-client.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-stress-client.c 2019-09-03 08:28:13.000000000 +0000 @@ -67,8 +67,9 @@ #include /* for isprint() */ #include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ #include /* for strcmp() */ -#include #include /* for writev() */ #include "dlt_client.h" @@ -97,8 +98,6 @@ char *evalue; int nvalue; int bvalue; - int sendSerialHeaderFlag; - int resyncSerialHeaderFlag; char ecuid[4]; int ohandle; @@ -144,8 +143,6 @@ printf(" -s Print DLT messages; only headers\n"); printf(" -v Verbose mode\n"); printf(" -h Usage\n"); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode\n"); printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); printf(" -e ecuid Set ECU ID (Default: ECU1)\n"); @@ -178,8 +175,6 @@ dltdata.fvalue = 0; dltdata.evalue = 0; dltdata.bvalue = 0; - dltdata.sendSerialHeaderFlag = 0; - dltdata.resyncSerialHeaderFlag = 0; dltdata.nvalue = 10000; dltdata.ohandle = -1; @@ -206,7 +201,7 @@ /* Fetch command line arguments */ opterr = 0; - while ((c = getopt (argc, argv, "vashSRyxmf:o:e:b:n:")) != -1) + while ((c = getopt (argc, argv, "vashyxmf:o:e:b:n:")) != -1) switch (c) { case 'v': { @@ -238,16 +233,6 @@ usage(); return -1; } - case 'S': - { - dltdata.sendSerialHeaderFlag = 1; - break; - } - case 'R': - { - dltdata.resyncSerialHeaderFlag = 1; - break; - } case 'y': { dltdata.yflag = 1; @@ -343,10 +328,6 @@ dlt_client_setbaudrate(&dltclient, dltdata.bvalue); } - /* Update the send and resync serial header flags based on command line option */ - dltclient.send_serial_header = dltdata.sendSerialHeaderFlag; - dltclient.resync_serial_header = dltdata.resyncSerialHeaderFlag; - /* initialise structure to use DLT file */ dlt_file_init(&(dltdata.file), dltdata.vflag); @@ -541,7 +522,7 @@ iov[1].iov_base = message->databuffer; iov[1].iov_len = message->datasize; - bytes_written = (int) writev(dltdata->ohandle, iov, 2); + bytes_written = writev(dltdata->ohandle, iov, 2); if (0 > bytes_written) { printf("dlt_testclient_message_callback, error when: writev(dltdata->ohandle, iov, 2) \n"); diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-stress-user.c dlt-daemon-2.18.4/src/tests/dlt-test-stress-user.c --- dlt-daemon-2.18.9/src/tests/dlt-test-stress-user.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-stress-user.c 2019-09-03 08:28:13.000000000 +0000 @@ -81,7 +81,15 @@ int testall(int count, int repeat, int delay, int size); /* Context declaration.. */ -DltContext context_info; +DLT_DECLARE_CONTEXT(context_info) + +/* for macro interface */ +DLT_DECLARE_CONTEXT(context_macro_callback) +DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]) + +/* for function interface */ +DltContext context_function_callback; +DltContext context_function_test[DLT_TEST_NUM_CONTEXT]; DltContextData context_data; @@ -184,10 +192,10 @@ } /* Register APP */ - dlt_register_app("DIFT", "DLT Interface Test"); + DLT_REGISTER_APP("DIFT", "DLT Interface Test"); /* Register CONTEXTS... */ - dlt_register_context(&context_info, "INFO", "Information context"); + DLT_REGISTER_CONTEXT(context_info, "INFO", "Information context"); /* Tests starting */ printf("Tests starting\n"); @@ -206,10 +214,10 @@ /*sleep(3); */ /* Unregister CONTEXTS... */ - dlt_unregister_context(&context_info); + DLT_UNREGISTER_CONTEXT(context_info); /* Unregister APP */ - dlt_unregister_app(); + DLT_UNREGISTER_APP(); return 0; } @@ -225,7 +233,7 @@ struct timespec ts; for (num = 0; num < size; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Test All: Test all start */ /*printf("Test1: Test all\n"); */ @@ -233,11 +241,7 @@ for (rnum = 0; rnum < repeat; rnum++) for (num = 1; num <= count; num++) { - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_int(&context_data, num); - dlt_user_log_write_raw(&context_data, buffer, size); - dlt_user_log_write_finish(&context_data); - } + DLT_LOG(context_info, DLT_LOG_INFO, DLT_INT(num), DLT_RAW(buffer, size)); ts.tv_sec = (delay * 1000) / 1000000000; ts.tv_nsec = (delay * 1000) % 1000000000; nanosleep(&ts, NULL); diff -Nru dlt-daemon-2.18.9/src/tests/dlt-test-user.c dlt-daemon-2.18.4/src/tests/dlt-test-user.c --- dlt-daemon-2.18.9/src/tests/dlt-test-user.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/src/tests/dlt-test-user.c 2019-09-03 08:28:13.000000000 +0000 @@ -74,9 +74,7 @@ #include "dlt.h" -#define DLT_TEST_NUM_CONTEXT 11 - -#define DLT_MAX_TIMESTAMP 0xFFFFFFFF +#define DLT_TEST_NUM_CONTEXT 9 /* LogLevel string representation */ static const char *loglevelstr[DLT_LOG_MAX] = { @@ -91,7 +89,6 @@ /* Test functions... */ -#if !DLT_DISABLE_MACRO /* for macro interface */ int test1m(void); int test2m(void); @@ -102,9 +99,6 @@ int test7m(void); int test8m(void); int test9m(void); -int test10m(void); -int test11m(void); -#endif /* for function interface */ int test1f(void); @@ -116,24 +110,17 @@ int test7f(void); int test8f(void); int test9f(void); -int test10f(void); -int test11f(void); /* Declaration of callback functions */ int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length); int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length); -/* Message copying for test11f() */ -void test11f_internal(DltContext context, DltContextData contextData, uint32_t type_info, void *data, size_t data_size); - /* Context declaration.. */ -DltContext context_info; +DLT_DECLARE_CONTEXT(context_info) -#if !DLT_DISABLE_MACRO /* for macro interface */ DLT_DECLARE_CONTEXT(context_macro_callback) DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]) -#endif /* for function interface */ DltContext context_function_callback; @@ -157,9 +144,7 @@ printf(" -v Verbose mode\n"); printf(" -f filename Use local log file instead of sending to daemon\n"); printf(" -n count Repeats of tests (Default: 1)\n"); - printf(" -t test num Test number to be executed (Default: all)\n"); printf("Tests:\n"); -#if !DLT_DISABLE_MACRO printf(" 1m: (Macro IF) Test all log levels\n"); printf(" 2m: (Macro IF) Test all variable types (verbose) \n"); printf(" 3m: (Macro IF) Test all variable types (non-verbose) \n"); @@ -169,9 +154,6 @@ printf(" 7m: (Macro IF) Test network trace\n"); printf(" 8m: (Macro IF) Test truncated network trace\n"); printf(" 9m: (Macro IF) Test segmented network trace\n"); - printf(" 10m: (Macro IF) Test user-specified timestamps\n"); - printf(" 11m: (Macro IF) Test log buffer input interface\n"); -#endif printf(" 1f: (Function IF) Test all log levels\n"); printf(" 2f: (Function IF) Test all variable types (verbose) \n"); printf(" 3f: (Function IF) Test all variable types (non-verbose) \n"); @@ -181,8 +163,6 @@ printf(" 7f: (Function IF) Test network trace\n"); printf(" 8f: (Function IF) Test truncated network trace\n"); printf(" 9f: (Function IF) Test segmented network trace\n"); - printf(" 10f: (Function IF) Test user-specified timestamps\n"); - printf(" 11f: (Function IF) Test log buffer input interface\n"); } /** @@ -193,18 +173,17 @@ /*int vflag = 0; */ char *fvalue = 0; char *nvalue = 0; - int tvalue = 0; int c; int i; - char ctid[5], ctdesc[255]; + char ctid[4], ctdesc[255]; int num, maxnum; opterr = 0; - while ((c = getopt (argc, argv, "vf:n:t:")) != -1) + while ((c = getopt (argc, argv, "vf:n:")) != -1) switch (c) { case 'v': { @@ -221,11 +200,6 @@ nvalue = optarg; break; } - case 't': - { - tvalue = atoi(optarg); - break; - } case '?': { if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n')) @@ -260,39 +234,35 @@ maxnum = 1; /* Register APP */ - dlt_register_app("DIFT", "DLT Interface Test"); + DLT_REGISTER_APP("DIFT", "DLT Interface Test"); /* Register CONTEXTS... */ - dlt_register_context(&context_info, "INFO", "Information context"); + DLT_REGISTER_CONTEXT(context_info, "INFO", "Information context"); -#if !DLT_DISABLE_MACRO /* used for macro interface tests */ DLT_REGISTER_CONTEXT(context_macro_callback, "CBM", "Callback Test context for macro interface"); for (i = 0; i < DLT_TEST_NUM_CONTEXT; i++) { - snprintf(ctid, 5, "TM%02d", i + 1); + snprintf(ctid, 4, "TM%d", i + 1); snprintf(ctdesc, 255, "Test %d context for macro interface", i + 1); DLT_REGISTER_CONTEXT(context_macro_test[i], ctid, ctdesc); } -#endif /* used for function interface tests */ dlt_register_context(&context_function_callback, "CBF", "Callback Test context for function interface"); for (i = 0; i < DLT_TEST_NUM_CONTEXT; i++) { - snprintf(ctid, 5, "TF%02d", i + 1); + snprintf(ctid, 4, "TF%d", i + 1); snprintf(ctdesc, 255, "Test %d context for function interface", i + 1); dlt_register_context(&(context_function_test[i]), ctid, ctdesc); } /* Register callbacks... */ -#if !DLT_DISABLE_MACRO /* with macro interface */ DLT_LOG(context_macro_callback, DLT_LOG_INFO, DLT_STRING("Register callback (Macro Interface) for Injection ID: 0xFFF")); DLT_REGISTER_INJECTION_CALLBACK(context_macro_callback, 0xFFF, test_injection_macro_callback); -#endif /* with function interface */ if (dlt_user_log_write_start(&context_function_callback, &context_data, DLT_LOG_INFO) > 0) { @@ -304,10 +274,7 @@ /* Tests starting */ printf("Tests starting\n"); - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Tests starting"); - dlt_user_log_write_finish(&context_data); - } + DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Tests starting")); /* wait 3 seconds before starting */ sleep(3); @@ -315,125 +282,27 @@ for (num = 0; num < maxnum; num++) { /* Execute tests... */ - switch(tvalue) { - case 1: - { -#if !DLT_DISABLE_MACRO - test1m(); -#endif - test1f(); - break; - } - case 2: - { -#if !DLT_DISABLE_MACRO - test2m(); -#endif - test2f(); - break; - } - case 3: - { -#if !DLT_DISABLE_MACRO - test3m(); -#endif - test3f(); - break; - } - case 4: - { -#if !DLT_DISABLE_MACRO - test4m(); -#endif - test4f(); - break; - } - case 5: - { -#if !DLT_DISABLE_MACRO - test5m(); -#endif - test5f(); - break; - } - case 6: - { -#if !DLT_DISABLE_MACRO - test6m(); -#endif - test6f(); - break; - } - case 7: - { -#if !DLT_DISABLE_MACRO - test7m(); -#endif - test7f(); - break; - } - case 8: - { -#if !DLT_DISABLE_MACRO - test8m(); -#endif - test8f(); - break; - } - case 9: - { -#if !DLT_DISABLE_MACRO - test9m(); -#endif - test9f(); - break; - } - case 10: - { -#if !DLT_DISABLE_MACRO - test10m(); -#endif - test10f(); - break; - } - case 11: - { -#if !DLT_DISABLE_MACRO - test11m(); -#endif - test11f(); - break; - } - default: -#if !DLT_DISABLE_MACRO - /* with macro interface */ - test1m(); - test2m(); - test3m(); - test4m(); - test5m(); - test6m(); - test7m(); - test8m(); - test9m(); - test10m(); - test11m(); -#endif - - /* with function interface */ - test1f(); - test2f(); - test3f(); - test4f(); - test5f(); - test6f(); - test7f(); - test8f(); - test9f(); - test10f(); - test11f(); - break; - } + /* with macro interface */ + test1m(); + test2m(); + test3m(); + test4m(); + test5m(); + test6m(); + test7m(); + test8m(); + test9m(); + + /* with function interface */ + test1f(); + test2f(); + test3f(); + test4f(); + test5f(); + test6f(); + test7f(); + test8f(); + test9f(); /* wait 1 second before next repeat of tests */ sleep(1); @@ -441,24 +310,19 @@ /* Tests finished */ printf("Tests finished\n"); - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Tests finished"); - dlt_user_log_write_finish(&context_data); - } + DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Tests finished")); /* wait 3 seconds before terminating application */ sleep(3); /* Unregister CONTEXTS... */ - dlt_unregister_context(&context_info); + DLT_UNREGISTER_CONTEXT(context_info); -#if !DLT_DISABLE_MACRO /* used for macro interface tests */ for (i = 0; i < DLT_TEST_NUM_CONTEXT; i++) DLT_UNREGISTER_CONTEXT(context_macro_test[i]); DLT_UNREGISTER_CONTEXT(context_macro_callback); -#endif /* used for function interface tests */ for (i = 0; i < DLT_TEST_NUM_CONTEXT; i++) @@ -467,7 +331,7 @@ dlt_unregister_context(&context_function_callback); /* Unregister APP */ - dlt_unregister_app(); + DLT_UNREGISTER_APP(); return 0; } @@ -476,7 +340,6 @@ /* The test cases */ /******************/ -#if !DLT_DISABLE_MACRO int test1m(void) { /* Test 1: (Macro IF) Test all log levels */ @@ -523,7 +386,7 @@ DLT_LOG(context_macro_test[1], DLT_LOG_INFO, DLT_STRING("float64"), DLT_FLOAT64(DBL_MIN), DLT_FLOAT64(DBL_MAX)); for (num2 = 0; num2 < 10; num2++) - buffer[num2] = (char) num2; + buffer[num2] = num2; DLT_LOG(context_macro_test[1], DLT_LOG_INFO, DLT_STRING("raw"), DLT_RAW(buffer, 10)); @@ -572,7 +435,7 @@ DLT_FLOAT64(DBL_MAX)); for (num2 = 0; num2 < 10; num2++) - buffer[num2] = (char) num2; + buffer[num2] = num2; DLT_LOG_ID(context_macro_test[2], DLT_LOG_INFO, 14, DLT_STRING("raw"), DLT_RAW(buffer, 10)); @@ -591,7 +454,7 @@ int num; for (num = 0; num < 1024; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Test 4: (Macro IF) Message size test */ printf("Test4m: (Macro IF) Test different message sizes\n"); @@ -618,7 +481,7 @@ void *ptr = malloc(sizeof(int)); for (num = 0; num < 32; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Test 5: (Macro IF) Test high-level API */ printf("Test5m: (Macro IF) Test high-level API\n"); @@ -689,12 +552,11 @@ int test7m(void) { -#ifdef DLT_NETWORK_TRACE_ENABLE char buffer[32]; int num; for (num = 0; num < 32; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Show all log messages and traces */ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON); @@ -715,23 +577,17 @@ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT); sleep(2); -#else - /* Test 7: (Macro IF) Test network trace */ - printf("Test7m: (Macro IF) Test network trace: Network trace interface is not supported, skipping\n"); - DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 7: (Macro IF) Test network trace: Network trace interface is not supported, skipping"); -#endif return 0; } int test8m(void) { -#ifdef DLT_NETWORK_TRACE_ENABLE char buffer[1024 * 5]; int num; for (num = 0; num < 1024 * 5; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Show all log messages and traces */ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON); @@ -752,23 +608,17 @@ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT); sleep(2); -#else - /* Test 8: (Macro IF) Test truncated network trace*/ - printf("Test8m: (Macro IF) Test truncated network trace: Network trace interface is not supported, skipping\n"); - DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 8: (Macro IF) Test truncated network trace: Network trace interface is not supported, skipping"); -#endif return 0; } int test9m(void) { -#ifdef DLT_NETWORK_TRACE_ENABLE char buffer[1024 * 5]; int num; for (num = 0; num < 1024 * 5; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Show all log messages and traces */ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON); @@ -789,58 +639,9 @@ DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT); sleep(2); -#else - /* Test 9: (Macro IF) Test segmented network trace*/ - printf("Test9m: (Macro IF) Test segmented network trace: Network trace interface is not supported, skipping\n"); - DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 9: (Macro IF) Test segmented network trace: Network trace interface is not supported, skipping"); -#endif - - return 0; -} - -int test10m(void) -{ - unsigned long timestamp[] = { 0, 100000, DLT_MAX_TIMESTAMP }; - /* Test 10: test minimum, regular and maximum timestamp for both verbose and non verbose mode*/ - - printf("Test10m: (Macro IF) Test user-supplied time stamps\n"); - DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test10: (Macro IF) Test user-supplied timestamps"); - - for (int i = 0; i < 3; i++) { - char s[12]; - snprintf(s, 12, "%d.%04d", (int)(timestamp[i] / 10000), (int)(timestamp[i] % 10000)); - - DLT_VERBOSE_MODE(); - DLT_LOG_TS(context_macro_test[9], DLT_LOG_INFO, timestamp[i], DLT_STRING("Tested Timestamp:"), DLT_STRING(s)); - - DLT_NONVERBOSE_MODE(); - DLT_LOG_ID_TS(context_macro_test[9], DLT_LOG_INFO, 16, timestamp[i], DLT_STRING(s)); - } - - DLT_VERBOSE_MODE(); - - /* wait 2 second before next test */ - sleep(2); - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test10: (Macro IF) finished")); - - return 0; -} - -int test11m(void) -{ - printf("Test11m: (Macro IF) Test log buffer input interface\n"); - DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test11m: (Macro IF) Test log buffer input interface"); - - /* Test11m: (Macro IF) Test log buffer input interface */ - /* Do nothing as there is no macro interface implemented as of now */ - - /* wait 2 second before next test */ - sleep(2); - DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test11: (Macro IF) finished")); return 0; } -#endif int test1f(void) { @@ -987,7 +788,7 @@ } for (num2 = 0; num2 < 10; num2++) - buffer[num2] = (char) num2; + buffer[num2] = num2; if (dlt_user_log_write_start(&(context_function_test[1]), &context_data, DLT_LOG_INFO) > 0) { dlt_user_log_write_string(&context_data, "raw"); @@ -1102,7 +903,7 @@ } for (num2 = 0; num2 < 10; num2++) - buffer[num2] = (char) num2; + buffer[num2] = num2; if (dlt_user_log_write_start_id(&(context_function_test[2]), &context_data, DLT_LOG_INFO, 14) > 0) { dlt_user_log_write_string(&context_data, "raw"); @@ -1129,7 +930,7 @@ int num; for (num = 0; num < 1024; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Test 4: (Function IF) Message size test */ printf("Test4f: (Function IF) Test different message sizes\n"); @@ -1182,7 +983,7 @@ char log[DLT_USER_BUF_MAX_SIZE]; for (num = 0; num < 32; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Test 5: (Function IF) Test high-level API */ printf("Test5f: (Function IF) Test high-level API\n"); @@ -1263,12 +1064,11 @@ int test7f(void) { -#ifdef DLT_NETWORK_TRACE_ENABLE char buffer[32]; int num; for (num = 0; num < 32; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Show all log messages and traces */ dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON); @@ -1297,27 +1097,17 @@ dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT); sleep(2); -#else - /* Test 7: (Function IF) Test network trace */ - printf("Test7f: (Function IF) Test network trace: Network trace interface is not supported, skipping\n"); - - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test 7: (Function IF) Test network trace: Network trace interface is not supported, skipping"); - dlt_user_log_write_finish(&context_data); - } -#endif return 0; } int test8f(void) { -#ifdef DLT_NETWORK_TRACE_ENABLE char buffer[1024 * 5]; int num; for (num = 0; num < 1024 * 5; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Show all log messages and traces */ dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON); @@ -1347,27 +1137,17 @@ dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT); sleep(2); -#else - /* Test 8: (Function IF) Test truncated network trace */ - printf("Test8f: (Function IF) Test truncated network trace: Network trace interface is not supported, skipping\n"); - - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test 8: (Function IF) Test truncated network trace: Network trace interface is not supported, skipping"); - dlt_user_log_write_finish(&context_data); - } -#endif return 0; } int test9f(void) { -#ifdef DLT_NETWORK_TRACE_ENABLE char buffer[1024 * 5]; int num; for (num = 0; num < 1024 * 5; num++) - buffer[num] = (char) num; + buffer[num] = num; /* Show all log messages and traces */ dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON); @@ -1396,139 +1176,10 @@ dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT); sleep(2); -#else - /* Test 9: (Function IF) Test segmented network trace */ - printf("Test9f: (Function IF) Test segmented network trace: Network trace interface is not supported, skipping\n"); - - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test 9: (Function IF) Test segmented network trace: Network trace interface is not supported, skipping"); - dlt_user_log_write_finish(&context_data); - } -#endif - - return 0; -} - -int test10f(void) -{ - unsigned long timestamp[] = { 0, 100000, DLT_MAX_TIMESTAMP }; - /* Test 10: test minimum, regular and maximum timestamp for both verbose and non verbose mode*/ - - printf("Test10f: (Function IF) Test user-supplied timestamps\n"); - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test10: (Function IF) Test user-supplied time stamps"); - dlt_user_log_write_finish(&context_data); - } - - for (int i = 0; i < 3; i++) { - char s[12]; - snprintf(s, 12, "%d.%04d", (int)(timestamp[i] / 10000), (int)(timestamp[i] % 10000)); - - dlt_verbose_mode(); - if (dlt_user_log_write_start(&context_function_test[9], &context_data, DLT_LOG_INFO) > 0) { - context_data.use_timestamp = DLT_USER_TIMESTAMP; - context_data.user_timestamp = (uint32_t) timestamp[i]; - dlt_user_log_write_string(&context_data, "Tested Timestamp:"); - dlt_user_log_write_string(&context_data, s); - dlt_user_log_write_finish(&context_data); - } - - dlt_nonverbose_mode(); - if (dlt_user_log_write_start_id(&(context_function_test[9]), &context_data, DLT_LOG_INFO, 16) > 0) { - context_data.use_timestamp = DLT_USER_TIMESTAMP; - context_data.user_timestamp = (uint32_t) timestamp[i]; - dlt_user_log_write_string(&context_data, s); - dlt_user_log_write_finish(&context_data); - } - } - - dlt_verbose_mode(); - - /* wait 2 second before next test */ - sleep(2); - - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test10: (Function IF) finished"); - dlt_user_log_write_finish(&context_data); - } - - return 0; -} - -int test11f(void) -{ - uint32_t type_info; - - printf("Test11f: (Function IF) Test log buffer input interface\n"); - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test11: (Function IF) Test log buffer input interface"); - dlt_user_log_write_finish(&context_data); - } - - uint8_t data_bool = 1; /* true */ - type_info = DLT_TYPE_INFO_BOOL; - test11f_internal(context_function_test[10], context_data, type_info, &data_bool, sizeof(uint8_t)); - - int8_t data_int8 = INT8_MIN; /* (-128) */ - type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_int8, sizeof(int8_t)); - - int16_t data_int16 = INT16_MIN; /* (-32768) */ - type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_int16, sizeof(int16_t)); - - int32_t data_int32 = INT32_MIN; /* (-2147483648) */ - type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_int32, sizeof(int32_t)); - - int64_t data_int64 = INT64_MIN; /* (-9223372036854775808) */ - type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_int64, sizeof(int64_t)); - - uint8_t data_uint8 = UINT8_MAX; /* (255) */ - type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_uint8, sizeof(uint8_t)); - - uint16_t data_uint16 = UINT16_MAX; /* (65535) */ - type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_uint16, sizeof(uint16_t)); - - uint32_t data_uint32 = UINT32_MAX; /* (4294967295) */ - type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_uint32, sizeof(uint32_t)); - - uint64_t data_uint64 = UINT64_MAX; /* (18446744073709551615) */ - type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_uint64, sizeof(uint64_t)); - - float32_t data_float32 = FLT_MIN; /* (1.17549e-38) */ - type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_float32, sizeof(float32_t)); - - data_float32 = FLT_MAX; /* (3.40282e+38) */ - type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_float32, sizeof(float32_t)); - - float64_t data_float64 = DBL_MIN; /* (2.22507e-308) */ - type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_float64, sizeof(float64_t)); - - data_float64 = DBL_MAX; /* (1.79769e+308) */ - type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - test11f_internal(context_function_test[10], context_data, type_info, &data_float64, sizeof(float64_t)); - - /* wait 2 second before next test */ - sleep(2); - /* Test11f: (Function IF) Test log buffer input interface */ - if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Test11: (Function IF) finished"); - dlt_user_log_write_finish(&context_data); - } return 0; } -#if !DLT_DISABLE_MACRO int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length) { char text[1024]; @@ -1541,13 +1192,12 @@ memset(text, 0, 1024); if (length > 0) { - dlt_print_mixed_string(text, 1024, data, (int) length, 0); + dlt_print_mixed_string(text, 1024, data, length, 0); printf("%s \n", text); } return 0; } -#endif int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length) { @@ -1557,34 +1207,16 @@ snprintf(text, 1024, "Injection received (function IF). ID: 0x%.4x, Length: %d", service_id, length); printf("%s \n", text); - if (dlt_user_log_write_start(&context_function_callback, &context_data, DLT_LOG_INFO) > 0) { - dlt_user_log_write_string(&context_data, "Injection received (function IF). ID: "); - dlt_user_log_write_uint32(&context_data, service_id); - dlt_user_log_write_string(&context_data, "Data:"); - dlt_user_log_write_string(&context_data, text); - } + DLT_LOG(context_function_callback, DLT_LOG_INFO, DLT_STRING("Injection received (function IF). ID: "), + DLT_UINT32(service_id), DLT_STRING("Data:"), DLT_STRING(text)); memset(text, 0, 1024); if (length > 0) { - dlt_print_mixed_string(text, 1024, data, (int) length, 0); + dlt_print_mixed_string(text, 1024, data, length, 0); printf("%s \n", text); } return 0; } -void test11f_internal(DltContext context, DltContextData contextData, uint32_t type_info, void *data, size_t data_size) -{ - char buffer[DLT_USER_BUF_MAX_SIZE] = {0}; - size_t size = 0; - int32_t args_num = 0; - - memcpy(buffer + size, &(type_info), sizeof(uint32_t)); - size += sizeof(uint32_t); - memcpy(buffer + size, data, data_size); - size += data_size; - args_num++; - if (dlt_user_log_write_start_w_given_buffer(&context, &contextData, DLT_LOG_WARN, buffer, size, args_num) > 0) { - dlt_user_log_write_finish_w_given_buffer(&contextData); - } -} + diff -Nru dlt-daemon-2.18.9/systemd/3rdparty/sd-daemon.c dlt-daemon-2.18.4/systemd/3rdparty/sd-daemon.c --- dlt-daemon-2.18.9/systemd/3rdparty/sd-daemon.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/systemd/3rdparty/sd-daemon.c 2019-09-03 08:28:13.000000000 +0000 @@ -35,7 +35,7 @@ #ifdef __BIONIC__ #include #else -#include +#include #endif #include #include diff -Nru dlt-daemon-2.18.9/systemd/CMakeLists.txt dlt-daemon-2.18.4/systemd/CMakeLists.txt --- dlt-daemon-2.18.9/systemd/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/systemd/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -53,7 +53,7 @@ install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt-example-user.service DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) endif(WITH_DLT_EXAMPLES) - if(WITH_DLT_ADAPTOR_UDP OR WITH_DLT_ADAPTOR) + if(WITH_DLT_ADAPTOR) set( DLT_ADAPTOR_UDP_APPID "DUDP" ) set( DLT_ADAPTOR_UDP_CTID "DCTI" ) set( DLT_ADAPTOR_UDP_PORT 4712 ) @@ -61,13 +61,7 @@ message( STATUS "Configured systemd unit file:dlt-adaptor-udp.service" ) message(STATUS "DLT adaptor udp configuration: APPID=${DLT_ADAPTOR_UDP_APPID} CTID=${DLT_ADAPTOR_UDP_CTID} PORT=${DLT_ADAPTOR_UDP_PORT}" ) install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt-adaptor-udp.service DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) - endif(WITH_DLT_ADAPTOR_UDP) - - if (WITH_SYSTEMD_SOCKET_ACTIVATION) - configure_file(${PROJECT_SOURCE_DIR}/systemd/dlt.socket.cmake ${PROJECT_BINARY_DIR}/systemd/dlt.socket) - message( STATUS "Configured systemd socket file:dlt.socket" ) - install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt.socket DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) - endif() + endif(WITH_DLT_ADAPTOR) message(STATUS "Unit files will be installed to ${SYSTEMD_CONFIGURATIONS_FILES_DIR} after make install" ) diff -Nru dlt-daemon-2.18.9/systemd/dlt.socket.cmake dlt-daemon-2.18.4/systemd/dlt.socket.cmake --- dlt-daemon-2.18.9/systemd/dlt.socket.cmake 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/systemd/dlt.socket.cmake 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -[Socket] -ListenStream=@DLT_USER_IPC_PATH@/dlt -FileDescriptorName=@DLT_USER_IPC_PATH@/dlt -SocketGroup=dlt -SocketMode=0666 - -[Install] -WantedBy=sockets.target \ No newline at end of file diff -Nru dlt-daemon-2.18.9/tests/CMakeLists.txt dlt-daemon-2.18.4/tests/CMakeLists.txt --- dlt-daemon-2.18.9/tests/CMakeLists.txt 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/CMakeLists.txt 2019-09-03 08:28:13.000000000 +0000 @@ -1,92 +1,53 @@ # Setup testing enable_testing() -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${gtest_SOURCE_DIR}/include") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${gtest_SOURCE_DIR}/include -std=gnu++0x") +#add_compile_options(-g -fsanitize=address) +add_compile_options(-isystem ${gtest_SOURCE_DIR}/include) configure_file(${PROJECT_SOURCE_DIR}/tests/testfile.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY) -configure_file(${PROJECT_SOURCE_DIR}/tests/testfilter.txt ${PROJECT_BINARY_DIR}/tests COPYONLY) -configure_file(${PROJECT_SOURCE_DIR}/tests/testfile_filetransfer.txt ${PROJECT_BINARY_DIR}/tests COPYONLY) -if("${GTEST_BOTH_LIBRARIES}" STREQUAL "") - set(GTEST_LIBS gtest gtest_main) - set(GTEST_LIBS ${GTEST_LIBS} CACHE STRING "Gtest libraries") +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(LIBRARIES gtest gtest_main) else() - set(GTEST_LIBS ${GTEST_BOTH_LIBRARIES}) + set(LIBRARIES gtest socket) endif() -if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN") - set(LIBRARIES "") -else() - set(LIBRARIES socket) -endif() +set(DLT_LIBRARIES ${LIBRARIES} dlt) +set(DLT_DAEMON_LIBRARIES ${LIBRARIES} dlt_daemon) -set(DLT_LIBRARIES dlt ${GTEST_LIBS} ${LIBRARIES}) -set(DLT_DAEMON_LIBRARIES dlt_daemon ${GTEST_LIBS} ${LIBRARIES}) -set(DLT_CONTROL_LIBRARIES dlt dlt_control_common_lib ${GTEST_LIBS}) +if(WITH_SYSTEMD OR WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD_JOURNAL) + add_definitions( -DSD_EXPORT_SYMBOLS ) +endif() -#Receiver used for QTs. add_test() is not required +add_executable(gtest_dlt_common gtest_dlt_common.cpp) +add_executable(gtest_dlt_user gtest_dlt_user.cpp) +add_executable(gtest_dlt_daemon_common gtest_dlt_daemon_common.cpp ../src/daemon/dlt_daemon_common.c) add_executable(dlt_test_receiver dlt_test_receiver.c) -target_link_libraries(dlt_test_receiver ${DLT_LIBRARIES}) +add_executable(dlt_env_ll_unit_test dlt_env_ll_unit_test.cpp) +add_executable(dlt-test-preregister-context dlt-test-preregister-context.c) +add_executable(gtest_dlt_daemon_gateway gtest_dlt_daemon_gateway.cpp ${systemd_SRCS}) +add_executable(gtest_dlt_daemon_event_handler gtest_dlt_daemon_event_handler.cpp ${systemd_SRCS}) +add_executable(gtest_dlt_daemon_offline_log gtest_dlt_daemon_offline_log.cpp ${systemd_SRCS}) -#################### -# DLT library tests -#################### -set(TARGET_LIST gtest_dlt_common - gtest_dlt_user - gtest_dlt_daemon_common - dlt_env_ll_unit_test - ) - -foreach(target IN LISTS TARGET_LIST) - set(target_SRCS ${target}) - if(${target} STREQUAL "gtest_dlt_daemon_common") - set(target_SRCS ${target_SRCS} ../src/daemon/dlt_daemon_common.c) - endif() - add_executable(${target} ${target_SRCS}) - target_link_libraries(${target} ${DLT_LIBRARIES}) - add_test(NAME ${target} - COMMAND ${target}) -endforeach() - -################### -# DLT daemon tests -################### -set(TARGET_LIST gtest_dlt_daemon_gateway - gtest_dlt_daemon_offline_log - gtest_dlt_daemon_event_handler - gtest_dlt_daemon_multiple_files_logging - ) if(WITH_DLT_SHM_ENABLE) - list(APPEND TARGET_LIST gtest_dlt_shm) -endif() + add_executable(gtest_dlt_shm gtest_dlt_shm.cpp) +endif(WITH_DLT_SHM_ENABLE) -foreach(target IN LISTS TARGET_LIST) - set(target_SRCS ${target}) - add_executable(${target} ${target_SRCS} ${systemd_SRCS}) - target_link_libraries(${target} ${DLT_DAEMON_LIBRARIES}) - if(${target} STREQUAL "gtest_dlt_daemon_event_handler" - OR ${target} STREQUAL "gtest_dlt_shm" - OR ${target} STREQUAL "gtest_dlt_daemon_multiple_files_logging") - add_test(NAME ${target} - COMMAND ${target}) - else() - configure_file(${PROJECT_SOURCE_DIR}/tests/${target}.sh ${PROJECT_BINARY_DIR}/tests COPYONLY) - add_test(NAME ${target} - COMMAND /bin/sh "${target}.sh" - ${target}) - endif() -endforeach() - -##################### -# DLT conotrol tests -##################### -if(WITH_EXTENDED_FILTERING) - configure_file(${PROJECT_SOURCE_DIR}/tests/testfile_extended.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY) - configure_file(${PROJECT_SOURCE_DIR}/tests/testfilter.json ${PROJECT_BINARY_DIR}/tests COPYONLY) - add_executable(gtest_dlt_json_filter gtest_dlt_json_filter.cpp) - target_link_libraries(gtest_dlt_json_filter ${DLT_CONTROL_LIBRARIES}) - add_test(NAME gtest_dlt_json_filter - COMMAND gtest_dlt_json_filter) -endif() +target_link_libraries(gtest_dlt_common ${DLT_LIBRARIES}) +target_link_libraries(gtest_dlt_user ${DLT_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_common ${DLT_LIBRARIES}) +target_link_libraries(dlt_test_receiver dlt) +target_link_libraries(dlt_env_ll_unit_test ${DLT_LIBRARIES}) +target_link_libraries(dlt-test-preregister-context ${DLT_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_gateway ${DLT_DAEMON_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_event_handler ${DLT_DAEMON_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_offline_log ${DLT_DAEMON_LIBRARIES}) + +if(WITH_DLT_SHM_ENABLE) + target_link_libraries(gtest_dlt_shm ${DLT_DAEMON_LIBRARIES}) +endif(WITH_DLT_SHM_ENABLE) +if(WITH_DLT_CXX11_EXT) + add_executable(dlt-test-cpp-extension dlt-test-cpp-extension.cpp) + target_link_libraries(dlt-test-cpp-extension ${DLT_LIBRARIES}) +endif() diff -Nru dlt-daemon-2.18.9/tests/dlt-test-cpp-extension.cpp dlt-daemon-2.18.4/tests/dlt-test-cpp-extension.cpp --- dlt-daemon-2.18.9/tests/dlt-test-cpp-extension.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/tests/dlt-test-cpp-extension.cpp 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,117 @@ +/* + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * For further information see http://www.genivi.org/. + */ + +/*! + * \author Stefan Vacek Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-cpp-extension.cpp + */ + +#include "dlt_cpp_extension.hpp" +#include +#include + +struct MyStruct +{ + int64_t uuid; + int32_t interfaceId; + int32_t registrationState; +}; + +template<> +inline int logToDlt(DltContextData &log, MyStruct const &value) +{ + int result = 0; + + result += dlt_user_log_write_string(&log, "("); + result += logToDlt(log, value.uuid); + result += dlt_user_log_write_string(&log, ","); + result += logToDlt(log, value.interfaceId); + result += dlt_user_log_write_string(&log, ","); + result += logToDlt(log, value.registrationState); + result += dlt_user_log_write_string(&log, ")"); + + if (result != 0) + result = -1; + + return result; +} + +/** + * Sample code to show usage of the cpp-extension + * mainly the variadic templates + */ +int main() +{ + if (dlt_register_app("TCPP", "Test cpp extension") < 0) { + printf("Failed to register application\n"); + return -1; + } + + DltContext ctx; + + if (dlt_register_context_ll_ts(&ctx, "TCPP", "Test cpp extension", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF) < 0) { + printf("Failed to register context\n"); + return -1; + } + + dlt_enable_local_print(); + dlt_verbose_mode(); + + DLT_LOG(ctx, DLT_LOG_WARN, DLT_STRING("a message")); /* the classic way to go */ + + int an_int = 42; + float a_float = 22.7; + DLT_LOG_FCN_CXX(ctx, DLT_LOG_WARN, "Testing DLT_LOG_CXX_FCN", an_int, a_float); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, 1.0, 65); + + /* Example for logging user-defined types */ + MyStruct myData = { 1u, 2u, 3u }; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "MyStruct myData", myData); + + char *non_const_string = (char *)malloc(17); + memcpy(non_const_string, "non_const_string", 16); + non_const_string[16] = 0; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "char *", non_const_string); + + std::string aString = "std::string"; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "std::string", aString); + + std::vector intVector; + intVector.push_back(0); + intVector.push_back(1); + intVector.push_back(2); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector); + + std::vector doubleList; + doubleList.push_back(10.); + doubleList.push_back(11.); + doubleList.push_back(12.); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList); + + std::map testMap; + testMap["apple"] = 100; + testMap["plum"] = 200; + testMap["orange"] = 300; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "map", testMap); + + dlt_unregister_context(&ctx); + dlt_unregister_app(); + + return 0; +} diff -Nru dlt-daemon-2.18.9/tests/dlt-test-preregister-context.c dlt-daemon-2.18.4/tests/dlt-test-preregister-context.c --- dlt-daemon-2.18.9/tests/dlt-test-preregister-context.c 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/tests/dlt-test-preregister-context.c 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,56 @@ +/* + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * For further information see http://www.genivi.org/. + */ + +/*! + * \author Stefan Vacek Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-preregister-context.c + */ + +#include /* for fork() */ + +#include "dlt.h" + +/** + * @brief sample code for using pre-registered contexts + */ +int main() +{ + DltContext mainContext; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 200000 * 1000; + + DLT_REGISTER_CONTEXT(mainContext, "CTXP", "main context"); + + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before app registered")); + nanosleep(&ts, NULL); + + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Second message before app registered")); + nanosleep(&ts, NULL); + + DLT_REGISTER_APP("PRNT", "Sample pre-register application"); + + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message after app registered")); + nanosleep(&ts, NULL); + + DLT_UNREGISTER_APP() + ; + + return 0; +} diff -Nru dlt-daemon-2.18.9/tests/dlt_test_receiver.c dlt-daemon-2.18.4/tests/dlt_test_receiver.c --- dlt-daemon-2.18.9/tests/dlt_test_receiver.c 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/dlt_test_receiver.c 2019-09-03 08:28:13.000000000 +0000 @@ -78,6 +78,7 @@ #include #include "dlt_client.h" +#include #define DLT_RECEIVE_ECU_ID "RECV" @@ -95,8 +96,6 @@ int systemloggervalue; char ecuid[4]; int ohandle; - int sendSerialHeaderFlag; - int resyncSerialHeaderFlag; DltFile file; DltFilter filter; } DltReceiveData; @@ -120,8 +119,6 @@ printf("Options:\n"); printf(" -v Verbose mode\n"); printf(" -h Usage\n"); - printf(" -S Send message with serial header (Default: Without serial header)\n"); - printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode\n"); printf(" -f Activate filetransfer test case\n"); printf(" -s Activate systemd journal test case\n"); @@ -147,8 +144,6 @@ dltdata.ovalue = 0; dltdata.evalue = 0; dltdata.bvalue = 0; - dltdata.sendSerialHeaderFlag = 0; - dltdata.resyncSerialHeaderFlag = 0; dltdata.ohandle = -1; dltdata.filetransfervalue = 0; dltdata.systemjournalvalue = 0; @@ -156,7 +151,7 @@ /* Fetch command line arguments */ opterr = 0; - while ((c = getopt (argc, argv, "vshSRyfla:o:e:b:")) != -1) + while ((c = getopt (argc, argv, "vshyfla:o:e:b:")) != -1) switch (c) { case 'v': { @@ -168,16 +163,6 @@ usage(); return -1; } - case 'S': - { - dltdata.sendSerialHeaderFlag = 1; - break; - } - case 'R': - { - dltdata.resyncSerialHeaderFlag = 1; - break; - } case 'y': { dltdata.yflag = 1; @@ -278,10 +263,6 @@ dlt_client_setbaudrate(&dltclient, dltdata.bvalue); } - /* Update the send and resync serial header flags based on command line option */ - dltclient.send_serial_header = dltdata.sendSerialHeaderFlag; - dltclient.resync_serial_header = dltdata.resyncSerialHeaderFlag; - /* initialise structure to use DLT file */ dlt_file_init(&(dltdata.file), dltdata.vflag); diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_common.cpp dlt-daemon-2.18.4/tests/gtest_dlt_common.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_common.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_common.cpp 2019-09-03 08:28:13.000000000 +0000 @@ -34,8 +34,6 @@ #include "dlt-daemon_cfg.h" #include "dlt_user_cfg.h" #include "dlt_version.h" -#include "dlt_client.h" -#include "dlt_protocol.h" int dlt_buffer_increase_size(DltBuffer *); int dlt_buffer_minimize_size(DltBuffer *); @@ -331,10 +329,8 @@ dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (unsigned int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / (size + sizeof(DltBufferBlockHead))); i++) - { + for (unsigned int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / size); i++) EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&test, size)); - } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } @@ -421,7 +417,7 @@ dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (unsigned int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / (size * 3 + sizeof(DltBufferBlockHead))); i++) + for (int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / size); i++) EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push3(&buf, (unsigned char *)&test, size, (unsigned char *)&test, size, (unsigned char *)&test, @@ -1110,27 +1106,27 @@ dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /*printf("##### %i\n", dlt_buffer_get_message_count(&buf)); */ - EXPECT_EQ(0, dlt_buffer_get_message_count(&buf)); + EXPECT_LE(0, dlt_buffer_get_message_count(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - /* Normal Use-Case, with pushing data, expected 1 */ + /* Normal Use-Case, with pushing data, expected > 0 */ EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); /*printf("#### %i\n", dlt_buffer_get_message_count(&buf)); */ - EXPECT_EQ(1, dlt_buffer_get_message_count(&buf)); + EXPECT_LE(0, dlt_buffer_get_message_count(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - /* Pushing DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)) mesages */ + /* Pushing 1000 mesages, expected 10000 */ EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (unsigned int i = 1; i <= DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); i++) { + for (int i = 1; i <= 10000; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); /*printf("#### %i\n", dlt_buffer_get_message_count(&buf)); */ - EXPECT_EQ(i, dlt_buffer_get_message_count(&buf)); + EXPECT_LE(i, dlt_buffer_get_message_count(&buf)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); @@ -1197,35 +1193,33 @@ { DltBuffer buf; DltUserHeader header; - int sum = 0; /* Normal Use Cas buffer empty, expected 0 */ EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /*printf("##### %i\n", dlt_buffer_get_used_size(&buf)); */ - EXPECT_EQ(0, dlt_buffer_get_used_size(&buf)); + EXPECT_LE(0, dlt_buffer_get_used_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - /* Normal Use-Case with pushing data, expected sum of DltUserHeader and DltBufferBlockHead */ + /* Normal Use-Case with pushing data, expected > 0 */ EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); /*printf("##### %i\n", dlt_buffer_get_used_size(&buf)); */ - EXPECT_EQ(sizeof(DltUserHeader) + sizeof(DltBufferBlockHead), dlt_buffer_get_used_size(&buf)); + EXPECT_LE(0, dlt_buffer_get_used_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - /* Normal Use-Case with pushing DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)) data */ + /* Normal Use-Case with pushing 10000 data, expected > 0 */ EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (unsigned int i = 1; i <= DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); i++) { + for (int i = 1; i <= 10000; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); /*printf("#### %i\n", dlt_buffer_get_used_size(&buf)); */ - sum += sizeof(DltUserHeader) + sizeof(DltBufferBlockHead); - EXPECT_EQ(sum, dlt_buffer_get_used_size(&buf)); + EXPECT_LE(1, dlt_buffer_get_used_size(&buf)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); @@ -1283,20 +1277,8 @@ } TEST(t_dlt_buffer_write_block, abnormal) { - /* Boundary check of write position */ - DltBuffer buf; - const char *data = "data"; - int write = DLT_USER_RINGBUFFER_MIN_SIZE; - write -= sizeof(DltBufferHead); - int size = sizeof(data); - // when write = buf->size, it should not throw any warning - // and write should equal to size. - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf,DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, (unsigned char *)&data, size)); - EXPECT_EQ(size , write); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); + /* actual no abnormal test cases */ + /* because of void funktion and missing gtest tools for that */ } TEST(t_dlt_buffer_write_block, nullpointer) { @@ -1376,23 +1358,8 @@ } TEST(t_dlt_buffer_read_block, abnormal) { - /* Boundary check of read position */ - DltBuffer buf; - /* Buffer to read data from DltBuffer */ - unsigned char *data_read; - data_read = (unsigned char *) calloc(1000, sizeof(char)); - int read = DLT_USER_RINGBUFFER_MIN_SIZE; - read -= sizeof(DltBufferHead); - int size = 1000; - // when read = buf->size, it should not throw any warning - // and read position should equal to size. - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, data_read, size)); - EXPECT_EQ(size,read); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - free(data_read); + /* actual no abnormal test cases */ + /* because of void funktion and missing gtest tools for that */ } TEST(t_dlt_buffer_read_block, nullpointer) { @@ -1656,59 +1623,6 @@ -/* Begin Method: dlt_common::dlt_file_quick_parsing */ -TEST(t_dlt_file_quick_parsing, normal) -{ - DltFile file; - /* Get PWD so file can be used*/ - char pwd[100]; - char openfile[114]; - char output[128] = "/tmp/output_testfile.txt"; - - /* ignore returned value from getcwd */ - if (getcwd(pwd, 100) == NULL) {} - - sprintf(openfile, "%s/testfile.dlt", pwd); - /*---------------------------------------*/ - - /* Normal Use-Case, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_quick_parsing(&file, output, DLT_OUTPUT_ASCII, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); - unlink(output); -} - -TEST(t_dlt_file_quick_parsing, abnormal) -{ - DltFile file; - /* Get PWD so file can be used*/ - char pwd[100]; - char openfile[114]; - char output[128] = "/tmp/output_testfile.txt"; - - /* ignore returned value from getcwd */ - if (getcwd(pwd, 100) == NULL) {} - - sprintf(openfile, "%s/testfile.dlt", pwd); - /*---------------------------------------*/ - - /* Abnormal Use-Case, expected DLT_RETURN_WRONG_PARAMETER (-5) */ - EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - EXPECT_GE(DLT_RETURN_WRONG_PARAMETER, dlt_file_quick_parsing(&file, NULL, DLT_OUTPUT_ASCII, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); - - EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - EXPECT_GE(DLT_RETURN_WRONG_PARAMETER, dlt_file_quick_parsing(NULL, output, DLT_OUTPUT_ASCII, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); -} -/* End Method: dlt_common::dlt_file_quick_parsing */ - - - - /* Begin Method: dlt_common::dlt_message_print_ascii*/ TEST(t_dlt_message_print_ascii, normal) { @@ -3210,44 +3124,56 @@ } TEST(t_dlt_message_payload, abnormal) { - DltFile file; - static char text[DLT_DAEMON_TEXTSIZE]; +/* DltFile file; */ +/* static char text[DLT_DAEMON_TEXTSIZE]; */ /* Get PWD so file and filter can be used*/ - char pwd[100]; - if (getcwd(pwd, 100) == NULL) {} - - char openfile[114]; - sprintf(openfile, "%s/testfile.dlt", pwd); +/* char pwd[100]; */ +/* getcwd(pwd, 100); */ +/* char openfile[114]; */ +/* sprintf(openfile, "%s/testfile.dlt", pwd); */ /*---------------------------------------*/ /* Uninizialised, expected -1 */ - memset(&file, 0x00, sizeof(DltFile)); - - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); */ +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); */ /* USE own DLT_HEADER_SHOW , expected -1 */ - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0)); +/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0)); */ - EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file,0)>=0){} - for(int i=0;i=0){} */ +/* for(int i=0;i=0){} */ +/* for(int i=0;iservice_id, &resp->status); - EXPECT_EQ(DLT_RETURN_OK, ret); - EXPECT_EQ(DLT_SERVICE_ID_GET_LOG_INFO, resp->service_id); - EXPECT_EQ(GET_LOG_INFO_STATUS_MAX, resp->status); - - ret = dlt_client_parse_get_log_info_resp_text(resp, input); - EXPECT_EQ(DLT_RETURN_OK, ret); - - EXPECT_EQ(2,resp->log_info_type.count_app_ids); - - EXPECT_EQ(0, memcmp( "LOG", resp->log_info_type.app_ids[0].app_id,4)); - EXPECT_EQ(0, strcmp("Test Application for Logging", resp->log_info_type.app_ids[0].app_description)); - EXPECT_EQ(28, resp->log_info_type.app_ids[0].len_app_description); - - EXPECT_EQ(3, resp->log_info_type.app_ids[0].count_context_ids); - - EXPECT_EQ(0, memcmp( "TEST", resp->log_info_type.app_ids[0].context_id_info[0].context_id,4)); - EXPECT_EQ(0, strcmp( "Test Context for Logging",resp->log_info_type.app_ids[0].context_id_info[0].context_description )); - EXPECT_EQ(24,resp->log_info_type.app_ids[0].context_id_info[0].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[0].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[0].trace_status); - - EXPECT_EQ(0, memcmp( "TS1", resp->log_info_type.app_ids[0].context_id_info[1].context_id,4)); - EXPECT_EQ(0, strcmp( "Test Context1 for injection",resp->log_info_type.app_ids[0].context_id_info[1].context_description )); - EXPECT_EQ(27,resp->log_info_type.app_ids[0].context_id_info[1].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[1].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[1].trace_status); - - EXPECT_EQ(0, memcmp( "TS2", resp->log_info_type.app_ids[0].context_id_info[2].context_id,4)); - EXPECT_EQ(0, strcmp( "Test Context2 for injection",resp->log_info_type.app_ids[0].context_id_info[2].context_description )); - EXPECT_EQ(27,resp->log_info_type.app_ids[0].context_id_info[2].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[2].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[2].trace_status); - - EXPECT_EQ(0, memcmp( "SYS", resp->log_info_type.app_ids[1].app_id,4)); - EXPECT_EQ(0, strcmp("DLT System Manager", resp->log_info_type.app_ids[1].app_description)); - EXPECT_EQ(18, resp->log_info_type.app_ids[1].len_app_description); - - EXPECT_EQ(2, resp->log_info_type.app_ids[1].count_context_ids); - - EXPECT_EQ(0, memcmp( "JOUR", resp->log_info_type.app_ids[1].context_id_info[0].context_id,4)); - EXPECT_EQ(0, strcmp( "Journal Adapter",resp->log_info_type.app_ids[1].context_id_info[0].context_description )); - EXPECT_EQ(15,resp->log_info_type.app_ids[1].context_id_info[0].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[0].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[0].trace_status); - - EXPECT_EQ(0, memcmp( "MGR", resp->log_info_type.app_ids[1].context_id_info[1].context_id,4)); - EXPECT_EQ(0, strcmp( "Context of main dlt system manager",resp->log_info_type.app_ids[1].context_id_info[1].context_description )); - EXPECT_EQ(34,resp->log_info_type.app_ids[1].context_id_info[1].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[1].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[1].trace_status); - - ret = (DltReturnValue)dlt_client_cleanup_get_log_info(resp); - EXPECT_EQ(DLT_RETURN_OK,ret); -} -TEST(dlt_getloginfo_conv_ascii_to_string, normal) -{ - /* NULL-Pointer, expect exeption */ - char rp_1[] = "72 65 6d 6f"; - char rp_2[] = "123456789 72 65 6d 6f"; - int rp_count = 0; - char rp_str[] = - { 0x72, 0x65, 0x6d, 0x6f, 0x00 }; - char wp[5]; - - dlt_getloginfo_conv_ascii_to_string(rp_1, &rp_count, wp, 4); - EXPECT_EQ(0, strcmp(rp_str, wp)); - EXPECT_EQ(12, rp_count); - - rp_count = 10; - dlt_getloginfo_conv_ascii_to_string(rp_2, &rp_count, wp, 4); - EXPECT_EQ(0, strcmp(rp_str, wp)); - EXPECT_EQ(22, rp_count); - -} /*##############################################################################################################################*/ /*##############################################################################################################################*/ diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_common.cpp dlt-daemon-2.18.4/tests/gtest_dlt_daemon_common.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_common.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_common.cpp 2019-09-03 08:28:13.000000000 +0000 @@ -1727,6 +1727,9 @@ } /* End Method: dlt_daemon_common::dlt_daemon_user_send_log_state */ + + + /*##############################################################################################################################*/ /*##############################################################################################################################*/ /*##############################################################################################################################*/ diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_gateway.cpp dlt-daemon-2.18.4/tests/gtest_dlt_daemon_gateway.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_gateway.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_gateway.cpp 2019-09-03 08:28:13.000000000 +0000 @@ -95,22 +95,13 @@ /* Begin Method: dlt_gateway::t_dlt_gateway_send_control_message*/ TEST(t_dlt_gateway_send_control_message, Normal) { + int ret = 0; DltDaemonLocal daemon_local; DltGatewayConnection connections; DltConnection connections1; DltReceiver receiver1; - DltPassiveControlMessage p_control_msgs; - DltServiceSetLogLevel req; - memset(&daemon_local,0, sizeof(DltDaemonLocal)); - memset(&connections, 0, sizeof(DltGatewayConnection)); - memset(&p_control_msgs,0, sizeof(DltPassiveControlMessage)); - strcpy(req.apid,"LOG"); - strcpy(req.ctid,"TES"); - req.log_level = 1; - daemon_local.pGateway.connections = &connections; daemon_local.pEvent.connections = &connections1; - daemon_local.pGateway.connections->p_control_msgs = &p_control_msgs; daemon_local.pEvent.connections->next = NULL; daemon_local.pEvent.pfd = 0; daemon_local.pEvent.nfds = 0; @@ -118,55 +109,20 @@ daemon_local.pEvent.connections->receiver = &receiver1; memset(daemon_local.flags.gatewayConfigFile, 0, DLT_DAEMON_FLAG_MAX); strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); - (void) dlt_gateway_init(&daemon_local, 0); + ret = dlt_gateway_init(&daemon_local, 0); + + EXPECT_EQ(DLT_RETURN_OK, ret); - daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_GET_LOG_INFO; - daemon_local.pGateway.connections->p_control_msgs->type = CONTROL_MESSAGE_ON_DEMAND; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); - - daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); - - daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); - - daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_SET_LOG_LEVEL; - - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - (void*)&req, 0)); + dlt_gateway_send_control_message(daemon_local.pGateway.connections, + daemon_local.pGateway.connections->p_control_msgs, + NULL, + 0); + dlt_gateway_deinit(&daemon_local.pGateway, 0); } TEST(t_dlt_gateway_send_control_message, nullpointer) { - DltDaemonLocal daemon_local; - DltGatewayConnection connections; - DltConnection connections1; - DltReceiver receiver1; - DltPassiveControlMessage p_control_msgs; - memset(&daemon_local,0, sizeof(DltDaemonLocal)); - memset(&connections, 0, sizeof(DltGatewayConnection)); - memset(&p_control_msgs,0, sizeof(DltPassiveControlMessage)); - daemon_local.pGateway.connections = &connections; - daemon_local.pEvent.connections = &connections1; - daemon_local.pGateway.connections->p_control_msgs = &p_control_msgs; - daemon_local.pEvent.connections->next = NULL; - daemon_local.pEvent.connections->receiver = &receiver1; - memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX); - strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_send_control_message(NULL, NULL, NULL, 0)); - - daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_SET_LOG_LEVEL; - EXPECT_EQ(DLT_RETURN_ERROR,dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_store_connection*/ @@ -365,7 +321,7 @@ { DltGatewayConnection tmp; DltGatewayConnection *con; - char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "-1"; + char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "0"; con = &tmp; EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_timeout(con, value)); diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_gateway.sh dlt-daemon-2.18.4/tests/gtest_dlt_daemon_gateway.sh --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_gateway.sh 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_gateway.sh 2019-09-03 08:28:13.000000000 +0000 @@ -153,13 +153,6 @@ echo "Error in creating dlt_gateway file" return 1 fi - - if [ $# -eq 1 ] && [ "$1" = "1" ] - then - echo "[General]" >>$tmpPath/dlt_gateway.conf - echo "Interval=1">>$tmpPath/dlt_gateway.conf - fi - echo "[PassiveNode1]" >>$tmpPath/dlt_gateway.conf echo "IPaddress=$ipaddr">>$tmpPath/dlt_gateway.conf echo "Port=3490" >>$tmpPath/dlt_gateway.conf @@ -169,10 +162,8 @@ echo "SendControl=0x03,0x13" >>$tmpPath/dlt_gateway.conf echo "SendSerialHeader=0" >>$tmpPath/dlt_gateway.conf echo "NOFiles=1" >>$tmpPath/dlt_gateway.conf - return 0 } - # # Function: -startDaemons() # @@ -186,7 +177,7 @@ { DLT_PASSIVE_SHM_NAME="" tmpPath=/tmp - dlt-daemon -c $tmpPath/dlt_passive.conf & + dlt-daemon -d sleep 1 # Check if the dlt shm file exist (DLT_SHM_ENABLE=ON) @@ -194,7 +185,7 @@ DLT_PASSIVE_SHM_NAME="-s dlt-shm-passive" fi - dlt-daemon -p 3495 -c $tmpPath/dlt.conf $DLT_PASSIVE_SHM_NAME & + dlt-daemon -d -p 3495 -c $tmpPath/dlt.conf $DLT_PASSIVE_SHM_NAME return 0 } @@ -214,7 +205,7 @@ if [ $total -ne '2' ]; then echo "Initialization of dlt-daemon instances failed" - exit 1 + exit fi } @@ -244,14 +235,7 @@ fi echo "Initializing test" - -if [ $# -eq 1 ] && [ "$1" = "-w" ] -then - echo "Including General section in dlt_gateway.conf" - setupTest 1 -else - setupTest -fi +setupTest if [ $? -ne '0' ] then diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_logstorage.sh dlt-daemon-2.18.4/tests/gtest_dlt_daemon_logstorage.sh --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_logstorage.sh 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_logstorage.sh 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,57 @@ +#!/bin/sh +######################################################################################## +#file : g_test_dlt_daemon_logstorage.sh +# +#Description : logstorage unit test preparation +# +#Author Name : Onkar Palkar +#Email Id : onkar.palkar@wipro.com +# +#History : Last modified date : 02/09/2016 +######################################################################################## +# +# Function: -cleanup() +# +# Description -Delete dlt_logstorage.conf file from tmp folder if present +# +# Return -Zero on success +# -Non zero on failure +# + +cleanup() +{ + tmpPath=/tmp + cd $tmpPath + rm -rf $tmpPath/dlt_logstorage.conf + return 0 +} + +# +# Function: -setupTest() +# +# Description -create logstorage.conf file +# +# Return -Zero on success +# -Non zero on failure +# +setupTest() +{ + touch $tmpPath/dlt_logstorage.conf + if [ $? -eq '1' ] + then + echo "Error in creating dlt_logstorage.conf file" + return 1 + fi + echo "[FILTER1]" >>$tmpPath/dlt_logstorage.conf + echo "LogAppName=DLST" >>$tmpPath/dlt_logstorage.conf + echo "ContextName=.*" >>$tmpPath/dlt_logstorage.conf + echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/dlt_logstorage.conf + echo "File=Test" >>$tmpPath/dlt_logstorage.conf + echo "FileSize=1000000" >>$tmpPath/dlt_logstorage.conf + echo "NOFiles=1" >>$tmpPath/dlt_logstorage.conf + return 0 +} +#main function +######################################################################################## +cleanup +setupTest diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp dlt-daemon-2.18.4/tests/gtest_dlt_daemon_multiple_files_logging.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_multiple_files_logging.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_multiple_files_logging.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,277 +0,0 @@ -/* - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2011-2015, BMW AG - * - * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. - * - * This Source Code Form is subject to the terms of the - * Mozilla Public License (MPL), v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information see http://www.genivi.org/. - */ - -/*! - * \author - * Oleg Tropmann - * Daniel Weber - * - * \copyright Copyright © 2022 Daimler TSS GmbH. \n - * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. - * - * \file gtest_dlt_daemon_multiple_files_logging.ccpp - */ - -#include - -int connectServer(void); - -extern "C" -{ -#include "dlt_common.h" -#include -#include -#include -} - -// publish prototypes -void configure(const char* path, const char* file_name, bool enable_limit, int file_size, int max_files_size); -void write_log_message(); -void verify_multiple_files(const char* path, const char* file_name, int file_size, int max_files_size); -void verify_single_file(const char* path, const char* file_name); -void verify_in_one_file(const char* path, const char* file_name, const char* log1, const char* log2); -bool file_contains_strings(const char* abs_file_path, const char* str1, const char* str2); -int get_file_index(char* file_name); -int compare_int(const void* a, const void* b); - -/** - * Configure dlt logging using file size limits. - */ -TEST(t_dlt_logging_multiple_files, normal) -{ - const char* path = "/tmp"; - const char* file_name = "dlt.log"; - const int file_size = 128; - const int max_file_size = 512; - configure(path, file_name, true, file_size, max_file_size); - write_log_message(); - EXPECT_NO_THROW(dlt_log_free()); - verify_multiple_files(path, file_name, file_size, max_file_size); -} - -/** - * Configure dlt logging using file size limits. - * Though, due to an error during initialization dlt logging defaults to one file logging. - */ -TEST(t_dlt_logging_one_file_as_fallback, normal) -{ - const char* path = "/tmp"; - const char* file_name = "dltlog"; - configure(path, file_name, true, 128, 512); - write_log_message(); - EXPECT_NO_THROW(dlt_log_free()); - verify_single_file(path, file_name); -} - -/** - * Configure dlt logging without file size limits resulting in one file logging. - */ -TEST(t_dlt_logging_one_file, normal) -{ - const char* path = "/tmp"; - const char* file_name = "dlt.log"; - configure(path, file_name, false, 128, 512); - write_log_message(); - EXPECT_NO_THROW(dlt_log_free()); - verify_single_file(path, file_name); -} - -/** - * The dlt_daemon calls dlt_log_init multiple times. In the past, so we create - * unnecessary two files. The reinit have to append to the first file. - */ -TEST(t_dlt_logging_multiple_files_append_reinit, normal) -{ - const char* path = "/tmp"; - const char* file_name = "dlt.log"; - const int file_size = 256; - const int max_file_size = 512; - - const char* log1 = "ONE\n"; - const char* log2 = "TWO\n"; - - configure(path, file_name, true, file_size, max_file_size); - dlt_vlog(LOG_INFO, log1); - EXPECT_NO_THROW(dlt_log_free()); - - configure(path, file_name, true, file_size, max_file_size); - dlt_vlog(LOG_INFO, log2); - EXPECT_NO_THROW(dlt_log_free()); - verify_in_one_file(path, file_name, log1, log2); -} - -void configure(const char *path, const char* file_name, const bool enable_limit, const int file_size, const int max_files_size) -{ - char abs_file_path[PATH_MAX]; - snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, file_name); - printf("debug test: %s\n", abs_file_path); - - EXPECT_NO_THROW(dlt_log_set_filename(abs_file_path)); - EXPECT_NO_THROW(dlt_log_set_level(6)); - EXPECT_NO_THROW(dlt_log_init_multiple_logfiles_support(DLT_LOG_TO_FILE, enable_limit, file_size, max_files_size)); -} - -void write_log_message() -{ - for (unsigned int i = 0; i < 10; i++) { - dlt_vlog(LOG_INFO, "%d. Unit test logging into multiple files if configured.\n", i); - } -} - -void verify_multiple_files(const char* path, const char* file_name, const int file_size, const int max_files_size) -{ - int sum_size = 0; - int num_files = 0; - int file_indices[100]; - - char filename[PATH_MAX + 1]; - struct dirent *dp; - struct stat status; - - char file_name_copy[NAME_MAX]; - strncpy(file_name_copy, file_name, NAME_MAX); - char filename_base[NAME_MAX]; - EXPECT_TRUE(dlt_extract_base_name_without_ext(file_name_copy, filename_base, sizeof(filename_base))); - const char *filename_ext = get_filename_ext(file_name); - EXPECT_TRUE(filename_ext); - - DIR *dir = opendir(path); - while ((dp = readdir(dir)) != NULL) { - if (strstr(dp->d_name, filename_base) && - strstr(dp->d_name, filename_ext)) { - - snprintf(filename, sizeof(filename), "%s/%s", path, dp->d_name); - - if (0 == stat(filename, &status)) { - EXPECT_LE(status.st_size, file_size); - EXPECT_GE(status.st_size, file_size/2); - sum_size += status.st_size; - file_indices[num_files++] = get_file_index(filename); - } else { - EXPECT_TRUE(false); - } - } - } - - EXPECT_LE(sum_size, max_files_size); - EXPECT_GT(sum_size, 0); - EXPECT_GT(num_files, 0); - - //check that file indices are successive in ascending order - qsort(file_indices, num_files, sizeof(int), compare_int); - int index = file_indices[0]; - for (int i=1; id_name, filename_base) && - strstr(dp->d_name, filename_ext)) { - - snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, dp->d_name); - - if (file_contains_strings(abs_file_path, log1, log2)) { - found = true; - break; - } - } - } - - EXPECT_TRUE(found); -} - -bool file_contains_strings(const char* abs_file_path, const char* str1, const char* str2) -{ - bool found = false; - FILE *file = fopen(abs_file_path, "r"); - if (file != nullptr) { - fseek (file , 0 , SEEK_END); - long size = ftell (file); - rewind (file); - - char* buffer = (char*) malloc(size); - long read_bytes = fread(buffer, 1, size, file); - - EXPECT_EQ(size, read_bytes); - - if ((strstr(buffer, str1) != nullptr) && - (strstr(buffer, str2) != nullptr)) { - - found = true; - } - - fclose(file); - free(buffer); - } - return found; -} - -int get_file_index(char* file_name) -{ - char *dot = strrchr(file_name, '.'); - *dot = '\0'; - - //start with the first zero - char *iterator = strchr(file_name, '0'); - do {} while (*(++iterator) == '0'); - //now iterator points to the first character after 0 - - return atoi(iterator); -} - -int compare_int(const void* a, const void* b) -{ - if (*((int*)a) == *((int*)b)) return 0; - else if (*((int*)a) < *((int*)b)) return -1; - else return 1; -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - ::testing::FLAGS_gtest_break_on_failure = true; - /*::testing::FLAGS_gtest_filter = "*.normal"; */ - /*::testing::FLAGS_gtest_repeat = 10000; */ - return RUN_ALL_TESTS(); -} diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_offline_log.cpp dlt-daemon-2.18.4/tests/gtest_dlt_daemon_offline_log.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_offline_log.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_offline_log.cpp 2019-09-03 08:28:13.000000000 +0000 @@ -26,10 +26,12 @@ #include #include #include -#include } -unsigned int g_logstorage_cache_max; +#ifndef DLT_DAEMON_BLOCKING_TEST +# define DLT_DAEMON_BLOCKING_TEST 1 +#endif + /* Begin Method: dlt_logstorage::t_dlt_logstorage_list_add*/ TEST(t_dlt_logstorage_list_add, normal) { @@ -107,17 +109,15 @@ data->ctids = strdup(ctid); dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, data, &list)); + ASSERT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, data, &list)); num_configs = dlt_logstorage_list_find(key, &list, config); - EXPECT_EQ(1, num_configs); - EXPECT_NE((DltLogStorageFilterConfig *)NULL, config[0]); + ASSERT_EQ(1, num_configs); + ASSERT_NE((DltLogStorageFilterConfig *)NULL, config[0]); - if (num_configs > 0) { - EXPECT_STREQ(apid, config[0]->apids); - EXPECT_STREQ(ctid, config[0]->ctids); - } + EXPECT_STREQ(apid, config[0]->apids); + EXPECT_STREQ(ctid, config[0]->ctids); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, &file_config, path, 0)); } @@ -452,8 +452,8 @@ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = 0; handle.write_errors = 0; + handle.config_list = NULL; - handle.newest_file_list = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_filters(&handle, config_file_name)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&handle.config_list, &file_config, path, 0)); @@ -474,7 +474,6 @@ handle.config_status = 0; handle.write_errors = 0; handle.config_list = NULL; - handle.newest_file_list = NULL; strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_load_config(&handle)); @@ -494,7 +493,6 @@ handle.config_status = 0; handle.write_errors = 0; handle.config_list = NULL; - handle.newest_file_list = NULL; strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_device_connected(&handle, handle.device_mount_point)); @@ -511,7 +509,6 @@ DltLogStorage handle; int reason = 0; handle.config_status = 0; - handle.newest_file_list = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_device_disconnected(&handle, reason)); } @@ -531,7 +528,6 @@ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; - handle.newest_file_list = NULL; int num_keys = 1; config = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); @@ -614,7 +610,6 @@ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; - handle.newest_file_list = NULL; int num_keys = 1; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(handle.config_list))); @@ -651,7 +646,6 @@ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; - handle.newest_file_list = NULL; DltLogStorageFilterConfig value; value.apids = apid; value.ctids = ctid; @@ -743,7 +737,7 @@ EXPECT_EQ(4, ((*head)->next)->idx); EXPECT_EQ(1, ((((*head)->next)->next)->idx)); - EXPECT_EQ(8, dlt_logstorage_sort_file_name(head)); + dlt_logstorage_sort_file_name(head); EXPECT_EQ(1, (*head)->idx); EXPECT_EQ(4, ((*head)->next)->idx); @@ -765,13 +759,14 @@ if (node3 != NULL) free(node3); } + TEST(t_dlt_logstorage_sort_file_name, null) { dlt_logstorage_sort_file_name(NULL); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_rearrange_file_name*/ -TEST(t_dlt_logstorage_rearrange_file_name, normal1) +TEST(t_dlt_logstorage_rearrange_file_name, normal) { DltLogStorageFileList *node1, *node2, *node3; DltLogStorageFileList **head; @@ -787,66 +782,19 @@ head = &node1; - node1->idx = 1; + node1->idx = 8; node2->idx = 4; - node3->idx = 8; + node3->idx = 1; - EXPECT_EQ(1, (*head)->idx); + EXPECT_EQ(8, (*head)->idx); EXPECT_EQ(4, ((*head)->next)->idx); - EXPECT_EQ(8, ((((*head)->next)->next)->idx)); - - dlt_logstorage_rearrange_file_name(head); - - EXPECT_EQ(4, (*head)->idx); - EXPECT_EQ(8, ((*head)->next)->idx); EXPECT_EQ(1, ((((*head)->next)->next)->idx)); - free((((*head)->next)->next)); - free(((*head)->next)); - free(*head); - node1 = NULL; - node2 = NULL; - node3 = NULL; - } - - if (node1 != NULL) - free(node1); - - if (node2 != NULL) - free(node2); - - if (node3 != NULL) - free(node3); -} - -TEST(t_dlt_logstorage_rearrange_file_name, normal2) -{ - DltLogStorageFileList *node1, *node2, *node3; - DltLogStorageFileList **head; - node1 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node2 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node3 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - - if ((node1 != NULL) && (node2 != NULL) && (node3 != NULL)) { - - node1->next = node2; - node2->next = node3; - node3->next = NULL; - - head = &node1; - - node1->idx = 2; - node2->idx = 4; - node3->idx = 8; - - EXPECT_EQ(2, (*head)->idx); - EXPECT_EQ(4, ((*head)->next)->idx); - EXPECT_EQ(8, ((((*head)->next)->next)->idx)); dlt_logstorage_rearrange_file_name(head); - EXPECT_EQ(2, (*head)->idx); - EXPECT_EQ(4, ((*head)->next)->idx); - EXPECT_EQ(8, ((((*head)->next)->next)->idx)); + EXPECT_EQ(1, (*head)->idx); + EXPECT_EQ(8, ((*head)->next)->idx); + EXPECT_EQ(4, ((((*head)->next)->next)->idx)); free((((*head)->next)->next)); free(((*head)->next)); free(*head); @@ -927,18 +875,16 @@ config.ctids = &ctids; config.file_name = (char *)"Test"; config.records = NULL; - config.working_file_name = NULL; - config.wrap_id = 0; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_open_log_file(&config, &file_config, path, 1, true)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_open_log_file(&config, &file_config, path, 1)); } TEST(t_dlt_logstorage_open_log_file, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_open_log_file(NULL, NULL, NULL, 0, true)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_open_log_file(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_prepare_on_msg*/ -TEST(t_dlt_logstorage_prepare_on_msg, normal1) +TEST(t_dlt_logstorage_prepare_on_msg, normal) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 191132; @@ -954,104 +900,13 @@ config.file_name = (char *)"Test"; config.records = NULL; config.log = NULL; - config.working_file_name = NULL; - config.wrap_id = 0; - DltNewestFileName newest_file_name; - newest_file_name.file_name = (char *)"Test"; - newest_file_name.newest_file = (char *)"Test_003_20200728_191132.dlt"; - newest_file_name.wrap_id = 0; - newest_file_name.next = NULL; - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); -} - -TEST(t_dlt_logstorage_prepare_on_msg, normal2) -{ - DltLogStorageUserConfig file_config; - file_config.logfile_timestamp = 191132; - file_config.logfile_delimiter = { '_' }; - file_config.logfile_maxcounter = 2; - file_config.logfile_counteridxlen = 2; - char *path = (char *)"/tmp"; - DltLogStorageFilterConfig config; - char apids; - char ctids; - config.apids = &apids; - config.ctids = &ctids; - config.file_name = (char *)"Test"; - config.records = NULL; - config.log = NULL; - config.working_file_name = NULL; - config.wrap_id = 0; - - DltNewestFileName newest_file_name; - newest_file_name.file_name = (char *)"Test"; - newest_file_name.newest_file = (char *)"Test_003_20200728_191132.dlt"; - newest_file_name.wrap_id = 1; - newest_file_name.next = NULL; - - /* Create dummy file */ - char dummy_file[100] = ""; - sprintf(dummy_file, "%s/%s", path, newest_file_name.newest_file); - int ret = 0; - FILE *fp = fopen(dummy_file, "w"); - ret = ftruncate(fileno(fp), 1024); - fclose(fp); - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); - - if (ret == 0) - { - remove(dummy_file); - } -} - -TEST(t_dlt_logstorage_prepare_on_msg, normal3) -{ - DltLogStorageUserConfig file_config; - file_config.logfile_timestamp = 191132; - file_config.logfile_delimiter = { '_' }; - file_config.logfile_maxcounter = 2; - file_config.logfile_counteridxlen = 2; - char *path = (char *)"/tmp"; - DltLogStorageFilterConfig config; - char apids; - char ctids; - char *working_file_name = (char *)"Test_002_20160509_191132.dlt"; - config.apids = &apids; - config.ctids = &ctids; - config.file_name = (char *)"Test"; - config.records = NULL; - config.log = NULL; - config.working_file_name = strdup(working_file_name); - config.wrap_id = 0; - - DltNewestFileName newest_file_name; - newest_file_name.file_name = (char *)"Test"; - newest_file_name.newest_file = (char *)"Test_003_20200728_191132.dlt"; - newest_file_name.wrap_id = 1; - newest_file_name.next = NULL; - - /* Create dummy file */ - char dummy_file[100] = ""; - sprintf(dummy_file, "%s/%s", path, newest_file_name.newest_file); - int ret = 0; - FILE *fp = fopen(dummy_file, "w"); - ret = ftruncate(fileno(fp), 1024); - fclose(fp); - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); - - if (ret == 0) - { - remove(dummy_file); - } + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1)); } TEST(t_dlt_logstorage_prepare_on_msg, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_on_msg(NULL, NULL, NULL, 0, NULL)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_on_msg(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_write_on_msg*/ @@ -1071,20 +926,12 @@ config.file_name = (char *)"Test"; config.records = NULL; config.log = NULL; - config.working_file_name = NULL; - config.wrap_id = 0; unsigned int size = 8; unsigned char data1[] = "dlt_data"; unsigned char data2[] = "dlt_data"; unsigned char data3[] = "dlt_data"; - DltNewestFileName newest_file_name; - newest_file_name.file_name = (char *)"Test"; - newest_file_name.newest_file = (char *)"Test_003_20200728_191132.dlt"; - newest_file_name.wrap_id = 0; - newest_file_name.next = NULL; - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, &file_config, path, data1, size, data2, size, data3, size)); } @@ -1107,8 +954,6 @@ config.file_name = (char *)"Test"; config.records = NULL; config.log = NULL; - config.working_file_name = NULL; - config.wrap_id = 0; char *path = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_on_msg(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_MSG)); @@ -1129,7 +974,6 @@ file_config.logfile_counteridxlen = 2; char *path = (char *)"/tmp"; DltLogStorageFilterConfig config; - DltNewestFileName newest_info; char apids; char ctids; config.apids = &apids; @@ -1140,18 +984,16 @@ config.cache = NULL; config.file_size = 0; config.sync = DLT_LOGSTORAGE_SYNC_ON_DEMAND; - config.working_file_name = NULL; - config.wrap_id = 0; g_logstorage_cache_max = 16; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1, &newest_info)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); free(config.cache); } TEST(t_dlt_logstorage_prepare_msg_cache, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_msg_cache(NULL, NULL, NULL, 0, NULL)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_msg_cache(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_write_msg_cache*/ @@ -1681,7 +1523,6 @@ free(config.cache); } } - TEST(t_dlt_logstorage_find_last_dlt_header, null) { char data[] = {'N','o','H','e','a','d','e','r'}; @@ -1708,7 +1549,6 @@ file_config.logfile_counteridxlen = 2; char *path = (char *)"/tmp"; DltLogStorageFilterConfig config; - DltNewestFileName newest_info; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; char ctids; @@ -1726,14 +1566,12 @@ unsigned char data1[10] = "dlt_data0"; unsigned char data2[10] = "dlt_data1"; unsigned char data3[10] = "dlt_data2"; - newest_info.wrap_id = 0; - config.wrap_id = 0; DltLogStorageCacheFooter *footer = NULL; config.cache = calloc(1, config.file_size + sizeof(DltLogStorageCacheFooter)); if (config.cache != NULL) { - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1, &newest_info)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, &file_config, path, data1, size, data2, size, data3, size)); @@ -1764,7 +1602,6 @@ char *path = (char *)"/tmp"; DltLogStorageFilterConfig config; - DltNewestFileName newest_info; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; char ctids; @@ -1787,7 +1624,7 @@ config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter)); if (config.cache != NULL) { - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1, &newest_info)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, &file_config, path, data1, size, data2, size, data3, size)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_msg_cache(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_DEMAND)); @@ -1803,7 +1640,7 @@ int connectServer(void) { -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC int sockfd, portno; struct sockaddr_in serv_addr; struct hostent *server; @@ -1822,7 +1659,7 @@ close(sockfd); return -1; } -#else /* DLT_DAEMON_USE_FIFO_IPC */ +#else char filename[1024]; int sockfd; snprintf(filename, 1024, "/tmp/dltpipes/dlt%d", getpid()); @@ -1841,7 +1678,7 @@ int main(int argc, char **argv) { -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC pid_t cpid; cpid = fork(); @@ -1912,7 +1749,7 @@ ::testing::FLAGS_gtest_break_on_failure = false; /* ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; */ return RUN_ALL_TESTS(); -#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC +#ifdef DLT_USE_UNIX_SOCKET_IPC } #endif diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_daemon_offline_log.sh dlt-daemon-2.18.4/tests/gtest_dlt_daemon_offline_log.sh --- dlt-daemon-2.18.9/tests/gtest_dlt_daemon_offline_log.sh 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_daemon_offline_log.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -#!/bin/sh -######################################################################################## -#file : g_test_dlt_daemon_logstorage.sh -# -#Description : logstorage unit test preparation -# -#Author Name : Onkar Palkar -#Email Id : onkar.palkar@wipro.com -# -#History : Last modified date : 02/09/2016 -######################################################################################## -# -# Function: -cleanup() -# -# Description -Delete dlt_logstorage.conf file from tmp folder if present -# -# Return -Zero on success -# -Non zero on failure -# - -cleanup() -{ - tmpPath=/tmp - cd $tmpPath - rm -rf $tmpPath/dlt_logstorage.conf - return 0 -} - -# -# Function: -setupTest() -# -# Description -create logstorage.conf file -# -# Return -Zero on success -# -Non zero on failure -# -setupTest() -{ - touch $tmpPath/dlt_logstorage.conf - if [ $? -eq '1' ] - then - echo "Error in creating dlt_logstorage.conf file" - return 1 - fi - echo "[FILTER1]" >>$tmpPath/dlt_logstorage.conf - echo "LogAppName=DLST" >>$tmpPath/dlt_logstorage.conf - echo "ContextName=.*" >>$tmpPath/dlt_logstorage.conf - echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/dlt_logstorage.conf - echo "File=Test" >>$tmpPath/dlt_logstorage.conf - echo "FileSize=1000000" >>$tmpPath/dlt_logstorage.conf - echo "NOFiles=1" >>$tmpPath/dlt_logstorage.conf - return 0 -} -#main function -######################################################################################## -cleanup -setupTest diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_json_filter.cpp dlt-daemon-2.18.4/tests/gtest_dlt_json_filter.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_json_filter.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_json_filter.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -#include -#include -#include -#include - -extern "C" -{ - #include "dlt-control-common.h" - #include "dlt-daemon.h" -} - -/* Begin Method: dlt_common::dlt_message_print_ascii with json filter*/ -TEST(t_dlt_message_print_ascii_with_json_filter, normal) -{ - DltFile file; - DltFilter filter; - static char text[DLT_DAEMON_TEXTSIZE]; - - /* Get PWD so file can be used*/ - char pwd[100]; - char openfile[114]; - - /* ignore returned value from getcwd */ - if (getcwd(pwd, 100) == NULL) {} - - char openfilter[117]; - sprintf(openfile, "%s/testfile_extended.dlt", pwd); - sprintf(openfilter, "%s/testfilter.json", pwd); - /*---------------------------------------*/ - - /* Normal Use-Case, expect 0 */ - EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_filter_init(&filter, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_json_filter_load(&filter, openfilter, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - - char tmp[DLT_ID_SIZE+1]; - strncpy(tmp, filter.apid[0], DLT_ID_SIZE); - tmp[DLT_ID_SIZE] = {}; - EXPECT_STREQ("LOG",tmp); - EXPECT_EQ(3,filter.log_level[0]); - EXPECT_EQ(0,filter.payload_min[0]); - EXPECT_EQ(INT32_MAX,filter.payload_max[0]); - - - strncpy(tmp, filter.apid[1], DLT_ID_SIZE); - EXPECT_STREQ("app",tmp); - strncpy(tmp, filter.ctid[1], DLT_ID_SIZE); - EXPECT_STREQ("",tmp); - - EXPECT_EQ(0,filter.log_level[2]); - EXPECT_EQ(20,filter.payload_min[2]); - EXPECT_EQ(50,filter.payload_max[2]); - - while (dlt_file_read(&file, 0) >= 0) {} - - for (int i = 0; i < file.counter; i++) { - EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); - } - - for (int i = 0; i < file.counter; i++) { - EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); - } - - EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); -} -TEST(t_dlt_message_print_ascii_with_json_filter, abnormal) -{ - /* equal with t_dlt_message_print_ascii */ -} -TEST(t_dlt_message_print_ascii_with_json_filter, nullpointer) -{ - /* equal with t_dlt_message_print_ascii */ -} -/* End Method: dlt_common::dlt_message_print_ascii with json filter*/ diff -Nru dlt-daemon-2.18.9/tests/gtest_dlt_user.cpp dlt-daemon-2.18.4/tests/gtest_dlt_user.cpp --- dlt-daemon-2.18.9/tests/gtest_dlt_user.cpp 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/gtest_dlt_user.cpp 2019-09-03 08:28:13.000000000 +0000 @@ -27,10 +27,6 @@ #include "gtest/gtest.h" #include #include -#include -#include -#include -#include extern "C" { #include "dlt_user.h" @@ -49,55 +45,27 @@ * int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid); * int dlt_user_log_write_finish(DltContextData *log); * int dlt_user_log_write_bool(DltContextData *log, uint8_t data); - * int dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name); * int dlt_user_log_write_float32(DltContextData *log, float32_t data); - * int dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit); * int dlt_user_log_write_float64(DltContextData *log, double data); - * int dlt_user_log_write_float64_attr(DltContextData *log, double data, const char *name, const char *unit); * int dlt_user_log_write_uint(DltContextData *log, unsigned int data); - * int dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit); * int dlt_user_log_write_uint8(DltContextData *log, uint8_t data); - * int dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit); * int dlt_user_log_write_uint16(DltContextData *log, uint16_t data); - * int dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit); * int dlt_user_log_write_uint32(DltContextData *log, uint32_t data); - * int dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit); * int dlt_user_log_write_uint64(DltContextData *log, uint64_t data); - * int dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit); * int dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type); * int dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type); * int dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type); * int dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type); * int dlt_user_log_write_int(DltContextData *log, int data); - * int dlt_user_log_write_int_attr(DltContextData *log, int data, const char *name, const char *unit); * int dlt_user_log_write_int8(DltContextData *log, int8_t data); - * int dlt_user_log_write_int8_attr(DltContextData *log, int8_t data, const char *name, const char *unit); * int dlt_user_log_write_int16(DltContextData *log, int16_t data); - * int dlt_user_log_write_int16_attr(DltContextData *log, int16_t data, const char *name, const char *unit); * int dlt_user_log_write_int32(DltContextData *log, int32_t data); - * int dlt_user_log_write_int32_attr(DltContextData *log, int32_t data, const char *name, const char *unit); * int dlt_user_log_write_int64(DltContextData *log, int64_t data); - * int dlt_user_log_write_int64_attr(DltContextData *log, int64_t data, const char *name, const char *unit); * int dlt_user_log_write_string( DltContextData *log, const char *text); - * int dlt_user_log_write_string_attr(DltContextData *log, const char *text, const char *name); - * int dlt_user_log_write_sized_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); * int dlt_user_log_write_constant_string( DltContextData *log, const char *text); - * int dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name); - * int dlt_user_log_write_sized_constant_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); * int dlt_user_log_write_utf8_string(DltContextData *log, const char *text); - * int dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); - * int dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - * int dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text); - * int dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); - * int dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text); - * int dlt_user_log_write_sized_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length); - * int dlt_user_log_write_raw_attr(DltContextData *log,void *data,uint16_t length, const char *name); * int dlt_user_log_write_raw_formatted(DltContextData *log,void *data,uint16_t length,DltFormatType type); - * int dlt_user_log_write_raw_formatted_attr(DltContextData *log,void *data,uint16_t length,DltFormatType type, const char *name); */ /* @@ -136,6 +104,90 @@ * int dlt_nonverbose_mode(void); */ + + + +/* define some min and max values (if not present in ) */ +#ifndef UINT8_MIN +# define UINT8_MIN 0 +#endif + +#ifndef UINT16_MIN +# define UINT16_MIN 0 +#endif + +#ifndef UINT32_MIN +# define UINT32_MIN 0 +#endif + +#ifndef UINT64_MIN +# define UINT64_MIN 0 +#endif + +#ifndef UINT8_MAX +# define UINT8_MAX 255 +#endif + +#ifndef UINT16_MAX +# define UINT16_MAX 65535 +#endif + +#ifndef UINT32_MAX +# define UINT32_MAX 4294967295 +#endif + +#ifndef UINT64_MAX +# define UINT64_MAX 18446744073709551615UL +#endif + +#ifndef INT8_MIN +# define INT8_MIN -128 +#endif + +#ifndef INT16_MIN +# define INT16_MIN -32768 +#endif + +#ifndef INT32_MIN +# define INT32_MIN -2147483648 +#endif + +#ifndef INT64_MIN +# define INT64_MIN -9223372036854775807 +#endif + +#ifndef INT8_MAX +# define INT8_MAX 127 +#endif + +#ifndef INT16_MAX +# define INT16_MAX 32767 +#endif + +#ifndef INT32_MAX +# define INT32_MAX 2147483647 +#endif + +#ifndef INT64_MAX +# define INT64_MAX 9223372036854775807 +#endif + +#ifndef UINT_MIN +# define UINT_MIN UINT32_MIN +#endif + +#ifndef UINT_MAX +# define UINT_MAX UINT32_MAX +#endif + +#ifndef INT_MIN +# define INT_MIN INT32_MIN +#endif + +#ifndef INT_MAX +# define INT_MAX INT32_MAX +#endif + static const char *STR_TRUNCATED_MESSAGE = "... <>"; /*/////////////////////////////////////// */ @@ -164,6 +216,8 @@ /* the defined enum values for log level */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_FATAL)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_ERROR)); @@ -172,13 +226,10 @@ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_INFO)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - /* To test the default behaviour and the default log level set to DLT_LOG_INFO */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_OFF)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEBUG)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_VERBOSE)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -258,9 +309,11 @@ EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id normal")); /* the defined enum values for log level */ - messageid = 0; + messageid = UINT32_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_OFF, messageid)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_FATAL, messageid)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_ERROR, messageid)); @@ -269,17 +322,16 @@ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_INFO, messageid)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - /* To test the default behaviour and the default log level set to DLT_LOG_INFO */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_OFF, messageid)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEBUG, messageid)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_VERBOSE, messageid)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); messageid = UINT32_MAX; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_OFF, messageid)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_FATAL, messageid)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_ERROR, messageid)); @@ -288,13 +340,10 @@ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_INFO, messageid)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - /* To test the default behaviour and the default log level set to DLT_LOG_INFO */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_OFF, messageid)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEBUG, messageid)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_VERBOSE, messageid)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_user_log_write_finish(&contextData)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -314,7 +363,7 @@ /* undefined values for DltLogLevelType */ /* shouldn't it return -1? */ - /* TODO: messageid = 0; */ + /* TODO: messageid = UINT32_MIN; */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)-100, messageid)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)-10, messageid)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)10, messageid)); */ @@ -336,7 +385,7 @@ EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id startstartfinish")); - messageid = 0; + messageid = UINT32_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); /* shouldn't it return -1, because it is already started? */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); */ @@ -359,7 +408,7 @@ dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id nullpointer")); /* NULL's */ - messageid = 0; + messageid = UINT32_MIN; EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_start_id(NULL, &contextData, DLT_LOG_DEFAULT, messageid)); /*EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_finish(&contextData)); */ EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_start_id(NULL, NULL, DLT_LOG_DEFAULT, messageid)); @@ -403,26 +452,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_finish */ -TEST(t_dlt_user_log_write_finish, finish_with_timestamp) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_finish finish")); - - /* finish with start and initialized context */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - contextData.use_timestamp = DLT_USER_TIMESTAMP; - contextData.user_timestamp = UINT32_MAX; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_bool */ TEST(t_dlt_user_log_write_bool, normal) { @@ -492,28 +521,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_bool_attr */ -TEST(t_dlt_user_log_write_bool_attr, normal) -{ - DltContext context; - DltContextData contextData; - uint8_t data; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - data = true; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_bool_attr(&contextData, data, "state")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_bool_attr(&contextData, data, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_bool_attr(&contextData, data, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_float32 */ TEST(t_dlt_user_log_write_float32, normal) { @@ -566,32 +573,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_float32_attr */ -TEST(t_dlt_user_log_write_float32_attr, normal) -{ - DltContext context; - DltContextData contextData; - float32_t data; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float32_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - data = 3.141592653589793238f; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float32_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_float64 */ TEST(t_dlt_user_log_write_float64, normal) { @@ -644,32 +625,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_float64_attr */ -TEST(t_dlt_user_log_write_float64_attr, normal) -{ - DltContext context; - DltContextData contextData; - double data; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float64_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - data = 3.14159265358979323846; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_float64_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_uint */ TEST(t_dlt_user_log_write_uint, normal) { @@ -684,7 +639,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint(&contextData, data)); data = 1; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint(&contextData, data)); @@ -737,32 +692,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_uint_attr */ -TEST(t_dlt_user_log_write_uint_attr, normal) -{ - DltContext context; - DltContextData contextData; - unsigned int data; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - data = 42; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_uint8 */ TEST(t_dlt_user_log_write_uint8, normal) { @@ -777,7 +706,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT8_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8(&contextData, data)); data = 1; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8(&contextData, data)); @@ -809,31 +738,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_uint8_attr */ -TEST(t_dlt_user_log_write_uint8_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - uint8_t data = 0xaa; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_uint16 */ TEST(t_dlt_user_log_write_uint16, normal) { @@ -848,7 +752,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT16_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16(&contextData, data)); data = 1; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16(&contextData, data)); @@ -880,31 +784,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_uint16_attr */ -TEST(t_dlt_user_log_write_uint16_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - uint16_t data = 0xaa55; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_uint32 */ TEST(t_dlt_user_log_write_uint32, normal) { @@ -919,7 +798,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT32_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32(&contextData, data)); data = 1; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32(&contextData, data)); @@ -951,31 +830,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_uint32_attr */ -TEST(t_dlt_user_log_write_uint32_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - uint32_t data = 0xaabbccdd; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_uint64 */ TEST(t_dlt_user_log_write_uint64, normal) { @@ -990,7 +844,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT64_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64(&contextData, data)); data = 1; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64(&contextData, data)); @@ -1022,31 +876,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_uint64_attr */ -TEST(t_dlt_user_log_write_uint64_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - uint64_t data = 0x11223344aabbccddULL; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_uint8_formatted */ TEST(t_dlt_user_log_write_uint8_formatted, normal) { @@ -1062,7 +891,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT8_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_formatted(&contextData, data, DLT_FORMAT_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_formatted(&contextData, data, DLT_FORMAT_HEX8)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint8_formatted(&contextData, data, DLT_FORMAT_HEX16)); @@ -1158,7 +987,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT16_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_formatted(&contextData, data, DLT_FORMAT_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_formatted(&contextData, data, DLT_FORMAT_HEX8)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint16_formatted(&contextData, data, DLT_FORMAT_HEX16)); @@ -1254,7 +1083,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT32_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_formatted(&contextData, data, DLT_FORMAT_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_formatted(&contextData, data, DLT_FORMAT_HEX8)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_formatted(&contextData, data, DLT_FORMAT_HEX16)); @@ -1350,7 +1179,7 @@ /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - data = 0; + data = UINT64_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_formatted(&contextData, data, DLT_FORMAT_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_formatted(&contextData, data, DLT_FORMAT_HEX8)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint64_formatted(&contextData, data, DLT_FORMAT_HEX16)); @@ -1480,31 +1309,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_int_attr */ -TEST(t_dlt_user_log_write_int_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - int data = -42; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_int8 */ TEST(t_dlt_user_log_write_int8, normal) { @@ -1555,31 +1359,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_int8_attr */ -TEST(t_dlt_user_log_write_int8_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int8_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - int8_t data = 0xaa; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int8_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_int16 */ TEST(t_dlt_user_log_write_int16, normal) { @@ -1630,31 +1409,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_int16_attr */ -TEST(t_dlt_user_log_write_int16_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int16_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - int16_t data = 0xaa55; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int16_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_int32 */ TEST(t_dlt_user_log_write_int32, normal) { @@ -1705,31 +1459,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_int32_attr */ -TEST(t_dlt_user_log_write_int32_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int32_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - int32_t data = 0xffeeddcc; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int32_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_int64 */ TEST(t_dlt_user_log_write_int64, normal) { @@ -1780,31 +1509,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_int64_attr */ -TEST(t_dlt_user_log_write_int64_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int64_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - int64_t data = 0xffeeddcc44332211LL; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, "name", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, "", "unit")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, "name", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, "", "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, NULL, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, "", NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_int64_attr(&contextData, data, NULL, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_string */ TEST(t_dlt_user_log_write_string, normal) { @@ -2151,31 +1855,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_string */ - -TEST(t_dlt_user_log_write_sized_string, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_string normal")); - - /* normal values */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - const char text1[] = "TheQuickBrownFox"; - const char *arg1_start = strchr(text1, 'Q'); - const size_t arg1_len = 5; - /* from the above string, send only the substring "Quick" */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_string(&contextData, arg1_start, arg1_len)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_constant_string */ TEST(t_dlt_user_log_write_constant_string, normal) { @@ -2317,42 +1996,17 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_constant_string */ - -TEST(t_dlt_user_log_write_sized_constant_string, normal) +/* t_dlt_user_log_write_utf8_string */ +TEST(t_dlt_user_log_write_utf8_string, normal) { DltContext context; DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_string normal")); - - /* normal values */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - const char text1[] = "TheQuickBrownFox"; - const char *arg1_start = strchr(text1, 'Q'); - const size_t arg1_len = 5; - /* from the above string, send only the substring "Quick" */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_string(&contextData, arg1_start, arg1_len)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_utf8_string */ -TEST(t_dlt_user_log_write_utf8_string, normal) -{ - DltContext context; - DltContextData contextData; - - - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal")); + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -3300,383 +2954,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_utf8_string */ - -TEST(t_dlt_user_log_write_sized_utf8_string, partial_string) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string normal")); - - /* normal values */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - const char text1[] = "TheQuickBrownFox"; - const char* arg1_start = strchr(text1, 'Q'); - const size_t arg1_len = 5; - /* from the above string, send only the substring "Quick" */ - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_utf8_string(&contextData, arg1_start, arg1_len)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_sized_utf8_string, nullpointer) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string nullpointer")); - - /* NULL */ - const char *text1 = "test1"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_sized_utf8_string(NULL, text1, 5)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_sized_utf8_string(NULL, NULL, 5)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_sized_utf8_string(&contextData, NULL, 5)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_constant_utf8_string*/ -TEST(t_dlt_user_log_write_constant_utf8_string, verbose) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string verbose")); - - const char *text1 = "test1"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, text1)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_constant_utf8_string, nullpointer) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nullpointer")); - - const char *text1 = "test1"; - EXPECT_LE(DLT_RETURN_TRUE, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(NULL, text1)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(NULL, NULL)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, NULL)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_constant_utf8_string, nonverbose) -{ - dlt_nonverbose_mode(); - - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nonverbose")); - - const char *text2 = "test2"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, text2)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); - - dlt_verbose_mode(); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_constant_utf8_string */ -TEST(t_dlt_user_log_write_sized_constant_utf8_string, verbose) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string verbose")); - - const char *text1 = "test1text"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, text1, 5)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_sized_constant_utf8_string, nullpointer) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nullpointer")); - - const char *text1 = "test1text"; - EXPECT_LE(DLT_RETURN_TRUE, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(NULL, text1, 5)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(NULL, NULL, 5)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, NULL, 5)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_sized_constant_utf8_string, nonverbose) -{ - dlt_nonverbose_mode(); - - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nonverbose")); - - const char *text2 = "test2text"; - size_t text2len = 5; // only use a (non-null-terminated) substring - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, text2, text2len)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); - - dlt_verbose_mode(); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_string_attr */ -TEST(t_dlt_user_log_write_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_string_attr(&contextData, data, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_string_attr(&contextData, data, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_string_attr(&contextData, data, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_string_attr */ -TEST(t_dlt_user_log_write_sized_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_string_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456789"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_string_attr(&contextData, data, 6, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_string_attr(&contextData, data, 6, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_string_attr(&contextData, data, 6, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_constant_string_attr */ -TEST(t_dlt_user_log_write_constant_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string_attr(&contextData, data, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string_attr(&contextData, data, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string_attr(&contextData, data, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_constant_string_attr */ -TEST(t_dlt_user_log_write_sized_constant_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_string_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456789"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_string_attr(&contextData, data, 6, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_string_attr(&contextData, data, 6, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_string_attr(&contextData, data, 6, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_utf8_string_attr */ -TEST(t_dlt_user_log_write_utf8_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_utf8_string_attr(&contextData, data, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_utf8_string_attr(&contextData, data, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_utf8_string_attr(&contextData, data, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_utf8_string_attr */ -TEST(t_dlt_user_log_write_sized_utf8_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456789"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_utf8_string_attr(&contextData, data, 6, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_utf8_string_attr(&contextData, data, 6, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_utf8_string_attr(&contextData, data, 6, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_constant_utf8_string_attr */ -TEST(t_dlt_user_log_write_constant_utf8_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr normal")); - - const char *text1 = "test1"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(&contextData, text1, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_constant_utf8_string_attr, nullpointer) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr nullpointer")); - - const char *text1 = "test1"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(NULL, text1, "name")); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(NULL, NULL, "name")); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(&contextData, NULL, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_sized_constant_utf8_string_attr */ -TEST(t_dlt_user_log_write_sized_constant_utf8_string_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr normal")); - - const char *text1 = "test1text"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(&contextData, text1, 5, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -TEST(t_dlt_user_log_write_sized_constant_utf8_string_attr, nullpointer) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr nullpointer")); - - const char *text1 = "test1text"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(NULL, text1, 5, "name")); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(NULL, NULL, 5, "name")); - EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(&contextData, NULL, 5, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_raw */ TEST(t_dlt_user_log_write_raw, normal) { @@ -3724,27 +3001,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_log_write_raw_attr */ -TEST(t_dlt_user_log_write_raw_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_raw_attr(&contextData, data, 6, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_raw_attr(&contextData, data, 6, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_raw_attr(&contextData, data, 6, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ /* t_dlt_user_log_write_raw_formatted */ TEST(t_dlt_user_log_write_raw_formatted, normal) { @@ -3837,67 +3093,6 @@ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); } -/*/////////////////////////////////////// */ -/* t_dlt_user_log_write_raw_formatted_attr */ -TEST(t_dlt_user_log_write_raw_formatted_attr, normal) -{ - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted_attr normal")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - - char data[] = "123456"; - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_raw_formatted_attr(&contextData, data, 6, DLT_FORMAT_DEFAULT, "name")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_raw_formatted_attr(&contextData, data, 6, DLT_FORMAT_DEFAULT, "")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_raw_formatted_attr(&contextData, data, 6, DLT_FORMAT_DEFAULT, NULL)); - - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); -} - -/*/////////////////////////////////////// */ -/* - * Test sending Verbose and Non-Verbose messages in the same session. - */ - -/*/////////////////////////////////////// */ -/* t_dlt_user_nonverbose*/ -TEST(t_dlt_user_nonverbose, nonverbosemode) -{ - dlt_nonverbose_mode(); - dlt_use_extended_header_for_non_verbose(false); - - DltContext context; - DltContextData contextData; - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_message_modes")); - - // Send a Verbose message - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string_attr(&contextData, "hello", "msg")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, 0x01020304, "val1", "unit1")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, 0x04030201, "val2", "unit2")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - // Send a Non-Verbose message - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string_attr(&contextData, "hello", "msg")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, 0x01020304, "val1", "unit1")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_uint32_attr(&contextData, 0x04030201, "val2", "unit2")); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); - - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); - - dlt_use_extended_header_for_non_verbose(true); - dlt_verbose_mode(); -} - -/*/////////////////////////////////////// */ /* * int dlt_log_string(DltContext *handle,DltLogLevelType loglevel, const char *text); * int dlt_log_string_int(DltContext *handle,DltLogLevelType loglevel, const char *text, int data); @@ -4093,7 +3288,7 @@ /* normal values */ const char text1[6] = "test1"; - unsigned int data = 0; + unsigned int data = UINT_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_log_string_uint(&context, DLT_LOG_DEFAULT, text1, data)); EXPECT_LE(DLT_RETURN_OK, dlt_log_string_uint(&context, DLT_LOG_OFF, text1, data)); EXPECT_LE(DLT_RETURN_OK, dlt_log_string_uint(&context, DLT_LOG_FATAL, text1, data)); @@ -4263,7 +3458,7 @@ EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_log_uint normal")); /* normal values */ - unsigned int data = 0; + unsigned int data = UINT_MIN; EXPECT_LE(DLT_RETURN_OK, dlt_log_uint(&context, DLT_LOG_DEFAULT, data)); EXPECT_LE(DLT_RETURN_OK, dlt_log_uint(&context, DLT_LOG_OFF, data)); EXPECT_LE(DLT_RETURN_OK, dlt_log_uint(&context, DLT_LOG_FATAL, data)); @@ -4855,7 +4050,7 @@ } -#ifdef DLT_NETWORK_TRACE_ENABLE + /*/////////////////////////////////////// */ /* t_dlt_user_trace_network */ TEST(t_dlt_user_trace_network, normal) @@ -5148,7 +4343,7 @@ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); } -#endif /* DLT_NETWORK_TRACE_ENABLE */ + /*/////////////////////////////////////// */ /* t_dlt_set_log_mode */ @@ -5250,92 +4445,6 @@ } /*/////////////////////////////////////// */ -/* t_dlt_user_shutdown_while_init_is_running */ - -struct ShutdownWhileInitParams { - ShutdownWhileInitParams() = default; - // delete copy constructor - ShutdownWhileInitParams(const ShutdownWhileInitParams&) = delete; - - std::chrono::time_point stop_time; - - pthread_cond_t dlt_free_done = PTHREAD_COND_INITIALIZER; - pthread_mutex_t dlt_free_mtx = PTHREAD_MUTEX_INITIALIZER; - bool has_error = false; - -}; - -void* dlt_free_call_and_deadlock_detection(void *arg) { - auto *params = static_cast(arg); - - // allow thread to be canceled - int old_thread_type; - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_thread_type); - - dlt_free(); - - // signal that we are done - pthread_mutex_lock(¶ms->dlt_free_mtx); - pthread_cond_signal(¶ms->dlt_free_done); - pthread_mutex_unlock(¶ms->dlt_free_mtx); - return nullptr; -} - -void *dlt_free_thread(void *arg) { - auto *params = static_cast(arg); - while (std::chrono::steady_clock::now() < params->stop_time && !params->has_error) { - - // pthread cond_timedwait expects an absolute time to wait - struct timespec abs_time{}; - clock_gettime(CLOCK_REALTIME, &abs_time); - abs_time.tv_sec += 3; // wait at most 3 seconds - - pthread_t dlt_free_deadlock_detection_thread_id; - - pthread_mutex_lock(¶ms->dlt_free_mtx); - pthread_create(&dlt_free_deadlock_detection_thread_id, nullptr, dlt_free_call_and_deadlock_detection, params); - const auto err = pthread_cond_timedwait(¶ms->dlt_free_done, ¶ms->dlt_free_mtx, &abs_time); - pthread_mutex_unlock(¶ms->dlt_free_mtx); - - if (err == ETIMEDOUT) { - fprintf(stderr, "\n%s: detected DLT-deadlock!\n", __func__); - params->has_error = true; - - // cancel thread after timeout, so join won't block forever. - pthread_cancel(dlt_free_deadlock_detection_thread_id); - } - - pthread_join(dlt_free_deadlock_detection_thread_id, nullptr); - } - - return nullptr; -} - -TEST(t_dlt_user_shutdown_while_init_is_running, normal) { - const auto max_runtime = std::chrono::seconds(15); - const auto stop_time = std::chrono::steady_clock::now() + max_runtime; - - struct ShutdownWhileInitParams args{}; - args.stop_time = stop_time; - - pthread_t dlt_free_thread_id; - pthread_create(&dlt_free_thread_id, nullptr, dlt_free_thread, &args); - - while (std::chrono::steady_clock::now() < stop_time && !args.has_error) { - dlt_init(); - } - - pthread_join(dlt_free_thread_id, nullptr); - EXPECT_FALSE(args.has_error); - - const auto last_init = dlt_init(); - const auto last_free = dlt_free(); - - EXPECT_EQ(last_init, DLT_RETURN_OK); - EXPECT_EQ(last_free, DLT_RETURN_OK); -} - -/*/////////////////////////////////////// */ /* main */ int main(int argc, char **argv) { diff -Nru dlt-daemon-2.18.9/tests/start_qnx_system_test.sh dlt-daemon-2.18.4/tests/start_qnx_system_test.sh --- dlt-daemon-2.18.9/tests/start_qnx_system_test.sh 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/start_qnx_system_test.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,280 +0,0 @@ -#!/bin/sh - -################################################################################ -# This software has been developed by Advanced Driver Information Technology. -# Copyright(c) 2021 Advanced Driver Information Technology GmbH, -# Advanced Driver Information Technology Corporation, Robert Bosch GmbH, -# Robert Bosch Car Multimedia GmbH and DENSO Corporation. -# All rights reserved. -################################################################################ - -################################################################################ -# File: start_qnx_system_test.sh -# -# Description: Test script to verify dlt-qnx-system using dlt-test-qnx-slogger -################################################################################ - -usage() -{ - cat < "${DLT_RECEIVE_FILTER}" - - # Start dlt-receive - echo "Start dlt-receive" - "${DEV_AAP_DLT_PATH}"/dlt-receive -a -f "${DLT_RECEIVE_FILTER}" localhost > "${DLT_TEST_RESULT}" & - sleep "${SLEEP_TIME}" - - # Start dlt-qnx-system - echo "Start dlt-qnx-system" - "${DEV_AAP_DLT_PATH}"/dlt-qnx-system > /dev/null & - sleep "${SLEEP_TIME}" - - # Start dlt-test-qnx-slogger and wait until it's done - echo "Start dlt-test-qnx-slogger" - "${DEV_AAP_DLT_PATH}"/dlt-test-qnx-slogger -n "${COUNT}" -d "${DELAY}" -l "${LENGTH}" > /dev/null - sleep "${SLEEP_TIME}" -} - -################################################################################ -# Function: dlt_qnx_test_result -# -# Description: Verify result from dlt_run_app() function -################################################################################ -dlt_qnx_test_result() -{ - echo "" - echo "Verify test result" - - TEST_RESULT_1="PASS" - TEST_RESULT_2="PASS" - TEST_RESULT_3="PASS" - BUFFER_NAME="dlt_test_qnx_slogger" - - ######################################### - # 1. Verify if all messages are received - ######################################### - RESULT_COUNT=$(grep "${BUFFER_NAME}.*slog" -c "${DLT_TEST_RESULT}") - if [ "${RESULT_COUNT}" -ne "${COUNT}" ]; then - echo "Number of log messages are not matching (Expected: ${COUNT}, Actual: ${RESULT_COUNT})" - TEST_RESULT_1="FAIL" - fi - - #### - RESULT=$(grep "${BUFFER_NAME}.*slog" "${DLT_TEST_RESULT}") - RESULT_TIME_PREV=0 - echo "$RESULT"| while read LINE - do - pr_verbose "$0" "TEST : LINE=${LINE}" - - RESULT_TIME=$(echo "${LINE}" | awk -F " " '{print $3}') - RESULT_PAYLOAD=$(echo "${LINE}" | awk -F " " '{print $17}') - - ############################################################# - # 2. Verify if each log messages have expected time interval - # Allow diff between ${DELAY} and ${DELAY}+10 msec - ############################################################# - pr_verbose "$0" "TEST2: RESULT_TIME=${RESULT_TIME}, RESULT_TIME_PREV=${RESULT_TIME_PREV}" - - # Compare diff of timestamps from second log message - if [ "${RESULT_TIME_PREV}" -ne 0 ]; then - RESULT_TIME_DIFF=$((RESULT_TIME - RESULT_TIME_PREV)) - - RANGE_MIN=$((DELAY * 10)) - RANGE_MAX=$(((DELAY + 10) * 10)) - if [[ "${RANGE_MIN}" -gt "${RESULT_TIME_DIFF}" ]] | [[ "${RANGE_MAX}" -le "${RESULT_TIME_DIFF}" ]]; then - echo "Diff of timestamp is too big (Expected diff: ${RANGE_MIN}-${RANGE_MAX}, Actual diff: ${RESULT_TIME_DIFF}" - TEST_RESULT_2="FAIL" - fi - fi - RESULT_TIME_PREV=${RESULT_TIME} - - ################################################################# - # 3. Verify if each log messages receives expected string length - ################################################################# - pr_verbose "$0" "TEST2: RESULT_PAYLOAD=${RESULT_PAYLOAD}" - - RESULT_LENGTH=$(echo ${#RESULT_PAYLOAD}) - if [ "${RESULT_LENGTH}" -ne "${LENGTH}" ]; then - echo "Length is not matching (Excepted:${LENGTH}, Actual:${RESULT_LENGTH})" - TEST_RESULT_3="FAIL" - fi - done - - # Print test result - echo " 1. Verify if all messages are received : ${TEST_RESULT_1}" - echo " 2. Verify if each log messages have expected time interval : ${TEST_RESULT_2}" - echo " 3. Verify if each log messages receives expected string length: ${TEST_RESULT_3}" -} - -################################################################################ -# Function: dlt_qnx_verify_app -# -# Description: Verify if necessary binaries are existing on the target and have -# execute permission -################################################################################ -dlt_qnx_verify_app() -{ - APP=$1 - - pr_verbose "$0" "Verify ${APP} is existing on the target and have execute permission" - - if [ ! -e "${APP}" ]; then - echo "${APP} is missing!" - exit 1 - elif [ ! -x "${APP}" ]; then - echo "${APP} does not have execute permission!" - exit 1 - fi -} - -################################################################################ -# Main -################################################################################ - -VERBOSE=0 - -SLEEP_TIME=1 - -COUNT=10 -DELAY=500 -LENGTH=100 - -DLT_TEST_RESULT="dlt_qnx_system_test.txt" -DLT_RECEIVE_FILTER="dlt_receive_filter.txt" - -DEV_AAP_DLT_PATH="/usr/bin" - -# OS -if [ "$(uname)" != "QNX" ]; then - echo "This script can be only run under QNX system!" - exit 1 -fi - -# Options -while getopts "vn:d:l:h" optKey; do - case "${optKey}" in - v) - VERBOSE=1 - ;; - n) - COUNT=${OPTARG} - ;; - d) - DELAY=${OPTARG} - ;; - l) - LENGTH=${OPTARG} - ;; - '-h'|'--help'|*) - usage - ;; - esac -done - -echo "*******************************" -echo " Run dlt-test-qnx-system with:" -echo " Number of logs: ${COUNT}" -echo " Delay : ${DELAY} msec" -echo " Payload length: ${LENGTH} bytes" -echo "*******************************" -echo "" - -# Verify if rb-dltd is running -if [ ! "$(slay -p -Q rb-dltd)" ]; then - echo "Start rb-dltd before running this script!" - exit 1 -fi - -# Verify necessary binaries are available under the target -dlt_qnx_verify_app ${DEV_AAP_DLT_PATH}/dlt-receive -dlt_qnx_verify_app ${DEV_AAP_DLT_PATH}/dlt-qnx-system -dlt_qnx_verify_app ${DEV_AAP_DLT_PATH}/dlt-test-qnx-slogger - -#dlt_qnx_configure_setup - -dlt_qnx_clean_app -dlt_qnx_clean_log - -dlt_qnx_run_app -dlt_qnx_clean_app - -dlt_qnx_test_result -dlt_qnx_clean_log Binary files /tmp/tmpd42071rz/3t7x5JdZTJ/dlt-daemon-2.18.9/tests/testfile_extended.dlt and /tmp/tmpd42071rz/EkLYkosTTH/dlt-daemon-2.18.4/tests/testfile_extended.dlt differ diff -Nru dlt-daemon-2.18.9/tests/testfilter.json dlt-daemon-2.18.4/tests/testfilter.json --- dlt-daemon-2.18.9/tests/testfilter.json 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/tests/testfilter.json 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -{ -"filter1": { - "AppId": "LOG", - "ContextId": "TEST", - "LogLevel": "3" - }, -"filter2": { - "AppId": "app", - "LogLevel": "4" - }, -"filter3": { - "AppId": "app2", - "ContextId": "con2", - "PayloadMin": "20", - "PayloadMax": "50" - } -} diff -Nru dlt-daemon-2.18.9/.travis/gtest_dlt_all.sh dlt-daemon-2.18.4/.travis/gtest_dlt_all.sh --- dlt-daemon-2.18.9/.travis/gtest_dlt_all.sh 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/.travis/gtest_dlt_all.sh 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,62 @@ +#!/bin/bash +################################################################################ +# SPDX license identifier: MPL-2.0 +# +# Copyright (C) 2019, Advanced Driver Information Technology +# This code is developed by Advanced Driver Information Technology. +# Copyright of Advanced Driver Information Technology, Bosch and DENSO. +# +# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. +# +# This Source Code Form is subject to the terms of the +# Mozilla Public License (MPL), v. 2.0. +# If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# For further information see http://www.genivi.org/. +################################################################################ + +################################################################################ +#file : gtest_dlt_all.sh +# +#Description : Run all unit tests in Travis CI +# +#Author Name : Saya Sugiura +################################################################################ + +function gtest_run_test() +{ + LOG="../.travis/$1.log" + + # Execute unit test + ./$1 > $LOG + + # Check for result + grep "FAILED TEST" $LOG + if [ $? -eq 0 ] + then + cat $LOG + exit 1 + fi + echo "$1 passed" +} + +pushd tests > /dev/null + +gtest_run_test gtest_dlt_common + +gtest_run_test gtest_dlt_user + +gtest_run_test gtest_dlt_daemon_common + +gtest_run_test gtest_dlt_daemon_event_handler + +./gtest_dlt_daemon_gateway.sh > /dev/null +gtest_run_test gtest_dlt_daemon_gateway + +./gtest_dlt_daemon_logstorage.sh > /dev/null +gtest_run_test gtest_dlt_daemon_offline_log + +gtest_run_test dlt_env_ll_unit_test + +popd > /dev/null diff -Nru dlt-daemon-2.18.9/util/create_dlt_user_h.py dlt-daemon-2.18.4/util/create_dlt_user_h.py --- dlt-daemon-2.18.9/util/create_dlt_user_h.py 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/util/create_dlt_user_h.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -#!/usr/bin/python3 -# This software has been developed by Advanced Driver Information Technology. -# Copyright(c) 2020 Advanced Driver Information Technology GmbH, -# Advanced Driver Information Technology Corporation, Robert Bosch GmbH, -# Robert Bosch Car Multimedia GmbH and DENSO Corporation. -# -# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -import pathlib -import argparse - - -def main(header_in_file, header_out_file): - header_in = pathlib.Path(header_in_file) - header_out = pathlib.Path(header_out_file) - with header_in.open() as hi, header_out.open('w') as ho: - for line in hi: - if line.startswith("#cmakedefine"): - continue - ho.write(line) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('header_in') - parser.add_argument('header_out') - args = parser.parse_args() - main(args.header_in, args.header_out) diff -Nru dlt-daemon-2.18.9/util/create_dlt_version_h.py dlt-daemon-2.18.4/util/create_dlt_version_h.py --- dlt-daemon-2.18.9/util/create_dlt_version_h.py 2023-04-17 13:02:23.000000000 +0000 +++ dlt-daemon-2.18.4/util/create_dlt_version_h.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,73 +0,0 @@ -#!/usr/bin/python3 -# This software has been developed by Advanced Driver Information Technology. -# Copyright(c) 2019 Advanced Driver Information Technology GmbH, -# Advanced Driver Information Technology Corporation, Robert Bosch GmbH, -# Robert Bosch Car Multimedia GmbH and DENSO Corporation. -# -# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -import pathlib -import subprocess -import argparse -import re - - -def get_cmd(cmd, cwd): - return subprocess.check_output(cmd, cwd=cwd, shell=True, - stderr=subprocess.STDOUT - ).decode().strip() - - -def get_revision(git_dir): - try: - rev = get_cmd('git describe --tags', git_dir) - if not rev.startswith("fatal:"): - return rev - - rev = get_cmd('git rev-parse HEAD', git_dir) - if not rev.startswith("fatal:"): - return rev - except subprocess.CalledProcessError: - pass - - return get_cmd('date +%F', git_dir) - - -def main(cmake_file, header_in_file, header_out_file): - cmakelists = pathlib.Path(cmake_file) - header_in = pathlib.Path(header_in_file) - header_out = pathlib.Path(header_out_file) - git_dir = str(header_in.parent) - cmake_vars = {} - - for m in re.finditer( - 'project\(\S+ VERSION (?P\d+)\.(?P\d+)\.(?P\d+)(\.(?P\d+))?', - cmakelists.open().read()): - cmake_vars['PROJECT_VERSION_MAJOR'] = m.group('major') - cmake_vars['PROJECT_VERSION_MINOR'] = m.group('minor') - cmake_vars['PROJECT_VERSION_PATCH'] = m.group('patch') - cmake_vars['PROJECT_VERSION'] = "{}.{}.{}".format(m.group('major'), m.group('minor'), m.group('patch')) - cmake_vars['PROJECT_VERSION_TWEAK'] = m.group('tweak') - cmake_vars['DLT_REVISION'] = get_revision(git_dir) - cmake_vars['DLT_VERSION_STATE'] = 'STABLE' - - header_out.parent.mkdir(parents=True, exist_ok=True) - with header_in.open() as hi, header_out.open('w') as ho: - for line in hi: - text, _ = re.subn('@(?P\w+)@', lambda x: cmake_vars.get(x.group('var_name'), "NONE"), line) - ho.write(text) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('cmakelists') - parser.add_argument('header_in') - parser.add_argument('header_out') - args = parser.parse_args() - main(args.cmakelists, args.header_in, args.header_out) diff -Nru dlt-daemon-2.18.9/util/uncrustify.cfg dlt-daemon-2.18.4/util/uncrustify.cfg --- dlt-daemon-2.18.9/util/uncrustify.cfg 1970-01-01 00:00:00.000000000 +0000 +++ dlt-daemon-2.18.4/util/uncrustify.cfg 2019-09-03 08:28:13.000000000 +0000 @@ -0,0 +1,2736 @@ +# Uncrustify-0.68_f + +# +# General options +# + +# The type of line endings. +# +# Default: auto +newlines = auto # lf/crlf/cr/auto + +# The original size of tabs in the input. +# +# Default: 8 +input_tab_size = 4 # unsigned number + +# The size of tabs in the output (only used if align_with_tabs=true). +# +# Default: 8 +output_tab_size = 4 # unsigned number + +# The ASCII value of the string escape char, usually 92 (\) or (Pawn) 94 (^). +# +# Default: 92 +string_escape_char = 92 # unsigned number + +# Alternate string escape char (usually only used for Pawn). +# Only works right before the quote char. +string_escape_char2 = 0 # unsigned number + +# Replace tab characters found in string literals with the escape sequence \t +# instead. +string_replace_tab_chars = false # true/false + +# Allow interpreting '>=' and '>>=' as part of a template in code like +# 'void f(list>=val);'. If true, 'assert(x<0 && y>=3)' will be broken. +# Improvements to template detection may make this option obsolete. +tok_split_gte = false # true/false + +# Specify the marker used in comments to disable processing of part of the +# file. +# +# Default: *INDENT-OFF* +disable_processing_cmt = "" # string + +# Specify the marker used in comments to (re)enable processing in a file. +# +# Default: *INDENT-ON* +enable_processing_cmt = "" # string + +# Enable parsing of digraphs. +enable_digraphs = false # true/false + +# Add or remove the UTF-8 BOM (recommend 'remove'). +utf8_bom = ignore # ignore/add/remove/force + +# If the file contains bytes with values between 128 and 255, but is not +# UTF-8, then output as UTF-8. +utf8_byte = false # true/false + +# Force the output encoding to UTF-8. +utf8_force = false # true/false + +# +# Spacing options +# + +# Add or remove space around non-assignment symbolic operators ('+', '/', '%', +# '<<', and so forth). +sp_arith = force # ignore/add/remove/force + +# Add or remove space around arithmetic operators '+' and '-'. +# +# Overrides sp_arith. +sp_arith_additive = ignore # ignore/add/remove/force + +# Add or remove space around assignment operator '=', '+=', etc. +sp_assign = force # ignore/add/remove/force + +# Add or remove space around '=' in C++11 lambda capture specifications. +# +# Overrides sp_assign. +sp_cpp_lambda_assign = ignore # ignore/add/remove/force + +# Add or remove space after the capture specification in C++11 lambda. +sp_cpp_lambda_paren = ignore # ignore/add/remove/force + +# Add or remove space around assignment operator '=' in a prototype. +sp_assign_default = ignore # ignore/add/remove/force + +# Add or remove space before assignment operator '=', '+=', etc. +# +# Overrides sp_assign. +sp_before_assign = ignore # ignore/add/remove/force + +# Add or remove space after assignment operator '=', '+=', etc. +# +# Overrides sp_assign. +sp_after_assign = ignore # ignore/add/remove/force + +# Add or remove space in 'NS_ENUM ('. +sp_enum_paren = ignore # ignore/add/remove/force + +# Add or remove space around assignment '=' in enum. +sp_enum_assign = force # ignore/add/remove/force + +# Add or remove space before assignment '=' in enum. +# +# Overrides sp_enum_assign. +sp_enum_before_assign = ignore # ignore/add/remove/force + +# Add or remove space after assignment '=' in enum. +# +# Overrides sp_enum_assign. +sp_enum_after_assign = ignore # ignore/add/remove/force + +# Add or remove space around assignment ':' in enum. +sp_enum_colon = ignore # ignore/add/remove/force + +# Add or remove space around preprocessor '##' concatenation operator. +# +# Default: add +sp_pp_concat = ignore # ignore/add/remove/force + +# Add or remove space after preprocessor '#' stringify operator. +# Also affects the '#@' charizing operator. +sp_pp_stringify = ignore # ignore/add/remove/force + +# Add or remove space before preprocessor '#' stringify operator +# as in '#define x(y) L#y'. +sp_before_pp_stringify = ignore # ignore/add/remove/force + +# Add or remove space around boolean operators '&&' and '||'. +sp_bool = force # ignore/add/remove/force + +# Add or remove space around compare operator '<', '>', '==', etc. +sp_compare = force # ignore/add/remove/force + +# Add or remove space inside '(' and ')'. +sp_inside_paren = remove # ignore/add/remove/force + +# Add or remove space between nested parentheses, i.e. '((' vs. ') )'. +sp_paren_paren = remove # ignore/add/remove/force + +# Add or remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. +sp_cparen_oparen = ignore # ignore/add/remove/force + +# Whether to balance spaces inside nested parentheses. +sp_balance_nested_parens = false # true/false + +# Add or remove space between ')' and '{'. +sp_paren_brace = force # ignore/add/remove/force + +# Add or remove space between nested braces, i.e. '{{' vs '{ {'. +sp_brace_brace = ignore # ignore/add/remove/force + +# Add or remove space before pointer star '*'. +sp_before_ptr_star = force # ignore/add/remove/force + +# Add or remove space before pointer star '*' that isn't followed by a +# variable name. If set to 'ignore', sp_before_ptr_star is used instead. +sp_before_unnamed_ptr_star = force # ignore/add/remove/force + +# Add or remove space between pointer stars '*'. +sp_between_ptr_star = remove # ignore/add/remove/force + +# Add or remove space after pointer star '*', if followed by a word. +sp_after_ptr_star = remove # ignore/add/remove/force + +# Add or remove space after pointer caret '^', if followed by a word. +sp_after_ptr_block_caret = ignore # ignore/add/remove/force + +# Add or remove space after pointer star '*', if followed by a qualifier. +sp_after_ptr_star_qualifier = ignore # ignore/add/remove/force + +# Add or remove space after a pointer star '*', if followed by a function +# prototype or function definition. +sp_after_ptr_star_func = remove # ignore/add/remove/force + +# Add or remove space after a pointer star '*', if followed by an open +# parenthesis, as in 'void* (*)(). +sp_ptr_star_paren = ignore # ignore/add/remove/force + +# Add or remove space before a pointer star '*', if followed by a function +# prototype or function definition. +sp_before_ptr_star_func = add # ignore/add/remove/force + +# Add or remove space before a reference sign '&'. +sp_before_byref = add # ignore/add/remove/force + +# Add or remove space before a reference sign '&' that isn't followed by a +# variable name. If set to 'ignore', sp_before_byref is used instead. +sp_before_unnamed_byref = add # ignore/add/remove/force + +# Add or remove space after reference sign '&', if followed by a word. +sp_after_byref = remove # ignore/add/remove/force + +# Add or remove space after a reference sign '&', if followed by a function +# prototype or function definition. +sp_after_byref_func = remove # ignore/add/remove/force + +# Add or remove space before a reference sign '&', if followed by a function +# prototype or function definition. +sp_before_byref_func = add # ignore/add/remove/force + +# Add or remove space between type and word. +# +# Default: force +sp_after_type = force # ignore/add/remove/force + +# Add or remove space between 'decltype(...)' and word. +sp_after_decltype = ignore # ignore/add/remove/force + +# (D) Add or remove space before the parenthesis in the D constructs +# 'template Foo(' and 'class Foo('. +sp_before_template_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'template' and '<'. +# If set to ignore, sp_before_angle is used. +sp_template_angle = ignore # ignore/add/remove/force + +# Add or remove space before '<'. +sp_before_angle = ignore # ignore/add/remove/force + +# Add or remove space inside '<' and '>'. +sp_inside_angle = ignore # ignore/add/remove/force + +# Add or remove space between '>' and ':'. +sp_angle_colon = ignore # ignore/add/remove/force + +# Add or remove space after '<>'. +sp_after_angle = ignore # ignore/add/remove/force + +# Add or remove space between '>' and '(' as found in 'new List(foo);'. +sp_angle_paren = ignore # ignore/add/remove/force + +# Add or remove space between '>' and '()' as found in 'new List();'. +sp_angle_paren_empty = ignore # ignore/add/remove/force + +# Add or remove space between '>' and a word as in 'List m;' or +# 'template static ...'. +sp_angle_word = ignore # ignore/add/remove/force + +# Add or remove space between '>' and '>' in '>>' (template stuff). +# +# Default: add +sp_angle_shift = add # ignore/add/remove/force + +# (C++11) Permit removal of the space between '>>' in 'foo >'. Note +# that sp_angle_shift cannot remove the space without this option. +sp_permit_cpp11_shift = false # true/false + +# Add or remove space before '(' of control statements ('if', 'for', 'switch', +# 'while', etc.). +sp_before_sparen = force # ignore/add/remove/force + +# Add or remove space inside '(' and ')' of control statements. +sp_inside_sparen = remove # ignore/add/remove/force + +# Add or remove space after '(' of control statements. +# +# Overrides sp_inside_sparen. +sp_inside_sparen_open = ignore # ignore/add/remove/force + +# Add or remove space before ')' of control statements. +# +# Overrides sp_inside_sparen. +sp_inside_sparen_close = ignore # ignore/add/remove/force + +# Add or remove space after ')' of control statements. +sp_after_sparen = force # ignore/add/remove/force + +# Add or remove space between ')' and '{' of of control statements. +sp_sparen_brace = force # ignore/add/remove/force + +# (D) Add or remove space between 'invariant' and '('. +sp_invariant_paren = ignore # ignore/add/remove/force + +# (D) Add or remove space after the ')' in 'invariant (C) c'. +sp_after_invariant_paren = ignore # ignore/add/remove/force + +# Add or remove space before empty statement ';' on 'if', 'for' and 'while'. +sp_special_semi = remove # ignore/add/remove/force + +# Add or remove space before ';'. +# +# Default: remove +sp_before_semi = remove # ignore/add/remove/force + +# Add or remove space before ';' in non-empty 'for' statements. +sp_before_semi_for = remove # ignore/add/remove/force + +# Add or remove space before a semicolon of an empty part of a for statement. +sp_before_semi_for_empty = ignore # ignore/add/remove/force + +# Add or remove space after ';', except when followed by a comment. +# +# Default: add +sp_after_semi = add # ignore/add/remove/force + +# Add or remove space after ';' in non-empty 'for' statements. +# +# Default: force +sp_after_semi_for = force # ignore/add/remove/force + +# Add or remove space after the final semicolon of an empty part of a for +# statement, as in 'for ( ; ; )'. +sp_after_semi_for_empty = ignore # ignore/add/remove/force + +# Add or remove space before '[' (except '[]'). +sp_before_square = ignore # ignore/add/remove/force + +# Add or remove space before '[]'. +sp_before_squares = remove # ignore/add/remove/force + +# Add or remove space before C++17 structured bindings. +sp_cpp_before_struct_binding = ignore # ignore/add/remove/force + +# Add or remove space inside a non-empty '[' and ']'. +sp_inside_square = remove # ignore/add/remove/force + +# (OC) Add or remove space inside a non-empty Objective-C boxed array '@[' and +# ']'. If set to ignore, sp_inside_square is used. +sp_inside_square_oc_array = ignore # ignore/add/remove/force + +# Add or remove space after ',', i.e. 'a,b' vs. 'a, b'. +sp_after_comma = force # ignore/add/remove/force + +# Add or remove space before ','. +# +# Default: remove +sp_before_comma = remove # ignore/add/remove/force + +# (C#) Add or remove space between ',' and ']' in multidimensional array type +# like 'int[,,]'. +sp_after_mdatype_commas = ignore # ignore/add/remove/force + +# (C#) Add or remove space between '[' and ',' in multidimensional array type +# like 'int[,,]'. +sp_before_mdatype_commas = ignore # ignore/add/remove/force + +# (C#) Add or remove space between ',' in multidimensional array type +# like 'int[,,]'. +sp_between_mdatype_commas = ignore # ignore/add/remove/force + +# Add or remove space between an open parenthesis and comma, +# i.e. '(,' vs. '( ,'. +# +# Default: force +sp_paren_comma = force # ignore/add/remove/force + +# Add or remove space before the variadic '...' when preceded by a +# non-punctuator. +sp_before_ellipsis = ignore # ignore/add/remove/force + +# Add or remove space between a type and '...'. +sp_type_ellipsis = ignore # ignore/add/remove/force + +# Add or remove space between ')' and '...'. +sp_paren_ellipsis = ignore # ignore/add/remove/force + +# Add or remove space after class ':'. +sp_after_class_colon = ignore # ignore/add/remove/force + +# Add or remove space before class ':'. +sp_before_class_colon = ignore # ignore/add/remove/force + +# Add or remove space after class constructor ':'. +sp_after_constr_colon = ignore # ignore/add/remove/force + +# Add or remove space before class constructor ':'. +sp_before_constr_colon = ignore # ignore/add/remove/force + +# Add or remove space before case ':'. +# +# Default: remove +sp_before_case_colon = remove # ignore/add/remove/force + +# Add or remove space between 'operator' and operator sign. +sp_after_operator = ignore # ignore/add/remove/force + +# Add or remove space between the operator symbol and the open parenthesis, as +# in 'operator ++('. +sp_after_operator_sym = ignore # ignore/add/remove/force + +# Overrides sp_after_operator_sym when the operator has no arguments, as in +# 'operator *()'. +sp_after_operator_sym_empty = ignore # ignore/add/remove/force + +# Add or remove space after C/D cast, i.e. 'cast(int)a' vs. 'cast(int) a' or +# '(int)a' vs. '(int) a'. +sp_after_cast = remove # ignore/add/remove/force + +# Add or remove spaces inside cast parentheses. +sp_inside_paren_cast = remove # ignore/add/remove/force + +# Add or remove space between the type and open parenthesis in a C++ cast, +# i.e. 'int(exp)' vs. 'int (exp)'. +sp_cpp_cast_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'sizeof' and '('. +sp_sizeof_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'sizeof' and '...'. +sp_sizeof_ellipsis = ignore # ignore/add/remove/force + +# Add or remove space between 'sizeof...' and '('. +sp_sizeof_ellipsis_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'decltype' and '('. +sp_decltype_paren = ignore # ignore/add/remove/force + +# (Pawn) Add or remove space after the tag keyword. +sp_after_tag = ignore # ignore/add/remove/force + +# Add or remove space inside enum '{' and '}'. +sp_inside_braces_enum = ignore # ignore/add/remove/force + +# Add or remove space inside struct/union '{' and '}'. +sp_inside_braces_struct = ignore # ignore/add/remove/force + +# (OC) Add or remove space inside Objective-C boxed dictionary '{' and '}' +sp_inside_braces_oc_dict = ignore # ignore/add/remove/force + +# Add or remove space after open brace in an unnamed temporary +# direct-list-initialization. +sp_after_type_brace_init_lst_open = ignore # ignore/add/remove/force + +# Add or remove space before close brace in an unnamed temporary +# direct-list-initialization. +sp_before_type_brace_init_lst_close = ignore # ignore/add/remove/force + +# Add or remove space inside an unnamed temporary direct-list-initialization. +sp_inside_type_brace_init_lst = ignore # ignore/add/remove/force + +# Add or remove space inside '{' and '}'. +sp_inside_braces = force # ignore/add/remove/force + +# Add or remove space inside '{}'. +sp_inside_braces_empty = remove # ignore/add/remove/force + +# Add or remove space between return type and function name. A minimum of 1 +# is forced except for pointer return types. +sp_type_func = ignore # ignore/add/remove/force + +# Add or remove space between type and open brace of an unnamed temporary +# direct-list-initialization. +sp_type_brace_init_lst = ignore # ignore/add/remove/force + +# Add or remove space between function name and '(' on function declaration. +sp_func_proto_paren = ignore # ignore/add/remove/force + +# Add or remove space between function name and '()' on function declaration +# without parameters. +sp_func_proto_paren_empty = ignore # ignore/add/remove/force + +# Add or remove space between function name and '(' on function definition. +sp_func_def_paren = ignore # ignore/add/remove/force + +# Add or remove space between function name and '()' on function definition +# without parameters. +sp_func_def_paren_empty = ignore # ignore/add/remove/force + +# Add or remove space inside empty function '()'. +sp_inside_fparens = remove # ignore/add/remove/force + +# Add or remove space inside function '(' and ')'. +sp_inside_fparen = remove # ignore/add/remove/force + +# Add or remove space inside the first parentheses in a function type, as in +# 'void (*x)(...)'. +sp_inside_tparen = ignore # ignore/add/remove/force + +# Add or remove space between the ')' and '(' in a function type, as in +# 'void (*x)(...)'. +sp_after_tparen_close = ignore # ignore/add/remove/force + +# Add or remove space between ']' and '(' when part of a function call. +sp_square_fparen = ignore # ignore/add/remove/force + +# Add or remove space between ')' and '{' of function. +sp_fparen_brace = force # ignore/add/remove/force + +# Add or remove space between ')' and '{' of s function call in object +# initialization. +# +# Overrides sp_fparen_brace. +sp_fparen_brace_initializer = ignore # ignore/add/remove/force + +# (Java) Add or remove space between ')' and '{{' of double brace initializer. +sp_fparen_dbrace = ignore # ignore/add/remove/force + +# Add or remove space between function name and '(' on function calls. +sp_func_call_paren = ignore # ignore/add/remove/force + +# Add or remove space between function name and '()' on function calls without +# parameters. If set to 'ignore' (the default), sp_func_call_paren is used. +sp_func_call_paren_empty = ignore # ignore/add/remove/force + +# Add or remove space between the user function name and '(' on function +# calls. You need to set a keyword to be a user function in the config file, +# like: +# set func_call_user tr _ i18n +sp_func_call_user_paren = ignore # ignore/add/remove/force + +# Add or remove space inside user function '(' and ')'. +sp_func_call_user_inside_fparen = ignore # ignore/add/remove/force + +# Add or remove space between nested parentheses with user functions, +# i.e. '((' vs. '( ('. +sp_func_call_user_paren_paren = ignore # ignore/add/remove/force + +# Add or remove space between a constructor/destructor and the open +# parenthesis. +sp_func_class_paren = ignore # ignore/add/remove/force + +# Add or remove space between a constructor without parameters or destructor +# and '()'. +sp_func_class_paren_empty = ignore # ignore/add/remove/force + +# Add or remove space between 'return' and '('. +sp_return_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'return' and '{'. +sp_return_brace = ignore # ignore/add/remove/force + +# Add or remove space between '__attribute__' and '('. +sp_attribute_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'defined' and '(' in '#if defined (FOO)'. +sp_defined_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'throw' and '(' in 'throw (something)'. +sp_throw_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'throw' and anything other than '(' as in +# '@throw [...];'. +sp_after_throw = ignore # ignore/add/remove/force + +# Add or remove space between 'catch' and '(' in 'catch (something) { }'. +# If set to ignore, sp_before_sparen is used. +sp_catch_paren = ignore # ignore/add/remove/force + +# (OC) Add or remove space between '@catch' and '(' +# in '@catch (something) { }'. If set to ignore, sp_catch_paren is used. +sp_oc_catch_paren = ignore # ignore/add/remove/force + +# (D) Add or remove space between 'version' and '(' +# in 'version (something) { }'. If set to ignore, sp_before_sparen is used. +sp_version_paren = ignore # ignore/add/remove/force + +# (D) Add or remove space between 'scope' and '(' +# in 'scope (something) { }'. If set to ignore, sp_before_sparen is used. +sp_scope_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'super' and '(' in 'super (something)'. +# +# Default: remove +sp_super_paren = remove # ignore/add/remove/force + +# Add or remove space between 'this' and '(' in 'this (something)'. +# +# Default: remove +sp_this_paren = remove # ignore/add/remove/force + +# Add or remove space between a macro name and its definition. +sp_macro = ignore # ignore/add/remove/force + +# Add or remove space between a macro function ')' and its definition. +sp_macro_func = ignore # ignore/add/remove/force + +# Add or remove space between 'else' and '{' if on the same line. +sp_else_brace = force # ignore/add/remove/force + +# Add or remove space between '}' and 'else' if on the same line. +sp_brace_else = force # ignore/add/remove/force + +# Add or remove space between '}' and the name of a typedef on the same line. +sp_brace_typedef = force # ignore/add/remove/force + +# Add or remove space before the '{' of a 'catch' statement, if the '{' and +# 'catch' are on the same line, as in 'catch (decl) {'. +sp_catch_brace = force # ignore/add/remove/force + +# (OC) Add or remove space before the '{' of a '@catch' statement, if the '{' +# and '@catch' are on the same line, as in '@catch (decl) {'. +# If set to ignore, sp_catch_brace is used. +sp_oc_catch_brace = ignore # ignore/add/remove/force + +# Add or remove space between '}' and 'catch' if on the same line. +sp_brace_catch = force # ignore/add/remove/force + +# (OC) Add or remove space between '}' and '@catch' if on the same line. +# If set to ignore, sp_brace_catch is used. +sp_oc_brace_catch = ignore # ignore/add/remove/force + +# Add or remove space between 'finally' and '{' if on the same line. +sp_finally_brace = ignore # ignore/add/remove/force + +# Add or remove space between '}' and 'finally' if on the same line. +sp_brace_finally = ignore # ignore/add/remove/force + +# Add or remove space between 'try' and '{' if on the same line. +sp_try_brace = ignore # ignore/add/remove/force + +# Add or remove space between get/set and '{' if on the same line. +sp_getset_brace = ignore # ignore/add/remove/force + +# Add or remove space between a variable and '{' for C++ uniform +# initialization. +# +# Default: add +sp_word_brace = add # ignore/add/remove/force + +# Add or remove space between a variable and '{' for a namespace. +# +# Default: add +sp_word_brace_ns = add # ignore/add/remove/force + +# Add or remove space before the '::' operator. +sp_before_dc = ignore # ignore/add/remove/force + +# Add or remove space after the '::' operator. +sp_after_dc = ignore # ignore/add/remove/force + +# (D) Add or remove around the D named array initializer ':' operator. +sp_d_array_colon = ignore # ignore/add/remove/force + +# Add or remove space after the '!' (not) unary operator. +# +# Default: remove +sp_not = remove # ignore/add/remove/force + +# Add or remove space after the '~' (invert) unary operator. +# +# Default: remove +sp_inv = remove # ignore/add/remove/force + +# Add or remove space after the '&' (address-of) unary operator. This does not +# affect the spacing after a '&' that is part of a type. +# +# Default: remove +sp_addr = remove # ignore/add/remove/force + +# Add or remove space around the '.' or '->' operators. +# +# Default: remove +sp_member = remove # ignore/add/remove/force + +# Add or remove space after the '*' (dereference) unary operator. This does +# not affect the spacing after a '*' that is part of a type. +# +# Default: remove +sp_deref = remove # ignore/add/remove/force + +# Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7'. +# +# Default: remove +sp_sign = remove # ignore/add/remove/force + +# Add or remove space between '++' and '--' the word to which it is being +# applied, as in '(--x)' or 'y++;'. +# +# Default: remove +sp_incdec = remove # ignore/add/remove/force + +# Add or remove space before a backslash-newline at the end of a line. +# +# Default: add +sp_before_nl_cont = add # ignore/add/remove/force + +# (OC) Add or remove space after the scope '+' or '-', as in '-(void) foo;' +# or '+(int) bar;'. +sp_after_oc_scope = ignore # ignore/add/remove/force + +# (OC) Add or remove space after the colon in message specs, +# i.e. '-(int) f:(int) x;' vs. '-(int) f: (int) x;'. +sp_after_oc_colon = ignore # ignore/add/remove/force + +# (OC) Add or remove space before the colon in message specs, +# i.e. '-(int) f: (int) x;' vs. '-(int) f : (int) x;'. +sp_before_oc_colon = ignore # ignore/add/remove/force + +# (OC) Add or remove space after the colon in immutable dictionary expression +# 'NSDictionary *test = @{@"foo" :@"bar"};'. +sp_after_oc_dict_colon = ignore # ignore/add/remove/force + +# (OC) Add or remove space before the colon in immutable dictionary expression +# 'NSDictionary *test = @{@"foo" :@"bar"};'. +sp_before_oc_dict_colon = ignore # ignore/add/remove/force + +# (OC) Add or remove space after the colon in message specs, +# i.e. '[object setValue:1];' vs. '[object setValue: 1];'. +sp_after_send_oc_colon = ignore # ignore/add/remove/force + +# (OC) Add or remove space before the colon in message specs, +# i.e. '[object setValue:1];' vs. '[object setValue :1];'. +sp_before_send_oc_colon = ignore # ignore/add/remove/force + +# (OC) Add or remove space after the (type) in message specs, +# i.e. '-(int)f: (int) x;' vs. '-(int)f: (int)x;'. +sp_after_oc_type = ignore # ignore/add/remove/force + +# (OC) Add or remove space after the first (type) in message specs, +# i.e. '-(int) f:(int)x;' vs. '-(int)f:(int)x;'. +sp_after_oc_return_type = ignore # ignore/add/remove/force + +# (OC) Add or remove space between '@selector' and '(', +# i.e. '@selector(msgName)' vs. '@selector (msgName)'. +# Also applies to '@protocol()' constructs. +sp_after_oc_at_sel = ignore # ignore/add/remove/force + +# (OC) Add or remove space between '@selector(x)' and the following word, +# i.e. '@selector(foo) a:' vs. '@selector(foo)a:'. +sp_after_oc_at_sel_parens = ignore # ignore/add/remove/force + +# (OC) Add or remove space inside '@selector' parentheses, +# i.e. '@selector(foo)' vs. '@selector( foo )'. +# Also applies to '@protocol()' constructs. +sp_inside_oc_at_sel_parens = ignore # ignore/add/remove/force + +# (OC) Add or remove space before a block pointer caret, +# i.e. '^int (int arg){...}' vs. ' ^int (int arg){...}'. +sp_before_oc_block_caret = ignore # ignore/add/remove/force + +# (OC) Add or remove space after a block pointer caret, +# i.e. '^int (int arg){...}' vs. '^ int (int arg){...}'. +sp_after_oc_block_caret = ignore # ignore/add/remove/force + +# (OC) Add or remove space between the receiver and selector in a message, +# as in '[receiver selector ...]'. +sp_after_oc_msg_receiver = ignore # ignore/add/remove/force + +# (OC) Add or remove space after '@property'. +sp_after_oc_property = ignore # ignore/add/remove/force + +# (OC) Add or remove space between '@synchronized' and the open parenthesis, +# i.e. '@synchronized(foo)' vs. '@synchronized (foo)'. +sp_after_oc_synchronized = ignore # ignore/add/remove/force + +# Add or remove space around the ':' in 'b ? t : f'. +sp_cond_colon = ignore # ignore/add/remove/force + +# Add or remove space before the ':' in 'b ? t : f'. +# +# Overrides sp_cond_colon. +sp_cond_colon_before = ignore # ignore/add/remove/force + +# Add or remove space after the ':' in 'b ? t : f'. +# +# Overrides sp_cond_colon. +sp_cond_colon_after = ignore # ignore/add/remove/force + +# Add or remove space around the '?' in 'b ? t : f'. +sp_cond_question = ignore # ignore/add/remove/force + +# Add or remove space before the '?' in 'b ? t : f'. +# +# Overrides sp_cond_question. +sp_cond_question_before = ignore # ignore/add/remove/force + +# Add or remove space after the '?' in 'b ? t : f'. +# +# Overrides sp_cond_question. +sp_cond_question_after = ignore # ignore/add/remove/force + +# In the abbreviated ternary form '(a ?: b)', add or remove space between '?' +# and ':'. +# +# Overrides all other sp_cond_* options. +sp_cond_ternary_short = ignore # ignore/add/remove/force + +# Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make +# sense here. +sp_case_label = ignore # ignore/add/remove/force + +# (D) Add or remove space around the D '..' operator. +sp_range = ignore # ignore/add/remove/force + +# Add or remove space after ':' in a Java/C++11 range-based 'for', +# as in 'for (Type var : expr)'. +sp_after_for_colon = ignore # ignore/add/remove/force + +# Add or remove space before ':' in a Java/C++11 range-based 'for', +# as in 'for (Type var : expr)'. +sp_before_for_colon = ignore # ignore/add/remove/force + +# (D) Add or remove space between 'extern' and '(' as in 'extern (C)'. +sp_extern_paren = ignore # ignore/add/remove/force + +# Add or remove space after the opening of a C++ comment, +# i.e. '// A' vs. '//A'. +sp_cmt_cpp_start = ignore # ignore/add/remove/force + +# If true, space is added with sp_cmt_cpp_start will be added after doxygen +# sequences like '///', '///<', '//!' and '//!<'. +sp_cmt_cpp_doxygen = false # true/false + +# If true, space is added with sp_cmt_cpp_start will be added after Qt +# translator or meta-data comments like '//:', '//=', and '//~'. +sp_cmt_cpp_qttr = false # true/false + +# Add or remove space between #else or #endif and a trailing comment. +sp_endif_cmt = ignore # ignore/add/remove/force + +# Add or remove space after 'new', 'delete' and 'delete[]'. +sp_after_new = ignore # ignore/add/remove/force + +# Add or remove space between 'new' and '(' in 'new()'. +sp_between_new_paren = ignore # ignore/add/remove/force + +# Add or remove space between ')' and type in 'new(foo) BAR'. +sp_after_newop_paren = ignore # ignore/add/remove/force + +# Add or remove space inside parenthesis of the new operator +# as in 'new(foo) BAR'. +sp_inside_newop_paren = ignore # ignore/add/remove/force + +# Add or remove space after the open parenthesis of the new operator, +# as in 'new(foo) BAR'. +# +# Overrides sp_inside_newop_paren. +sp_inside_newop_paren_open = ignore # ignore/add/remove/force + +# Add or remove space before the close parenthesis of the new operator, +# as in 'new(foo) BAR'. +# +# Overrides sp_inside_newop_paren. +sp_inside_newop_paren_close = ignore # ignore/add/remove/force + +# Add or remove space before a trailing or embedded comment. +sp_before_tr_emb_cmt = ignore # ignore/add/remove/force + +# Number of spaces before a trailing or embedded comment. +sp_num_before_tr_emb_cmt = 0 # unsigned number + +# (Java) Add or remove space between an annotation and the open parenthesis. +sp_annotation_paren = ignore # ignore/add/remove/force + +# If true, vbrace tokens are dropped to the previous token and skipped. +sp_skip_vbrace_tokens = false # true/false + +# Add or remove space after 'noexcept'. +sp_after_noexcept = ignore # ignore/add/remove/force + +# If true, a is inserted after #define. +force_tab_after_define = false # true/false + +# +# Indenting options +# + +# The number of columns to indent per level. Usually 2, 3, 4, or 8. +# +# Default: 8 +indent_columns = 4 # unsigned number + +# The continuation indent. If non-zero, this overrides the indent of '(' and +# '=' continuation indents. Negative values are OK; negative value is absolute +# and not increased for each '(' level. +# +# For FreeBSD, this is set to 4. +indent_continue = 0 # number + +# The continuation indent, only for class header line(s). If non-zero, this +# overrides the indent of 'class' continuation indents. +indent_continue_class_head = 0 # unsigned number + +# Whether to indent empty lines (i.e. lines which contain only spaces before +# the newline character). +indent_single_newlines = false # true/false + +# The continuation indent for func_*_param if they are true. If non-zero, this +# overrides the indent. +indent_param = 0 # unsigned number + +# How to use tabs when indenting code. +# +# 0: Spaces only +# 1: Indent with tabs to brace level, align with spaces (default) +# 2: Indent and align with tabs, using spaces when not on a tabstop +# +# Default: 1 +indent_with_tabs = 0 # unsigned number + +# Whether to indent comments that are not at a brace level with tabs on a +# tabstop. Requires indent_with_tabs=2. If false, will use spaces. +indent_cmt_with_tabs = false # true/false + +# Whether to indent strings broken by '\' so that they line up. +indent_align_string = false # true/false + +# The number of spaces to indent multi-line XML strings. +# Requires indent_align_string=true. +indent_xml_string = 0 # unsigned number + +# Spaces to indent '{' from level. +indent_brace = 0 # unsigned number + +# Whether braces are indented to the body level. +indent_braces = false # true/false + +# Whether to disable indenting function braces if indent_braces=true. +indent_braces_no_func = false # true/false + +# Whether to disable indenting class braces if indent_braces=true. +indent_braces_no_class = false # true/false + +# Whether to disable indenting struct braces if indent_braces=true. +indent_braces_no_struct = false # true/false + +# Whether to indent based on the size of the brace parent, +# i.e. 'if' → 3 spaces, 'for' → 4 spaces, etc. +indent_brace_parent = false # true/false + +# Whether to indent based on the open parenthesis instead of the open brace +# in '({\n'. +indent_paren_open_brace = false # true/false + +# (C#) Whether to indent the brace of a C# delegate by another level. +indent_cs_delegate_brace = false # true/false + +# (C#) Whether to indent a C# delegate (to handle delegates with no brace) by +# another level. +indent_cs_delegate_body = false # true/false + +# Whether to indent the body of a 'namespace'. +indent_namespace = false # true/false + +# Whether to indent only the first namespace, and not any nested namespaces. +# Requires indent_namespace=true. +indent_namespace_single_indent = false # true/false + +# The number of spaces to indent a namespace block. +indent_namespace_level = 0 # unsigned number + +# If the body of the namespace is longer than this number, it won't be +# indented. Requires indent_namespace=true. 0 means no limit. +indent_namespace_limit = 0 # unsigned number + +# Whether the 'extern "C"' body is indented. +indent_extern = false # true/false + +# Whether the 'class' body is indented. +indent_class = false # true/false + +# Whether to indent the stuff after a leading base class colon. +indent_class_colon = false # true/false + +# Whether to indent based on a class colon instead of the stuff after the +# colon. Requires indent_class_colon=true. +indent_class_on_colon = false # true/false + +# Whether to indent the stuff after a leading class initializer colon. +indent_constr_colon = false # true/false + +# Virtual indent from the ':' for member initializers. +# +# Default: 2 +indent_ctor_init_leading = 2 # unsigned number + +# Additional indent for constructor initializer list. +# Negative values decrease indent down to the first column. +indent_ctor_init = 0 # number + +# Whether to indent 'if' following 'else' as a new block under the 'else'. +# If false, 'else\nif' is treated as 'else if' for indenting purposes. +indent_else_if = false # true/false + +# Amount to indent variable declarations after a open brace. +# +# <0: Relative +# ≥0: Absolute +indent_var_def_blk = 0 # number + +# Whether to indent continued variable declarations instead of aligning. +indent_var_def_cont = false # true/false + +# Whether to indent continued shift expressions ('<<' and '>>') instead of +# aligning. Set align_left_shift=false when enabling this. +indent_shift = false # true/false + +# Whether to force indentation of function definitions to start in column 1. +indent_func_def_force_col1 = false # true/false + +# Whether to indent continued function call parameters one indent level, +# rather than aligning parameters under the open parenthesis. +indent_func_call_param = false # true/false + +# Same as indent_func_call_param, but for function definitions. +indent_func_def_param = false # true/false + +# Same as indent_func_call_param, but for function prototypes. +indent_func_proto_param = false # true/false + +# Same as indent_func_call_param, but for class declarations. +indent_func_class_param = false # true/false + +# Same as indent_func_call_param, but for class variable constructors. +indent_func_ctor_var_param = false # true/false + +# Same as indent_func_call_param, but for template parameter lists. +indent_template_param = false # true/false + +# Double the indent for indent_func_xxx_param options. +# Use both values of the options indent_columns and indent_param. +indent_func_param_double = false # true/false + +# Indentation column for standalone 'const' qualifier on a function +# prototype. +indent_func_const = 0 # unsigned number + +# Indentation column for standalone 'throw' qualifier on a function +# prototype. +indent_func_throw = 0 # unsigned number + +# The number of spaces to indent a continued '->' or '.'. +# Usually set to 0, 1, or indent_columns. +indent_member = 0 # unsigned number + +# Whether lines broken at '.' or '->' should be indented by a single indent. +# The indent_member option will not be effective if this is set to true. +indent_member_single = false # true/false + +# Spaces to indent single line ('//') comments on lines before code. +indent_sing_line_comments = 0 # unsigned number + +# Whether to indent trailing single line ('//') comments relative to the code +# instead of trying to keep the same absolute column. +indent_relative_single_line_comments = false # true/false + +# Spaces to indent 'case' from 'switch'. Usually 0 or indent_columns. +indent_switch_case = 0 # unsigned number + +# Whether to indent preprocessor statements inside of switch statements. +# +# Default: true +indent_switch_pp = true # true/false + +# Spaces to shift the 'case' line, without affecting any other lines. +# Usually 0. +indent_case_shift = 0 # unsigned number + +# Spaces to indent '{' from 'case'. By default, the brace will appear under +# the 'c' in case. Usually set to 0 or indent_columns. Negative values are OK. +indent_case_brace = 0 # number + +# Whether to indent comments found in first column. +indent_col1_comment = false # true/false + +# How to indent goto labels. +# +# >0: Absolute column where 1 is the leftmost column +# ≤0: Subtract from brace indent +# +# Default: 1 +indent_label = 1 # number + +# Same as indent_label, but for access specifiers that are followed by a +# colon. +# +# Default: 1 +indent_access_spec = 1 # number + +# Whether to indent the code after an access specifier by one level. +# If true, this option forces 'indent_access_spec=0'. +indent_access_spec_body = false # true/false + +# If an open parenthesis is followed by a newline, whether to indent the next +# line so that it lines up after the open parenthesis (not recommended). +indent_paren_nl = false # true/false + +# How to indent a close parenthesis after a newline. +# +# 0: Indent to body level (default) +# 1: Align under the open parenthesis +# 2: Indent to the brace level +indent_paren_close = 0 # unsigned number + +# Whether to indent the open parenthesis of a function definition, +# if the parenthesis is on its own line. +indent_paren_after_func_def = false # true/false + +# Whether to indent the open parenthesis of a function declaration, +# if the parenthesis is on its own line. +indent_paren_after_func_decl = false # true/false + +# Whether to indent the open parenthesis of a function call, +# if the parenthesis is on its own line. +indent_paren_after_func_call = false # true/false + +# Whether to indent a comma when inside a parenthesis. +# If true, aligns under the open parenthesis. +indent_comma_paren = false # true/false + +# Whether to indent a Boolean operator when inside a parenthesis. +# If true, aligns under the open parenthesis. +indent_bool_paren = false # true/false + +# Whether to indent a semicolon when inside a for parenthesis. +# If true, aligns under the open for parenthesis. +indent_semicolon_for_paren = false # true/false + +# Whether to align the first expression to following ones +# if indent_bool_paren=true. +indent_first_bool_expr = false # true/false + +# Whether to align the first expression to following ones +# if indent_semicolon_for_paren=true. +indent_first_for_expr = false # true/false + +# If an open square is followed by a newline, whether to indent the next line +# so that it lines up after the open square (not recommended). +indent_square_nl = false # true/false + +# (ESQL/C) Whether to preserve the relative indent of 'EXEC SQL' bodies. +indent_preserve_sql = false # true/false + +# Whether to align continued statements at the '='. If false or if the '=' is +# followed by a newline, the next line is indent one tab. +# +# Default: true +indent_align_assign = false # true/false + +# Whether to align continued statements at the '('. If false or the '(' is not +# followed by a newline, the next line indent is one tab. +# +# Default: true +indent_align_paren = true # true/false + +# (OC) Whether to indent Objective-C blocks at brace level instead of usual +# rules. +indent_oc_block = false # true/false + +# (OC) Indent for Objective-C blocks in a message relative to the parameter +# name. +# +# =0: Use indent_oc_block rules +# >0: Use specified number of spaces to indent +indent_oc_block_msg = 0 # unsigned number + +# (OC) Minimum indent for subsequent parameters +indent_oc_msg_colon = 0 # unsigned number + +# (OC) Whether to prioritize aligning with initial colon (and stripping spaces +# from lines, if necessary). +# +# Default: true +indent_oc_msg_prioritize_first_colon = true # true/false + +# (OC) Whether to indent blocks the way that Xcode does by default +# (from the keyword if the parameter is on its own line; otherwise, from the +# previous indentation level). Requires indent_oc_block_msg=true. +indent_oc_block_msg_xcode_style = false # true/false + +# (OC) Whether to indent blocks from where the brace is, relative to a +# message keyword. Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_keyword = false # true/false + +# (OC) Whether to indent blocks from where the brace is, relative to a message +# colon. Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_colon = false # true/false + +# (OC) Whether to indent blocks from where the block caret is. +# Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_caret = false # true/false + +# (OC) Whether to indent blocks from where the brace caret is. +# Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_brace = false # true/false + +# When indenting after virtual brace open and newline add further spaces to +# reach this minimum indent. +indent_min_vbrace_open = 0 # unsigned number + +# Whether to add further spaces after regular indent to reach next tabstop +# when identing after virtual brace open and newline. +indent_vbrace_open_on_tabstop = false # true/false + +# How to indent after a brace followed by another token (not a newline). +# true: indent all contained lines to match the token +# false: indent all contained lines to match the brace +# +# Default: true +indent_token_after_brace = true # true/false + +# Whether to indent the body of a C++11 lambda. +indent_cpp_lambda_body = false # true/false + +# (C#) Whether to indent a 'using' block if no braces are used. +# +# Default: true +indent_using_block = true # true/false + +# How to indent the continuation of ternary operator. +# +# 0: Off (default) +# 1: When the `if_false` is a continuation, indent it under `if_false` +# 2: When the `:` is a continuation, indent it under `?` +indent_ternary_operator = 0 # unsigned number + +# If true, the indentation of the chunks after a `return new` sequence will be set at return indentation column. +indent_off_after_return_new = false # true/false + +# If true, the tokens after return are indented with regular single indentation. By default (false) the indentation is after the return token. +indent_single_after_return = false # true/false + +# Whether to ignore indent and alignment for 'asm' blocks (i.e. assume they +# have their own indentation). +indent_ignore_asm_block = false # true/false + +# +# Newline adding and removing options +# + +# Whether to collapse empty blocks between '{' and '}'. +nl_collapse_empty_body = true # true/false + +# Don't split one-line braced assignments, as in 'foo_t f = { 1, 2 };'. +nl_assign_leave_one_liners = false # true/false + +# Don't split one-line braced statements inside a 'class xx { }' body. +nl_class_leave_one_liners = false # true/false + +# Don't split one-line enums, as in 'enum foo { BAR = 15 };' +nl_enum_leave_one_liners = false # true/false + +# Don't split one-line get or set functions. +nl_getset_leave_one_liners = false # true/false + +# (C#) Don't split one-line property get or set functions. +nl_cs_property_leave_one_liners = false # true/false + +# Don't split one-line function definitions, as in 'int foo() { return 0; }'. +nl_func_leave_one_liners = false # true/false + +# Don't split one-line C++11 lambdas, as in '[]() { return 0; }'. +nl_cpp_lambda_leave_one_liners = false # true/false + +# Don't split one-line if/else statements, as in 'if(...) b++;'. +nl_if_leave_one_liners = false # true/false + +# Don't split one-line while statements, as in 'while(...) b++;'. +nl_while_leave_one_liners = false # true/false + +# Don't split one-line for statements, as in 'for(...) b++;'. +nl_for_leave_one_liners = false # true/false + +# (OC) Don't split one-line Objective-C messages. +nl_oc_msg_leave_one_liner = false # true/false + +# (OC) Add or remove newline between method declaration and '{'. +nl_oc_mdef_brace = ignore # ignore/add/remove/force + +# (OC) Add or remove newline between Objective-C block signature and '{'. +nl_oc_block_brace = ignore # ignore/add/remove/force + +# (OC) Add or remove newline between '@interface' and '{'. +nl_oc_interface_brace = ignore # ignore/add/remove/force + +# (OC) Add or remove newline between '@implementation' and '{'. +nl_oc_implementation_brace = ignore # ignore/add/remove/force + +# Add or remove newlines at the start of the file. +nl_start_of_file = ignore # ignore/add/remove/force + +# The minimum number of newlines at the start of the file (only used if +# nl_start_of_file is 'add' or 'force'). +nl_start_of_file_min = 0 # unsigned number + +# Add or remove newline at the end of the file. +nl_end_of_file = ignore # ignore/add/remove/force + +# The minimum number of newlines at the end of the file (only used if +# nl_end_of_file is 'add' or 'force'). +nl_end_of_file_min = 0 # unsigned number + +# Add or remove newline between '=' and '{'. +nl_assign_brace = remove # ignore/add/remove/force + +# (D) Add or remove newline between '=' and '['. +nl_assign_square = ignore # ignore/add/remove/force + +# Add or remove newline between '[]' and '{'. +nl_tsquare_brace = ignore # ignore/add/remove/force + +# (D) Add or remove newline after '= ['. Will also affect the newline before +# the ']'. +nl_after_square_assign = ignore # ignore/add/remove/force + +# The number of blank lines after a block of variable definitions at the top +# of a function body. +# +# 0 = No change (default). +nl_func_var_def_blk = 0 # unsigned number + +# The number of newlines before a block of typedefs. If nl_after_access_spec +# is non-zero, that option takes precedence. +# +# 0 = No change (default). +nl_typedef_blk_start = 0 # unsigned number + +# The number of newlines after a block of typedefs. +# +# 0 = No change (default). +nl_typedef_blk_end = 0 # unsigned number + +# The maximum number of consecutive newlines within a block of typedefs. +# +# 0 = No change (default). +nl_typedef_blk_in = 0 # unsigned number + +# The number of newlines before a block of variable definitions not at the top +# of a function body. If nl_after_access_spec is non-zero, that option takes +# precedence. +# +# 0 = No change (default). +nl_var_def_blk_start = 0 # unsigned number + +# The number of newlines after a block of variable definitions not at the top +# of a function body. +# +# 0 = No change (default). +nl_var_def_blk_end = 0 # unsigned number + +# The maximum number of consecutive newlines within a block of variable +# definitions. +# +# 0 = No change (default). +nl_var_def_blk_in = 0 # unsigned number + +# Add or remove newline between a function call's ')' and '{', as in +# 'list_for_each(item, &list) { }'. +nl_fcall_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'enum' and '{'. +nl_enum_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'enum' and 'class'. +nl_enum_class = ignore # ignore/add/remove/force + +# Add or remove newline between 'enum class' and the identifier. +nl_enum_class_identifier = ignore # ignore/add/remove/force + +# Add or remove newline between 'enum class' type and ':'. +nl_enum_identifier_colon = ignore # ignore/add/remove/force + +# Add or remove newline between 'enum class identifier :' and type. +nl_enum_colon_type = ignore # ignore/add/remove/force + +# Add or remove newline between 'struct and '{'. +nl_struct_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'union' and '{'. +nl_union_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'if' and '{'. +nl_if_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'else'. +nl_brace_else = add # ignore/add/remove/force + +# Add or remove newline between 'else if' and '{'. If set to ignore, +# nl_if_brace is used instead. +nl_elseif_brace = add # ignore/add/remove/force + +# Add or remove newline between 'else' and '{'. +nl_else_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'else' and 'if'. +nl_else_if = ignore # ignore/add/remove/force + +# Add or remove newline before 'if'/'else if' closing parenthesis. +nl_before_if_closing_paren = ignore # ignore/add/remove/force + +# Add or remove newline between '}' and 'finally'. +nl_brace_finally = ignore # ignore/add/remove/force + +# Add or remove newline between 'finally' and '{'. +nl_finally_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'try' and '{'. +nl_try_brace = ignore # ignore/add/remove/force + +# Add or remove newline between get/set and '{'. +nl_getset_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'for' and '{'. +nl_for_brace = remove # ignore/add/remove/force + +# Add or remove newline before the '{' of a 'catch' statement, as in +# 'catch (decl) {'. +nl_catch_brace = ignore # ignore/add/remove/force + +# (OC) Add or remove newline before the '{' of a '@catch' statement, as in +# '@catch (decl) {'. If set to ignore, nl_catch_brace is used. +nl_oc_catch_brace = ignore # ignore/add/remove/force + +# Add or remove newline between '}' and 'catch'. +nl_brace_catch = ignore # ignore/add/remove/force + +# (OC) Add or remove newline between '}' and '@catch'. If set to ignore, +# nl_brace_catch is used. +nl_oc_brace_catch = ignore # ignore/add/remove/force + +# Add or remove newline between '}' and ']'. +nl_brace_square = ignore # ignore/add/remove/force + +# Add or remove newline between '}' and ')' in a function invocation. +nl_brace_fparen = ignore # ignore/add/remove/force + +# Add or remove newline between 'while' and '{'. +nl_while_brace = remove # ignore/add/remove/force + +# (D) Add or remove newline between 'scope (x)' and '{'. +nl_scope_brace = ignore # ignore/add/remove/force + +# (D) Add or remove newline between 'unittest' and '{'. +nl_unittest_brace = ignore # ignore/add/remove/force + +# (D) Add or remove newline between 'version (x)' and '{'. +nl_version_brace = ignore # ignore/add/remove/force + +# (C#) Add or remove newline between 'using' and '{'. +nl_using_brace = ignore # ignore/add/remove/force + +# Add or remove newline between two open or close braces. Due to general +# newline/brace handling, REMOVE may not work. +nl_brace_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'do' and '{'. +nl_do_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'while' of 'do' statement. +nl_brace_while = remove # ignore/add/remove/force + +# Add or remove newline between 'switch' and '{'. +nl_switch_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'synchronized' and '{'. +nl_synchronized_brace = ignore # ignore/add/remove/force + +# Add a newline between ')' and '{' if the ')' is on a different line than the +# if/for/etc. +# +# Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch and +# nl_catch_brace. +nl_multi_line_cond = false # true/false + +# Force a newline in a define after the macro name for multi-line defines. +nl_multi_line_define = false # true/false + +# Whether to add a newline before 'case', and a blank line before a 'case' +# statement that follows a ';' or '}'. +nl_before_case = false # true/false + +# Whether to add a newline after a 'case' statement. +nl_after_case = false # true/false + +# Add or remove newline between a case ':' and '{'. +# +# Overrides nl_after_case. +nl_case_colon_brace = ignore # ignore/add/remove/force + +# Add or remove newline between ')' and 'throw'. +nl_before_throw = ignore # ignore/add/remove/force + +# Add or remove newline between 'namespace' and '{'. +nl_namespace_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'template<>' and whatever follows. +nl_template_class = ignore # ignore/add/remove/force + +# Add or remove newline between 'class' and '{'. +nl_class_brace = ignore # ignore/add/remove/force + +# Add or remove newline before or after (depending on pos_class_comma) each +# ',' in the base class list. +nl_class_init_args = ignore # ignore/add/remove/force + +# Add or remove newline after each ',' in the constructor member +# initialization. Related to nl_constr_colon, pos_constr_colon and +# pos_constr_comma. +nl_constr_init_args = ignore # ignore/add/remove/force + +# Add or remove newline before first element, after comma, and after last +# element, in 'enum'. +nl_enum_own_lines = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name in a function +# definition. +nl_func_type_name = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name inside a class +# definition. If set to ignore, nl_func_type_name or nl_func_proto_type_name +# is used instead. +nl_func_type_name_class = ignore # ignore/add/remove/force + +# Add or remove newline between class specification and '::' +# in 'void A::f() { }'. Only appears in separate member implementation (does +# not appear with in-line implementation). +nl_func_class_scope = ignore # ignore/add/remove/force + +# Add or remove newline between function scope and name, as in +# 'void A :: f() { }'. +nl_func_scope_name = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name in a prototype. +nl_func_proto_type_name = ignore # ignore/add/remove/force + +# Add or remove newline between a function name and the opening '(' in the +# declaration. +nl_func_paren = ignore # ignore/add/remove/force + +# Overrides nl_func_paren for functions with no parameters. +nl_func_paren_empty = ignore # ignore/add/remove/force + +# Add or remove newline between a function name and the opening '(' in the +# definition. +nl_func_def_paren = ignore # ignore/add/remove/force + +# Overrides nl_func_def_paren for functions with no parameters. +nl_func_def_paren_empty = ignore # ignore/add/remove/force + +# Add or remove newline between a function name and the opening '(' in the +# call. +nl_func_call_paren = ignore # ignore/add/remove/force + +# Overrides nl_func_call_paren for functions with no parameters. +nl_func_call_paren_empty = ignore # ignore/add/remove/force + +# Add or remove newline after '(' in a function declaration. +nl_func_decl_start = ignore # ignore/add/remove/force + +# Add or remove newline after '(' in a function definition. +nl_func_def_start = ignore # ignore/add/remove/force + +# Overrides nl_func_decl_start when there is only one parameter. +nl_func_decl_start_single = ignore # ignore/add/remove/force + +# Overrides nl_func_def_start when there is only one parameter. +nl_func_def_start_single = ignore # ignore/add/remove/force + +# Whether to add a newline after '(' in a function declaration if '(' and ')' +# are in different lines. If false, nl_func_decl_start is used instead. +nl_func_decl_start_multi_line = false # true/false + +# Whether to add a newline after '(' in a function definition if '(' and ')' +# are in different lines. If false, nl_func_def_start is used instead. +nl_func_def_start_multi_line = false # true/false + +# Add or remove newline after each ',' in a function declaration. +nl_func_decl_args = ignore # ignore/add/remove/force + +# Add or remove newline after each ',' in a function definition. +nl_func_def_args = ignore # ignore/add/remove/force + +# Whether to add a newline after each ',' in a function declaration if '(' +# and ')' are in different lines. If false, nl_func_decl_args is used instead. +nl_func_decl_args_multi_line = false # true/false + +# Whether to add a newline after each ',' in a function definition if '(' +# and ')' are in different lines. If false, nl_func_def_args is used instead. +nl_func_def_args_multi_line = false # true/false + +# Add or remove newline before the ')' in a function declaration. +nl_func_decl_end = ignore # ignore/add/remove/force + +# Add or remove newline before the ')' in a function definition. +nl_func_def_end = ignore # ignore/add/remove/force + +# Overrides nl_func_decl_end when there is only one parameter. +nl_func_decl_end_single = ignore # ignore/add/remove/force + +# Overrides nl_func_def_end when there is only one parameter. +nl_func_def_end_single = ignore # ignore/add/remove/force + +# Whether to add a newline before ')' in a function declaration if '(' and ')' +# are in different lines. If false, nl_func_decl_end is used instead. +nl_func_decl_end_multi_line = false # true/false + +# Whether to add a newline before ')' in a function definition if '(' and ')' +# are in different lines. If false, nl_func_def_end is used instead. +nl_func_def_end_multi_line = false # true/false + +# Add or remove newline between '()' in a function declaration. +nl_func_decl_empty = ignore # ignore/add/remove/force + +# Add or remove newline between '()' in a function definition. +nl_func_def_empty = ignore # ignore/add/remove/force + +# Add or remove newline between '()' in a function call. +nl_func_call_empty = ignore # ignore/add/remove/force + +# Whether to add a newline after '(' in a function call if '(' and ')' are in +# different lines. +nl_func_call_start_multi_line = false # true/false + +# Whether to add a newline after each ',' in a function call if '(' and ')' +# are in different lines. +nl_func_call_args_multi_line = false # true/false + +# Whether to add a newline before ')' in a function call if '(' and ')' are in +# different lines. +nl_func_call_end_multi_line = false # true/false + +# (OC) Whether to put each Objective-C message parameter on a separate line. +# See nl_oc_msg_leave_one_liner. +nl_oc_msg_args = false # true/false + +# Add or remove newline between function signature and '{'. +nl_fdef_brace = force # ignore/add/remove/force + +# Add or remove newline between C++11 lambda signature and '{'. +nl_cpp_ldef_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'return' and the return expression. +nl_return_expr = ignore # ignore/add/remove/force + +# Whether to add a newline after semicolons, except in 'for' statements. +nl_after_semicolon = false # true/false + +# (Java) Add or remove newline between the ')' and '{{' of the double brace +# initializer. +nl_paren_dbrace_open = ignore # ignore/add/remove/force + +# Whether to add a newline after the type in an unnamed temporary +# direct-list-initialization. +nl_type_brace_init_lst = ignore # ignore/add/remove/force + +# Whether to add a newline after the open brace in an unnamed temporary +# direct-list-initialization. +nl_type_brace_init_lst_open = ignore # ignore/add/remove/force + +# Whether to add a newline before the close brace in an unnamed temporary +# direct-list-initialization. +nl_type_brace_init_lst_close = ignore # ignore/add/remove/force + +# Whether to add a newline after '{'. This also adds a newline before the +# matching '}'. +nl_after_brace_open = false # true/false + +# Whether to add a newline between the open brace and a trailing single-line +# comment. Requires nl_after_brace_open=true. +nl_after_brace_open_cmt = false # true/false + +# Whether to add a newline after a virtual brace open with a non-empty body. +# These occur in un-braced if/while/do/for statement bodies. +nl_after_vbrace_open = false # true/false + +# Whether to add a newline after a virtual brace open with an empty body. +# These occur in un-braced if/while/do/for statement bodies. +nl_after_vbrace_open_empty = false # true/false + +# Whether to add a newline after '}'. Does not apply if followed by a +# necessary ';'. +nl_after_brace_close = false # true/false + +# Whether to add a newline after a virtual brace close, +# as in 'if (foo) a++; return;'. +nl_after_vbrace_close = false # true/false + +# Add or remove newline between the close brace and identifier, +# as in 'struct { int a; } b;'. Affects enumerations, unions and +# structures. If set to ignore, uses nl_after_brace_close. +nl_brace_struct_var = ignore # ignore/add/remove/force + +# Whether to alter newlines in '#define' macros. +nl_define_macro = false # true/false + +# Whether to alter newlines between consecutive parenthesis closes. The number +# of closing parentheses in a line will depend on respective open parenthesis +# lines. +nl_squeeze_paren_close = false # true/false + +# Whether to remove blanks after '#ifxx' and '#elxx', or before '#elxx' and +# '#endif'. Does not affect top-level #ifdefs. +nl_squeeze_ifdef = false # true/false + +# Makes the nl_squeeze_ifdef option affect the top-level #ifdefs as well. +nl_squeeze_ifdef_top_level = false # true/false + +# Add or remove blank line before 'if'. +nl_before_if = force # ignore/add/remove/force + +# Add or remove blank line after 'if' statement. Add/Force work only if the +# next token is not a closing brace. +nl_after_if = force # ignore/add/remove/force + +# Add or remove blank line before 'for'. +nl_before_for = force # ignore/add/remove/force + +# Add or remove blank line after 'for' statement. +nl_after_for = force # ignore/add/remove/force + +# Add or remove blank line before 'while'. +nl_before_while = force # ignore/add/remove/force + +# Add or remove blank line after 'while' statement. +nl_after_while = force # ignore/add/remove/force + +# Add or remove blank line before 'switch'. +nl_before_switch = force # ignore/add/remove/force + +# Add or remove blank line after 'switch' statement. +nl_after_switch = force # ignore/add/remove/force + +# Add or remove blank line before 'synchronized'. +nl_before_synchronized = ignore # ignore/add/remove/force + +# Add or remove blank line after 'synchronized' statement. +nl_after_synchronized = ignore # ignore/add/remove/force + +# Add or remove blank line before 'do'. +nl_before_do = force # ignore/add/remove/force + +# Add or remove blank line after 'do/while' statement. +nl_after_do = force # ignore/add/remove/force + +# Whether to double-space commented-entries in 'struct'/'union'/'enum'. +nl_ds_struct_enum_cmt = false # true/false + +# Whether to force a newline before '}' of a 'struct'/'union'/'enum'. +# (Lower priority than eat_blanks_before_close_brace.) +nl_ds_struct_enum_close_brace = false # true/false + +# Add or remove newline before or after (depending on pos_class_colon) a class +# colon, as in 'class Foo : public Bar'. +nl_class_colon = ignore # ignore/add/remove/force + +# Add or remove newline around a class constructor colon. The exact position +# depends on nl_constr_init_args, pos_constr_colon and pos_constr_comma. +nl_constr_colon = ignore # ignore/add/remove/force + +# Whether to collapse a two-line namespace, like 'namespace foo\n{ decl; }' +# into a single line. If true, prevents other brace newline rules from turning +# such code into four lines. +nl_namespace_two_to_one_liner = false # true/false + +# Whether to remove a newline in simple unbraced if statements, turning them +# into one-liners, as in 'if(b)\n i++;' → 'if(b) i++;'. +nl_create_if_one_liner = false # true/false + +# Whether to remove a newline in simple unbraced for statements, turning them +# into one-liners, as in 'for (...)\n stmt;' → 'for (...) stmt;'. +nl_create_for_one_liner = false # true/false + +# Whether to remove a newline in simple unbraced while statements, turning +# them into one-liners, as in 'while (expr)\n stmt;' → 'while (expr) stmt;'. +nl_create_while_one_liner = false # true/false + +# Whether to collapse a function definition whose body (not counting braces) +# is only one line so that the entire definition (prototype, braces, body) is +# a single line. +nl_create_func_def_one_liner = false # true/false + +# Whether to split one-line simple unbraced if statements into two lines by +# adding a newline, as in 'if(b) i++;'. +nl_split_if_one_liner = false # true/false + +# Whether to split one-line simple unbraced for statements into two lines by +# adding a newline, as in 'for (...) stmt;'. +nl_split_for_one_liner = false # true/false + +# Whether to split one-line simple unbraced while statements into two lines by +# adding a newline, as in 'while (expr) stmt;'. +nl_split_while_one_liner = false # true/false + +# +# Blank line options +# + +# The maximum number of consecutive newlines (3 = 2 blank lines). +nl_max = 0 # unsigned number + +# The maximum number of consecutive newlines in a function. +nl_max_blank_in_func = 0 # unsigned number + +# The number of newlines before a function prototype. +nl_before_func_body_proto = 0 # unsigned number + +# The number of newlines before a multi-line function definition. +nl_before_func_body_def = 0 # unsigned number + +# The number of newlines before a class constructor/destructor prototype. +nl_before_func_class_proto = 0 # unsigned number + +# The number of newlines before a class constructor/destructor definition. +nl_before_func_class_def = 0 # unsigned number + +# The number of newlines after a function prototype. +nl_after_func_proto = 0 # unsigned number + +# The number of newlines after a function prototype, if not followed by +# another function prototype. +nl_after_func_proto_group = 0 # unsigned number + +# The number of newlines after a class constructor/destructor prototype. +nl_after_func_class_proto = 0 # unsigned number + +# The number of newlines after a class constructor/destructor prototype, +# if not followed by another constructor/destructor prototype. +nl_after_func_class_proto_group = 0 # unsigned number + +# Whether one-line method definitions inside a class body should be treated +# as if they were prototypes for the purposes of adding newlines. +# +# Requires nl_class_leave_one_liners=true. Overrides nl_before_func_body_def +# and nl_before_func_class_def for one-liners. +nl_class_leave_one_liner_groups = false # true/false + +# The number of newlines after '}' of a multi-line function body. +nl_after_func_body = 0 # unsigned number + +# The number of newlines after '}' of a multi-line function body in a class +# declaration. Also affects class constructors/destructors. +# +# Overrides nl_after_func_body. +nl_after_func_body_class = 0 # unsigned number + +# The number of newlines after '}' of a single line function body. Also +# affects class constructors/destructors. +# +# Overrides nl_after_func_body and nl_after_func_body_class. +nl_after_func_body_one_liner = 0 # unsigned number + +# The minimum number of newlines before a multi-line comment. +# Doesn't apply if after a brace open or another multi-line comment. +nl_before_block_comment = 0 # unsigned number + +# The minimum number of newlines before a single-line C comment. +# Doesn't apply if after a brace open or other single-line C comments. +nl_before_c_comment = 0 # unsigned number + +# The minimum number of newlines before a CPP comment. +# Doesn't apply if after a brace open or other CPP comments. +nl_before_cpp_comment = 0 # unsigned number + +# Whether to force a newline after a multi-line comment. +nl_after_multiline_comment = false # true/false + +# Whether to force a newline after a label's colon. +nl_after_label_colon = false # true/false + +# The number of newlines after '}' or ';' of a struct/enum/union definition. +nl_after_struct = 0 # unsigned number + +# The number of newlines before a class definition. +nl_before_class = 0 # unsigned number + +# The number of newlines after '}' or ';' of a class definition. +nl_after_class = 0 # unsigned number + +# The number of newlines before an access specifier label. This also includes +# the Qt-specific 'signals:' and 'slots:'. Will not change the newline count +# if after a brace open. +# +# 0 = No change (default). +nl_before_access_spec = 0 # unsigned number + +# The number of newlines after an access specifier label. This also includes +# the Qt-specific 'signals:' and 'slots:'. Will not change the newline count +# if after a brace open. +# +# 0 = No change (default). +# +# Overrides nl_typedef_blk_start and nl_var_def_blk_start. +nl_after_access_spec = 0 # unsigned number + +# The number of newlines between a function definition and the function +# comment, as in '// comment\n void foo() {...}'. +# +# 0 = No change (default). +nl_comment_func_def = 0 # unsigned number + +# The number of newlines after a try-catch-finally block that isn't followed +# by a brace close. +# +# 0 = No change (default). +nl_after_try_catch_finally = 0 # unsigned number + +# (C#) The number of newlines before and after a property, indexer or event +# declaration. +# +# 0 = No change (default). +nl_around_cs_property = 0 # unsigned number + +# (C#) The number of newlines between the get/set/add/remove handlers. +# +# 0 = No change (default). +nl_between_get_set = 0 # unsigned number + +# (C#) Add or remove newline between property and the '{'. +nl_property_brace = ignore # ignore/add/remove/force + +# The number of newlines after '{' of a namespace. This also adds newlines +# before the matching '}'. +# +# 0 = Apply eat_blanks_after_open_brace or eat_blanks_before_close_brace if +# applicable, otherwise no change. +# +# Overrides eat_blanks_after_open_brace and eat_blanks_before_close_brace. +nl_inside_namespace = 0 # unsigned number + +# Whether to remove blank lines after '{'. +eat_blanks_after_open_brace = false # true/false + +# Whether to remove blank lines before '}'. +eat_blanks_before_close_brace = false # true/false + +# How aggressively to remove extra newlines not in preprocessor. +# +# 0: No change (default) +# 1: Remove most newlines not handled by other config +# 2: Remove all newlines and reformat completely by config +nl_remove_extra_newlines = 0 # unsigned number + +# Whether to put a blank line before 'return' statements, unless after an open +# brace. +nl_before_return = false # true/false + +# Whether to put a blank line after 'return' statements, unless followed by a +# close brace. +nl_after_return = false # true/false + +# (Java) Add or remove newline after an annotation statement. Only affects +# annotations that are after a newline. +nl_after_annotation = ignore # ignore/add/remove/force + +# (Java) Add or remove newline between two annotations. +nl_between_annotation = ignore # ignore/add/remove/force + +# +# Positioning options +# + +# The position of arithmetic operators in wrapped expressions. +pos_arith = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of assignment in wrapped expressions. Do not affect '=' +# followed by '{'. +pos_assign = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of Boolean operators in wrapped expressions. +pos_bool = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of comparison operators in wrapped expressions. +pos_compare = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of conditional operators, as in the '?' and ':' of +# 'expr ? stmt : stmt', in wrapped expressions. +pos_conditional = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in wrapped expressions. +pos_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in enum entries. +pos_enum_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in the base class list if there is more than one +# line. Affects nl_class_init_args. +pos_class_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in the constructor initialization list. +# Related to nl_constr_colon, nl_constr_init_args and pos_constr_colon. +pos_constr_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of trailing/leading class colon, between class and base class +# list. Affects nl_class_colon. +pos_class_colon = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of colons between constructor and member initialization. +# Related to nl_constr_colon, nl_constr_init_args and pos_constr_comma. +pos_constr_colon = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# +# Line splitting options +# + +# Try to limit code width to N columns. +code_width = 120 # unsigned number + +# Whether to fully split long 'for' statements at semi-colons. +ls_for_split_full = true # true/false + +# Whether to fully split long function prototypes/calls at commas. +ls_func_split_full = true # true/false + +# Whether to split lines as close to code_width as possible and ignore some +# groupings. +ls_code_width = false # true/false + +# +# Code alignment options (not left column spaces/tabs) +# + +# Whether to keep non-indenting tabs. +align_keep_tabs = false # true/false + +# Whether to use tabs for aligning. +align_with_tabs = false # true/false + +# Whether to bump out to the next tab when aligning. +align_on_tabstop = false # true/false + +# Whether to right-align numbers. +align_number_right = false # true/false + +# Whether to keep whitespace not required for alignment. +align_keep_extra_space = false # true/false + +# Whether to align variable definitions in prototypes and functions. +align_func_params = false # true/false + +# The span for aligning parameter definitions in function on parameter name. +# +# 0 = Don't align (default). +align_func_params_span = 0 # unsigned number + +# The threshold for aligning function parameter definitions. +# +# 0 = No limit (default). +align_func_params_thresh = 0 # unsigned number + +# The gap for aligning function parameter definitions. +align_func_params_gap = 0 # unsigned number + +# Whether to align parameters in single-line functions that have the same +# name. The function names must already be aligned with each other. +align_same_func_call_params = false # true/false + +# The span for aligning function-call parameters for single line functions. +# +# 0 = Don't align (default). +align_same_func_call_params_span = 0 # unsigned number + +# The threshold for aligning function-call parameters for single line +# functions. +# +# 0 = No limit (default). +align_same_func_call_params_thresh = 0 # unsigned number + +# The span for aligning variable definitions. +# +# 0 = Don't align (default). +align_var_def_span = 0 # unsigned number + +# How to align the '*' in variable definitions. +# +# 0: Part of the type 'void * foo;' (default) +# 1: Part of the variable 'void *foo;' +# 2: Dangling 'void *foo;' +align_var_def_star_style = 0 # unsigned number + +# How to align the '&' in variable definitions. +# +# 0: Part of the type 'long & foo;' (default) +# 1: Part of the variable 'long &foo;' +# 2: Dangling 'long &foo;' +align_var_def_amp_style = 0 # unsigned number + +# The threshold for aligning variable definitions. +# +# 0 = No limit (default). +align_var_def_thresh = 0 # unsigned number + +# The gap for aligning variable definitions. +align_var_def_gap = 0 # unsigned number + +# Whether to align the colon in struct bit fields. +align_var_def_colon = false # true/false + +# The gap for aligning the colon in struct bit fields. +align_var_def_colon_gap = 0 # unsigned number + +# Whether to align any attribute after the variable name. +align_var_def_attribute = false # true/false + +# Whether to align inline struct/enum/union variable definitions. +align_var_def_inline = false # true/false + +# The span for aligning on '=' in assignments. +# +# 0 = Don't align (default). +align_assign_span = 0 # unsigned number + +# The threshold for aligning on '=' in assignments. +# +# 0 = No limit (default). +align_assign_thresh = 0 # unsigned number + +# How to apply align_assign_span to function declaration "assignments", i.e. +# 'virtual void foo() = 0' or '~foo() = {default|delete}'. +# +# 0: Align with other assignments (default) +# 1: Align with each other, ignoring regular assignments +# 2: Don't align +align_assign_decl_func = 0 # unsigned number + +# The span for aligning on '=' in enums. +# +# 0 = Don't align (default). +align_enum_equ_span = 0 # unsigned number + +# The threshold for aligning on '=' in enums. +# +# 0 = no limit (default). +align_enum_equ_thresh = 0 # unsigned number + +# The span for aligning class member definitions. +# +# 0 = Don't align (default). +align_var_class_span = 0 # unsigned number + +# The threshold for aligning class member definitions. +# +# 0 = No limit (default). +align_var_class_thresh = 0 # unsigned number + +# The gap for aligning class member definitions. +align_var_class_gap = 0 # unsigned number + +# The span for aligning struct/union member definitions. +# +# 0 = Don't align (default). +align_var_struct_span = 0 # unsigned number + +# The threshold for aligning struct/union member definitions. +# +# 0 = No limit (default). +align_var_struct_thresh = 0 # unsigned number + +# The gap for aligning struct/union member definitions. +align_var_struct_gap = 0 # unsigned number + +# The span for aligning struct initializer values. +# +# 0 = Don't align (default). +align_struct_init_span = 0 # unsigned number + +# The minimum space between the type and the synonym of a typedef. +align_typedef_gap = 0 # unsigned number + +# The span for aligning single-line typedefs. +# +# 0 = Don't align (default). +align_typedef_span = 0 # unsigned number + +# How to align typedef'd functions with other typedefs. +# +# 0: Don't mix them at all (default) +# 1: Align the open parenthesis with the types +# 2: Align the function type name with the other type names +align_typedef_func = 0 # unsigned number + +# How to align the '*' in typedefs. +# +# 0: Align on typedef type, ignore '*' (default) +# 1: The '*' is part of type name: 'typedef int *pint;' +# 2: The '*' is part of the type, but dangling: 'typedef int *pint;' +align_typedef_star_style = 0 # unsigned number + +# How to align the '&' in typedefs. +# +# 0: Align on typedef type, ignore '&' (default) +# 1: The '&' is part of type name: 'typedef int &pint;' +# 2: The '&' is part of the type, but dangling: 'typedef int &pint;' +align_typedef_amp_style = 0 # unsigned number + +# The span for aligning comments that end lines. +# +# 0 = Don't align (default). +align_right_cmt_span = 0 # unsigned number + +# If aligning comments, whether to mix with comments after '}' and #endif with +# less than three spaces before the comment. +align_right_cmt_mix = false # true/false + +# Whether to only align trailing comments that are at the same brace level. +align_right_cmt_same_level = false # true/false + +# Minimum number of columns between preceding text and a trailing comment in +# order for the comment to qualify for being aligned. Must be non-zero to have +# an effect. +align_right_cmt_gap = 0 # unsigned number + +# Minimum column at which to align trailing comments. Comments which are +# aligned beyond this column, but which can be aligned in a lesser column, +# may be "pulled in". +# +# 0 = Ignore (default). +align_right_cmt_at_col = 0 # unsigned number + +# The span for aligning function prototypes. +# +# 0 = Don't align (default). +align_func_proto_span = 0 # unsigned number + +# Minimum gap between the return type and the function name. +align_func_proto_gap = 0 # unsigned number + +# Whether to align function prototypes on the 'operator' keyword instead of +# what follows. +align_on_operator = false # true/false + +# Whether to mix aligning prototype and variable declarations. If true, +# align_var_def_XXX options are used instead of align_func_proto_XXX options. +align_mix_var_proto = false # true/false + +# Whether to align single-line functions with function prototypes. +# Uses align_func_proto_span. +align_single_line_func = false # true/false + +# Whether to align the open brace of single-line functions. +# Requires align_single_line_func=true. Uses align_func_proto_span. +align_single_line_brace = false # true/false + +# Gap for align_single_line_brace. +align_single_line_brace_gap = 0 # unsigned number + +# (OC) The span for aligning Objective-C message specifications. +# +# 0 = Don't align (default). +align_oc_msg_spec_span = 0 # unsigned number + +# Whether to align macros wrapped with a backslash and a newline. This will +# not work right if the macro contains a multi-line comment. +align_nl_cont = false # true/false + +# Whether to align macro functions and variables together. +align_pp_define_together = false # true/false + +# The minimum space between label and value of a preprocessor define. +align_pp_define_gap = 0 # unsigned number + +# The span for aligning on '#define' bodies. +# +# =0: Don't align (default) +# >0: Number of lines (including comments) between blocks +align_pp_define_span = 0 # unsigned number + +# Whether to align lines that start with '<<' with previous '<<'. +# +# Default: true +align_left_shift = true # true/false + +# Whether to align text after 'asm volatile ()' colons. +align_asm_colon = false # true/false + +# (OC) Span for aligning parameters in an Objective-C message call +# on the ':'. +# +# 0 = Don't align. +align_oc_msg_colon_span = 0 # unsigned number + +# (OC) Whether to always align with the first parameter, even if it is too +# short. +align_oc_msg_colon_first = false # true/false + +# (OC) Whether to align parameters in an Objective-C '+' or '-' declaration +# on the ':'. +align_oc_decl_colon = false # true/false + +# +# Comment modification options +# + +# Try to wrap comments at N columns. +cmt_width = 0 # unsigned number + +# How to reflow comments. +# +# 0: No reflowing (apart from the line wrapping due to cmt_width) (default) +# 1: No touching at all +# 2: Full reflow +cmt_reflow_mode = 0 # unsigned number + +# Whether to convert all tabs to spaces in comments. If false, tabs in +# comments are left alone, unless used for indenting. +cmt_convert_tab_to_spaces = true # true/false + +# Whether to apply changes to multi-line comments, including cmt_width, +# keyword substitution and leading chars. +# +# Default: true +cmt_indent_multi = true # true/false + +# Whether to group c-comments that look like they are in a block. +cmt_c_group = false # true/false + +# Whether to put an empty '/*' on the first line of the combined c-comment. +cmt_c_nl_start = false # true/false + +# Whether to add a newline before the closing '*/' of the combined c-comment. +cmt_c_nl_end = false # true/false + +# Whether to change cpp-comments into c-comments. +cmt_cpp_to_c = true # true/false + +# Whether to group cpp-comments that look like they are in a block. Only +# meaningful if cmt_cpp_to_c=true. +cmt_cpp_group = false # true/false + +# Whether to put an empty '/*' on the first line of the combined cpp-comment +# when converting to a c-comment. +# +# Requires cmt_cpp_to_c=true and cmt_cpp_group=true. +cmt_cpp_nl_start = false # true/false + +# Whether to add a newline before the closing '*/' of the combined cpp-comment +# when converting to a c-comment. +# +# Requires cmt_cpp_to_c=true and cmt_cpp_group=true. +cmt_cpp_nl_end = false # true/false + +# Whether to put a star on subsequent comment lines. +cmt_star_cont = true # true/false + +# The number of spaces to insert at the start of subsequent comment lines. +cmt_sp_before_star_cont = 0 # unsigned number + +# The number of spaces to insert after the star on subsequent comment lines. +cmt_sp_after_star_cont = 0 # unsigned number + +# For multi-line comments with a '*' lead, remove leading spaces if the first +# and last lines of the comment are the same length. +# +# Default: true +cmt_multi_check_last = true # true/false + +# For multi-line comments with a '*' lead, remove leading spaces if the first +# and last lines of the comment are the same length AND if the length is +# bigger as the first_len minimum. +# +# Default: 4 +cmt_multi_first_len_minimum = 4 # unsigned number + +# Path to a file that contains text to insert at the beginning of a file if +# the file doesn't start with a C/C++ comment. If the inserted text contains +# '$(filename)', that will be replaced with the current file's name. +cmt_insert_file_header = "" # string + +# Path to a file that contains text to insert at the end of a file if the +# file doesn't end with a C/C++ comment. If the inserted text contains +# '$(filename)', that will be replaced with the current file's name. +cmt_insert_file_footer = "" # string + +# Path to a file that contains text to insert before a function definition if +# the function isn't preceded by a C/C++ comment. If the inserted text +# contains '$(function)', '$(javaparam)' or '$(fclass)', these will be +# replaced with, respectively, the name of the function, the javadoc '@param' +# and '@return' stuff, or the name of the class to which the member function +# belongs. +cmt_insert_func_header = "" # string + +# Path to a file that contains text to insert before a class if the class +# isn't preceded by a C/C++ comment. If the inserted text contains '$(class)', +# that will be replaced with the class name. +cmt_insert_class_header = "" # string + +# Path to a file that contains text to insert before an Objective-C message +# specification, if the method isn't preceded by a C/C++ comment. If the +# inserted text contains '$(message)' or '$(javaparam)', these will be +# replaced with, respectively, the name of the function, or the javadoc +# '@param' and '@return' stuff. +cmt_insert_oc_msg_header = "" # string + +# Whether a comment should be inserted if a preprocessor is encountered when +# stepping backwards from a function name. +# +# Applies to cmt_insert_oc_msg_header, cmt_insert_func_header and +# cmt_insert_class_header. +cmt_insert_before_preproc = false # true/false + +# Whether a comment should be inserted if a function is declared inline to a +# class definition. +# +# Applies to cmt_insert_func_header. +# +# Default: true +cmt_insert_before_inlines = true # true/false + +# Whether a comment should be inserted if the function is a class constructor +# or destructor. +# +# Applies to cmt_insert_func_header. +cmt_insert_before_ctor_dtor = false # true/false + +# +# Code modifying options (non-whitespace) +# + +# Add or remove braces on a single-line 'do' statement. +mod_full_brace_do = remove # ignore/add/remove/force + +# Add or remove braces on a single-line 'for' statement. +mod_full_brace_for = remove # ignore/add/remove/force + +# (Pawn) Add or remove braces on a single-line function definition. +mod_full_brace_function = force # ignore/add/remove/force + +# Add or remove braces on a single-line 'if' statement. Braces will not be +# removed if the braced statement contains an 'else'. +mod_full_brace_if = remove # ignore/add/remove/force + +# Whether to enforce that all blocks of an 'if'/'else if'/'else' chain either +# have, or do not have, braces. If true, braces will be added if any block +# needs braces, and will only be removed if they can be removed from all +# blocks. +# +# Overrides mod_full_brace_if. +mod_full_brace_if_chain = true # true/false + +# Whether to add braces to all blocks of an 'if'/'else if'/'else' chain. +# If true, mod_full_brace_if_chain will only remove braces from an 'if' that +# does not have an 'else if' or 'else'. +mod_full_brace_if_chain_only = false # true/false + +# Add or remove braces on single-line 'while' statement. +mod_full_brace_while = remove # ignore/add/remove/force + +# Add or remove braces on single-line 'using ()' statement. +mod_full_brace_using = ignore # ignore/add/remove/force + +# Don't remove braces around statements that span N newlines +mod_full_brace_nl = 0 # unsigned number + +# Whether to prevent removal of braces from 'if'/'for'/'while'/etc. blocks +# which span multiple lines. +# +# Affects: +# mod_full_brace_for +# mod_full_brace_if +# mod_full_brace_if_chain +# mod_full_brace_if_chain_only +# mod_full_brace_while +# mod_full_brace_using +# +# Does not affect: +# mod_full_brace_do +# mod_full_brace_function +mod_full_brace_nl_block_rem_mlcond = false # true/false + +# Add or remove unnecessary parenthesis on 'return' statement. +mod_paren_on_return = remove # ignore/add/remove/force + +# (Pawn) Whether to change optional semicolons to real semicolons. +mod_pawn_semicolon = false # true/false + +# Whether to fully parenthesize Boolean expressions in 'while' and 'if' +# statement, as in 'if (a && b > c)' → 'if (a && (b > c))'. +mod_full_paren_if_bool = true # true/false + +# Whether to remove superfluous semicolons. +mod_remove_extra_semicolon = true # true/false + +# If a function body exceeds the specified number of newlines and doesn't have +# a comment after the close brace, a comment will be added. +mod_add_long_function_closebrace_comment = 0 # unsigned number + +# If a namespace body exceeds the specified number of newlines and doesn't +# have a comment after the close brace, a comment will be added. +mod_add_long_namespace_closebrace_comment = 0 # unsigned number + +# If a class body exceeds the specified number of newlines and doesn't have a +# comment after the close brace, a comment will be added. +mod_add_long_class_closebrace_comment = 0 # unsigned number + +# If a switch body exceeds the specified number of newlines and doesn't have a +# comment after the close brace, a comment will be added. +mod_add_long_switch_closebrace_comment = 0 # unsigned number + +# If an #ifdef body exceeds the specified number of newlines and doesn't have +# a comment after the #endif, a comment will be added. +mod_add_long_ifdef_endif_comment = 0 # unsigned number + +# If an #ifdef or #else body exceeds the specified number of newlines and +# doesn't have a comment after the #else, a comment will be added. +mod_add_long_ifdef_else_comment = 0 # unsigned number + +# Whether to sort consecutive single-line 'import' statements. +mod_sort_import = false # true/false + +# (C#) Whether to sort consecutive single-line 'using' statements. +mod_sort_using = false # true/false + +# Whether to sort consecutive single-line '#include' statements (C/C++) and +# '#import' statements (Objective-C). Be aware that this has the potential to +# break your code if your includes/imports have ordering dependencies. +mod_sort_include = false # true/false + +# Whether to move a 'break' that appears after a fully braced 'case' before +# the close brace, as in 'case X: { ... } break;' → 'case X: { ... break; }'. +mod_move_case_break = false # true/false + +# Add or remove braces around a fully braced case statement. Will only remove +# braces if there are no variable declarations in the block. +mod_case_brace = ignore # ignore/add/remove/force + +# Whether to remove a void 'return;' that appears as the last statement in a +# function. +mod_remove_empty_return = false # true/false + +# Add or remove the comma after the last value of an enumeration. +mod_enum_last_comma = ignore # ignore/add/remove/force + +# (OC) Whether to organize the properties. If true, properties will be +# rearranged according to the mod_sort_oc_property_*_weight factors. +mod_sort_oc_properties = false # true/false + +# (OC) Weight of a class property modifier. +mod_sort_oc_property_class_weight = 0 # number + +# (OC) Weight of 'atomic' and 'nonatomic'. +mod_sort_oc_property_thread_safe_weight = 0 # number + +# (OC) Weight of 'readwrite' when organizing properties. +mod_sort_oc_property_readwrite_weight = 0 # number + +# (OC) Weight of a reference type specifier ('retain', 'copy', 'assign', +# 'weak', 'strong') when organizing properties. +mod_sort_oc_property_reference_weight = 0 # number + +# (OC) Weight of getter type ('getter=') when organizing properties. +mod_sort_oc_property_getter_weight = 0 # number + +# (OC) Weight of setter type ('setter=') when organizing properties. +mod_sort_oc_property_setter_weight = 0 # number + +# (OC) Weight of nullability type ('nullable', 'nonnull', 'null_unspecified', +# 'null_resettable') when organizing properties. +mod_sort_oc_property_nullability_weight = 0 # number + +# +# Preprocessor options +# + +# Add or remove indentation of preprocessor directives inside #if blocks +# at brace level 0 (file-level). +pp_indent = ignore # ignore/add/remove/force + +# Whether to indent #if/#else/#endif at the brace level. If false, these are +# indented from column 1. +pp_indent_at_level = false # true/false + +# Specifies the number of columns to indent preprocessors per level +# at brace level 0 (file-level). If pp_indent_at_level=false, also specifies +# the number of columns to indent preprocessors per level +# at brace level > 0 (function-level). +# +# Default: 1 +pp_indent_count = 1 # unsigned number + +# Add or remove space after # based on pp_level of #if blocks. +pp_space = force # ignore/add/remove/force + +# Sets the number of spaces per level added with pp_space. +pp_space_count = 3 # unsigned number + +# The indent for '#region' and '#endregion' in C# and '#pragma region' in +# C/C++. Negative values decrease indent down to the first column. +pp_indent_region = 0 # number + +# Whether to indent the code between #region and #endregion. +pp_region_indent_code = false # true/false + +# If pp_indent_at_level=true, sets the indent for #if, #else and #endif when +# not at file-level. Negative values decrease indent down to the first column. +# +# =0: Indent preprocessors using output_tab_size +# >0: Column at which all preprocessors will be indented +pp_indent_if = 0 # number + +# Whether to indent the code between #if, #else and #endif. +pp_if_indent_code = false # true/false + +# Whether to indent '#define' at the brace level. If false, these are +# indented from column 1. +pp_define_at_level = false # true/false + +# Whether to ignore the '#define' body while formatting. +pp_ignore_define_body = false # true/false + +# Whether to indent case statements between #if, #else, and #endif. +# Only applies to the indent of the preprocesser that the case statements +# directly inside of. +# +# Default: true +pp_indent_case = true # true/false + +# Whether to indent whole function definitions between #if, #else, and #endif. +# Only applies to the indent of the preprocesser that the function definition +# is directly inside of. +# +# Default: true +pp_indent_func_def = true # true/false + +# Whether to indent extern C blocks between #if, #else, and #endif. +# Only applies to the indent of the preprocesser that the extern block is +# directly inside of. +# +# Default: true +pp_indent_extern = true # true/false + +# Whether to indent braces directly inside #if, #else, and #endif. +# Only applies to the indent of the preprocesser that the braces are directly +# inside of. +# +# Default: true +pp_indent_brace = true # true/false + +# +# Sort includes options +# + +# The regex for include category with priority 0. +include_category_0 = "" # string + +# The regex for include category with priority 1. +include_category_1 = "" # string + +# The regex for include category with priority 2. +include_category_2 = "" # string + +# +# Use or Do not Use options +# + +# true: indent_func_call_param will be used (default) +# false: indent_func_call_param will NOT be used +# +# Default: true +use_indent_func_call_param = true # true/false + +# The value of the indentation for a continuation line is calculated +# differently if the statement is: +# - a declaration: your case with QString fileName ... +# - an assignment: your case with pSettings = new QSettings( ... +# +# At the second case the indentation value might be used twice: +# - at the assignment +# - at the function call (if present) +# +# To prevent the double use of the indentation value, use this option with the +# value 'true'. +# +# true: indent_continue will be used only once +# false: indent_continue will be used every time (default) +use_indent_continue_only_once = false # true/false + +# The value might be used twice: +# - at the assignment +# - at the opening brace +# +# To prevent the double use of the indentation value, use this option with the +# value 'true'. +# +# true: indentation will be used only once +# false: indentation will be used every time (default) +indent_cpp_lambda_only_once = false # true/false + +# Whether to apply special formatting for Qt SIGNAL/SLOT macros. Essentially, +# this tries to format these so that they match Qt's normalized form (i.e. the +# result of QMetaObject::normalizedSignature), which can slightly improve the +# performance of the QObject::connect call, rather than how they would +# otherwise be formatted. +# +# See options_for_QT.cpp for details. +# +# Default: true +use_options_overriding_for_qt_macros = true # true/false + +# +# Warn levels - 1: error, 2: warning (default), 3: note +# + +# (C#) Warning is given if doing tab-to-\t replacement and we have found one +# in a C# verbatim string literal. +# +# Default: 2 +warn_level_tabs_found_in_verbatim_string_literals = 2 # unsigned number + +# Meaning of the settings: +# Ignore - do not do any changes +# Add - makes sure there is 1 or more space/brace/newline/etc +# Force - makes sure there is exactly 1 space/brace/newline/etc, +# behaves like Add in some contexts +# Remove - removes space/brace/newline/etc +# +# +# - Token(s) can be treated as specific type(s) with the 'set' option: +# `set tokenType tokenString [tokenString...]` +# +# Example: +# `set BOOL __AND__ __OR__` +# +# tokenTypes are defined in src/token_enum.h, use them without the +# 'CT_' prefix: 'CT_BOOL' → 'BOOL' +# +# +# - Token(s) can be treated as type(s) with the 'type' option. +# `type tokenString [tokenString...]` +# +# Example: +# `type int c_uint_8 Rectangle` +# +# This can also be achieved with `set TYPE int c_uint_8 Rectangle` +# +# +# To embed whitespace in tokenStrings use the '\' escape character, or quote +# the tokenStrings. These quotes are supported: "'` +# +# +# - Support for the auto detection of languages through the file ending can be +# added using the 'file_ext' command. +# `file_ext langType langString [langString..]` +# +# Example: +# `file_ext CPP .ch .cxx .cpp.in` +# +# langTypes are defined in uncrusify_types.h in the lang_flag_e enum, use +# them without the 'LANG_' prefix: 'LANG_CPP' → 'CPP' +# +# +# - Custom macro-based indentation can be set up using 'macro-open', +# 'macro-else' and 'macro-close'. +# `(macro-open | macro-else | macro-close) tokenString` +# +# Example: +# `macro-open BEGIN_TEMPLATE_MESSAGE_MAP` +# `macro-open BEGIN_MESSAGE_MAP` +# `macro-close END_MESSAGE_MAP` +# +# +# option(s) with 'not default' value: 87 +#