r629 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Aug 4 08:23:08 CEST 2006


Author: phk
Date: 2006-08-04 08:23:08 +0200 (Fri, 04 Aug 2006)
New Revision: 629

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
Log:
(Re)Implement passthru of cli commands, we can now talk with the
cache process again.


Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2006-08-04 06:21:56 UTC (rev 628)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2006-08-04 06:23:08 UTC (rev 629)
@@ -20,6 +20,7 @@
 #include "mgt.h"
 
 static int		cli_i = -1, cli_o = -1;
+static pthread_mutex_t	cli_mtx;
 
 /*--------------------------------------------------------------------*/
 
@@ -35,6 +36,69 @@
 		mgt_start_child();
 }
 
+/*--------------------------------------------------------------------
+ * Passthru of cli commands.
+ */
+
+static void
+mcf_passthru(struct cli *cli, char **av, void *priv)
+{
+	char buf[BUFSIZ], *bp, *be;
+	char *p;
+	unsigned u, v;
+	int i, j, k;
+
+	AZ(pthread_mutex_lock(&cli_mtx));
+	/* Request */
+	if (cli_o <= 0) {
+		AZ(pthread_mutex_unlock(&cli_mtx));
+		cli_result(cli, CLIS_CANT);
+		cli_out(cli, "Cache process not running");
+		return;
+	}
+	(void)priv;
+	bp = buf;
+	be = bp + sizeof buf;
+	for (u = 1; av[u] != NULL; u++) {
+		v = strlen(av[u]);
+		if (5 + bp + 4 * v > be) {
+			*bp = '\0';
+			v = bp - buf;
+			i = write(cli_o, buf, v);
+			assert(i == v);
+			bp = buf;
+		}
+		*bp++ = '"';
+		for (p = av[u]; *p; p++) {
+			switch (*p) {
+			case '\\':	*bp++ = '\\'; *bp++ = '\\'; break;
+			case '\n':	*bp++ = '\\'; *bp++ = 'n'; break;
+			case '"':	*bp++ = '\\'; *bp++ = '"'; break;
+			default:	*bp++ = *p; break;
+			}
+		}
+		*bp++ = '"';
+		*bp++ = ' ';
+	}
+	if (bp != buf) {
+		*bp++ = '\n';
+		v = bp - buf;
+		i = write(cli_o, buf, v);
+		assert(i == v);
+	}
+
+	/* Response */
+	i = read(cli_i, buf, sizeof buf - 1);
+	assert(i > 0);
+	buf[i] = '\0';
+	j = sscanf(buf, "%u %u\n%n", &u, &v, &k);
+	assert(j == 2);
+	assert(i == k + v + 1);
+	cli_result(cli, u);
+	cli_out(cli, "%*.*s", v, v, buf + k);
+	AZ(pthread_mutex_unlock(&cli_mtx));
+}
+
 /*--------------------------------------------------------------------*/
 
 static struct cli_proto *cli_proto;
@@ -70,6 +134,7 @@
 	unsigned u, v;
 
 
+	AZ(pthread_mutex_init(&cli_mtx, NULL));
 	/*
 	 * Build the joint cli_proto by combining the manager process
 	 * entries with with the cache process entries.  The latter
@@ -93,7 +158,7 @@
 		if (v < u)
 			continue;
 		cli_proto[u] = *cp;
-		cli_proto[u].func = NULL;	/* XXX: pass */
+		cli_proto[u].func = mcf_passthru;
 		u++;
 	}
 




More information about the varnish-commit mailing list