]> err.no Git - varnish/commitdiff
Implement CLI ping in manager, this is a "per hop" command.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 4 Aug 2006 07:21:50 +0000 (07:21 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 4 Aug 2006 07:21:50 +0000 (07:21 +0000)
Add mgt_cli_askchild() function to poke the CLI interface to
the child.

Use it to ping the child every second.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@633 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/mgt.h
varnish-cache/bin/varnishd/mgt_child.c
varnish-cache/bin/varnishd/mgt_cli.c

index f3740db2b22097feac6ab916e31e075c59168114..ef2eeaa9e0688fae2c4d0a83f97c639054eabd5a 100644 (file)
@@ -15,6 +15,8 @@ void mgt_cli_init(void);
 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);
index 71fa133e5cf0df8b93d35c5e9dea13ff10146b88..aa8892f926a133495df92f895fde9d6aa5c71917 100644 (file)
@@ -63,8 +63,8 @@ child_poker(void *arg)
        (void)arg;
        while (1) {
                sleep (1);
-               /* CLI: ping/pong */
-               child_ticker = 0;
+               if (!mgt_cli_askchild(NULL, NULL, "ping\n"))
+                       child_ticker = 0;
        }
 }
 
index e6630b174bb63e7c1ae7c4ed8d96a46e2ad312de..cc75a179b93a9b28642a9f3ebbe05c77d466f5c9 100644 (file)
@@ -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 *cli_proto;
 
 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 @@ mgt_cli_init(void)
        /* 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