From b5d062dff197a0430aad37d032233edaa541eaee Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 28 Jul 2022 15:33:41 +0200 Subject: [PATCH] MINOR: cli: warning on _getsocks when socket were closed 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cli.c b/src/cli.c index 4724ba4f6..c2ca84de1 100644 --- 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;