Commit dd95dca9 by Geoff Simmons

Use VRT_fail() for failures in vcl_init, as now required by Varnish.

parent e5466e98
......@@ -28,25 +28,16 @@
#include "vmod_re2.h"
/* XXX: replace this with VRT_fail() */
void
errmsg(VRT_CTX, const char *fmt, ...)
{
va_list args;
AZ(ctx->method & VCL_MET_TASK_H);
va_start(args, fmt);
if (ctx->vsl)
VSLbv(ctx->vsl, SLT_VCL_Error, fmt, args);
else
VSLv(SLT_VCL_Error, 0, fmt, args);
va_end(args);
if (ctx->method == VCL_MET_INIT) {
AN(ctx->msg);
va_start(args, fmt);
VSB_vprintf(ctx->msg, fmt, args);
VSB_putc(ctx->msg, '\n');
va_end(args);
VRT_handling(ctx, VCL_RET_FAIL);
}
}
......@@ -136,7 +136,7 @@ vmod_set__init(VRT_CTX, struct vmod_re2_set **setp, const char *vcl_name,
dot_nl, case_sensitive, perl_classes,
word_boundary, one_line))
!= NULL) {
VERR(ctx, "new %s = re2.set(): %s", vcl_name, err);
VFAIL(ctx, "new %s = re2.set(): %s", vcl_name, err);
return;
}
......@@ -216,13 +216,13 @@ vmod_set_add(VRT_CTX, struct vmod_re2_set *set, VCL_STRING pattern,
}
if (set->compiled) {
VERR(ctx, ERR_PREFIX "%s has already been compiled",
set->vcl_name, pattern, set->vcl_name);
VFAIL(ctx, ERR_PREFIX "%s has already been compiled",
set->vcl_name, pattern, set->vcl_name);
return;
}
if ((err = vre2set_add(set->set, pattern, &n)) != NULL) {
VERR(ctx, ERR_PREFIX "Cannot compile '%.40s': %s",
set->vcl_name, pattern, pattern, err);
VFAIL(ctx, ERR_PREFIX "Cannot compile '%.40s': %s",
set->vcl_name, pattern, pattern, err);
return;
}
......@@ -230,8 +230,8 @@ vmod_set_add(VRT_CTX, struct vmod_re2_set *set, VCL_STRING pattern,
if ((set->string = realloc(set->string,
(n + 1) * (sizeof(char *))))
== NULL) {
VERRNOMEM(ctx, ERR_PREFIX "adding string %s",
set->vcl_name, pattern, string);
VFAILNOMEM(ctx, ERR_PREFIX "adding string %s",
set->vcl_name, pattern, string);
return;
}
set->string[n] = strdup(string);
......@@ -242,9 +242,9 @@ vmod_set_add(VRT_CTX, struct vmod_re2_set *set, VCL_STRING pattern,
if ((set->backend = realloc(set->backend,
(n + 1) * (sizeof(VCL_BACKEND))))
== NULL) {
VERRNOMEM(ctx, ERR_PREFIX "adding backend %s",
set->vcl_name, pattern,
VRT_BACKEND_string(backend));
VFAILNOMEM(ctx, ERR_PREFIX "adding backend %s",
set->vcl_name, pattern,
VRT_BACKEND_string(backend));
return;
}
set->backend[n] = backend;
......@@ -304,17 +304,17 @@ vmod_set_compile(VRT_CTX, struct vmod_re2_set *set)
return;
}
if (set->npatterns == 0) {
VERR(ctx, ERR_PREFIX "no patterns were added", set->vcl_name);
VFAIL(ctx, ERR_PREFIX "no patterns were added", set->vcl_name);
return;
}
if (set->compiled) {
VERR(ctx, ERR_PREFIX "%s has already been compiled",
VFAIL(ctx, ERR_PREFIX "%s has already been compiled",
set->vcl_name, set->vcl_name);
return;
}
if ((err = vre2set_compile(set->set)) != NULL) {
VERR(ctx, ERR_PREFIX "failed, possibly insufficient memory",
VFAIL(ctx, ERR_PREFIX "failed, possibly insufficient memory",
set->vcl_name);
return;
}
......
......@@ -257,14 +257,14 @@ vmod_regex__init(const struct vrt_ctx *ctx, struct vmod_re2_regex **rep,
longest_match, max_mem, literal, never_nl, dot_nl,
never_capture, case_sensitive, perl_classes,
word_boundary, one_line)) != NULL) {
VERR(ctx, "Cannot compile '%.40s' in %s constructor: %s",
pattern, vcl_name, err);
VFAIL(ctx, "Cannot compile '%.40s' in %s constructor: %s",
pattern, vcl_name, err);
return;
}
if (! never_capture) {
if ((err = vre2_ngroups(re->vre2, &re->ngroups)) != NULL) {
VERR(ctx, "Cannot obtain number of capturing groups in "
"%s constructor: %s", vcl_name, err);
VFAIL(ctx, "Cannot obtain number of capturing groups "
"in %s constructor: %s", vcl_name, err);
return;
}
assert(re->ngroups >= 0);
......
......@@ -50,6 +50,12 @@
#define VERRNOMEM(ctx, fmt, ...) \
VERR((ctx), fmt ", out of space", __VA_ARGS__)
#define VFAIL(ctx, fmt, ...) \
VRT_fail((ctx), "vmod re2 error: " fmt, __VA_ARGS__)
#define VFAILNOMEM(ctx, fmt, ...) \
VFAIL((ctx), fmt ", out of space", __VA_ARGS__)
struct vmod_re2_regex {
unsigned magic;
#define VMOD_RE2_REGEX_MAGIC 0x5c3f6f24
......
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