[master] f0dc9964e Implement "include file ..." command

Poul-Henning Kamp phk at FreeBSD.org
Wed Feb 7 11:41:05 UTC 2024


commit f0dc9964e953fbcc11869957f11382098be0a9ab
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 7 11:22:05 2024 +0000

    Implement "include file ..." command
    
    Submitted by: @AlveElde in Vtest repo on github

diff --git a/bin/varnishtest/cmds.h b/bin/varnishtest/cmds.h
index dfc097570..3b8a9e9fd 100644
--- a/bin/varnishtest/cmds.h
+++ b/bin/varnishtest/cmds.h
@@ -37,6 +37,7 @@
 CMD_GLOBAL(barrier)
 CMD_GLOBAL(delay)
 CMD_GLOBAL(shell)
+CMD_GLOBAL(include)
 #undef CMD_GLOBAL
 
 #ifndef CMD_TOP
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index 30784d61a..95d4387ee 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -48,6 +48,7 @@
 
 #include "vtc.h"
 
+#include "vfil.h"
 #include "vnum.h"
 #include "vre.h"
 #include "vtcp.h"
@@ -349,6 +350,40 @@ cmd_delay(CMD_ARGS)
 	VTIM_sleep(f);
 }
 
+/* SECTION: include include
+ *
+ * Executes a vtc fragment::
+ *
+ *         include FILE [...]
+ *
+ * Open a file and execute it as a VTC fragment. This command is available
+ * everywhere commands are given.
+ *
+ */
+void
+cmd_include(CMD_ARGS)
+{
+	char *spec;
+	unsigned i;
+
+	if (av == NULL)
+		return;
+
+	if (av[1] == NULL)
+		vtc_fatal(vl, "CMD include: At least 1 argument required");
+
+	for (i = 1; av[i] != NULL; i++) {
+		spec = VFIL_readfile(NULL, av[i], NULL);
+		if (spec == NULL)
+			vtc_fatal(vl, "CMD include: Unable to read file '%s' "
+			    "(%s)", av[i], strerror(errno));
+		vtc_log(vl, 2, "Begin include '%s'", av[i]);
+		parse_string(vl, priv, spec);
+		vtc_log(vl, 2, "End include '%s'", av[i]);
+		free(spec);
+	}
+}
+
 /**********************************************************************
  * Most test-cases use only numeric IP#'s but a few requires non-demented
  * DNS services.  This is a basic sanity check for those.


More information about the varnish-commit mailing list