summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Mohr <alexander.m.mohr@mercedes-benz.com>2023-01-31 13:25:48 +0100
committerAlexander Mohr <alexander.m.mohr@mercedes-benz.com>2023-02-22 12:25:52 +0100
commit4501146661a68c30a70574757f9197c04ba2d723 (patch)
treec85907a88fb0cb85ce9c9588241ac8fdeb1b50fe
parent73e12753843b69e9a06430cf8eb8ab43285ee6a1 (diff)
downloadDLT-daemon-4501146661a68c30a70574757f9197c04ba2d723.tar.gz
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 <alexander.m.mohr@mercedes-benz.com>
-rw-r--r--src/daemon/dlt_daemon_connection.c15
1 files changed, 15 insertions, 0 deletions
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++;