r451 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Jul 12 10:56:09 CEST 2006


Author: phk
Date: 2006-07-12 10:56:09 +0200 (Wed, 12 Jul 2006)
New Revision: 451

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_main.c
   trunk/varnish-cache/bin/varnishd/cache_vcl.c
Log:
Fix CLI "config.load"


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-12 08:44:56 UTC (rev 450)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-12 08:56:09 UTC (rev 451)
@@ -287,7 +287,7 @@
 /* cache_vcl.c */
 void RelVCL(struct VCL_conf *vc);
 struct VCL_conf *GetVCL(void);
-int CVCL_Load(const char *fn, const char *name);
+int CVCL_Load(const char *fn, const char *name, struct cli *cli);
 
 #define VCL_RET_MAC(l,u,b)
 #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2006-07-12 08:44:56 UTC (rev 450)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2006-07-12 08:56:09 UTC (rev 451)
@@ -105,7 +105,7 @@
 	setbuf(stderr, NULL);
 	printf("Child starts\n");
 
-	CVCL_Load(heritage.vcl_file, "boot");
+	CVCL_Load(heritage.vcl_file, "boot", NULL);
 	AZ(pthread_mutex_init(&sessmtx, NULL));
 	VBE_Init();
 	VSL_Init();

Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vcl.c	2006-07-12 08:44:56 UTC (rev 450)
+++ trunk/varnish-cache/bin/varnishd/cache_vcl.c	2006-07-12 08:56:09 UTC (rev 451)
@@ -58,30 +58,59 @@
 
 /*--------------------------------------------------------------------*/
 
+static struct vcls *
+find_vcls(const char *name)
+{
+	struct vcls *vcl;
+
+	TAILQ_FOREACH(vcl, &vcl_head, list)
+		if (!strcmp(vcl->name, name))
+			return (vcl);
+	return (NULL);
+}
+
 int
-CVCL_Load(const char *fn, const char *name)
+CVCL_Load(const char *fn, const char *name, struct cli *cli)
 {
 	struct vcls *vcl;
 
+	vcl = find_vcls(name);
+	if (vcl != NULL) {
+		if (cli == NULL)
+			fprintf(stderr, "Config '%s' already loaded", name);
+		else 
+			cli_out(cli, "Config '%s' already loaded", name);
+		return (1);
+	}
+
 	vcl = calloc(sizeof *vcl, 1);
 	assert(vcl != NULL);
 
 	vcl->dlh = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
 	unlink(fn);
 	if (vcl->dlh == NULL) {
-		fprintf(stderr, "dlopen(%s): %s\n", fn, dlerror());
+		if (cli == NULL)
+			fprintf(stderr, "dlopen(%s): %s\n", fn, dlerror());
+		else
+			cli_out(cli, "dlopen(%s): %s\n", fn, dlerror());
 		free(vcl);
 		return (1);
 	}
 	vcl->conf = dlsym(vcl->dlh, "VCL_conf");
 	if (vcl->conf == NULL) {
-		fprintf(stderr, "No VCL_conf symbol\n");
+		if (cli == NULL)
+			fprintf(stderr, "No VCL_conf symbol\n");
+		else 
+			cli_out(cli, "No VCL_conf symbol\n");
 		dlclose(vcl->dlh);
 		free(vcl);
 		return (1);
 	}
 	if (vcl->conf->magic != VCL_CONF_MAGIC) {
-		fprintf(stderr, "Wrong VCL_CONF_MAGIC\n");
+		if (cli == NULL) 
+			fprintf(stderr, "Wrong VCL_CONF_MAGIC\n");
+		else
+			cli_out(cli, "Wrong VCL_CONF_MAGIC\n");
 		dlclose(vcl->dlh);
 		free(vcl);
 		return (1);
@@ -93,7 +122,10 @@
 	if (active_vcl == NULL)
 		active_vcl = vcl;
 	AZ(pthread_mutex_unlock(&sessmtx));
-	fprintf(stderr, "Loaded \"%s\" as \"%s\"\n", fn , name);
+	if (cli == NULL)
+		fprintf(stderr, "Loaded \"%s\" as \"%s\"\n", fn , name);
+	else 
+		cli_out(cli, "Loaded \"%s\" as \"%s\"\n", fn , name);
 	vcl->conf->init_func();
 	return (0);
 }
@@ -111,57 +143,12 @@
 	}
 }
 
-static struct vcls *
-find_vcls(const char *name)
-{
-	struct vcls *vcl;
-
-	TAILQ_FOREACH(vcl, &vcl_head, list)
-		if (!strcmp(vcl->name, name))
-			return (vcl);
-	return (NULL);
-}
-
 void
 cli_func_config_load(struct cli *cli, char **av, void *priv __unused)
 {
-	struct vcls *vcl;
 
-	vcl = find_vcls(av[2]);
-	if (vcl != NULL) {
-		cli_out(cli, "Config '%s' already loaded", av[2]);
+	if (CVCL_Load(av[3], av[2], cli))
 		cli_result(cli, CLIS_PARAM);
-		return;
-	}
-	vcl = calloc(sizeof *vcl, 1);
-	assert(vcl != NULL);
-
-	vcl->dlh = dlopen(av[3], RTLD_NOW | RTLD_LOCAL);
-	if (vcl->dlh == NULL) {
-		cli_out(cli, "dlopen(%s): %s\n", av[3], dlerror());
-		cli_result(cli, CLIS_PARAM);
-		free(vcl);
-		return;
-	}
-	vcl->conf = dlsym(vcl->dlh, "VCL_conf");
-	if (vcl->conf == NULL) {
-		cli_out(cli, "No VCL_conf symbol\n");
-		cli_result(cli, CLIS_PARAM);
-		dlclose(vcl->dlh);
-		free(vcl);
-		return;
-	}
-	if (vcl->conf->magic != VCL_CONF_MAGIC) {
-		cli_out(cli, "Wrong VCL_CONF_MAGIC\n");
-		cli_result(cli, CLIS_PARAM);
-		dlclose(vcl->dlh);
-		free(vcl);
-		return;
-	}
-	vcl->name = strdup(av[2]);
-	assert(vcl->name != NULL);
-	TAILQ_INSERT_TAIL(&vcl_head, vcl, list);
-	cli_out(cli, "Loaded \"%s\" from \"%s\"\n", vcl->name , av[3]);
 	return;
 }
 




More information about the varnish-commit mailing list