diff options
author | Alexander Mohr <alexander.m.mohr@mercedes-benz.com> | 2023-01-31 13:25:48 +0100 |
---|---|---|
committer | Alexander Mohr <alexander.m.mohr@mercedes-benz.com> | 2023-02-22 12:25:52 +0100 |
commit | 4501146661a68c30a70574757f9197c04ba2d723 (patch) | |
tree | c85907a88fb0cb85ce9c9588241ac8fdeb1b50fe /src | |
parent | 73e12753843b69e9a06430cf8eb8ab43285ee6a1 (diff) | |
download | DLT-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>
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/dlt_daemon_connection.c | 15 |
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++; |