r999 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Sep 16 10:20:39 CEST 2006


Author: phk
Date: 2006-09-16 10:20:39 +0200 (Sat, 16 Sep 2006)
New Revision: 999

Modified:
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt_child.c
   trunk/varnish-cache/bin/varnishd/mgt_param.c
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Open and close the listen socket when we start and stop the child.

Make the listen address a parameter.



Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2006-09-16 07:49:35 UTC (rev 998)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2006-09-16 08:20:39 UTC (rev 999)
@@ -56,6 +56,11 @@
 
 	/* VCL traces */
 	unsigned		vcl_trace;
+
+	/* Listen address */
+	char			*listen_address;
+	char			*listen_host;
+	char			*listen_port;
 };
 
 extern struct params *params;

Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c	2006-09-16 07:49:35 UTC (rev 998)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c	2006-09-16 08:20:39 UTC (rev 999)
@@ -102,6 +102,13 @@
 	if (child_state != CH_STOPPED && child_state != CH_DIED)
 		return;
 
+	if (heritage.socket < 0) {
+		heritage.socket =
+		    TCP_open(params->listen_host, params->listen_port, 1);
+		if (heritage.socket < 0)
+			return;
+	}
+
 	child_state = CH_STARTING;
 
 	AZ(pipe(&heritage.fds[0]));
@@ -179,6 +186,8 @@
 	if (child_state != CH_RUNNING)
 		return;
 
+	close(heritage.socket);
+	heritage.socket = -1;
 	child_state = CH_STOPPING;
 
 	if (ev_poker != NULL) {
@@ -249,8 +258,11 @@
 
 	if (child_state == CH_DIED && params->auto_restart)
 		start_child();
-	else if (child_state == CH_DIED)
+	else if (child_state == CH_DIED) {
+		close(heritage.socket);
+		heritage.socket = -1;
 		child_state = CH_STOPPED;
+	}
 	else if (child_state == CH_STOPPING)
 		child_state = CH_STOPPED;
 	return (0);

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2006-09-16 07:49:35 UTC (rev 998)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2006-09-16 08:20:39 UTC (rev 999)
@@ -249,11 +249,43 @@
 			return;
 		}
 	}
-	cli_out(cli, params->vcl_trace ? "on" : "off");
+	if (cli == NULL)
+		return;
+	cli_out(cli, params->vcl_trace ? "on\n" : "off\n");
 }
 
 /*--------------------------------------------------------------------*/
 
+static void
+tweak_listen_address(struct cli *cli, struct parspec *par, const char *arg)
+{
+	char *a, *p;
+
+	(void)par;
+	if (arg != NULL) {
+		if (TCP_parse(arg, &a, &p) != 0) {
+			cli_out(cli, "Invalid listen address");
+			cli_result(cli, CLIS_PARAM);
+			return;
+		}
+		free(params->listen_address);
+		free(params->listen_host);
+		free(params->listen_port);
+		params->listen_address = strdup(arg);
+		AN(params->listen_address);
+		params->listen_host = a;
+		if (p == NULL) {
+			p = strdup("http");
+			AN(p);
+		}
+		params->listen_port = p;
+	}
+	if (cli == NULL)
+		return;
+	cli_out(cli, "%s", params->listen_address);
+}
+/*--------------------------------------------------------------------*/
+
 /*
  * Make sure to end all lines with either a space or newline of the
  * formatting will go haywire.
@@ -332,6 +364,10 @@
 	{ "vcl_trace", tweak_vcl_trace,
 		"Trace VCL execution in the shmlog\n"
 		"Default is off", "off" },
+	{ "listen_address", tweak_listen_address,
+		"The network address/port where Varnish services requests.\n"
+		MUST_RESTART
+		"Default is \"0.0.0.0:80\"", "0.0.0.0:80" },
 	{ NULL, NULL, NULL }
 };
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2006-09-16 07:49:35 UTC (rev 998)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2006-09-16 08:20:39 UTC (rev 999)
@@ -179,13 +179,13 @@
 
 	TAILQ_FOREACH(vp, &vclhead, list) {
 		if (mgt_cli_askchild(status, p,
-		    "config.load %s %s\n", vp->name, vp->fname))
+		    "vcl.load %s %s\n", vp->name, vp->fname))
 			return (1);
 		free(*p);
 		if (!vp->active)
 			continue;
-		if (mgt_cli_askchild(status, p, "config.use %s\n",
-		    vp->name, vp->fname))
+		if (mgt_cli_askchild(status, p,
+		    "vcl.use %s\n", vp->name))
 			return (1);
 		free(*p);
 	}

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2006-09-16 07:49:35 UTC (rev 998)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2006-09-16 08:20:39 UTC (rev 999)
@@ -321,7 +321,7 @@
 	int o;
 	unsigned d_flag = 0;
 	char *addr, *port;
-	const char *a_arg = "0.0.0.0:http";
+	const char *a_arg = NULL;
 	const char *b_arg = NULL;
 	const char *f_arg = NULL;
 	const char *h_flag = "classic";
@@ -332,6 +332,7 @@
 	setbuf(stdout, NULL);
 	setbuf(stderr, NULL);
 
+	heritage.socket = -1;
 	memset(&param, 0, sizeof param);
 	params = &param;
 	mgt_vcc_init(); 
@@ -397,20 +398,19 @@
 	setup_storage(s_arg);
 	setup_hash(h_flag);
 
-	/*
-	 * XXX: Lacking the suspend/resume facility (due to the socket API
-	 * missing an unlisten(2) facility) we may want to push this into
-	 * the child to limit the amount of time where the socket(s) exists
-	 * but do not answer.  That, on the other hand, would eliminate the
-	 * possibility of doing a "no-glitch" restart of the child process.
-	 */
-	if (TCP_parse(a_arg, &addr, &port) != 0)
-		fprintf(stderr, "invalid listen address\n");
-	heritage.socket = TCP_open(addr, port ? port : "http", 1);
-	free(addr);
-	free(port);
-	if (heritage.socket < 0)
-		exit (2);
+	if (a_arg != NULL) {
+		if (TCP_parse(a_arg, &addr, &port) != 0) {
+			fprintf(stderr, "invalid listen address\n");
+			exit (2);
+		}
+		free(params->listen_address);
+		free(params->listen_host);
+		free(params->listen_port);
+		params->listen_address = strdup(a_arg);
+		AN(params->listen_address);
+		params->listen_host = addr;
+		params->listen_port = port;
+	}
 
 	VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024);
 




More information about the varnish-commit mailing list