r2751 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Fri Jun 20 23:33:22 CEST 2008
Author: phk
Date: 2008-06-20 23:33:21 +0200 (Fri, 20 Jun 2008)
New Revision: 2751
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_ban.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Give BAN_Add() an (option) cli argument so errors can be reported
but also give it a return value since we don't have a cli in VCL.
However, I'm not sure how we will report the error in VCL, so still
log the trouble in shmlog.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-06-20 21:16:22 UTC (rev 2750)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-06-20 21:33:21 UTC (rev 2751)
@@ -426,7 +426,7 @@
void VBE_SelectBackend(struct sess *sp);
/* cache_ban.c */
-void BAN_Add(const char *, int hash);
+int BAN_Add(struct cli *cli, const char *regexp, int hash);
void BAN_Init(void);
void BAN_NewObj(struct object *o);
void BAN_DestroyObj(struct object *o);
Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-06-20 21:16:22 UTC (rev 2750)
+++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-06-20 21:33:21 UTC (rev 2751)
@@ -65,22 +65,29 @@
*/
static struct ban * volatile ban_start;
-void
-BAN_Add(const char *regexp, int hash)
+int
+BAN_Add(struct cli *cli, const char *regexp, int hash)
{
struct ban *b;
+ char buf[512];
int i;
ALLOC_OBJ(b, BAN_MAGIC);
- XXXAN(b);
+ if (b == NULL) {
+ cli_out(cli, "Out of Memory");
+ cli_result(cli, CLIS_CANT);
+ return (-1);
+ }
i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (i) {
- char buf[512];
-
(void)regerror(i, &b->regexp, buf, sizeof buf);
+ regfree(&b->regexp);
VSL(SLT_Debug, 0, "REGEX: <%s>", buf);
- return;
+ cli_out(cli, "%s", buf);
+ cli_result(cli, CLIS_PARAM);
+ FREE_OBJ(b);
+ return (-1);
}
b->hash = hash;
b->ban = strdup(regexp);
@@ -89,6 +96,7 @@
VTAILQ_INSERT_HEAD(&ban_head, b, list);
ban_start = b;
UNLOCK(&ban_mtx);
+ return (0);
}
void
@@ -179,8 +187,7 @@
{
(void)priv;
- BAN_Add(av[2], 0);
- cli_out(cli, "URL_PURGE %s\n", av[2]);
+ (void)BAN_Add(cli, av[2], 0);
}
static void
@@ -188,8 +195,7 @@
{
(void)priv;
- BAN_Add(av[2], 1);
- cli_out(cli, "HASH_PURGE %s\n", av[2]);
+ (void)BAN_Add(cli, av[2], 1);
}
static void
@@ -211,7 +217,9 @@
if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL)
break;
cli_out(cli, "%5u %s \"%s\"\n",
- b0->refcount, b0->hash ? "hash" : "url ", b0->ban);
+ b0->refcount,
+ b0->hash ? "hash" : "url ",
+ b0->ban);
}
}
@@ -236,5 +244,5 @@
MTX_INIT(&ban_mtx);
CLI_AddFuncs(PUBLIC_CLI, ban_cmds);
/* Add an initial ban, since the list can never be empty */
- BAN_Add(".", 0);
+ (void)BAN_Add(NULL, ".", 0);
}
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-06-20 21:16:22 UTC (rev 2750)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-06-20 21:33:21 UTC (rev 2751)
@@ -638,7 +638,7 @@
VRT_purge(const char *regexp, int hash)
{
- BAN_Add(regexp, hash);
+ (void)BAN_Add(NULL, regexp, hash);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list