From: phk Date: Fri, 4 Aug 2006 11:10:57 +0000 (+0000) Subject: Now that we keep track of loaded VCLs in the manager, we might X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29331b8940d4312ddfd9bfc2f66c82ab0a0cafba;p=varnish Now that we keep track of loaded VCLs in the manager, we might as well allow their manipulation also when the child is not running. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@639 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index 83373b30..5537c9d0 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -8,7 +8,7 @@ void mgt_run(int dflag); void mgt_start_child(void); void mgt_stop_child(void); -extern pid_t mgt_pid; +extern pid_t mgt_pid, child_pid; /* mgt_cli.c */ diff --git a/varnish-cache/bin/varnishd/mgt_child.c b/varnish-cache/bin/varnishd/mgt_child.c index cfcc9a73..8284466b 100644 --- a/varnish-cache/bin/varnishd/mgt_child.c +++ b/varnish-cache/bin/varnishd/mgt_child.c @@ -25,8 +25,8 @@ #include "mgt_cli.h" pid_t mgt_pid; +pid_t child_pid = -1; -static pid_t child_pid = -1; static int child_fds[2]; static unsigned child_should_run; static pthread_t child_listen_thread; diff --git a/varnish-cache/bin/varnishd/mgt_cli.c b/varnish-cache/bin/varnishd/mgt_cli.c index 36c63f47..8f6f1803 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.c +++ b/varnish-cache/bin/varnishd/mgt_cli.c @@ -113,6 +113,7 @@ static struct cli_proto mgt_cli_proto[] = { { CLI_CONFIG_INLINE, mcf_config_inline, NULL }, { CLI_CONFIG_USE, mcf_config_use, NULL }, { CLI_CONFIG_DISCARD, mcf_config_discard, NULL }, + { CLI_CONFIG_LIST, mcf_config_list, NULL }, #if 0 { CLI_SERVER_STOP, m_cli_func_server_stop, NULL }, { CLI_SERVER_RESTART }, diff --git a/varnish-cache/bin/varnishd/mgt_cli.h b/varnish-cache/bin/varnishd/mgt_cli.h index 5d05d78e..0c8f280b 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.h +++ b/varnish-cache/bin/varnishd/mgt_cli.h @@ -10,3 +10,4 @@ cli_func_t mcf_config_load; cli_func_t mcf_config_inline; cli_func_t mcf_config_use; cli_func_t mcf_config_discard; +cli_func_t mcf_config_list; diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index 778b4c30..f53ed03b 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -246,7 +246,8 @@ mcf_config_inline(struct cli *cli, char **av, void *priv) return; } sbuf_delete(sb); - if (mgt_cli_askchild(&status, &p, "config.load %s %s\n", av[2], vf)) { + if (child_pid >= 0 && + mgt_cli_askchild(&status, &p, "config.load %s %s\n", av[2], vf)) { cli_result(cli, status); cli_out(cli, "%s", p); free(p); @@ -276,7 +277,8 @@ mcf_config_load(struct cli *cli, char **av, void *priv) return; } sbuf_delete(sb); - if (mgt_cli_askchild(&status, &p, "config.load %s %s\n", av[2], vf)) { + if (child_pid >= 0 && + mgt_cli_askchild(&status, &p, "config.load %s %s\n", av[2], vf)) { cli_result(cli, status); cli_out(cli, "%s", p); free(p); @@ -334,6 +336,7 @@ mcf_config_discard(struct cli *cli, char **av, void *priv) int status; char *p; struct vcls *vp; + (void)priv; AZ(pthread_mutex_lock(&vcc_mtx)); vp = mcf_find_vcl(cli, av[2]); @@ -352,3 +355,29 @@ mcf_config_discard(struct cli *cli, char **av, void *priv) } AZ(pthread_mutex_unlock(&vcc_mtx)); } + +void +mcf_config_list(struct cli *cli, char **av, void *priv) +{ + int status; + char *p; + struct vcls *vp; + + (void)av; + (void)priv; + if (child_pid >= 0) { + mgt_cli_askchild(&status, &p, "config.list\n"); + cli_result(cli, status); + cli_out(cli, "%s", p); + free(p); + } else { + AZ(pthread_mutex_lock(&vcc_mtx)); + TAILQ_FOREACH(vp, &vclhead, list) { + cli_out(cli, "%s %6s %s\n", + vp->active ? "*" : " ", + "N/A", vp->name); + } + AZ(pthread_mutex_unlock(&vcc_mtx)); + } +} +