]> err.no Git - varnish/commitdiff
Give BAN_Add() an (option) cli argument so errors can be reported
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 21:33:21 +0000 (21:33 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 21:33:21 +0000 (21:33 +0000)
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.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2751 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_ban.c
varnish-cache/bin/varnishd/cache_vrt.c

index fcb12dc7bbbe41029e04207f13b2766426932ba3..be10e374513cc2b21640be4067cf5c1b36257134 100644 (file)
@@ -426,7 +426,7 @@ void VBE_AddHostHeader(struct sess *sp);
 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);
index 05cf412a6fce87255e1bf6d8bbef8c3e8b473075..519b60682ace6c6e18c2e9e2e7d7f79f4b1605b1 100644 (file)
@@ -65,22 +65,29 @@ static MTX ban_mtx;
  */
 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 @@ BAN_Add(const char *regexp, int hash)
        VTAILQ_INSERT_HEAD(&ban_head, b, list);
        ban_start = b;
        UNLOCK(&ban_mtx);
+       return (0);
 }
 
 void
@@ -179,8 +187,7 @@ ccf_purge_url(struct cli *cli, const char * const *av, void *priv)
 {
 
        (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 @@ ccf_purge_hash(struct cli *cli, const char * const *av, void *priv)
 {
 
        (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 @@ ccf_purge_list(struct cli *cli, const char * const *av, void *priv)
                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 @@ BAN_Init(void)
        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);
 }
index bf2f21f549227ed9d6c9a94452a2ea5fcde09b8d..9c2bb23049bce2052976c35bbdff977f4b01c571 100644 (file)
@@ -638,7 +638,7 @@ void
 VRT_purge(const char *regexp, int hash)
 {
        
-       BAN_Add(regexp, hash);
+       (void)BAN_Add(NULL, regexp, hash);
 }
 
 /*--------------------------------------------------------------------