r633 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Aug 4 09:21:50 CEST 2006


Author: phk
Date: 2006-08-04 09:21:50 +0200 (Fri, 04 Aug 2006)
New Revision: 633

Modified:
   trunk/varnish-cache/bin/varnishd/mgt.h
   trunk/varnish-cache/bin/varnishd/mgt_child.c
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
Log:
Implement CLI ping in manager, this is a "per hop" command.

Add mgt_cli_askchild() function to poke the CLI interface to
the child.

Use it to ping the child every second.


Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h	2006-08-04 07:20:49 UTC (rev 632)
+++ trunk/varnish-cache/bin/varnishd/mgt.h	2006-08-04 07:21:50 UTC (rev 633)
@@ -15,7 +15,9 @@
 void mgt_cli_setup(int fdi, int fdo, int verbose);
 void mgt_cli_start_child(int fdi, int fdo);
 void mgt_cli_stop_child(void);
+int mgt_cli_askchild(int *status, char **resp, const char *fmt, ...);
 
+
 /* tcp.c */
 int open_tcp(const char *port);
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c	2006-08-04 07:20:49 UTC (rev 632)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c	2006-08-04 07:21:50 UTC (rev 633)
@@ -63,8 +63,8 @@
 	(void)arg;
 	while (1) {
 		sleep (1);
-		/* CLI: ping/pong */
-		child_ticker = 0;
+		if (!mgt_cli_askchild(NULL, NULL, "ping\n"))
+			child_ticker = 0;
 	}
 }
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2006-08-04 07:20:49 UTC (rev 632)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2006-08-04 07:21:50 UTC (rev 633)
@@ -9,6 +9,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdarg.h>
 #include <pthread.h>
 #include <sys/types.h>
 
@@ -99,6 +100,7 @@
 
 static struct cli_proto mgt_cli_proto[] = {
 	{ CLI_HELP,		cli_func_help, NULL },	/* must be first */
+	{ CLI_PING,		cli_func_ping },
 	{ CLI_SERVER_START,	mcf_server_startstop, NULL },
 	{ CLI_SERVER_STOP,	mcf_server_startstop, &cli_proto },
 	{ CLI_CONFIG_LOAD },
@@ -163,6 +165,36 @@
 	/* XXX: open listening sockets, contact cluster server etc */
 }
 
+/*--------------------------------------------------------------------
+ * Ask the child something over CLI, return zero only if everything is
+ * happy happy.
+ */
+
+int
+mgt_cli_askchild(int *status, char **resp, const char *fmt, ...)
+{
+	char *p;
+	int i, j;
+	va_list ap;
+
+	va_start(ap, fmt);
+	i = vasprintf(&p, fmt, ap);
+	va_end(ap);
+	if (i < 0)
+		return (i);
+	AZ(pthread_mutex_lock(&cli_mtx));
+	assert(p[i - 1] == '\n');
+	i = write(cli_o, p, strlen(p));
+	assert(i == strlen(p));
+	free(p);
+
+	i = cli_readres(cli_i, &j, resp);
+	AZ(pthread_mutex_unlock(&cli_mtx));
+	if (status != NULL)
+		*status = j;
+	return (j == CLIS_OK ? 0 : j);
+}
+
 /*--------------------------------------------------------------------*/
 
 void




More information about the varnish-commit mailing list