]> err.no Git - varnish/commitdiff
Add a "panic" vcl command, which does what you would expect.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Jul 2008 08:06:16 +0000 (08:06 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Jul 2008 08:06:16 +0000 (08:06 +0000)
Takes a string argument, so it is possible to do:

 panic "Trouble with " req.url " (not the way I expected it!);

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

varnish-cache/bin/varnishd/cache_panic.c
varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/include/vrt.h
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_fixed_token.c

index 890fd633eabebfa12434b81da2a0ed4635298502..8265b95a3579a931dec9081b5556e34397988ef4 100644 (file)
@@ -246,16 +246,24 @@ pan_ic(const char *func, const char *file, int line, const char *cond, int err,
        const char *q;
        const struct sess *sp;
 
-       if (xxx) {
+       switch(xxx) {
+       case 2:
+               vsb_printf(vsp,
+                   "Panic from VCL:\n%s\n", cond);
+               break;
+       case 1:
                vsb_printf(vsp,
                    "Missing errorhandling code in %s(), %s line %d:\n"
                    "  Condition(%s) not true.",
                    func, file, line, cond);
-       } else {
+               break;
+       default:
+       case 0:
                vsb_printf(vsp,
                    "Assert error in %s(), %s line %d:\n"
                    "  Condition(%s) not true.",
                    func, file, line, cond);
+               break;
        }
        if (err)
                vsb_printf(vsp, "  errno = %d (%s)", err, strerror(err));
index 2ac8eada1daf3f62fa32eb24dee31efe1de0955a..6c08a1ad573100e1af96e0c5637ecb75175a3498 100644 (file)
@@ -626,6 +626,20 @@ VRT_Rollback(struct sess *sp)
        
 /*--------------------------------------------------------------------*/
 
+void
+VRT_panic(struct sess *sp, const char *str, ...)
+{
+       va_list ap;
+       char *b;
+
+       va_start(ap, str);
+       b = vrt_assemble_string(sp->http, "PANIC: ", str, ap);
+       va_end(ap);
+       lbv_assert("VCL", "", 0, b, 0, 2);
+}
+
+/*--------------------------------------------------------------------*/
+
 void
 VRT_purge(const char *regexp, int hash)
 {
index 013c0778437f25965b582e03a7cf006e2921e814..d5d4cb1f1c4fa9c3ca3a2719a311d69bb6d54447 100644 (file)
@@ -141,6 +141,7 @@ int VRT_re_match(const char *, void *re);
 int VRT_re_test(struct vsb *, const char *, int sub);
 const char *VRT_regsub(const struct sess *sp, int all, const char *, void *, const char *);
 
+void VRT_panic(struct sess *sp,  const char *, ...);
 void VRT_purge(const char *, int hash);
 
 void VRT_count(const struct sess *, unsigned);
index f419490641f47037a846fd212af0c96a24c4f2d1..59c248380cc98249978d79a8754348bef87136c6 100644 (file)
@@ -355,6 +355,24 @@ parse_esi(struct tokenlist *tl)
 
 /*--------------------------------------------------------------------*/
 
+static void
+parse_panic(struct tokenlist *tl)
+{
+       vcc_NextToken(tl);
+       
+       Fb(tl, 1, "VRT_panic(sp, ");
+       if (!vcc_StringVal(tl)) {
+               vcc_ExpectedStringval(tl);
+               return;
+       }
+       do 
+               Fb(tl, 0, ", ");
+       while (vcc_StringVal(tl));
+       Fb(tl, 0, " 0);\n");
+}
+
+/*--------------------------------------------------------------------*/
+
 typedef void action_f(struct tokenlist *tl);
 
 static struct action_table {
@@ -367,15 +385,17 @@ static struct action_table {
 #include "vcl_returns.h"
 #undef VCL_RET_MAC
 #undef VCL_RET_MAC_E
-       { "call",       parse_call },
-       { "set",        parse_set },
-       { "unset",      parse_unset },
-       { "remove",     parse_unset }, /* backward compatibility */
-       { "purge_url",  parse_purge_url },
-       { "purge_hash", parse_purge_hash },
-       { "esi",        parse_esi },
-
-       { NULL,         NULL }
+
+       /* Keep list sorted from here */
+       { "call",               parse_call },
+       { "esi",                parse_esi },
+       { "panic",              parse_panic },
+       { "purge_hash",         parse_purge_hash },
+       { "purge_url",          parse_purge_url },
+       { "remove",             parse_unset }, /* backward compatibility */
+       { "set",                parse_set },
+       { "unset",              parse_unset },
+       { NULL,                 NULL }
 };
 
 void
index 8254a75f8c3037a9f06bddb12611a6dec42e7bf9..14634afc3db9d318d3caf0ad5969fadfaf03be28 100644 (file)
@@ -422,6 +422,7 @@ vcl_output_lang_h(struct vsb *sb)
        vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n");
        vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all, const char *, void *, const char *);\n");
        vsb_cat(sb, "\n");
+       vsb_cat(sb, "void VRT_panic(struct sess *sp,  const char *, ...);\n");
        vsb_cat(sb, "void VRT_purge(const char *, int hash);\n");
        vsb_cat(sb, "\n");
        vsb_cat(sb, "void VRT_count(const struct sess *, unsigned);\n");