[master] 84708f9fb Add simplified VEXT loading as -E<name>
Nils Goroll
nils.goroll at uplex.de
Mon Dec 8 15:02:05 UTC 2025
commit 84708f9fb2cc8b4feaa9fd0a0a5dca79af130d2d
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Fri Nov 28 17:14:20 2025 +0100
Add simplified VEXT loading as -E<name>
Similar to how vmods can be loaded by their base name, we now support loading
extensions using, for example, -Estd:
If a path is specified (-E argument contains "/"), it is taken literally as
before. Otherwise, the -E argument is expanded to libvmod_%s.so and a search in
vmod_path is conducted.
diff --git a/bin/varnishd/mgt/mgt_vext.c b/bin/varnishd/mgt/mgt_vext.c
index 30c0b2661..c2f61f576 100644
--- a/bin/varnishd/mgt/mgt_vext.c
+++ b/bin/varnishd/mgt/mgt_vext.c
@@ -45,6 +45,7 @@
#include "vas.h"
#include "miniobj.h"
#include "vav.h"
+#include "vfil.h"
#include "vqueue.h"
#include "vrnd.h"
#include "vsb.h"
@@ -65,10 +66,25 @@ struct vext {
static VTAILQ_HEAD(,vext) vext_list =
VTAILQ_HEAD_INITIALIZER(vext_list);
+static int
+vext_tryopen(void *priv, const char *fn)
+{
+ struct vext *vp;
+
+ CAST_OBJ_NOTNULL(vp, priv, VEXT_MAGIC);
+ vp->fd = open(fn, O_RDONLY);
+ if (vp->fd < 0)
+ return (1);
+ return (0);
+}
+
void
vext_argument(const char *arg)
{
struct vext *vp;
+ char fn[1024];
+ char *fno = NULL;
+ struct vfil_path *vmod_path = NULL;
fprintf(stderr, "EEE <%s>\n", arg);
ALLOC_OBJ(vp, VEXT_MAGIC);
@@ -79,11 +95,20 @@ vext_argument(const char *arg)
ARGV_ERR("\tParse failure in argument: %s\n\t%s\n",
arg, vp->argv[0]);
VTAILQ_INSERT_TAIL(&vext_list, vp, list);
- fprintf(stderr, "eee <%s>\n", vp->argv[1]);
- vp->fd = open(vp->argv[1], O_RDONLY);
- if (vp->fd < 0)
+
+ if (strchr(vp->argv[1], '/'))
+ bstrcpy(fn, vp->argv[1]);
+ else
+ bprintf(fn, "libvmod_%s.so", vp->argv[1]);
+
+ VFIL_setpath(&vmod_path, mgt_vmod_path);
+ if (VFIL_searchpath(vmod_path, vext_tryopen, vp, fn, &fno)) {
ARGV_ERR("\tCannot open %s\n\t%s\n",
- vp->argv[1], strerror(errno));
+ fn, strerror(errno));
+ }
+
+ fprintf(stderr, "eee <%s>\n", fno);
+ free(fno);
}
void
@@ -115,7 +140,7 @@ vext_copyin(struct vsb *vi)
if (p != NULL)
p++;
else
- p = vp->argv[0];
+ p = vp->argv[1];
VSB_printf(vi, ",-E%s", p);
VSB_printf(vp->vsb, "vext_cache/%s,", p);
for (i = 0; i < 8; i++) {
diff --git a/bin/varnishtest/tests/x00000.vtc b/bin/varnishtest/tests/x00000.vtc
index 7069f4c2c..5baea5986 100644
--- a/bin/varnishtest/tests/x00000.vtc
+++ b/bin/varnishtest/tests/x00000.vtc
@@ -2,7 +2,7 @@ varnishtest "Test VMOD import from VEXT"
feature topbuild
-server s1 {
+server s1 -repeat 2 {
rxreq
txresp
} -start
@@ -23,3 +23,26 @@ client c1 {
rxresp
expect resp.http.foobar ~ [0-9]
} -run
+
+varnish v1 -stop
+
+varnish v2 \
+ -arg "-Estd" \
+ -vcl+backend {
+ import std;
+
+ sub vcl_deliver {
+ set resp.http.foobar = std.random(10,99);
+ }
+ } -start
+
+client c2 -connect ${v2_sock} {
+ txreq
+ rxresp
+ expect resp.http.foobar ~ [0-9]
+} -run
+
+varnish v2 -stop
+
+shell -err -match {Error:.*Cannot open libvmod_std.so} \
+ "varnishd -pvmod_path=/nonexistent -Estd -b none -a ${tmpdir}/vtc.sock"
More information about the varnish-commit
mailing list