Commit 5aaa91d8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.


git-svn-id: http://www.varnish-cache.org/svn/trunk@633 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 302f0e8f
......@@ -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);
......
......@@ -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;
}
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment