[master] 8d0f2b836 Make mgt_has_vcl() return an error string

Nils Goroll nils.goroll at uplex.de
Tue Nov 16 11:41:07 UTC 2021


commit 8d0f2b83687dc8a60b3dc6f361985cf429529ad5
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Oct 19 13:56:16 2021 +0200

    Make mgt_has_vcl() return an error string
    
    mgt_has_vcl() now returns an error string describing why it doesn't have a
    valid VCL.
    
    This is taken from #3711 by @bsdphk

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index c8db1954e..f2d2f0f7e 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -231,7 +231,7 @@ void mgt_vcl_init(void);
 void mgt_vcl_startup(struct cli *, const char *vclsrc, const char *origin,
     const char *vclname, int Cflag);
 int mgt_push_vcls(struct cli *, unsigned *status, char **p);
-int mgt_has_vcl(void);
+const char *mgt_has_vcl(void);
 extern char *mgt_cc_cmd;
 extern const char *mgt_vcl_path;
 extern const char *mgt_vmod_path;
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index a8181bd56..5e7ed7cb1 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -706,15 +706,17 @@ mch_pid_json(struct cli *cli, const char * const *av, void *priv)
 static void v_matchproto_(cli_func_t)
 mch_cli_server_start(struct cli *cli, const char * const *av, void *priv)
 {
+	const char *err;
 
 	(void)av;
 	(void)priv;
 	if (child_state == CH_STOPPED) {
-		if (mgt_has_vcl()) {
+		err = mgt_has_vcl();
+		if (err == NULL) {
 			mgt_launch_child(cli);
 		} else {
 			VCLI_SetResult(cli, CLIS_CANT);
-			VCLI_Out(cli, "No VCL available");
+			VCLI_Out(cli, "%s", err);
 		}
 	} else {
 		VCLI_SetResult(cli, CLIS_CANT);
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index f5d2ede33..ecc09dc3f 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -483,6 +483,7 @@ main(int argc, char * const *argv)
 	char *p;
 	struct cli cli[1];
 	char **av;
+	const char *err;
 	unsigned u;
 	struct sigaction sac;
 	struct vev *e;
@@ -909,10 +910,11 @@ main(int argc, char * const *argv)
 	}
 	assert(I_fd == -1);
 
-	if (!d_flag && !mgt_has_vcl() && !novcl)
-		MGT_Complain(C_ERR, "No VCL loaded yet");
+	err = mgt_has_vcl();
+	if (!d_flag && err != NULL && !novcl)
+		MGT_Complain(C_ERR, "%s", err);
 
-	if (mgt_has_vcl() && ! d_flag)
+	if (err == NULL && !d_flag)
 		u = MCH_Start_Child();
 	else
 		u = 0;
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index b5507d3ff..d14c9d95c 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -281,11 +281,16 @@ mgt_vcl_del(struct vclprog *vp)
 	FREE_OBJ(vp);
 }
 
-int
+const char *
 mgt_has_vcl(void)
 {
-
-	return (!VTAILQ_EMPTY(&vclhead));
+	if (VTAILQ_EMPTY(&vclhead))
+		return ("No VCL loaded");
+	if (mgt_vcl_active == NULL)
+		return ("No active VCL");
+	CHECK_OBJ_NOTNULL(mgt_vcl_active, VCLPROG_MAGIC);
+	AN(mgt_vcl_active->warm);
+	return (NULL);
 }
 
 /*


More information about the varnish-commit mailing list