[master] 6df4d96 Split mcf_server_startstop() into two separate functions

Poul-Henning Kamp phk at FreeBSD.org
Thu Feb 4 02:55:26 CET 2016


commit 6df4d965a9ded8cb50d184fe0435f0c066841b79
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Feb 4 00:20:41 2016 +0000

    Split mcf_server_startstop() into two separate functions

diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 8cedeaf..8baaa6d 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -611,17 +611,16 @@ mgt_stop_child(void)
 }
 
 /*=====================================================================
- * CLI command to start/stop child
+ * CLI commands to start/stop child
  */
 
 void __match_proto__(cli_func_t)
-mcf_server_startstop(struct cli *cli, const char * const *av, void *priv)
+mcf_server_start(struct cli *cli, const char * const *av, void *priv)
 {
 
 	(void)av;
-	if (priv != NULL && child_state == CH_RUNNING)
-		mgt_stop_child();
-	else if (priv == NULL && child_state == CH_STOPPED) {
+	(void)priv;
+	if (child_state == CH_STOPPED) {
 		if (mgt_has_vcl()) {
 			mgt_launch_child(cli);
 		} else {
@@ -634,6 +633,20 @@ mcf_server_startstop(struct cli *cli, const char * const *av, void *priv)
 	}
 }
 
+void __match_proto__(cli_func_t)
+mcf_server_stop(struct cli *cli, const char * const *av, void *priv)
+{
+
+	(void)av;
+	(void)priv;
+	if (child_state == CH_RUNNING) {
+		mgt_stop_child();
+	} else {
+		VCLI_SetResult(cli, CLIS_CANT);
+		VCLI_Out(cli, "Child in state %s", ch_state[child_state]);
+	}
+}
+
 /*--------------------------------------------------------------------*/
 
 void
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index fa021d6..2317822 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -89,20 +89,20 @@ mcf_banner(struct cli *cli, const char *const *av, void *priv)
 
 /* XXX: what order should this list be in ? */
 static struct cli_proto cli_proto[] = {
-	{ CLI_BANNER,		"", mcf_banner, NULL },
-	{ CLI_SERVER_STATUS,	"", mcf_server_status, NULL },
-	{ CLI_SERVER_START,	"", mcf_server_startstop, NULL },
-	{ CLI_SERVER_STOP,	"", mcf_server_startstop, cli_proto },
-	{ CLI_VCL_LOAD,		"", mcf_vcl_load, NULL },
-	{ CLI_VCL_INLINE,	"", mcf_vcl_inline, NULL },
-	{ CLI_VCL_USE,		"", mcf_vcl_use, NULL },
-	{ CLI_VCL_STATE,	"", mcf_vcl_state, NULL },
-	{ CLI_VCL_DISCARD,	"", mcf_vcl_discard, NULL },
-	{ CLI_VCL_LIST,		"", mcf_vcl_list, NULL },
-	{ CLI_PARAM_SHOW,	"", mcf_param_show, NULL },
-	{ CLI_PARAM_SET,	"", mcf_param_set, NULL },
-	{ CLI_PANIC_SHOW,	"", mcf_panic_show, NULL },
-	{ CLI_PANIC_CLEAR,	"", mcf_panic_clear, NULL },
+	{ CLI_BANNER,		"", mcf_banner },
+	{ CLI_SERVER_STATUS,	"", mcf_server_status },
+	{ CLI_SERVER_START,	"", mcf_server_start },
+	{ CLI_SERVER_STOP,	"", mcf_server_stop },
+	{ CLI_VCL_LOAD,		"", mcf_vcl_load },
+	{ CLI_VCL_INLINE,	"", mcf_vcl_inline },
+	{ CLI_VCL_USE,		"", mcf_vcl_use },
+	{ CLI_VCL_STATE,	"", mcf_vcl_state },
+	{ CLI_VCL_DISCARD,	"", mcf_vcl_discard },
+	{ CLI_VCL_LIST,		"", mcf_vcl_list },
+	{ CLI_PARAM_SHOW,	"", mcf_param_show },
+	{ CLI_PARAM_SET,	"", mcf_param_set },
+	{ CLI_PANIC_SHOW,	"", mcf_panic_show },
+	{ CLI_PANIC_CLEAR,	"", mcf_panic_clear },
 	{ NULL }
 };
 
diff --git a/bin/varnishd/mgt/mgt_cli.h b/bin/varnishd/mgt/mgt_cli.h
index 0210aa1..49d849a 100644
--- a/bin/varnishd/mgt/mgt_cli.h
+++ b/bin/varnishd/mgt/mgt_cli.h
@@ -29,7 +29,8 @@
  */
 
 /* mgt_child.c */
-cli_func_t mcf_server_startstop;
+cli_func_t mcf_server_start;
+cli_func_t mcf_server_stop;
 cli_func_t mcf_server_status;
 cli_func_t mcf_panic_show;
 cli_func_t mcf_panic_clear;



More information about the varnish-commit mailing list