From: phk Date: Tue, 22 Jul 2008 08:06:16 +0000 (+0000) Subject: Add a "panic" vcl command, which does what you would expect. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75870abfc9b63ff87a24727a5ce7daa73dea975b;p=varnish Add a "panic" vcl command, which does what you would expect. 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 --- diff --git a/varnish-cache/bin/varnishd/cache_panic.c b/varnish-cache/bin/varnishd/cache_panic.c index 890fd633..8265b95a 100644 --- a/varnish-cache/bin/varnishd/cache_panic.c +++ b/varnish-cache/bin/varnishd/cache_panic.c @@ -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)); diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 2ac8eada..6c08a1ad 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -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) { diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 013c0778..d5d4cb1f 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -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); diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index f4194906..59c24838 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -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 diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 8254a75f..14634afc 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -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");