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.
This commit is contained in:
William Lallemand 2022-07-28 15:33:41 +02:00
parent 9c821e615e
commit b5d062dff1

View File

@ -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;