]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: warning on _getsocks when socket were closed
authorWilliam Lallemand <wlallemand@haproxy.org>
Thu, 28 Jul 2022 13:33:41 +0000 (15:33 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Thu, 28 Jul 2022 13:49:43 +0000 (15:49 +0200)
The previous attempt was reverted because it would emit a warning when
the sockets are still in the process when a reload failed, so this was
an expected 2nd try.

This warning however, will be displayed if a new process successfully
get the previous sockets AND the sendable number of sockets is 0.

This way the user will be warned if he tried to get the sockets fromt
the wrong process.

src/cli.c

index 4724ba4f6b3f117abed4e90cc4702e731d5044eb..c2ca84de133f7b5c386e5833de0f10721cca320f 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1981,6 +1981,7 @@ static int bind_parse_severity_output(char **args, int cur_arg, struct proxy *px
 /* Send all the bound sockets, always returns 1 */
 static int _getsocks(char **args, char *payload, struct appctx *appctx, void *private)
 {
+       static int already_sent = 0;
        char *cmsgbuf = NULL;
        unsigned char *tmpbuf = NULL;
        struct cmsghdr *cmsg;
@@ -2036,8 +2037,11 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
        for (cur_fd = 0;cur_fd < global.maxsock; cur_fd++)
                tot_fd_nb += !!(fdtab[cur_fd].state & FD_EXPORTED);
 
-       if (tot_fd_nb == 0)
+       if (tot_fd_nb == 0) {
+               if (already_sent)
+                       ha_warning("_getsocks: attempt to get sockets but they were already sent and closed in this process!\n");
                goto out;
+       }
 
        /* First send the total number of file descriptors, so that the
         * receiving end knows what to expect.
@@ -2144,6 +2148,8 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
                }
        }
 
+       already_sent = 1;
+
        /* flush pending stuff */
        if (nb_queued) {
                iov.iov_len = curoff;