From b74854521a653fe49134ce12cc77d45849f992b9 Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Wed, 16 Dec 2020 17:27:58 +0100 Subject: [PATCH 1/3] dlt_user: fix invalid poll timeout The poll timeout was only set for fifo. TCP connections require this timeout as well. dlt_user_log_check_user_message also validated the file descriptor to be greater 0. Because 0 is a valid file descriptor this check has been changed to greater or equal 0. poll receives a timeout in milliseconds. The given paramter was in nanoseconds. An additional define takes adds the delay in miliseconds. Signed-off-by: Alexander Mohr --- src/lib/dlt_user.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index ccebd4f61..2051312a3 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -4242,13 +4242,8 @@ DltReturnValue dlt_user_log_check_user_message(void) nfd[0].events = POLLIN; nfd[0].fd = fd; -#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC - if (fd != DLT_FD_INIT) { - ret = poll(nfd, 1, -1); -#else /* DLT_LIB_USE_FIFO_IPC */ - if (fd != DLT_FD_INIT && dlt_user.dlt_log_handle > 0) { - ret = poll(nfd, 1, DLT_USER_RECEIVE_NDELAY); -#endif + if (fd >= 0) { + ret = poll(nfd, 1, 1000); if (ret) { if (nfd[0].revents & (POLLHUP | POLLNVAL | POLLERR)) { dlt_user.dlt_log_handle = DLT_FD_INIT; From 5a73b99270f4c4e674e731488b71b1e3f967ce38 Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Wed, 16 Dec 2020 17:31:50 +0100 Subject: [PATCH 2/3] bug-fix: fix invalid file descriptor check Some functions validated file descriptor to be greater 0. If a process is started without stdin, stdout and stderr the first file descriptor allocated by the process will be 0. This also will be the case if the above mentioned file descriptors will be closed on purpose. As 0 is a valid fd, some methods had to be changed to reflect this. Signed-off-by: Alexander Mohr --- src/shared/dlt_offline_trace.c | 4 ++-- src/shared/dlt_user_shared.c | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c index 1f6a5d576..2d70a77f1 100644 --- a/src/shared/dlt_offline_trace.c +++ b/src/shared/dlt_offline_trace.c @@ -396,7 +396,7 @@ DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace, int size3) { - if (trace->ohandle <= 0) + if (trace->ohandle < 0) return DLT_RETURN_ERROR; /* check file size here */ @@ -440,7 +440,7 @@ DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace, DltReturnValue dlt_offline_trace_free(DltOfflineTrace *trace) { - if (trace->ohandle <= 0) + if (trace->ohandle < 0) return DLT_RETURN_ERROR; /* close last used log file */ diff --git a/src/shared/dlt_user_shared.c b/src/shared/dlt_user_shared.c index 857a6e9ab..732301c6d 100644 --- a/src/shared/dlt_user_shared.c +++ b/src/shared/dlt_user_shared.c @@ -108,7 +108,7 @@ DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2 struct iovec iov[2]; uint32_t bytes_written; - if (handle <= 0) + if (handle < 0) /* Invalid handle */ return DLT_RETURN_ERROR; @@ -130,7 +130,7 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2 struct iovec iov[3]; uint32_t bytes_written; - if (handle <= 0) + if (handle < 0) /* Invalid handle */ return DLT_RETURN_ERROR; @@ -145,6 +145,11 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2 if (bytes_written != (len1 + len2 + len3)) { switch (errno) { + case ETIMEDOUT: + { + return DLT_RETURN_PIPE_ERROR; /* ETIMEDOUT - connect timeout */ + break; + } case EBADF: { return DLT_RETURN_PIPE_ERROR; /* EBADF - handle not open */ From 4f506da087640f7539f17530461df0e25227eb4b Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Sun, 3 Jan 2021 15:38:43 +0100 Subject: [PATCH 3/3] dlt_user: changed poll timeout Changed the poll timeout to 500ms after performance measurements resulted this as a good compromise. Introduced a define which is used in poll. Signed-off-by: Alexander Mohr --- src/lib/dlt_user.c | 2 +- src/lib/dlt_user_cfg.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 2051312a3..ec05cd220 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -4243,7 +4243,7 @@ DltReturnValue dlt_user_log_check_user_message(void) nfd[0].fd = fd; if (fd >= 0) { - ret = poll(nfd, 1, 1000); + ret = poll(nfd, 1, DLT_USER_RECEIVE_MDELAY); if (ret) { if (nfd[0].revents & (POLLHUP | POLLNVAL | POLLERR)) { dlt_user.dlt_log_handle = DLT_FD_INIT; diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h index 8951b7567..e8997f0fa 100644 --- a/src/lib/dlt_user_cfg.h +++ b/src/lib/dlt_user_cfg.h @@ -126,6 +126,9 @@ /* delay for housekeeper thread (nsec) while receiving messages*/ #define DLT_USER_RECEIVE_NDELAY (500 * 1000 * 1000) +/* timeout for poll operations in milliseconds*/ +#define DLT_USER_RECEIVE_MDELAY (500) + /* Name of environment variable for local print mode */ #define DLT_USER_ENV_LOCAL_PRINT_MODE "DLT_LOCAL_PRINT_MODE"