[master] 1e09f422f Move Emit_UDS_Path() to vcc_backend.c where it belongs

Poul-Henning Kamp phk at FreeBSD.org
Thu Nov 5 13:55:09 UTC 2020


commit 1e09f422f7890965990730b4a5c7826e29d4421c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Nov 5 11:13:49 2020 +0000

    Move Emit_UDS_Path() to vcc_backend.c where it belongs

diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index f6a268800..6747a7544 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -34,6 +34,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include "vcc_compile.h"
 
@@ -86,6 +87,46 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host,
 	Fb(tl, 0, "\t.path = (void *) 0,\n");
 }
 
+/*
+ * For UDS, we do not create a VSA. Check if it's an absolute path, can
+ * be accessed, and is a socket. If so, just emit the path field and set
+ * the IP suckaddrs to NULL.
+ */
+static void
+Emit_UDS_Path(struct vcc *tl, const struct token *t_path, const char *errid)
+{
+	struct stat st;
+
+	AN(t_path);
+	AN(t_path->dec);
+
+	if (*t_path->dec != '/') {
+		VSB_printf(tl->sb,
+			   "%s: Must be an absolute path:\n", errid);
+		vcc_ErrWhere(tl, t_path);
+		return;
+	}
+	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);
+		if (err == ENOENT || err == EACCES)
+			vcc_Warn(tl);
+		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;
+	}
+	Fb(tl, 0, "\t.path = \"%s\",\n", t_path->dec);
+	Fb(tl, 0, "\t.ipv4_suckaddr = (void *) 0,\n");
+	Fb(tl, 0, "\t.ipv6_suckaddr = (void *) 0,\n");
+}
+
+
 /*--------------------------------------------------------------------
  * Disallow mutually exclusive field definitions
  */
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 173617e84..815b25918 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -360,8 +360,6 @@ void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport,
     const char **ipv4, const char **ipv4_ascii, const char **ipv6,
     const char **ipv6_ascii, const char **p_ascii, int maxips,
     const struct token *t_err, const char *errid);
-void Emit_UDS_Path(struct vcc *tl, const struct token *t_path,
-    const char *errid);
 double vcc_DurationUnit(struct vcc *);
 void vcc_ByteVal(struct vcc *, double *);
 void vcc_Duration(struct vcc *tl, double *);
diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index efe8f4861..8536d9984 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -257,45 +257,6 @@ Resolve_Sockaddr(struct vcc *tl,
 	ZERO_OBJ(rss, sizeof rss);
 }
 
-/*
- * For UDS, we do not create a VSA. Check if it's an absolute path, can
- * be accessed, and is a socket. If so, just emit the path field and set
- * the IP suckaddrs to NULL.
- */
-void
-Emit_UDS_Path(struct vcc *tl, const struct token *t_path, const char *errid)
-{
-	struct stat st;
-
-	AN(t_path);
-	AN(t_path->dec);
-
-	if (*t_path->dec != '/') {
-		VSB_printf(tl->sb,
-			   "%s: Must be an absolute path:\n", errid);
-		vcc_ErrWhere(tl, t_path);
-		return;
-	}
-	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);
-		if (err == ENOENT || err == EACCES)
-			vcc_Warn(tl);
-		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;
-	}
-	Fb(tl, 0, "\t.path = \"%s\",\n", t_path->dec);
-	Fb(tl, 0, "\t.ipv4_suckaddr = (void *) 0,\n");
-	Fb(tl, 0, "\t.ipv6_suckaddr = (void *) 0,\n");
-}
-
 /*--------------------------------------------------------------------
  * Recognize and convert units of duration, return seconds.
  */


More information about the varnish-commit mailing list