From 4363b863e9dcd3b31c1d2b2febd9b11c40ec3eec Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 21 Jul 2017 08:52:44 +0200 Subject: [PATCH] db_postgres: handle return code for setsockopt() --- src/modules/db_postgres/pg_con.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/db_postgres/pg_con.c b/src/modules/db_postgres/pg_con.c index 7b8085c8ac8..851685d3532 100644 --- a/src/modules/db_postgres/pg_con.c +++ b/src/modules/db_postgres/pg_con.c @@ -302,8 +302,14 @@ int pg_con_connect(db_con_t* con) #if defined(SO_KEEPALIVE) && defined(TCP_KEEPIDLE) if (pg_keepalive) { i = 1; - setsockopt(PQsocket(pcon->con), SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i)); - setsockopt(PQsocket(pcon->con), IPPROTO_TCP, TCP_KEEPIDLE, &pg_keepalive, sizeof(pg_keepalive)); + if(setsockopt(PQsocket(pcon->con), SOL_SOCKET, SO_KEEPALIVE, &i, + sizeof(i))<0) { + LM_WARN("failed to set socket option keepalive\n"); + } + if(setsockopt(PQsocket(pcon->con), IPPROTO_TCP, TCP_KEEPIDLE, + &pg_keepalive, sizeof(pg_keepalive))<0) { + M_WARN("failed to set socket option keepidle\n"); + } } #endif