Commit 24861b93 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk/varnish-cache@2984 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 435ea12e
......@@ -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));
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment