]> granicus.if.org Git - pgbouncer/commitdiff
Give more detailed error messages in tune_socket()
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Sep 2019 20:14:06 +0000 (22:14 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Sep 2019 20:14:06 +0000 (22:14 +0200)
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.

src/util.c

index d532d393b3ba85b8e0d272b12c9b3371c140d1ff..6880a98a64e9c8d8bc1fbe51bc2c2494d20f3486 100644 (file)
@@ -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;
 }