[master] fb07bc7 If we are going to start the client automatically, test that the accept-sockets can actually be bound before we muck about with daemon() or SHM files.
Poul-Henning Kamp
phk at varnish-cache.org
Tue Feb 12 13:28:05 CET 2013
commit fb07bc720fb190f139d00f6c7e77e4487e6175bb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 12 12:27:21 2013 +0000
If we are going to start the client automatically, test that the
accept-sockets can actually be bound before we muck about with
daemon() or SHM files.
Belived to be implicated in #1262
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index b66e729..8f0fd3b 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -44,6 +44,8 @@ void MGT_Run(void);
void mgt_stop_child(void);
void mgt_got_fd(int fd);
void MGT_Child_Cli_Fail(void);
+int MGT_open_sockets(void);
+void MGT_close_sockets(void);
/* mgt_cli.c */
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 3def397..fbb10ad 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -222,13 +222,13 @@ mgt_child_inherit(int fd, const char *what)
* (The child is priv-sep'ed, so it can't do it.)
*/
-static int
-open_sockets(void)
+int
+MGT_open_sockets(void)
{
- struct listen_sock *ls, *ls2;
+ struct listen_sock *ls;
int good = 0;
- VTAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) {
+ VTAILQ_FOREACH(ls, &heritage.socks, list) {
if (ls->sock >= 0) {
good++;
continue;
@@ -248,8 +248,8 @@ open_sockets(void)
/*--------------------------------------------------------------------*/
-static void
-close_sockets(void)
+void
+MGT_close_sockets(void)
{
struct listen_sock *ls;
@@ -326,7 +326,7 @@ mgt_launch_child(struct cli *cli)
if (child_state != CH_STOPPED && child_state != CH_DIED)
return;
- if (open_sockets() != 0) {
+ if (MGT_open_sockets() != 0) {
child_state = CH_STOPPED;
if (cli != NULL) {
VCLI_SetResult(cli, CLIS_CANT);
@@ -410,7 +410,7 @@ mgt_launch_child(struct cli *cli)
mgt_child_inherit(heritage.cli_out, NULL);
closex(&heritage.cli_out);
- close_sockets();
+ MGT_close_sockets();
child_std_vlu = VLU_New(NULL, child_line, 0);
AN(child_std_vlu);
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index b5829a9..b41133c 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -602,6 +602,15 @@ main(int argc, char * const *argv)
if (C_flag)
exit (0);
+ if (!d_flag) {
+ if (MGT_open_sockets()) {
+ fprintf(stderr,
+ "Failed to open (any) accept sockets.\n");
+ exit(1);
+ }
+ MGT_close_sockets();
+ }
+
/* If no -s argument specified, process default -s argument */
if (!s_arg_given)
STV_Config(s_arg);
More information about the varnish-commit
mailing list