Commit a4a7384e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Do not restart if we cannot get all our listen sockets, and add

a test-case to cover this case.
parent c62cb719
......@@ -42,6 +42,8 @@ extern int exit_status;
/* mgt_acceptor.c */
void MAC_Arg(const char *);
int MAC_open_sockets(struct cli *);
void MAC_close_sockets(void);
/* mgt_child.c */
extern pid_t child_pid;
......@@ -49,8 +51,6 @@ void MGT_Run(void);
void mgt_stop_child(void);
void mgt_got_fd(int fd);
void MGT_Child_Cli_Fail(void);
int MAC_open_sockets(void);
void MAC_close_sockets(void);
/* mgt_cli.c */
......
......@@ -44,6 +44,7 @@
#include "common/heritage.h"
#include "vav.h"
#include "vcli_priv.h"
#include "vsa.h"
#include "vss.h"
#include "vtcp.h"
......@@ -55,7 +56,7 @@
*/
int
MAC_open_sockets(void)
MAC_open_sockets(struct cli *cli)
{
struct listen_sock *ls;
int fail;
......@@ -73,6 +74,8 @@ MAC_open_sockets(void)
if (ls == NULL)
return (0);
MAC_close_sockets();
VCLI_Out(cli, "Could not get socket %s: %s\n",
ls->name, strerror(fail));
errno = fail;
return (-1);
}
......@@ -109,6 +112,8 @@ mac_callback(void *priv, const struct suckaddr *sa)
struct mac_help *mh;
struct listen_sock *ls;
int sock;
char abuf[VTCP_ADDRBUFSIZE], pbuf[VTCP_PORTBUFSIZE];
char nbuf[VTCP_ADDRBUFSIZE+VTCP_PORTBUFSIZE+2];
CAST_OBJ_NOTNULL(mh, priv, MAC_HELP_MAGIC);
sock = VTCP_bind(sa, NULL);
......@@ -119,15 +124,23 @@ mac_callback(void *priv, const struct suckaddr *sa)
ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC);
AN(ls);
if (VSA_Port(sa) == 0)
if (VSA_Port(sa) == 0) {
/*
* If the port number is zero, we adopt whatever port number
* this VTCP_bind() found us, as if specified by argument.
*/
ls->addr = VTCP_my_suckaddr(sock);
else
VTCP_myname(sock, abuf, sizeof abuf, pbuf, sizeof pbuf);
bprintf(nbuf, "%s:%s", abuf, pbuf);
ls->name = strdup(nbuf);
} else {
ls->addr = VSA_Clone(sa);
ls->name = strdup(mh->name);
}
AN(ls->addr);
AN(ls->name);
AZ(close(sock));
ls->sock = -1;
ls->name = strdup(priv);
AN(ls->name);
VTAILQ_INSERT_TAIL(&heritage.socks, ls, list);
mh->good++;
return (0);
......
......@@ -303,11 +303,10 @@ mgt_launch_child(struct cli *cli)
if (child_state != CH_STOPPED && child_state != CH_DIED)
return;
if (MAC_open_sockets() != 0) {
if (MAC_open_sockets(cli) != 0) {
child_state = CH_STOPPED;
if (cli != NULL) {
VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli, "Could not open sockets");
return;
}
REPORT0(LOG_ERR,
......
varnishtest "Test failure if our listen socket gets stolen"
server s1 {
rxreq
txresp
} -start
varnish v1 -arg "-a :0" -vcl+backend {} -start
client c1 {
txreq
rxresp
expect resp.status == 200
} -run
varnish v1 -stop
# Now have another varnish steal the listen socket
varnish v2 -arg "-a ${v1_addr}:${v1_port}" -vcl+backend {} -start
varnish v1 -clierr 300 "start"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment