]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: socket transfer: Set a timeout on the socket.
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 6 Apr 2017 12:45:14 +0000 (14:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Apr 2017 17:15:17 +0000 (19:15 +0200)
Make sure we're not stuck forever by setting a timeout on the socket.

src/cli.c
src/haproxy.c

index 20e143b965a0dbf1e1a41c76fabd3a283b5dd5c1..55baee3928378ed5c2fda44d256e424f4bbcf688 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1025,6 +1025,7 @@ static int _getsocks(char **args, struct appctx *appctx, void *private)
        struct connection *remote = objt_conn(si_opposite(si)->end);
        struct msghdr msghdr;
        struct iovec iov;
+       struct timeval tv = { .tv_sec = 1, .tv_usec = 0 };
        int *tmpfd;
        int tot_fd_nb = 0;
        struct proxy *px;
@@ -1049,6 +1050,7 @@ static int _getsocks(char **args, struct appctx *appctx, void *private)
                Warning("Cannot make the unix socket blocking\n");
                goto out;
        }
+       setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv));
        iov.iov_base = &tot_fd_nb;
        iov.iov_len = sizeof(tot_fd_nb);
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
index 01969c90d1778f3214b2a30259541b3407c3f303..2b1db00b484cf9adee5fa0ee2fe7ab141f48928b 100644 (file)
@@ -574,6 +574,7 @@ static int get_old_sockets(const char *unixsocket)
        struct msghdr msghdr;
        struct iovec iov;
        struct xfer_sock_list *xfer_sock = NULL;
+       struct timeval tv = { .tv_sec = 1, .tv_usec = 0 };
        int sock = -1;
        int ret = -1;
        int ret2 = -1;
@@ -603,6 +604,7 @@ static int get_old_sockets(const char *unixsocket)
                    unixsocket);
                goto out;
        }
+       setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv));
        iov.iov_base = &fd_nb;
        iov.iov_len = sizeof(fd_nb);
        msghdr.msg_iov = &iov;