summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-14 22:24:59 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-23 20:34:17 (GMT)
commitb946286617a36e74b5ee6efd09930ed18683afd7 (patch) (side-by-side diff)
treefa7d72320520bc9b0681c3058f8b2777d49f190b
parentc90ba2a863a446b51b9ee960cead69a4b2884045 (diff)
downloadvmod-variable-b946286617a36e74b5ee6efd09930ed18683afd7.tar.gz
vmod-variable-b946286617a36e74b5ee6efd09930ed18683afd7.tar.bz2
Store per-session symtabs in private storage. Drop v.3 support.
* src/variable.c (symtabv, symtabc) (symtab_mtx): Remove globals. (get_symtab): Save symtab in private data pointer. (vmod_clear, vmod_get_string) (vmod_set_string, vmod_get, vmod_set) (DEFGET, DEFSET) (vmod_defined, vmod_type_of) (vmod_unset, vmod_regset) (vmod_queryset): Expect struct vmod_priv * as 2nd argument. * src/variable.vcc: Change prototypes. * NEWS: Version 1.0.90 * configure.ac: Update.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS11
-rw-r--r--configure.ac53
-rw-r--r--src/Makefile.am19
-rw-r--r--src/variable.c108
-rw-r--r--src/variable.vcc32
5 files changed, 111 insertions, 112 deletions
diff --git a/NEWS b/NEWS
index 1c3e867..c0d662a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,15 @@
-vmod-variable -- history of user-visible changes. 2015-02-16
-Copyright (C) 2015 Sergey Poznyakoff
+vmod-variable -- history of user-visible changes. 2016-01-15
+Copyright (C) 2015-2016 Sergey Poznyakoff
See the end of file for copying conditions.
Please send vmod-variable bug reports to <gray@gnu.org>
+Version 1.0.90, (Git)
+
+Fix coredumps.
+
+
Version 1.0, 2015-02-16
Initial release
@@ -12,7 +17,7 @@ Initial release
=========================================================================
Copyright information:
-Copyright (C) 2015 Sergey Poznyakoff
+Copyright (C) 2015-2016 Sergey Poznyakoff
Permission is granted to anyone to make or distribute verbatim copies
of this document as received, in any medium, provided that the
diff --git a/configure.ac b/configure.ac
index 9a69658..4f328e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
# This file is part of vmod-variable -*- autoconf -*-
-# Copyright (C) 2015 Sergey Poznyakoff
+# Copyright (C) 2015-2016 Sergey Poznyakoff
#
# Vmod-variable is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with vmod-variable. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ(2.69)
-AC_INIT([vmod-variable], [1.0], [gray@gnu.org])
+AC_INIT([vmod-variable], [1.0.90], [gray@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/variable.vcc)
@@ -71,17 +71,36 @@ case "$VARNISHSRC" in
esac
VARNISHSRC=`cd $VARNISHSRC && pwd`
-VARNISHVERSION=
-AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
- [VARNISHVERSION=3],
- [AC_CHECK_FILE([$VARNISHSRC/include/vapi/vsm.h],
- [VARNISHVERSION=4],
- [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]) ])
-AC_SUBST([VARNISHVERSION],$VARNISHVERSION)
-
-AC_DEFINE_UNQUOTED([VARNISHVERSION],$VARNISHVERSION,[Varnish major version number])
-AM_CONDITIONAL([VARNISH3],[test $VARNISHVERSION -eq 3])
-AM_CONDITIONAL([VARNISH4],[test $VARNISHVERSION -eq 4])
+
+# pkg-config
+PKG_PROG_PKG_CONFIG
+PKG_CHECK_MODULES([libvarnishapi], [varnishapi])
+
+varnishapi_version() {
+ VARNISHAPI_MAJOR=$1
+ VARNISHAPI_MINOR=$2
+ VARNISHAPI_PATCH=$3
+}
+
+v=$($PKG_CONFIG --modversion varnishapi)
+if test -n "$v"; then
+ save_IFS=$IFS
+ IFS='.'
+ varnishapi_version $v
+ IFS=$save_IFS
+else
+ AC_MSG_ERROR([unknown varnishapi version])
+fi
+
+if test $VARNISHAPI_MAJOR -ne 4; then
+ AC_MSG_ERROR([unsupported varnishapi version])
+fi
+
+case $VARNISHAPI_MINOR in
+0) AC_MSG_ERROR([unsupported varnishapi version]);;
+1) ;;
+*) AC_MSG_WARN([varnishapi minor version probably unsupported])
+esac
# Check that varnishtest is built in the varnish source directory
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
@@ -98,7 +117,7 @@ AC_ARG_WITH([vmoddir],
/*) VMODDIR=$withval;;
no) unset VMODDIR;;
*) AC_MSG_ERROR([argument to --with-vmoddir must be absolute pathname])
- esac],[VMODDIR=`pkg-config --variable=vmoddir varnishapi`
+ esac],[VMODDIR=$($PKG_CONFIG --variable=vmoddir varnishapi)
if test -z "$VMODDIR"; then
AC_MSG_FAILURE([cannot determine vmod installation directory])
fi])
@@ -112,10 +131,12 @@ AC_CONFIG_COMMANDS([status],[
delim="-------------------------------------------------------------------"
echo ""
echo $delim
-echo "Building for Varnish version $VARNISHVERSION"
+echo "Building for Varnish version $VARNISHAPI_MAJOR.$VARNISHAPI_MINOR"
echo $delim
],
-[VARNISHVERSION=$VARNISHVERSION])
+[VARNISHAPI_MAJOR=$VARNISHAPI_MAJOR
+VARNISHAPI_MINOR=$VARNISHAPI_MINOR
+])
AC_CONFIG_TESTDIR(tests)
AC_CONFIG_FILES([tests/Makefile tests/atlocal])
diff --git a/src/Makefile.am b/src/Makefile.am
index ee04055..81c5b4e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,21 +38,10 @@ variable.lo: vcc_if.h
CLEANFILES = vcc_if.c vcc_if.h *.rst
-if VARNISH4
- vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
- vmodtoolargs = --strict
- vccfile = $(top_srcdir)/src/variable.vcc
-else
- vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
- vmodtoolargs =
- vccfile = variable.vcc3
-
-variable.vcc3: $(top_srcdir)/src/variable.vcc
- CLEANFILES += variable.vcc3
-endif
-
-.vcc.vcc3:
- sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@
+vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
+vmodtoolargs = --strict
+vccfile = $(top_srcdir)/src/variable.vcc
+
vcc_if.c vcc_if.h: $(vmodtool) $(vccfile)
@PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile)
diff --git a/src/variable.c b/src/variable.c
index e6bad1a..d9030a3 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -18,25 +18,16 @@
#include <stdlib.h>
#include <stdarg.h>
#include <syslog.h>
+#include <errno.h>
#include <ctype.h>
#include <pcre.h>
#include "vrt.h"
#include "vcc_if.h"
#include "pthread.h"
-#if VARNISHVERSION == 3
-# include "bin/varnishd/cache.h"
-# define VCL_VOID void
-# define VCL_STRING const char *
-# define VCL_REAL double
-# define VCL_DURATION double
-# define WS_Copy(w,s,l) WS_Dup(w,s)
-# define VARIABLE_CTX struct sess *
-# define WSPTR(s) ((s)->wrk->ws)
-#else
-# include "bin/varnishd/cache/cache.h"
-# define VARIABLE_CTX const struct vrt_ctx *
-# define WSPTR(s) ((s)->ws)
-#endif
+
+#include "bin/varnishd/cache/cache.h"
+#define VARIABLE_CTX const struct vrt_ctx *
+#define WSPTR(s) ((s)->ws)
/* |hash_size| defines a sequence of symbol table sizes. These are prime
numbers, each of which is approximately twice its predecessor. */
@@ -310,10 +301,6 @@ symtab_free(struct symtab *st)
}
-static struct symtab **symtabv;
-static size_t symtabc;
-static pthread_mutex_t symtab_mtx = PTHREAD_MUTEX_INITIALIZER;
-
static struct symtab *global_symtab;
static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -381,28 +368,20 @@ vmod_global_unset(VARIABLE_CTX ctx, VCL_STRING name)
AZ(pthread_mutex_unlock(&global_mtx));
}
+static void
+priv_symtab_free(void *p)
+{
+ symtab_free(p);
+}
+
static struct symtab *
-get_symtab(VARIABLE_CTX ctx)
+get_symtab(struct vmod_priv *priv)
{
- struct symtab *st;
- int fd = ctx->req->sp->fd;
-
- assert(fd >= 0);
- AZ(pthread_mutex_lock(&symtab_mtx));
- if (symtabc <= fd) {
- size_t n = fd + 1;
- symtabv = realloc(symtabv, n * sizeof(symtabv[0]));
- while (symtabc < n)
- symtabv[symtabc++] = NULL;
+ if (!priv->priv) {
+ priv->priv = symtab_create();
+ priv->free = priv_symtab_free;
}
- if (!symtabv[fd])
- symtabv[fd] = symtab_create();
- st = symtabv[fd];
- if (st->vxid != ctx->req->sp->vxid)
- symtab_clear(st);
- st->vxid = ctx->req->sp->vxid;
- AZ(pthread_mutex_unlock(&symtab_mtx));
- return st;
+ return priv->priv;
}
#define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL)
@@ -424,24 +403,25 @@ defvar(struct symtab *vt, const char *name, enum variable_type t,
}
VCL_VOID
-vmod_clear(VARIABLE_CTX ctx)
+vmod_clear(VARIABLE_CTX ctx, struct vmod_priv *priv)
{
- symtab_clear(get_symtab(ctx));
+ symtab_clear(get_symtab(priv));
}
VCL_STRING
-vmod_get_string(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_get_string(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- struct variable *var = getvar(get_symtab(ctx), name);
+ struct variable *var = getvar(get_symtab(priv), name);
if (var && var->type == variable_string)
return var->v.s;
return NULL;
}
VCL_VOID
-vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
+vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING name, VCL_STRING value)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct variable *var = defvar(vt, name, variable_unset, NULL);
var->type = variable_string;
var->v.s = strdup(value ? value : "");
@@ -449,23 +429,25 @@ vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
}
VCL_STRING
-vmod_get(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_get(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- return vmod_get_string(ctx, name);
+ return vmod_get_string(ctx, priv, name);
}
VCL_VOID
-vmod_set(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
+vmod_set(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING name, VCL_STRING value)
{
- vmod_set_string(ctx, name, value);
+ vmod_set_string(ctx, priv, name, value);
}
#define __cat__(a,b) a ## b
#define DEFGET(r_type, vcl_type, memb) \
vcl_type \
-__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \
+__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
+ VCL_STRING name) \
{ \
- struct variable *var = getvar(get_symtab(ctx), name); \
+ struct variable *var = getvar(get_symtab(priv), name); \
if (var && var->type == __cat__(variable_,r_type)) \
return var->v.memb; \
return 0; \
@@ -473,10 +455,11 @@ __cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \
#define DEFSET(r_type, vcl_type, memb) \
VCL_VOID \
-__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, VCL_STRING name, \
+__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
+ VCL_STRING name, \
vcl_type value) \
{ \
- struct symtab *vt = get_symtab(ctx); \
+ struct symtab *vt = get_symtab(priv); \
struct variable *var = defvar(vt, name, variable_unset, NULL); \
var->type = __cat__(variable_,r_type); \
var->v.memb = value; \
@@ -491,22 +474,22 @@ DEF(real, VCL_REAL, r)
DEF(duration, VCL_DURATION, d)
VCL_BOOL
-vmod_defined(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_defined(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- return !!getvar(get_symtab(ctx), name);
+ return !!getvar(get_symtab(priv), name);
}
VCL_STRING
-vmod_type_of(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_type_of(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- struct variable *var = getvar(get_symtab(ctx), name);
+ struct variable *var = getvar(get_symtab(priv), name);
return typestr[var ? var->type : variable_unset];
}
VCL_VOID
-vmod_unset(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_unset(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- symtab_remove(get_symtab(ctx), name);
+ symtab_remove(get_symtab(priv), name);
}
static void
@@ -718,10 +701,10 @@ setval(union value *val, const char *s, enum variable_type type, char **err)
}
VCL_VOID
-vmod_regset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING rxs,
- VCL_STRING input)
+vmod_regset(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING vars, VCL_STRING rxs, VCL_STRING input)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct vardef *head = NULL, *tail = NULL, *def;
size_t count = 0;
size_t n;
@@ -894,9 +877,10 @@ define_param(struct symtab *vt, struct vardef *def,
}
VCL_VOID
-vmod_queryset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING query)
+vmod_queryset(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING vars, VCL_STRING query)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct vardef *head = NULL, *tail = NULL, *def;
size_t count = 0;
const char *v = vars;
diff --git a/src/variable.vcc b/src/variable.vcc
index 3745a8d..7a3151f 100644
--- a/src/variable.vcc
+++ b/src/variable.vcc
@@ -22,26 +22,26 @@ Due to limitations of the vmodtool.py utility, this document contains
only prototypes of the functions provided by the **vmod-variable** module.
For a detailed documentation, please see vmod-variable(3) manual page.
-$Function VOID set(STRING, STRING)
-$Function STRING get(STRING)
+$Function VOID set(PRIV_TASK, STRING, STRING)
+$Function STRING get(PRIV_TASK, STRING)
$Function VOID global_set(STRING, STRING)
$Function STRING global_get(STRING)
-$Function VOID set_int(STRING, INT)
-$Function INT get_int(STRING)
-$Function VOID set_string(STRING, STRING)
-$Function STRING get_string(STRING)
-$Function VOID set_real(STRING, REAL)
-$Function REAL get_real(STRING)
-$Function VOID set_duration(STRING, DURATION)
-$Function DURATION get_duration(STRING)
-$Function VOID clear()
+$Function VOID set_int(PRIV_TASK, STRING, INT)
+$Function INT get_int(PRIV_TASK, STRING)
+$Function VOID set_string(PRIV_TASK, STRING, STRING)
+$Function STRING get_string(PRIV_TASK, STRING)
+$Function VOID set_real(PRIV_TASK, STRING, REAL)
+$Function REAL get_real(PRIV_TASK, STRING)
+$Function VOID set_duration(PRIV_TASK, STRING, DURATION)
+$Function DURATION get_duration(PRIV_TASK, STRING)
+$Function VOID clear(PRIV_TASK)
$Function VOID global_clear()
$Function BOOL global_defined(STRING)
$Function VOID global_unset(STRING)
-$Function BOOL defined(STRING)
-$Function STRING type_of(STRING)
-$Function VOID unset(STRING)
-$Function VOID regset(STRING, STRING, STRING)
-$Function VOID queryset(STRING, STRING)
+$Function BOOL defined(PRIV_TASK, STRING)
+$Function STRING type_of(PRIV_TASK, STRING)
+$Function VOID unset(PRIV_TASK, STRING)
+$Function VOID regset(PRIV_TASK, STRING, STRING, STRING)
+$Function VOID queryset(PRIV_TASK, STRING, STRING)

Return to:

Send suggestions and report system problems to the System administrator.