summaryrefslogtreecommitdiff
path: root/src/shared/dlt_common.c
Commit message (Collapse)AuthorAgeFilesLines
* gtest_dlt_common: fix seg fault when using memcpy().Dinh Cong Toan2021-01-061-5/+9
| | | | | | | | - Checking size of buffer and size of message before using memcpy(). - Adding configuration file for testfilter in /tests/CMakeLists.txt. Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* other: fix remaining conversion warningsDinh Cong Toan2021-01-061-34/+34
| | | | | | | | | | | - Converting datatype to the correct one. - As macro do not perform type-checking before, so these functions used it with different datatype could create a lot of conversion warnings. For this reason, these warnings could be consider as normal information and will not be fixed. Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* library: fix conversion warningsDinh Cong Toan(RBVH/ECM12)2021-01-061-21/+42
| | | | | | | | | | | | - Change the data type of variable 'size' in DltContextData struct (dlt_user.h.in). Variable 'size' was used repeated with function 'sizeof()' many time, so change type to 'size_t' can avoid a lot of warnings. - Adding temporary variable to calculate the datasize header (define in dlt_common.h) in 'dlt_common.c' file. Signed-off-by: Dinh Cong Toan(RBVH/ECM12) <Toan.DinhCong@vn.bosch.com>
* shared: fix conversion warningsiod1hc2021-01-061-66/+66
| | | | | | | | | | | - Data type of 'textlength' create a lot of warnings while using in function 'snprintf()', so change data type to 'size_t' will resolve these warnings. - Change data type of variable 'size' to the right type 'unsigned int', which is located in struct DltBuffer in dlt_common.h (line 832). Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com> Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* gateway: fix compile warningsDinh Cong Toan(RBVH/ECM12)2021-01-061-4/+3
| | | | | | | | | - Correct the data type of 'headersize' and 'datasize' variables in header 'dlt_common.h', then config those functions using this library. - Explicit the data type. Signed-off-by: Dinh Cong Toan(RBVH/ECM12) <Toan.DinhCong@vn.bosch.com>
* dlt_common: Execute system command using execvpKHANH LUONG HONG DUY2021-01-061-0/+55
| | | | | | | Add function dlt_execute_command() to execute system command using execvp. Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* Add support for logging with VSOCK (#255)Martin Ejdestig2020-12-141-46/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For more information about VSOCK, see "man vsock" ( https://man7.org/linux/man-pages/man7/vsock.7.html ). Makes it possible for processes in a virtual machine to log directly in DLT running on host without setting up a network connection between guest and host. It is also probably more efficient. Have not done any performance measurements (not main reason for patch), but no forwarding is required as when running DLT in a multi-node setup. When building dlt-daemon for host, WITH_DLT_DAEMON_VSOCK_IPC should be enabled for daemon to listen on incoming VSOCK requests. Local communication method between applications and daemon is still determined with DLT_IPC. When building for guest, WITH_DLT_LIB_VSOCK_IPC should be enabled and DLT_IPC will be ignored, which will make libdlt open a VSOCK socket to the deamon for logging messages. VSOCK can be tested without a virtual machine. Since VMADDR_CID_HOST is used by libdlt when connecting, see vsock man page, clients can be run on host to test VSOCK communication. Some modifications has been done to be able to handle logging through FIFO pipe and socket in the same build of dlt-daemon: - dlt_receiver_init/free_unix_socket() is renamed to dlt_receiver_init/free_global_buffer() and used for FIFO as well. Also fixes memory leak since dlt_receiver_free_unix_socket() was used regardless of whether DLT_USE_UNIX_SOCKET was defined or not. - Pass type to dlt_receiver_init() instead of dlt_receiver_receive(). And remove preprocessor conditionals for handling DLT_CONNECTION_APP_MSG in dlt_daemon_process_user_messages(). Also fixes wrong enum type being passed to dlt_receiver_receive() in dlt_client.c (DltClient::mode was used as a DltReceiverType enum but it is a DltClientMode enum). - Add a flag to DltDaemonApplication to indicate whether file descriptor is "owned" by the DltDaemonApplication or not. When dlt_daemon_application_add() is called due to message received on a socket, fd is passed as an argument (app does not own fd). For FIFO, a per application FIFO is opened (app owns the fd). Also fixes so that user handle is reset for both application and all its contexts when resetting any. Prevents fd from being used by accident after it has been closed. dlt_mkdir_recursive() is moved to src/daemon since it is only used in the daemon. Minimizes use of DLT_USE_UNIX_SOCKET_IPC. Other bugfixes: - Call DLT_SEM_FREE() if setting socket to O_NONBLOCK fails in src/lib/dlt_user.c:dlt_initialize_socket_connection(). - Close socket if dlt_receiver_init() fails in src/lib/dlt_user.c:dlt_initialize_socket_connection(). Signed-off-by: Martin Ejdestig <martin.ejdestig@volvocars.com>
* Check size of ring buffer (#269)schrewe2020-12-071-12/+26
| | | | | | | | | | | | | | There is no check if "data" fits into the ring buffer buffer. This causes a write heap buffer overflow. If data is too big for the ringbuffer nothing is written to the ringbuffer and a error is logged If the buffers are bigger than the free space in the ringbuffer, the ringbuffer is increased by a step size set at initialization. But there is no check if this increase was sufficient. Fix this by using a while loop that increases the ring buffer size until it is big enough or the buffer can not be further increased. Signed-off-by: Jan Schrewe <schrewe@uni-bonn.de>
* dlt_common: Fix buffer overflow in dlt_filter_load (#275)gy7412020-11-301-2/+2
| | | | | | | A buffer overflow in the dlt_filter_load function in dlt_common.c in dlt-daemon allows arbitrary code execution via an unsafe usage of fscanf, because it does not limit the number of characters to be read in a format argument. Fixed: #274 Signed-off-by: GwanYeong Kim <gy741.kim@gmail.com>
* Avoid memory access errors with 4-chars context ids (#250)Martin Willers2020-11-171-8/+15
| | | | | | | | | | | | | | | | | | | | | | | | For a 4-chars CTXID, i.e. one that does not include a null character, the strlen() calls were happily accessing memory until they eventually encountered a null character somewhere in memory. This was detected by valgrind, which reported a memory error when using a CTXID such as "INTM": ==21924== Conditional jump or move depends on uninitialised value(s) ==21924== at 0x4C30F78: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21924== by 0x4E4B5A0: dlt_print_id (dlt_common.c:303) ==21924== by 0x4E4CF47: dlt_message_header_flags (dlt_common.c:687) ==21924== by 0x4E51434: dlt_message_print_ascii (dlt_common.c:3169) ==21924== by 0x4E4247A: dlt_user_print_msg (dlt_user.c:4108) ==21924== by 0x4E46D92: dlt_user_log_send_log (dlt_user.c:3670) ==21924== by 0x4E46F14: dlt_user_log_write_finish (dlt_user.c:1611) Sanitize some code Using memset() and memcpy() is always preferable to hand-rolled loops, because compilers have built-in support for them. Signed-off-by: Martin Willers <M.Willers@gmx.net>
* dlt-common.c: ensure null terminated string (#256)Moritz Warning2020-11-101-1/+1
| | | Signed-off-by: Moritz Warning <moritzwarning@web.de>
* Implement DLTClient for UDP multicast (#240)João Sousa2020-08-311-1/+14
| | | | | | | | | * Add UDP multicast support on client side UDP multicast support is already present on server side. This patch add seemless support for UDP multicast on client side in dlt-receive. Signed-off-by: Joao Sousa <joao.sa.sousa@ctw.bmwgroup.com>
* common: Isolate FIFO/Unix socketLUONG HONG DUY KHANH(RBVH/ENG42)2020-07-061-3/+9
| | | | | | | | | | | | | | dlt_common - Add preprocessor DLT_USE_UNIX_SOCKET_IPC for dlt_log_set_fifo_basedir() and dltFifoBaseDir variable - Rename input parameter of dlt_log_set_fifo_basedir() dlt-daemon - Replace setting dltFifoBaseDir by dlt_log_set_fifo_basedir() and add preproc DLT_USE_UNIX_SOCKET_IPC - Update -h opt and flags.loggingFilename based on IPC type Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
* libdlt: Relocate dltFifoBaseDir settingLUONG HONG DUY KHANH(RBVH/ENG42)2020-07-061-0/+3
| | | | | | | Relocate the setting of dltFifoBaseDir variable from dlt_init() to dlt_check_envvar() Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
* Improve performance of DLT file parsingBui Nguyen Quoc Thanh2020-07-061-0/+69
| | | | | | Introduce new API to support quick parsing a DLT file. Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
* Redirect stdout to stderrLUONG HONG DUY KHANH(RBVH/ENG42)2020-07-061-13/+45
| | | | | | | | | | | | - daemon: New feature for LoggingMode at /etc/dlt.conf to be able to set value at 3 in order to redirect all stdout messages to stderr. - libdlt: New feature for DLT_LOG_MODE environment variable to be able to set value at 3 in order to redirect all stdout messages to stderr. - unit test: Add test cases for DLT_LOG_TO_STDERR Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
* fix some gcc9 compiler warningsFelix Herrmann2020-07-061-3/+4
| | | | | | | | | Many stringop-truncation and stringop-overflow warnings are still there (so many). https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* Android: Enable Android buildFelix Herrmann2020-07-061-2/+5
| | | | | Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* shared: Read DLT header until it's foundSaya Sugiura2020-07-061-13/+31
| | | | | | | | | Current dlt_file_read_header() function which is used for e.g. dlt-convert, dlt-sortbytimestamp, etc. stops finding DLT header if it's not available in the next file position. It is improved to read the header in a loop until it's found. Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* Revert "dlt_common: Fix buffer overflow in dlt_buffer_get (#215)"Saya Sugiura2020-06-161-4/+2
| | | | This reverts commit e420ee62d89d5efab6ad7275910cb3eec8497da6.
* common: Fix uint64 type (#217)Saya Sugiura2020-04-021-1/+1
| | | | | | The log message was printed as a signed value for uint64 type. This commit fixes to print as an unsigned value. Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* dlt_common: Fix buffer overflow in dlt_buffer_get (#215)Ricardo Leite2020-03-301-2/+4
| | | | | | A DLT lib user can create a message large enough that dlt_user.resend_buffer is not large enough, and thus it will overflow Signed-off-by: Ricardo Leite <rleite@dcc.fc.up.pt>
* FIX: Check validity of `file` pointer before usage.Sebastian Kloska2020-02-201-3/+3
| | | | | | | Check for file == null before accessing the pointer for a debug message Signed-off-by: Sebastian Kloska <sebastian.kloska@snafu.de>
* Fix compiler warnings: pointer of type ‘void *’ used in arithmetic (#196)Sebastian Lipponer2019-12-101-2/+2
| | | Signed-off-by: Sebastian Lipponer <mail@sebastianlipponer.de>
* Change the DLT_CHECK_RCV_DATA_SIZE macro to an internal function (#191)Sebastian Lipponer2019-11-251-0/+10
| | | | | | | | | The use of this macro in a if condition is actually non-standard C++ code. GCC issues a warning that ISO C++ forbids braced-groups within expressions when compiled with -Wpedantic. Other compilers fail with an error. Change the macro to an internal function in order to improve the portability to other platforms (i.e. MSVC, proprietary embedded). Signed-off-by: Sebastian Lipponer <mail@sebastianlipponer.de>
* Avoided Seg fault in dlt_message_payload (#179) (#181)Vo Trung Chi2019-11-141-54/+60
| | | | | | | | | * Avoided Seg fault in dlt_message_payload (#179) Avoided Seg fault by adding boundary check before buffer access. Signed-off-by: Ravi Sankar P <ponnurangamravi.sankar@in.bosch.com> Signed-off-by: Vo Trung Chi <chi.votrung@vn.bosch.com>
* libdlt: fix memory leakVo Trung Chi2019-10-241-8/+20
| | | | | | | This commit is fixed the memory leak in case the dlt application do reattach to the daemon. Signed-off-by: Vo Trung Chi <chi.votrung@vn.bosch.com>
* dlt-system: Call tzset before localtime_r (#165)Saya Sugiura2019-09-231-0/+1
| | | | | | Since localtime() was calling tzset() internally, it should be used before localtime_r(). Refer to man page of localtime_r() for detail. Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* dlt_common: Use defined macroVo Trung Chi2019-09-131-1/+1
| | | | Signed-off-by: Vo Trung Chi <Chi.VoTrung@vn.bosch.com>
* using POSIX shared memory APIs (#90) (#151)Vo Trung Chi2019-08-011-0/+20
| | | | | Replace all Linux specific shared memory APIs with POSIX alternatives. Signed-off-by: Vo Trung Chi <Chi.VoTrung@vn.bosch.com>
* doxygen: Remove licenceSaya Sugiura2019-07-191-2/+0
| | | | Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* define DLT_PATH_MAX for max path buffer lengthRadoslaw Kaczorowski2019-07-031-4/+4
| | | | | | | | DLT limits the path length and does not do anything else to determine the actual value, because the least that is supported on any system that DLT runs on is 1024 bytes. Signed-off-by: Vo Trung Chi <Chi.VoTrung@vn.bosch.com>
* cleanup: Use dlt_vlog()Saya Sugiura2019-06-191-98/+54
| | | | | | | There were a couple of places which used snprintf-dlt_log. It is now replaced with dlt_vlog(). Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* Fix alerts from lgtmSaya Sugiura2019-06-191-10/+8
| | | | Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* daemon: Remove bytes_sentSaya Sugiura2019-06-181-1/+0
| | | | | | | | | | | | | | | | | | | | | When it fails to send a log message to connected client, daemon tries to store the remaining partial message to internal ring buffer and send again later. When calculating the number of bytes which were sent to client, it had a bug which it keeps on incrementing instead of initializing the variable on every message, which never reached to the condition mentioned above and had a possibility to overflow and access invalid memory. On the other hand, daemon doesn't need to store the unsent partial message, as the socket to the client will be closed on failure and the sent partial message will be dropped anyways. This commit removes the lines where the daemon tries to store the partial message to ring buffer. With this, variable bytes_sent is now removed. Related commit: 2262f8b Made socket send reliable Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* dlt-control: Bug fix for broken get log infoRavi Sankar P2019-05-061-1/+1
| | | | | | | | strtol converts extra data in the array, so it leads to data crash. It is now fixed to fill the last byte of the array with null character once data copy complete and before convert. Signed-off-by: Ravi Sankar P <ponnurangamravi.sankar@in.bosch.com>
* dlt-daemon: fix internal logging to file after daemonizeChristoph Lipka2019-05-061-1/+1
| | | | Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
* Code beautification using uncrustifyChristoph Lipka2018-12-211-1673/+1424
| | | | Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
* libdlt: Add error handlingSaya Sugiura2018-12-211-0/+15
| | | | | | | Error handling was added in case it failed to send to daemon. Signed-off-by: S. Hameed <shameed@jp.adit-jv.com> Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* Made socket send reliableManikandan C2018-12-211-0/+1
| | | | | | | | Made TCP socket send reliable by storing the unsent/partial message in the ring buffer. This will avoid the corrupted messages/Gaps in Viewer side Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
* buffer: Code cleanupSaya Sugiura2018-12-211-48/+56
| | | | Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* buffer: Improve loggingSaya Sugiura2018-12-211-43/+51
| | | | | | | Add more logs to places where any pointer of buffer may get modified, to get more information when we get unexpected behaviour Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* Fixed compiler error with previous commitManikandan C2018-12-121-2/+2
| | | | Signed-off-by: Manikandan C <mchockalingam@de.adit-jv.com>
* Dynamic allocation of msg bufferManikandanC2018-12-101-33/+82
| | | | | | | | | | | | | It is possible to change the default buffer size for log message creation via environment variable: export DLT_LOG_MSG_BUF_LEN=<value> Instead of using a static buffer with size of 1390 bytes, the buffer is allocated dynamically with the specified value.The max size is restricted to approx 65k. Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com> Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
* Use poll in the dlt-daemon for POSIX complianceManikandanC2018-11-301-0/+2
| | | | | | | | | | | The poll system call is now used in the daemon to enable DLT use in POSIX compliant systems. Also added introduced new unregister_app macro to avoid missing of logs in startup buffer. Signed-off-by: Frederic Berat <fberat@de.adit-jv.com> Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com> Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com> Signed-off-by: S. Hameed <shameed@jp.adit-jv.com>
* dlt-client: logging: Extended the receiver buffer sizeManikandan C2018-11-231-2/+2
| | | | | | | | | | | - dlt-control couldn't receive all the GET_LOG_INFO response message when many applications and contexts are registered. Therefore the receiver buffer size was extended to 65K. Also the receive buffer size macros are reduced to one variable. - Code cleanup and improvements Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* Gateway ImprovementsManikandan C2018-11-231-0/+145
| | | | | | | | | | | | | -Support to send and parse periodic control messages -add application/contexts to passive ECU list -Refactor dlt_gateway_send_control_message -Gateway issues with corrupted data and on demand connection -Unit Test update Signed-off-by: Saya Sugiura ssugiura@jp.adit-jv.com Signed-off-by: Christoph Lipka clipka@jp.adit-jv.com Signed-off-by: S. Hameed shameed@jp.adit-jv.com Signed-off-by: ManikandanC Manikandan.Chockalingam@in.bosch.com
* Log storage - Updates (#82)ManikandanChockalingam2018-11-151-1/+1
| | | | | | | | | | - improvements and refactor key creation - Sync strategies added Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com> Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com> Signed-off-by: S. Hameed <shameed@jp.adit-jv.com> Signed-off-by: Ravi Sankar P <ponnurangamravi.sankar@in.bosch.com> Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
* Fflush stdout in the intenal logger (#81)Alexander Menzhinsky2018-10-301-0/+1
|
* IPC: Unix socket added (#43)ManikandanChockalingam2018-05-181-0/+11
| | | | | | | | | * IPC: Unix socket added The user can select either FIFO or UNIX socket as IPC between user library and daemon through CMakelist option. Socket path configurable for both FIFO and Unix Socket now configurable in CMake Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com> Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>