From 4501146661a68c30a70574757f9197c04ba2d723 Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Tue, 31 Jan 2023 13:25:48 +0100 Subject: dlt-connection: add socket timeout in some scenarios a socket might block forever. This means dlt-daemon won't respond properly anymore. To fix this a timeout is added to the dlt-daemon socket connection. Signed-off-by: Alexander Mohr --- src/daemon/dlt_daemon_connection.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c index 805afed..1658e26 100644 --- a/src/daemon/dlt_daemon_connection.c +++ b/src/daemon/dlt_daemon_connection.c @@ -402,6 +402,21 @@ int dlt_connection_create(DltDaemonLocal *daemon_local, return -1; } + struct timeval timeout; + timeout.tv_sec = 5; + timeout.tv_usec = 0; +#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE + char *watchdogUSec = getenv("WATCHDOG_USEC"); + if (watchdogUSec) { + timeout.tv_sec = atoi(watchdogUSec) / 1000000; + timeout.tv_usec = atoi(watchdogUSec) % 1000000; + } +#endif + + if (setsockopt (temp->receiver->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof timeout) < 0) { + dlt_vlog(LOG_WARNING, "Unable to set send timeout %s.\n", strerror(errno)); + } + /* We are single threaded no need for protection. */ temp->id = connectionId++; -- cgit v1.2.1