256 changes: 131 additions & 125 deletions README.md

Large diffs are not rendered by default.

70 changes: 69 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,78 @@ Back to [README.md](../README.md)

## Version

2.18.5 STABLE
2.18.6 STABLE

## Changes

### 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
Expand Down
6 changes: 6 additions & 0 deletions doc/dlt.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ Initial trace-status that is sent when an application registers. DLT_TRACE_STATU
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

Expand Down
81 changes: 81 additions & 0 deletions doc/dlt_build_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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\<Variable\>=\<Value\>, 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.

## 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

## 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.
88 changes: 88 additions & 0 deletions doc/dlt_demo_setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 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?
42 changes: 34 additions & 8 deletions doc/dlt_design_specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ applications using the DLT user library.
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) or
UNIX_SOCKET based on compile time configuration.
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
Expand Down Expand Up @@ -94,6 +94,8 @@ mode, it uses the syslog daemon for log messages of the DLT daemon application.
- 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:
Expand Down Expand Up @@ -126,8 +128,8 @@ and possibly on the serial device, via poll() call.
- 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 (from DLT user library
to DLT daemon):
- 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
Expand Down Expand Up @@ -213,8 +215,8 @@ contains one entry for each context:
- Setup signal handler and atexit handler
- Ignore all pipe signals
- Create and open own named pipe (with the name /tmp/dlt<PID>, where <PID> is the
process id of the application using the DLT user library) or Unix socket IPC to
the DLT daemon
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
Expand Down Expand Up @@ -331,6 +333,12 @@ During sending of a network trace message, the following things occur:
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:
Expand All @@ -342,10 +350,18 @@ steps are executed:
- 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 or UNIX_SOCKETS, based on compile time configuration).
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
Expand Down Expand Up @@ -379,6 +395,16 @@ 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.
Expand Down Expand Up @@ -746,7 +772,7 @@ The shared directory contains the following files:
| --------- | ----------- |
| 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_SOCKET |
| 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 |

Expand Down
106 changes: 106 additions & 0 deletions doc/dlt_example_user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
% 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\] \[**-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.

-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

# 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 <http://mozilla.org/MPL/2.0/>.

# BUGS

See Github issue: <https://github.com/GENIVI/dlt-daemon/issues>

# SEE ALSO

**dlt-daemon(1)**
21 changes: 21 additions & 0 deletions doc/dlt_for_developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ and to TARGET\_LINK\_LIBRARIES:
${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
Expand Down Expand Up @@ -779,3 +784,19 @@ context changed. The usage is similar to DLT\_REGISTER\_INJECTION\_CALLBACK.
```
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
```
2 changes: 2 additions & 0 deletions doc/dlt_glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Application ID | Application Identifier is a unique identifier for an applicatio
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.
Expand Down
25 changes: 24 additions & 1 deletion doc/dlt_offline_logstorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,27 @@ The following strategies are implemented:
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`
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.
22 changes: 20 additions & 2 deletions include/dlt/dlt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ typedef enum
DLT_CLIENT_MODE_UNDEFINED = -1,
DLT_CLIENT_MODE_TCP,
DLT_CLIENT_MODE_SERIAL,
DLT_CLIENT_MODE_UNIX
DLT_CLIENT_MODE_UNIX,
DLT_CLIENT_MODE_UDP_MULTICAST
} DltClientMode;

typedef struct
{
DltReceiver receiver; /**< receiver pointer to dlt receiver structure */
int sock; /**< sock Connection handle/socket */
char *servIP; /**< servIP IP adress/Hostname of TCP/IP interface */
char *servIP; /**< servIP IP adress/Hostname of interface */
char *hostip; /**< hostip IP address of UDP host receiver interface */
int port; /**< Port for TCP connections (optional) */
char *serialDevice; /**< serialDevice Devicename of serial device */
char *socketPath; /**< socketPath Unix socket path */
Expand Down Expand Up @@ -269,6 +271,14 @@ DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client);
*/
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
Expand All @@ -277,6 +287,14 @@ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate);
*/
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
Expand Down
80 changes: 51 additions & 29 deletions include/dlt/dlt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
# include <stdio.h>
# ifdef __linux__
# include <linux/limits.h>
# include <sys/socket.h>
# else
# include <limits.h>
# endif
Expand All @@ -86,6 +87,12 @@
# include <time.h>
# endif

# if defined(__GNUC__)
# define PURE_FUNCTION __attribute__((pure))
# else
# define PURE_FUNCTION /* nothing */
# endif

# if !defined (__WIN32__) && !defined(_MSC_VER)
# include <termios.h>
# endif
Expand Down Expand Up @@ -290,10 +297,10 @@ enum {

# define DLT_MSG_READ_VALUE(dst, src, length, type) \
{ \
if ((length < 0) || ((length) < ((int32_t)sizeof(type)))) \
if ((length < 0) || ((length) < ((int32_t) sizeof(type)))) \
{ length = -1; } \
else \
{ dst = *((type *)src); src += sizeof(type); length -= sizeof(type); } \
{ dst = *((type *)src); src += sizeof(type); length -= (int32_t) sizeof(type); } \
}

# define DLT_MSG_READ_ID(dst, src, length) \
Expand All @@ -312,7 +319,7 @@ enum {
} \
else \
{ \
memcpy(dst, src, length); \
memcpy(dst, src, (size_t) length); \
dlt_clean_string(dst, length); \
dst[length] = 0; \
src += length; \
Expand Down Expand Up @@ -402,6 +409,7 @@ enum {
typedef enum
{
DLT_RECEIVE_SOCKET,
DLT_RECEIVE_UDP_SOCKET,
DLT_RECEIVE_FD
} DltReceiverType;

Expand All @@ -415,7 +423,7 @@ extern const char dltSerialHeader[DLT_ID_SIZE];
*/
extern char dltSerialHeaderChar[DLT_ID_SIZE];

#ifndef DLT_USE_UNIX_SOCKET_IPC
#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
*/
Expand Down Expand Up @@ -489,14 +497,14 @@ typedef struct sDltMessage
int32_t resync_offset;

/* size parameters */
int32_t headersize; /**< size of complete header including storage header */
int32_t datasize; /**< size of complete payload */
uint32_t headersize; /**< size of complete header including storage header */
uint32_t datasize; /**< size of complete payload */

/* buffer for current loaded message */
uint8_t headerbuffer[sizeof(DltStorageHeader) +
sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra) + sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */
uint8_t *databuffer; /**< buffer for loading payload */
int32_t databuffersize;
uint32_t databuffersize;

/* header values of current loaded message */
DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */
Expand Down Expand Up @@ -767,17 +775,19 @@ typedef struct
int32_t lastBytesRcvd; /**< bytes received in last receive call */
int32_t bytesRcvd; /**< received bytes */
int32_t totalBytesRcvd; /**< total number of received bytes */
char *buffer; /**< pointer to receiver buffer */
char *buf; /**< pointer to position within receiver buffer */
char *backup_buf; /** pointer to the buffer with partial messages if any **/
int fd; /**< connection handle */
int32_t buffersize; /**< size of receiver buffer */
char *buffer; /**< pointer to receiver buffer */
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 */
uint32_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 */
int size; /* size of data area in shared memory */
unsigned 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 */
Expand Down Expand Up @@ -857,6 +867,17 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr,
*/
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 text 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
Expand Down Expand Up @@ -961,7 +982,7 @@ DltReturnValue dlt_message_free(DltMessage *msg, int verbose);
* @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, int textlength, int verbose);
DltReturnValue dlt_message_header(DltMessage *msg, char *text, size_t textlength, int verbose);
/**
* Print Header into an ASCII string, selective.
* @param msg pointer to structure of organising access to DLT messages
Expand All @@ -971,7 +992,7 @@ DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, i
* @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, int textlength, int flags, int verbose);
DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t textlength, int flags, int verbose);
/**
* Print Payload into an ASCII string.
* @param msg pointer to structure of organising access to DLT messages
Expand All @@ -981,7 +1002,7 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, int textlen
* @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, int textlength, int type, int verbose);
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t 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
Expand Down Expand Up @@ -1137,7 +1158,7 @@ DltReturnValue dlt_file_free(DltFile *file, int verbose);
* @param filename the filename
*/
void dlt_log_set_filename(const char *filename);
#ifndef DLT_USE_UNIX_SOCKET_IPC
#if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC
/**
* Set FIFO base direction
* @param pipe_dir the pipe direction
Expand Down Expand Up @@ -1191,10 +1212,11 @@ void dlt_log_free(void);
* 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, int _buffersize);
DltReturnValue dlt_receiver_init(DltReceiver *receiver, int _fd, DltReceiverType type, int _buffersize);
/**
* De-Initialize a dlt receiver structure
* @param receiver pointer to dlt receiver structure
Expand All @@ -1205,23 +1227,23 @@ DltReturnValue dlt_receiver_free(DltReceiver *receiver);
* 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_unix_socket(DltReceiver *receiver, int fd, char **buffer);
DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, DltReceiverType type, 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_unix_socket(DltReceiver *receiver);
DltReturnValue dlt_receiver_free_global_buffer(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, DltReceiverType from_src);
int dlt_receiver_receive(DltReceiver *receiver);
/**
* Remove a specific size of bytes from the received data
* @param receiver pointer to dlt receiver structure
Expand Down Expand Up @@ -1269,7 +1291,7 @@ DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader);
* @param required size
* @return negative value if required size is not sufficient
* */
DltReturnValue dlt_check_rcv_data_size(int received, int required);
DltReturnValue dlt_check_rcv_data_size(uint32_t received, uint32_t required);

/**
* Initialise static ringbuffer with a size of size.
Expand Down Expand Up @@ -1541,7 +1563,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg,
uint8_t **ptr,
int32_t *datalength,
char *text,
int textlength,
size_t textlength,
int byteLength,
int verbose);

Expand Down Expand Up @@ -1596,13 +1618,13 @@ void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
*/
void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size);

# ifndef DLT_USE_UNIX_SOCKET_IPC
/**
* Create the specified path, recursive if necessary
* behaves like calling mkdir -p \<dir\> on the console
* 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_mkdir_recursive(const char *dir);
# endif
int dlt_execute_command(char *filename, char *command, ...);

# ifdef __cplusplus
}
Expand Down
9 changes: 8 additions & 1 deletion include/dlt/dlt_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,17 @@ typedef enum
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;

#ifdef DLT_USE_UNIX_SOCKET_IPC
#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC
/**
* Definition Library connection state
*/
Expand Down
5 changes: 3 additions & 2 deletions include/dlt/dlt_user.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ typedef struct
{
DltContext *handle; /**< pointer to DltContext */
unsigned char *buffer; /**< buffer for building log message*/
int32_t size; /**< payload size */
size_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*/
Expand Down Expand Up @@ -232,6 +232,7 @@ typedef struct

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,
Expand All @@ -253,7 +254,7 @@ typedef struct
int corrupt_message_size;
int16_t corrupt_message_size_size;
# endif
# ifdef DLT_USE_UNIX_SOCKET_IPC
# 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 */
Expand Down
32 changes: 23 additions & 9 deletions src/android/dlt-logd-converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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) /* Binary Buffer */
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)
Expand Down Expand Up @@ -65,9 +65,9 @@ static struct logger_list *init_logger_list(bool skip_binary_buffers)
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_CRASH);
init_logger(logger_list, LOG_ID_EVENTS);
init_logger(logger_list, LOG_ID_STATS);
init_logger(logger_list, LOG_ID_SECURITY);
Expand Down Expand Up @@ -167,9 +167,15 @@ static int logd_parser_loop(struct logger_list *logger_list)
DltLogLevelType log_level;
log_level = get_log_level_from_log_msg(&log_msg);

/* Look into system/core/liblog/logprint.c for buffer format */
auto tag = log_msg.msg()+1;
auto message = tag+strlen(tag)+1;
/* Look into system/core/liblog/logprint.c for buffer format.
"<priority:1><tag:N>\0<message:N>\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);
Expand All @@ -191,17 +197,20 @@ 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_evnt, "EVNT", "logd type: evnt");
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_stat, "STAT", "logd type: stat");
DLT_REGISTER_CONTEXT(dlt_ctx_secu, "SECU", "logd type: secu");
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;
Expand All @@ -211,7 +220,7 @@ int main(int argc, char *argv[])

struct logger_list *logger_list;
/* Binary buffers are currently not supported */
logger_list = init_logger_list(true);
logger_list = init_logger_list(skip_binary_buffers);
if (logger_list == nullptr)
return EXIT_FAILURE;

Expand All @@ -229,6 +238,11 @@ int main(int argc, char *argv[])
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();

Expand Down
22 changes: 11 additions & 11 deletions src/console/dlt-control-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static pthread_cond_t answer_cond = PTHREAD_COND_INITIALIZER;

static int local_verbose;
static char local_ecuid[DLT_CTRL_ECUID_LEN]; /* Name of ECU */
static long local_timeout;
static int local_timeout;

int get_verbosity(void)
{
Expand Down Expand Up @@ -130,12 +130,12 @@ void set_ecuid(char *ecuid)
}
}

long get_timeout(void)
int get_timeout(void)
{
return local_timeout;
}

void set_timeout(long t)
void set_timeout(int t)
{
local_timeout = DLT_CTRL_TIMEOUT;

Expand Down Expand Up @@ -251,16 +251,16 @@ static int dlt_control_send_message_to_socket(int sock, DltMessage *msg)
*/
static int prepare_extra_headers(DltMessage *msg, uint8_t *header)
{
int shift = 0;
uint32_t shift = 0;

pr_verbose("Preparing extra headers.\n");

if (!msg || !header)
return -1;

shift = sizeof(DltStorageHeader) +
shift = (uint32_t) (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());
Expand Down Expand Up @@ -326,12 +326,12 @@ static int prepare_headers(DltMessage *msg, uint8_t *header)
msg->standardheader->mcnt = 0;

/* prepare length information */
msg->headersize = sizeof(DltStorageHeader) +
msg->headersize = (uint32_t) (sizeof(DltStorageHeader) +
sizeof(DltStandardHeader) +
sizeof(DltExtendedHeader) +
DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp);
DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));

len = msg->headersize - sizeof(DltStorageHeader) + msg->datasize;
len = (uint32_t) (msg->headersize - sizeof(DltStorageHeader) + msg->datasize);

if (len > UINT16_MAX) {
pr_error("Message header is too long.\n");
Expand Down Expand Up @@ -377,7 +377,7 @@ static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data)
}

/* prepare payload of data */
msg->databuffersize = msg->datasize = data->size;
msg->databuffersize = msg->datasize = (uint32_t) data->size;

/* Allocate memory for Dlt Message's buffer */
msg->databuffer = (uint8_t *)calloc(1, data->size);
Expand Down Expand Up @@ -515,7 +515,7 @@ static int dlt_control_callback(DltMessage *message, void *data)
pthread_mutex_lock(&answer_lock);
callback_return = response_analyzer_cb(text,
message->databuffer,
message->datasize);
(int) message->datasize);
pthread_cond_signal(&answer_cond);
pthread_mutex_unlock(&answer_lock);

Expand Down
6 changes: 3 additions & 3 deletions src/console/dlt-control-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
typedef struct
{
void *data; /**< data to be send to DLT Daemon */
int size; /**< size of that data */
uint32_t size; /**< size of that data */
} DltControlMsgBody;

/* As verbosity, ecuid and timeout are needed during the communication,
Expand All @@ -68,8 +68,8 @@ void set_verbosity(int);
char *get_ecuid(void);
void set_ecuid(char *);

long get_timeout(void);
void set_timeout(long);
int get_timeout(void);
void set_timeout(int);

/* Parse dlt.conf file and return the value of requested configuration */
int dlt_parse_config_param(char *config_id, char **config_data);
Expand Down
92 changes: 55 additions & 37 deletions src/console/dlt-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,35 +282,29 @@ int main(int argc, char *argv[])
{
DltReceiveData dltdata;
int c;
int ret;
int index;
char *endptr = NULL;
struct timespec ts;

/* Initialize dltdata */
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;
dltdata.kvalue = 0;
dltdata = (DltReceiveData) {
.tvalue = 1000,
.lvalue = DLT_INVALID_LOG_LEVEL,
.rvalue = DLT_INVALID_TRACE_STATUS,
.dvalue = -1,
.fvalue = -1,
.ivalue = -1,
.oflag = -1,
.gflag = -1,
};

/* Fetch command line arguments */
opterr = 0;

/* Default return value */
ret = 0;

while ((c = getopt (argc, argv, "vhye:b:a:c:s:m:x:t:l:r:d:f:i:ogjku")) != -1)
switch (c) {
case 'v':
Expand Down Expand Up @@ -383,7 +377,7 @@ int main(int argc, char *argv[])
}
case 'l':
{
dltdata.lvalue = strtol(optarg, &endptr, 10);
dltdata.lvalue = (int) 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");
Expand All @@ -394,7 +388,7 @@ int main(int argc, char *argv[])
}
case 'r':
{
dltdata.rvalue = strtol(optarg, &endptr, 10);
dltdata.rvalue = (int) 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");
Expand Down Expand Up @@ -558,10 +552,12 @@ int main(int argc, char *argv[])
if (dlt_client_send_inject_msg(&g_dltclient,
dltdata.avalue,
dltdata.cvalue,
dltdata.svalue,
(uint32_t) dltdata.svalue,
(uint8_t *)dltdata.mvalue,
strlen(dltdata.mvalue)) != DLT_RETURN_OK)
(uint32_t) 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)
{
Expand All @@ -580,9 +576,11 @@ int main(int argc, char *argv[])
if (dlt_client_send_inject_msg(&g_dltclient,
dltdata.avalue,
dltdata.cvalue,
dltdata.svalue,
buffer, size) != DLT_RETURN_OK)
(uint32_t) dltdata.svalue,
buffer, (uint32_t)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)*/
{
Expand All @@ -593,8 +591,10 @@ int main(int argc, char *argv[])
}

if (0 != dlt_client_send_all_log_level(&g_dltclient,
dltdata.lvalue))
(uint8_t) dltdata.lvalue)) {
fprintf(stderr, "ERROR: Could not send log level\n");
ret = -1;
}
}
else {
/* log level */
Expand All @@ -609,8 +609,10 @@ int main(int argc, char *argv[])
if (0 != dlt_client_send_log_level(&g_dltclient,
dltdata.avalue,
dltdata.cvalue,
dltdata.lvalue))
(uint8_t) dltdata.lvalue)) {
fprintf(stderr, "ERROR: Could not send log level\n");
ret = -1;
}
}
}
else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS)
Expand All @@ -622,8 +624,10 @@ int main(int argc, char *argv[])
}

if (0 != dlt_client_send_all_trace_status(&g_dltclient,
dltdata.rvalue))
(uint8_t) dltdata.rvalue)) {
fprintf(stderr, "ERROR: Could not send trace status\n");
ret = -1;
}
}
else {
/* trace status */
Expand All @@ -638,8 +642,10 @@ int main(int argc, char *argv[])
if (0 != dlt_client_send_trace_status(&g_dltclient,
dltdata.avalue,
dltdata.cvalue,
dltdata.rvalue))
(uint8_t) dltdata.rvalue)) {
fprintf(stderr, "ERROR: Could not send trace status\n");
ret = -1;
}
}
}
else if (dltdata.dvalue != -1)
Expand All @@ -649,8 +655,10 @@ int main(int argc, char *argv[])
printf("Loglevel: %d\n", dltdata.dvalue);

/* send control message in*/
if (dlt_client_send_default_log_level(&g_dltclient, dltdata.dvalue) != DLT_RETURN_OK)
if (dlt_client_send_default_log_level(&g_dltclient, (uint8_t) dltdata.dvalue) != DLT_RETURN_OK) {
fprintf (stderr, "ERROR: Could not send default log level\n");
ret = -1;
}
}
else if (dltdata.fvalue != -1)
{
Expand All @@ -659,8 +667,10 @@ int main(int argc, char *argv[])
printf("TraceStatus: %d\n", dltdata.fvalue);

/* send control message in*/
if (dlt_client_send_default_trace_status(&g_dltclient, dltdata.fvalue) != DLT_RETURN_OK)
if (dlt_client_send_default_trace_status(&g_dltclient, (uint8_t) dltdata.fvalue) != DLT_RETURN_OK) {
fprintf (stderr, "ERROR: Could not send default trace status\n");
ret = -1;
}
}
else if (dltdata.ivalue != -1)
{
Expand All @@ -669,26 +679,32 @@ int main(int argc, char *argv[])
printf("Timing packets: %d\n", dltdata.ivalue);

/* send control message in*/
if (dlt_client_send_timing_pakets(&g_dltclient, dltdata.ivalue) != DLT_RETURN_OK)
if (dlt_client_send_timing_pakets(&g_dltclient, (uint8_t) dltdata.ivalue) != DLT_RETURN_OK) {
fprintf (stderr, "ERROR: Could not send timing packets\n");
ret = -1;
}
}
else if (dltdata.oflag != -1)
{
/* default trace status */
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)
{
/* reset to factory default */
printf("Reset to factory default\n");

/* send control message in*/
if (dlt_client_send_reset_to_factory_default(&g_dltclient) != DLT_RETURN_OK)
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;
}
}
else if (dltdata.jvalue == 1)
{
Expand All @@ -710,6 +726,8 @@ int main(int argc, char *argv[])
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 */
Expand All @@ -722,7 +740,7 @@ int main(int argc, char *argv[])

dlt_filter_free(&(dltdata.filter), dltdata.vflag);

return 0;
return ret;
}

int dlt_receive_message_callback(DltMessage *message, void *data)
Expand All @@ -744,7 +762,7 @@ int dlt_receive_message_callback(DltMessage *message, void *data)

/* get response service id */
ptr = message->databuffer;
datalength = message->datasize;
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);
Expand Down
33 changes: 16 additions & 17 deletions src/console/dlt-convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void empty_dir(const char *dir)

if (stat(dir, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
n = scandir(dir, &files, NULL, alphasort);
n = (uint32_t) scandir(dir, &files, NULL, alphasort);

/* Do not include /. and /.. */
if (n < 2)
Expand Down Expand Up @@ -216,7 +216,6 @@ int main(int argc, char *argv[])
char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 };

/* For handling compressed files */
char command[COMMAND_SIZE] = { 0 };
char tmp_filename[FILENAME_SIZE] = { 0 };
struct stat st = { 0 };
struct dirent **files = { 0 };
Expand Down Expand Up @@ -359,22 +358,22 @@ int main(int argc, char *argv[])
}

for (index = optind; index < argc; index++) {
memset(command, 0, COMMAND_SIZE);

/* Check extension of input file
* If it is a compressed file, uncompress it
*/
if (strcmp(get_filename_ext(argv[index]), DLT_EXTENSION) != 0)
snprintf(command, COMMAND_SIZE, "tar xf %s -C %s",
argv[index], DLT_CONVERT_WS);
else
snprintf(command, COMMAND_SIZE, "cp %s %s",
argv[index], DLT_CONVERT_WS);
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));
}

syserr = system(command);
if (syserr != 0)
fprintf(stderr, "ERROR: Failed to execute command [%s] with error [%d]\n",
command, syserr);
}

n = scandir(DLT_CONVERT_WS, &files, NULL, alphasort);
Expand Down Expand Up @@ -465,11 +464,11 @@ int main(int argc, char *argv[])
/* if file output enabled write message */
if (ovalue) {
iov[0].iov_base = file.msg.headerbuffer;
iov[0].iov_len = file.msg.headersize;
iov[0].iov_len = (uint32_t) file.msg.headersize;
iov[1].iov_base = file.msg.databuffer;
iov[1].iov_len = file.msg.datasize;
iov[1].iov_len = (uint32_t) file.msg.datasize;

bytes_written = writev(ohandle, iov, 2);
bytes_written =(int) writev(ohandle, iov, 2);

if (0 > bytes_written) {
printf("in main: writev(ohandle, iov, 2); returned an error!");
Expand Down
4 changes: 2 additions & 2 deletions src/console/dlt-passive-node-ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static int parse_args(int argc, char *argv[])
state = (int)strtol(optarg, NULL, 10);

if ((state == DLT_NODE_CONNECT) || (state == DLT_NODE_DISCONNECT)) {
set_connection_state(state);
set_connection_state((unsigned int) state);
set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECT);
}
else {
Expand All @@ -363,7 +363,7 @@ static int parse_args(int argc, char *argv[])
set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS);
break;
case 't':
set_timeout(strtol(optarg, NULL, 10));
set_timeout((int) strtol(optarg, NULL, 10));
break;
case 'v':
set_verbosity(1);
Expand Down
57 changes: 49 additions & 8 deletions src/console/dlt-receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
#include <string.h>
#include <glob.h>
#include <syslog.h>
#include <signal.h>
#include <sys/socket.h>
#ifdef __linux__
# include <linux/limits.h>
#else
Expand All @@ -86,6 +88,24 @@

#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);

Expand All @@ -96,6 +116,7 @@ typedef struct {
int mflag;
int vflag;
int yflag;
int uflag;
char *ovalue;
char *ovaluebase; /* ovalue without ".dlt" */
char *fvalue;
Expand Down Expand Up @@ -131,6 +152,7 @@ void usage()
printf(" -v Verbose mode\n");
printf(" -h Usage\n");
printf(" -y Serial device mode\n");
printf(" -u UDP multicast mode\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");
Expand Down Expand Up @@ -288,7 +310,6 @@ void dlt_receive_close_output_file(DltReceiveData *dltdata)
*/
int main(int argc, char *argv[])
{
DltClient dltclient;
DltReceiveData dltdata;
int c;
int index;
Expand All @@ -300,6 +321,7 @@ int main(int argc, char *argv[])
dltdata.mflag = 0;
dltdata.vflag = 0;
dltdata.yflag = 0;
dltdata.uflag = 0;
dltdata.ovalue = 0;
dltdata.ovaluebase = 0;
dltdata.fvalue = 0;
Expand All @@ -310,10 +332,19 @@ int main(int argc, char *argv[])
dltdata.totalbytes = 0;
dltdata.part_num = -1;

/* Config signal handler */
struct sigaction 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, "vashyxmf:o:e:b:c:")) != -1)
while ((c = getopt (argc, argv, "vashyuxmf:o:e:b:c:")) != -1)
switch (c) {
case 'v':
{
Expand Down Expand Up @@ -350,6 +381,11 @@ int main(int argc, char *argv[])
dltdata.yflag = 1;
break;
}
case 'u':
{
dltdata.uflag = 1;
break;
}
case 'f':
{
dltdata.fvalue = optarg;
Expand Down Expand Up @@ -425,9 +461,14 @@ int main(int argc, char *argv[])
dlt_client_register_message_callback(dlt_receive_message_callback);

/* Setup DLT Client structure */
dltclient.mode = dltdata.yflag;
if(dltdata.uflag) {
dltclient.mode = DLT_CLIENT_MODE_UDP_MULTICAST;
}
else {
dltclient.mode = dltdata.yflag;
}

if (dltclient.mode == DLT_CLIENT_MODE_TCP) {
if (dltclient.mode == DLT_CLIENT_MODE_TCP || dltclient.mode == DLT_CLIENT_MODE_UDP_MULTICAST) {
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");
Expand Down Expand Up @@ -576,12 +617,12 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
/* if file output enabled write message */
if (dltdata->ovalue) {
iov[0].iov_base = message->headerbuffer;
iov[0].iov_len = message->headersize;
iov[0].iov_len = (uint32_t) message->headersize;
iov[1].iov_base = message->databuffer;
iov[1].iov_len = message->datasize;
iov[1].iov_len = (uint32_t) message->datasize;

if (dltdata->climit > -1) {
int bytes_to_write = message->headersize + message->datasize;
uint32_t bytes_to_write = message->headersize + message->datasize;

if ((bytes_to_write + dltdata->totalbytes > dltdata->climit)) {
dlt_receive_close_output_file(dltdata);
Expand All @@ -596,7 +637,7 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
}
}

bytes_written = writev(dltdata->ohandle, iov, 2);
bytes_written = (int) writev(dltdata->ohandle, iov, 2);

dltdata->totalbytes += bytes_written;

Expand Down
6 changes: 3 additions & 3 deletions src/console/dlt-sortbytimestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void verbose(int level, char *msg, ...) {
}
}

int len = strlen(msg);
int len = (int) strlen(msg);
va_list args;
va_start (args, msg);
vprintf(msg, args);
Expand Down Expand Up @@ -229,7 +229,7 @@ int main(int argc, char *argv[]) {
uint32_t message_count = 0;

uint32_t count = 0;
int start = 0;
uint32_t start = 0;
uint32_t delta_tmsp = 0;
uint32_t delta_systime = 0;
size_t i;
Expand Down Expand Up @@ -390,7 +390,7 @@ int main(int argc, char *argv[]) {

verbose(1, "Allocating memory\n");

message_count = 1 + end - begin;
message_count = (uint32_t) (1 + end - begin);

timestamp_index = (TimestampIndex *) malloc(sizeof(TimestampIndex) * (message_count + 1));

Expand Down
4 changes: 2 additions & 2 deletions src/console/logstorage/dlt-logstorage-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int get_default_event_type(void)

void set_default_event_type(long type)
{
g_options.event_type = type;
g_options.event_type = (int) type;
}

char *get_default_path(void)
Expand Down Expand Up @@ -285,7 +285,7 @@ static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body,
serv = (DltServiceOfflineLogstorage *)(*body)->data;

serv->service_id = DLT_SERVICE_ID_OFFLINE_LOGSTORAGE;
serv->connection_type = conn_type;
serv->connection_type = (uint8_t) conn_type;
/* mount_point is DLT_MOUNT_PATH_MAX + 1 long,
* and the memory is already zeroed.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/console/logstorage/dlt-logstorage-ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ static int dlt_logstorage_ctrl_setup_event_loop(void)
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 %lds.\n", get_timeout());
sleep(get_timeout());
pr_error("Retrying to connect in %ds.\n", get_timeout());
sleep((unsigned int) get_timeout());
}

if (dlt_logstorage_must_exit()) {
Expand Down Expand Up @@ -370,8 +370,8 @@ static int dlt_logstorage_ctrl_single_request()
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 %lds.\n", get_timeout());
sleep(get_timeout());
pr_error("Retrying to connect in %ds.\n", get_timeout());
sleep( (unsigned int) get_timeout());
}

pr_verbose("event type is [%d]\t device path is [%s]\n",
Expand Down Expand Up @@ -452,7 +452,7 @@ static int parse_args(int argc, char *argv[])
set_default_path(optarg);
break;
case 't':
set_timeout(strtol(optarg, NULL, 10));
set_timeout((int) strtol(optarg, NULL, 10));
break;
case 'h':
usage();
Expand Down
504 changes: 384 additions & 120 deletions src/daemon/dlt-daemon.c

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions src/daemon/dlt-daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ typedef struct
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 */
int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */
uint32_t offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */
char offlineLogstorageDirPath[DLT_MOUNT_PATH_MAX]; /**< (String: Directory) DIR path to store offline logs */
int offlineLogstorageTimestamp; /**< (int) Append timestamp in offline logstorage filename */
char offlineLogstorageDelimiter; /**< (char) Append delimeter character in offline logstorage filename */
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_USE_UNIX_SOCKET_IPC
#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */
#else
#else /* DLT_DAEMON_USE_FIFO_IPC */
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) */
Expand All @@ -135,7 +135,8 @@ typedef struct
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 */
DltBindAddress_t* ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */
int injectionMode; /**< (Boolean) Injection mode */
} DltDaemonFlags;
/**
* The global parameters of a dlt daemon.
Expand Down Expand Up @@ -168,8 +169,10 @@ typedef struct

typedef struct
{
int timer_fd;
unsigned long long wakeups_missed;
int period_sec;
int starts_in;
int timer_id;
} DltDaemonPeriodicData;

typedef struct
Expand All @@ -196,6 +199,10 @@ int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_
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,
Expand All @@ -208,7 +215,7 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_l
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);
#ifdef DLT_USE_UNIX_SOCKET_IPC
#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
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,
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/dlt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ RingbufferStepSize = 500000
# 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 #
########################################################################
Expand Down
243 changes: 152 additions & 91 deletions src/daemon/dlt_daemon_client.c

Large diffs are not rendered by default.

178 changes: 94 additions & 84 deletions src/daemon/dlt_daemon_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
* aw 13.01.2010 initial
*/

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -139,9 +140,10 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon,
dlt_vlog(LOG_ERR, "Cannot find user list for ECU: %4s\n", ecu);
return (DltDaemonRegisteredUsers *)NULL;
}
int dlt_daemon_load_runtime_configuration(DltDaemon *daemon, const char *runtime_directory, int verbose)
int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, const char *runtime_directory, int verbose)
{
int append_length = 0;
PRINT_FUNCTION_VERBOSE(verbose);
size_t append_length = 0;

if (daemon == NULL)
return DLT_RETURN_ERROR;
Expand Down Expand Up @@ -192,14 +194,6 @@ int dlt_daemon_load_runtime_configuration(DltDaemon *daemon, const char *runtime

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;
}

Expand All @@ -221,9 +215,9 @@ int dlt_daemon_init(DltDaemon *daemon,
daemon->user_list = NULL;
daemon->num_user_lists = 0;

daemon->default_log_level = InitialContextLogLevel;
daemon->default_trace_status = InitialContextTraceStatus;
daemon->force_ll_ts = ForceLLTS;
daemon->default_log_level = (int8_t) InitialContextLogLevel;
daemon->default_trace_status = (int8_t) InitialContextTraceStatus;
daemon->force_ll_ts = (int8_t) ForceLLTS;

daemon->overflow_counter = 0;

Expand All @@ -242,8 +236,8 @@ int dlt_daemon_init(DltDaemon *daemon,
dlt_vlog(LOG_INFO, "Ringbuffer configuration: %lu/%lu/%lu\n",
RingbufferMinSize, RingbufferMaxSize, RingbufferStepSize);

if (dlt_buffer_init_dynamic(&(daemon->client_ringbuffer), RingbufferMinSize, RingbufferMaxSize,
RingbufferStepSize) == DLT_RETURN_ERROR)
if (dlt_buffer_init_dynamic(&(daemon->client_ringbuffer), (uint32_t) RingbufferMinSize, (uint32_t) RingbufferMaxSize,
(uint32_t) RingbufferStepSize) == DLT_RETURN_ERROR)
return -1;

daemon->storage_handle = NULL;
Expand Down Expand Up @@ -297,7 +291,7 @@ int dlt_daemon_init_user_information(DltDaemon *daemon,

if (gateway_mode == 0) {
/* initialize application list */
daemon->user_list = calloc(nodes, sizeof(DltDaemonRegisteredUsers));
daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers));

if (daemon->user_list == NULL) {
dlt_log(LOG_ERR, "Allocating memory for user information");
Expand All @@ -311,7 +305,7 @@ int dlt_daemon_init_user_information(DltDaemon *daemon,
nodes += gateway->num_connections;

/* initialize application list */
daemon->user_list = calloc(nodes, sizeof(DltDaemonRegisteredUsers));
daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers));

if (daemon->user_list == NULL) {
dlt_log(LOG_ERR, "Allocating memory for user information");
Expand Down Expand Up @@ -384,6 +378,33 @@ int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose)
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,
Expand All @@ -396,8 +417,9 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
DltDaemonApplication *old;
int new_application;
int dlt_user_handle;
bool owns_user_handle;
DltDaemonRegisteredUsers *user_list = NULL;
#ifndef DLT_USE_UNIX_SOCKET_IPC
#ifdef DLT_DAEMON_USE_FIFO_IPC
(void)fd; /* To avoid compiler warning : unused variable */
char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE];
#endif
Expand Down Expand Up @@ -455,6 +477,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
application->application_description = NULL;
application->num_contexts = 0;
application->user_handle = DLT_FD_INIT;
application->owns_user_handle = false;

new_application = 1;

Expand Down Expand Up @@ -487,56 +510,54 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
}
}

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;
}
if (application->pid != pid) {
dlt_daemon_application_reset_user_handle(daemon, application, verbose);
application->pid = 0;
}

/* open user pipe only if it is not yet opened */
if ((application->user_handle == DLT_FD_INIT) && (pid != 0)) {
#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 */
dlt_user_handle = DLT_FD_INIT;
owns_user_handle = false;

#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 */
dlt_daemon_applications_invalidate_fd(daemon, ecu, dlt_user_handle, verbose);
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,
user_list->num_applications,
(size_t) user_list->num_applications,
sizeof(DltDaemonApplication),
dlt_daemon_cmp_apid);

Expand Down Expand Up @@ -566,21 +587,15 @@ int dlt_daemon_application_del(DltDaemon *daemon,
return -1;

if (user_list->num_applications > 0) {
/* 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;
}
dlt_daemon_application_reset_user_handle(daemon, application, verbose);

/* Free description of application to be deleted */
if (application->application_description) {
free(application->application_description);
application->application_description = NULL;
}

pos = application - (user_list->applications);
pos = (int) (application - (user_list->applications));

/* move all applications above pos to pos */
memmove(&(user_list->applications[pos]),
Expand Down Expand Up @@ -627,7 +642,7 @@ DltDaemonApplication *dlt_daemon_application_find(DltDaemon *daemon,
dlt_set_id(application.apid, apid);
return (DltDaemonApplication *)bsearch(&application,
user_list->applications,
user_list->num_applications,
(size_t) user_list->num_applications,
sizeof(DltDaemonApplication),
dlt_daemon_cmp_apid);
}
Expand Down Expand Up @@ -830,7 +845,7 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon,
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(sizeof(DltDaemonContext) *
user_list->contexts = (DltDaemonContext *)malloc((size_t) sizeof(DltDaemonContext) *
((user_list->num_contexts /
DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) *
DLT_DAEMON_CONTEXT_ALLOC_SIZE);
Expand All @@ -843,7 +858,7 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon,

memcpy(user_list->contexts,
old,
sizeof(DltDaemonContext) * user_list->num_contexts);
(size_t) sizeof(DltDaemonContext) * user_list->num_contexts);
free(old);
}
}
Expand Down Expand Up @@ -910,7 +925,7 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon,
/* Sort */
if (new_context) {
qsort(user_list->contexts,
user_list->num_contexts,
(size_t) user_list->num_contexts,
sizeof(DltDaemonContext),
dlt_daemon_cmp_apid_ctid);

Expand Down Expand Up @@ -949,7 +964,7 @@ int dlt_daemon_context_del(DltDaemon *daemon,
context->context_description = NULL;
}

pos = context - (user_list->contexts);
pos = (int) (context - (user_list->contexts));

/* move all contexts above pos to pos */
memmove(&(user_list->contexts[pos]),
Expand Down Expand Up @@ -1003,7 +1018,7 @@ DltDaemonContext *dlt_daemon_context_find(DltDaemon *daemon,

return (DltDaemonContext *)bsearch(&context,
user_list->contexts,
user_list->num_contexts,
(size_t) user_list->num_contexts,
sizeof(DltDaemonContext),
dlt_daemon_cmp_apid_ctid);
}
Expand Down Expand Up @@ -1325,6 +1340,7 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context,
DltUserHeader userheader;
DltUserControlMsgLogLevel usercontext;
DltReturnValue ret;
DltDaemonApplication *app;

PRINT_FUNCTION_VERBOSE(verbose);

Expand All @@ -1338,15 +1354,16 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context,
return -1;
}

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;
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);
else /* Storage log level is not updated (is DEFAULT) then no device is yet connected so ignore */
usercontext.log_level =
((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level);
(uint8_t) ((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level);

usercontext.trace_status =
((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : context->trace_status);
(uint8_t) ((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : context->trace_status);

usercontext.log_level_pos = context->log_level_pos;

Expand All @@ -1370,11 +1387,9 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context,
errno != 0 ? strerror(errno) : "Unknown error");

if (errno == EPIPE) {
#ifndef DLT_USE_UNIX_SOCKET_IPC
/* Close connection */
close(context->user_handle);
#endif
context->user_handle = DLT_FD_INIT;
app = dlt_daemon_application_find(daemon, context->apid, daemon->ecuid, verbose);
if (app != NULL)
dlt_daemon_application_reset_user_handle(daemon, app, verbose);
}
}

Expand Down Expand Up @@ -1403,13 +1418,8 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app,
&(logstate), sizeof(DltUserControlMsgLogState));

if (ret < DLT_RETURN_OK) {
if (errno == EPIPE) {
#ifndef DLT_USE_UNIX_SOCKET_IPC
/* Close connection */
close(app->user_handle);
#endif
app->user_handle = DLT_FD_INIT;
}
if (errno == EPIPE)
dlt_daemon_application_reset_user_handle(daemon, app, verbose);
}

return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR;
Expand Down Expand Up @@ -1454,9 +1464,9 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,
unlink(filename1);
}

daemon->default_log_level = InitialContextLogLevel;
daemon->default_trace_status = InitialContextTraceStatus;
daemon->force_ll_ts = InitialEnforceLlTsStatus;
daemon->default_log_level = (int8_t) InitialContextLogLevel;
daemon->default_trace_status = (int8_t) InitialContextTraceStatus;
daemon->force_ll_ts = (int8_t) InitialEnforceLlTsStatus;

/* Reset all other things (log level, trace status, etc.
* to default values */
Expand Down
9 changes: 7 additions & 2 deletions src/daemon/dlt_daemon_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ typedef struct
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;
Expand Down Expand Up @@ -189,6 +190,7 @@ typedef struct
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;

/**
Expand Down Expand Up @@ -245,13 +247,16 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon,
char *ecu,
int verbose);
/**
* Loads the user saved configurations to daemon
* 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.
* @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_load_runtime_configuration(DltDaemon *daemon,
int dlt_daemon_init_runtime_configuration(DltDaemon *daemon,
const char *runtime_directory,
int verbose);

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/dlt_daemon_common_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
"/dlt-ctrl.sock"

#ifdef DLT_USE_UNIX_SOCKET_IPC
#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
# define DLT_DAEMON_DEFAULT_APP_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
"/dlt-app.sock"
#endif
Expand Down
38 changes: 23 additions & 15 deletions src/daemon/dlt_daemon_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <sys/socket.h>
#include <syslog.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "dlt_daemon_connection_types.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ DLT_STATIC int dlt_connection_send(DltConnection *conn,
case DLT_CONNECTION_CLIENT_MSG_TCP:
ret = dlt_daemon_socket_sendreliable(conn->receiver->fd,
msg,
msg_size);
(int) msg_size);
return ret;
default:
return DLT_DAEMON_ERROR_UNKNOWN;
Expand Down Expand Up @@ -124,10 +125,10 @@ int dlt_connection_send_multiple(DltConnection *con,
sizeof(dltSerialHeader));

if ((data1 != NULL) && (ret == DLT_RETURN_OK))
ret = dlt_connection_send(con, data1, size1);
ret = dlt_connection_send(con, data1, (size_t) size1);

if ((data2 != NULL) && (ret == DLT_RETURN_OK))
ret = dlt_connection_send(con, data2, size2);
ret = dlt_connection_send(con, data2, (size_t) size2);

return ret;
}
Expand Down Expand Up @@ -162,7 +163,7 @@ DLT_STATIC void dlt_connection_destroy_receiver(DltConnection *con)
/* We rely on the gateway for clean-up */
break;
case DLT_CONNECTION_APP_MSG:
dlt_receiver_free_unix_socket(con->receiver);
dlt_receiver_free_global_buffer(con->receiver);
free(con->receiver);
con->receiver = NULL;
break;
Expand Down Expand Up @@ -193,6 +194,8 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
int fd)
{
DltReceiver *ret = NULL;
DltReceiverType receiver_type = DLT_RECEIVE_FD;
struct stat statbuf;

switch (type) {
case DLT_CONNECTION_CONTROL_CONNECT:
Expand All @@ -205,29 +208,34 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
ret = calloc(1, sizeof(DltReceiver));

if (ret)
dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESOCK);
dlt_receiver_init(ret, fd, DLT_RECEIVE_SOCKET, DLT_DAEMON_RCVBUFSIZESOCK);

break;
case DLT_CONNECTION_CLIENT_MSG_SERIAL:
ret = calloc(1, sizeof(DltReceiver));

if (ret)
dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESERIAL);
dlt_receiver_init(ret, fd, DLT_RECEIVE_FD, DLT_DAEMON_RCVBUFSIZESERIAL);

break;
case DLT_CONNECTION_APP_MSG:
ret = calloc(1, sizeof(DltReceiver));

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
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)
dlt_receiver_init_global_buffer(ret, fd, receiver_type, &app_recv_buffer);

break;
#ifdef DLT_USE_UNIX_SOCKET_IPC
#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
case DLT_CONNECTION_APP_CONNECT:
/* FALL THROUGH */
#endif
Expand All @@ -243,7 +251,7 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
ret = calloc(1, sizeof(DltReceiver));

if (ret)
dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZE);
dlt_receiver_init(ret, fd, DLT_RECEIVE_FD, DLT_DAEMON_RCVBUFSIZE);

break;
case DLT_CONNECTION_GATEWAY:
Expand Down Expand Up @@ -286,7 +294,7 @@ void *dlt_connection_get_callback(DltConnection *con)
case DLT_CONNECTION_CLIENT_MSG_SERIAL:
ret = dlt_daemon_process_client_messages_serial;
break;
#ifdef DLT_USE_UNIX_SOCKET_IPC
#if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE
case DLT_CONNECTION_APP_CONNECT:
ret = dlt_daemon_process_app_connect;
break;
Expand Down
8 changes: 4 additions & 4 deletions src/daemon/dlt_daemon_event_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ int dlt_daemon_prepare_event_handling(DltEventHandler *ev)
static void dlt_event_handler_enable_fd(DltEventHandler *ev, int fd, int mask)
{
if (ev->max_nfds <= ev->nfds) {
int i = ev->nfds;
int max = 2 * ev->max_nfds;
struct pollfd *tmp = realloc(ev->pfd, max * sizeof(*ev->pfd));
int i = (int) ev->nfds;
int max = (int) (2 * ev->max_nfds);
struct pollfd *tmp = realloc(ev->pfd, (size_t) (max) * sizeof(*ev->pfd));

if (!tmp) {
dlt_log(LOG_CRIT,
Expand Down Expand Up @@ -143,7 +143,7 @@ static void dlt_event_handler_disable_fd(DltEventHandler *ev, int fd)
{
unsigned int i = 0;
unsigned int j = 0;
unsigned int nfds = ev->nfds;
unsigned int nfds = (unsigned int) ev->nfds;

for (; i < nfds; i++, j++) {
if (ev->pfd[i].fd == fd) {
Expand Down
Loading