[master] 18e255742 VCC warns (only) if stat(UDS backend) fails with ENOENT or EACCES.
Geoff Simmons
geoff at uplex.de
Mon Jan 28 12:27:08 UTC 2019
commit 18e255742334720be7e7a02cc4c088d78be1fb67
Author: Geoff Simmons <geoff at uplex.de>
Date: Fri Jan 25 16:44:20 2019 +0100
VCC warns (only) if stat(UDS backend) fails with ENOENT or EACCES.
This makes it easier to start the UDS-listening peer, and/or set
permissions on the socket file, after starting Varnish or loading
VCL with a UDS backend.
Closes #2884
diff --git a/bin/varnishtest/tests/c00086.vtc b/bin/varnishtest/tests/c00086.vtc
index e14943729..2ab6350ee 100644
--- a/bin/varnishtest/tests/c00086.vtc
+++ b/bin/varnishtest/tests/c00086.vtc
@@ -1,4 +1,4 @@
-varnishtest "-a sub-args user, group and mode"
+varnishtest "-a sub-args user, group and mode; and warn if stat(EACCES) fails for UDS"
feature user_vcache
feature group_varnish
@@ -51,3 +51,14 @@ shell -match "vcache" { ls -l ${tmpdir}/v6.sock }
varnish v7 -arg "-a ${tmpdir}/v7.sock,group=varnish" -vcl+backend {}
shell -match "root.+varnish" { ls -l ${tmpdir}/v7.sock }
+
+# VCC warns, but does not fail, if stat(UDS) fails with EACCES.
+shell { mkdir ${tmpdir}/dir }
+server s2 -listen ${tmpdir}/dir/s1.sock {} -start
+
+shell { chmod go-rx ${tmpdir}/dir }
+
+varnish v8 -arg "-j unix,user=vcache" -vcl { backend b {.host="${bad_ip}";} }
+
+varnish v8 -cliexpect "(?s)Cannot stat:.+That was just a warning" \
+ {vcl.inline test "vcl 4.1; backend b {.path=\"${tmpdir}/dir/s1.sock\";}"}
diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc
index d93d4d5f6..d408896b8 100644
--- a/bin/varnishtest/tests/v00038.vtc
+++ b/bin/varnishtest/tests/v00038.vtc
@@ -123,16 +123,40 @@ varnish v1 -errvcl "Must be an absolute path:" {
}
}
-shell { rm -f ${tmpdir}/foo }
-
-varnish v1 -errvcl "Cannot stat:" {
- backend b1 {
- .path = "${tmpdir}/foo";
- }
-}
-
varnish v1 -errvcl "Not a socket:" {
backend b1 {
.path = "${tmpdir}";
}
}
+
+# VCC warns, but does not fail, if stat(UDS) fails with ENOENT.
+shell { rm -f ${tmpdir}/foo }
+
+varnish v1 -vcl { backend b {.host="${bad_ip}";} }
+
+varnish v1 -cliexpect "(?s)Cannot stat:.+That was just a warning" \
+ {vcl.inline test "vcl 4.1; backend b {.path=\"${tmpdir}/foo\";}"}
+
+# VCC also warns but doesn't fail for EACCES. Tested in c00086.vtc.
+
+# The following test verifies that Varnish continues connecting to a
+# socket file, even if the listener at that location changes.
+
+server s1 -listen "${tmpdir}/server.sock" {
+ rxreq
+ txresp -hdr "Connection: close" -hdr "Cache-Control: max-age=0"
+} -start
+
+varnish v1 -vcl {
+ backend b {.path = "${s1_sock}"; }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 200
+} -run
+
+server s1 -start
+
+client c1 -run
diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index e92be266f..f03762b34 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -276,12 +276,16 @@ Emit_UDS_Path(struct vcc *tl, const struct token *t_path, const char *errid)
}
errno = 0;
if (stat(t_path->dec, &st) != 0) {
+ int err = errno;
VSB_printf(tl->sb, "%s: Cannot stat: %s\n", errid,
strerror(errno));
vcc_ErrWhere(tl, t_path);
- return;
- }
- if (!S_ISSOCK(st.st_mode)) {
+ if (err == ENOENT || err == EACCES) {
+ VSB_printf(tl->sb, "(That was just a warning)\n");
+ tl->err = 0;
+ } else
+ return;
+ } else if (!S_ISSOCK(st.st_mode)) {
VSB_printf(tl->sb, "%s: Not a socket:\n", errid);
vcc_ErrWhere(tl, t_path);
return;
More information about the varnish-commit
mailing list