r3949 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl

sky at projects.linpro.no sky at projects.linpro.no
Wed Mar 18 13:10:46 CET 2009


Author: sky
Date: 2009-03-18 13:10:46 +0100 (Wed, 18 Mar 2009)
New Revision: 3949

Modified:
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
add new option to set the identity of a varnish instance and allow it to be accessed using server.identity

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-03-18 12:10:46 UTC (rev 3949)
@@ -623,6 +623,16 @@
 }
 
 const char*
+VRT_r_server_identity(struct sess *sp)
+{
+	if (heritage.identity[0] != '\0')
+		return heritage.identity;
+	else 
+		return heritage.name;
+}
+
+
+const char*
 VRT_r_server_hostname(struct sess *sp)
 {
 	if (vrt_hostname[0] == '\0')

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2009-03-18 12:10:46 UTC (rev 3949)
@@ -65,6 +65,7 @@
 	struct hash_slinger		*hash;
 
 	char				name[1024];
+	char                            identity[1024];
 };
 
 struct params {

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2009-03-18 12:10:46 UTC (rev 3949)
@@ -190,6 +190,7 @@
 	fprintf(stderr, FMT, "", "  -h simple_list");
 	fprintf(stderr, FMT, "", "  -h classic  [default]");
 	fprintf(stderr, FMT, "", "  -h classic,<buckets>");
+	fprintf(stderr, FMT, "-i identity", "Identity of varnish instance");
 	fprintf(stderr, FMT, "-l bytesize", "Size of shared memory log");
 	fprintf(stderr, FMT, "-n dir", "varnishd working directory");
 	fprintf(stderr, FMT, "-P file", "PID file");
@@ -399,6 +400,7 @@
 	unsigned F_flag = 0;
 	const char *b_arg = NULL;
 	const char *f_arg = NULL;
+	const char *i_arg = NULL;
 	const char *l_arg = "80m";
 	uintmax_t l_size;
 	const char *q;
@@ -450,7 +452,7 @@
 	cli_check(cli);
 
 	while ((o = getopt(argc, argv,
-	    "a:b:Cdf:Fg:h:l:n:P:p:S:s:T:t:u:Vw:")) != -1)
+	    "a:b:Cdf:Fg:h:i:l:n:P:p:S:s:T:t:u:Vw:")) != -1)
 		switch (o) {
 		case 'a':
 			MCF_ParamSet(cli, "listen_address", optarg);
@@ -477,6 +479,9 @@
 		case 'h':
 			h_arg = optarg;
 			break;
+		case 'i':
+			i_arg = optarg;
+			break;
 		case 'l':
 			l_arg = optarg;
 			break;
@@ -571,6 +576,17 @@
 		exit(1);
 	}
 
+
+	if (i_arg != NULL) {
+		size_t len;
+		if (snprintf(heritage.identity, sizeof heritage.identity, "%s", i_arg) > sizeof heritage.identity) {
+			fprintf(stderr, "Invalid identity name: %s\n",
+			    strerror(ENAMETOOLONG));
+			exit(1);
+		}
+	}
+	
+
 	if (n_arg != NULL)
 		openlog(n_arg, LOG_PID, LOG_LOCAL0);
 	else

Modified: trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc	2009-03-18 12:10:46 UTC (rev 3949)
@@ -39,6 +39,9 @@
 		set resp.proto = "HTTP/1.2";
 		set resp.response = "Naah, lets fail it";
 		set resp.status = 904;
+		# XXX should be moved to it's own test
+		set resp.http.x-served-by-hostname = server.hostname;
+		set resp.http.x-served-by-identity = server.identity;
 		set resp.http.foobar =
 		    resp.proto
 		    resp.status;

Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/include/vrt_obj.h	2009-03-18 12:10:46 UTC (rev 3949)
@@ -9,6 +9,7 @@
 struct sockaddr * VRT_r_client_ip(const struct sess *);
 struct sockaddr * VRT_r_server_ip(struct sess *);
 const char * VRT_r_server_hostname(struct sess *);
+const char * VRT_r_server_identity(struct sess *);
 int VRT_r_server_port(struct sess *);
 const char * VRT_r_req_request(const struct sess *);
 void VRT_l_req_request(const struct sess *, const char *, ...);

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-03-18 12:10:46 UTC (rev 3949)
@@ -322,13 +322,16 @@
 
 	/* ../../include/vrt_obj.h */
 
-	vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3880 2009-03-04 13:00:18Z ");
-	vsb_cat(sb, "phk $\n *\n * NB:  This file is machine generated, DO ");
-	vsb_cat(sb, "NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n");
+	vsb_cat(sb, "/*\n * $Id$\n");
+	vsb_cat(sb, " *\n * NB:  This file is machine generated, DO NOT EDI");
+	vsb_cat(sb, "T!\n *\n * Edit vcc_gen_obj.tcl instead\n");
 	vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct ");
 	vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses");
-	vsb_cat(sb, "s *);\nconst char * VRT_r_server_hostname(struct sess ");
-	vsb_cat(sb, "*);\nint VRT_r_server_port(struct sess *);\n");
+	vsb_cat(sb, "s *);\n<<<<<<< .mine\nconst char * VRT_r_server_hostna");
+	vsb_cat(sb, "me(struct sess *);\nconst char * VRT_r_server_identity");
+	vsb_cat(sb, "(struct sess *);\n=======\nconst char * VRT_r_server_h");
+	vsb_cat(sb, "ostname(struct sess *);\n>>>>>>> .r3947\n");
+	vsb_cat(sb, "int VRT_r_server_port(struct sess *);\n");
 	vsb_cat(sb, "const char * VRT_r_req_request(const struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_req_request(const struct sess *, const char");
 	vsb_cat(sb, " *, ...);\nconst char * VRT_r_req_url(const struct ses");

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-03-18 12:10:46 UTC (rev 3949)
@@ -56,6 +56,11 @@
 	{recv pipe pass hash miss hit fetch deliver                error }
 	"struct sess *"
     }
+    { server.identity
+	RO STRING
+	{recv pipe pass hash miss hit fetch deliver                error }
+	"struct sess *"
+    }
     { server.port
 	RO INT
 	{recv pipe pass hash miss hit fetch deliver                error }

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2009-03-18 11:25:43 UTC (rev 3948)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2009-03-18 12:10:46 UTC (rev 3949)
@@ -32,6 +32,13 @@
 	     | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
 	     | VCL_MET_ERROR
 	},
+	{ "server.identity", STRING, 15,
+	    "VRT_r_server_identity(sp)",	    NULL,
+	    V_RO,	    0,
+	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH
+	     | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+	     | VCL_MET_ERROR
+	},
 	{ "server.port", INT, 11,
 	    "VRT_r_server_port(sp)",	    NULL,
 	    V_RO,	    0,



More information about the varnish-commit mailing list