From: Peter Eisentraut Date: Mon, 23 Sep 2019 20:14:06 +0000 (+0200) Subject: Give more detailed error messages in tune_socket() X-Git-Tag: pgbouncer_1_12_0~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a8f571b586f364bd3c985ec6ecd0a1cf4416dad6;p=pgbouncer Give more detailed error messages in tune_socket() Give details on the actual system call that failed, rather than one generic message for all. Style similar to add_listen(). These "tune_socket() failed" messages occasionally appear in user reports, but so far it was difficult to narrow down the issues. --- diff --git a/src/util.c b/src/util.c index d532d39..6880a98 100644 --- a/src/util.c +++ b/src/util.c @@ -115,11 +115,13 @@ bool tune_socket(int sock, bool is_unix) { int res; int val; + const char *errpos; bool ok; /* * Generic stuff + nonblock. */ + errpos = "socket_setup"; ok = socket_setup(sock, true); if (!ok) goto fail; @@ -133,6 +135,7 @@ bool tune_socket(int sock, bool is_unix) /* * TCP Keepalive */ + errpos = "socket_set_keepalive"; ok = socket_set_keepalive(sock, cf_tcp_keepalive, cf_tcp_keepidle, cf_tcp_keepintvl, cf_tcp_keepcnt); if (!ok) @@ -143,10 +146,12 @@ bool tune_socket(int sock, bool is_unix) */ if (cf_tcp_socket_buffer) { val = cf_tcp_socket_buffer; + errpos = "setsockopt/SO_SNDBUF"; res = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); if (res < 0) goto fail; val = cf_tcp_socket_buffer; + errpos = "setsockopt/SO_RCVBUF"; res = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)); if (res < 0) goto fail; @@ -156,12 +161,13 @@ bool tune_socket(int sock, bool is_unix) * Turn off kernel buffering, each send() will be one packet. */ val = 1; + errpos = "setsockopt/TCP_NODELAY"; res = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); if (res < 0) goto fail; return true; fail: - log_warning("tune_socket(%d) failed: %s", sock, strerror(errno)); + log_warning("%s(%d) failed: %s", errpos, sock, strerror(errno)); return false; }