aboutsummaryrefslogtreecommitdiff
path: root/src/binlog.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 16:28:19 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 16:34:10 +0200
commitfffbbfb089847644e2b0281faba2fa892df4f8b9 (patch)
tree83899ca03d92bdb4100c413904c83385ca0c7d6c /src/binlog.c
parentc16de06862f9b2106dcb7810fc20856689ef2aa6 (diff)
downloadvmod-binlog-fffbbfb089847644e2b0281faba2fa892df4f8b9.tar.gz
vmod-binlog-fffbbfb089847644e2b0281faba2fa892df4f8b9.tar.bz2
Support for VCL 4.0
* configure.ac: Version 1.0.91 Detect varnish version and set variables and conditionals accordingly. * NEWS: Update. * src/.gitignore: Update. * src/Makefile.am: Always build vcc_if.c and vcc_if.h. Don't distribute them. * src/binlog.c: Use VCL data type. Define them for VCL 3.0. (vmod_init): Fix premature memory deallocation. * src/vmod.vcc: Rewrite in VCL 4.0 syntax. * tests/atlocal.in (ret_vcl_recv): New variable. * tests/test01.at (vcl_recv): Return $ret_vcl_recv. * tests/test02.at: Likewise.
Diffstat (limited to 'src/binlog.c')
-rw-r--r--src/binlog.c66
1 files changed, 39 insertions, 27 deletions
diff --git a/src/binlog.c b/src/binlog.c
index 45299f2..e9fb16e 100644
--- a/src/binlog.c
+++ b/src/binlog.c
@@ -29,9 +29,20 @@
#include <time.h>
#include "vrt.h"
#include "vcc_if.h"
-#include "bin/varnishd/cache.h"
+#if VARNISHVERSION == 3
+# include "bin/varnishd/cache.h"
+# define VCL_VOID void
+# define VCL_STRING const char *
+# define MOD_CTX struct sess *
+# define WSPTR(s) ((s)->wrk->ws)
+#else
+# include "bin/varnishd/cache/cache.h"
+# define MOD_CTX const struct vrt_ctx *
+# define WSPTR(s) ((s)->ws)
+#endif
#include "vmod-binlog.h"
#include "pack.h"
+#include "pthread.h"
#ifndef O_SEARCH
# define O_SEARCH 0
@@ -262,7 +273,7 @@ make_key()
}
void
-vmod_init(struct sess *sp, struct vmod_priv *priv,
+vmod_init(MOD_CTX ctx, struct vmod_priv *priv,
const char *dir, const char *format, const char *param)
{
struct binlog_config *conf = priv->priv;
@@ -352,7 +363,6 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
binlog_error("invalid size value");
abort();
}
- free(p);
switch (*q) {
case 'g':
case 'G':
@@ -369,6 +379,7 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
abort();
}
conf->size = u;
+ free(p);
} else
conf->size = BINLOG_SIZE;
@@ -426,7 +437,7 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
}
static char *
-mkfilename(struct sess *sp, struct binlog_config *conf)
+mkfilename(MOD_CTX ctx, struct binlog_config *conf)
{
time_t ts = time(NULL);
size_t u, n;
@@ -434,16 +445,16 @@ mkfilename(struct sess *sp, struct binlog_config *conf)
if (conf->flags & BLF_ROUNDTS)
ts -= ts % conf->interval;
- u = WS_Reserve(sp->wrk->ws, 0);
- p = sp->wrk->ws->f;
+ u = WS_Reserve(WSPTR(ctx), 0);
+ p = WSPTR(ctx)->f;
n = strftime(p, u, conf->pattern, gmtime(&ts));
if (n == 0) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
}
q = strdup(p);
AN(q);
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return q;
}
@@ -481,7 +492,7 @@ mkdir_p(struct binlog_config *conf, char *dir)
}
static int
-createfile(struct sess *sp, struct binlog_config *conf)
+createfile(MOD_CTX ctx, struct binlog_config *conf)
{
char *fname;
int fd;
@@ -489,7 +500,7 @@ createfile(struct sess *sp, struct binlog_config *conf)
conf->fname = NULL;
conf->fd = -1;
- fname = mkfilename(sp, conf);
+ fname = mkfilename(ctx, conf);
if (!fname)
return -1;
if (mkdir_p(conf, fname)) {
@@ -591,7 +602,7 @@ checkheader(struct binlog_config *conf, size_t hdrsize)
}
static int
-newfile(struct sess *sp, struct binlog_config *conf)
+newfile(MOD_CTX ctx, struct binlog_config *conf)
{
int c;
void *base;
@@ -601,7 +612,7 @@ newfile(struct sess *sp, struct binlog_config *conf)
setstoptime(conf);
- if (createfile(sp, conf))
+ if (createfile(ctx, conf))
return -1;
hdrsize = ((sizeof(struct binlog_file_header) +
@@ -657,7 +668,8 @@ newfile(struct sess *sp, struct binlog_config *conf)
debug(conf,1,("reusing log file %s, recnum=%lu",
conf->fname, (unsigned long)conf->base->recnum));
} else {
- debug(conf,1,("created new log file %s",conf->fname));
+ debug(conf,1,("created new log file %s, size %lu",conf->fname,
+ (unsigned long)conf->size));
memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN);
conf->base->version = BINLOG_VERSION;
conf->base->recsize = conf->recsize;
@@ -674,7 +686,7 @@ newfile(struct sess *sp, struct binlog_config *conf)
}
static void
-closefile(struct sess *sp, struct binlog_config *conf)
+closefile(MOD_CTX ctx, struct binlog_config *conf)
{
size_t size;
@@ -691,8 +703,8 @@ closefile(struct sess *sp, struct binlog_config *conf)
reset(conf);
}
-void
-vmod_start(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_start(MOD_CTX ctx, struct vmod_priv *priv)
{
struct binlog_config *conf = priv->priv;
time_t ts;
@@ -705,8 +717,8 @@ vmod_start(struct sess *sp, struct vmod_priv *priv)
if (ts >= conf->stoptime) {
AZ(pthread_mutex_lock(&conf->mutex));
- closefile(sp, conf);
- newfile(sp, conf);
+ closefile(ctx, conf);
+ newfile(ctx, conf);
AZ(pthread_mutex_unlock(&conf->mutex));
}
@@ -714,8 +726,8 @@ vmod_start(struct sess *sp, struct vmod_priv *priv)
binlog_env_init(ep, conf, ts);
}
-void
-vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str)
+VCL_VOID
+vmod_pack(MOD_CTX ctx, struct vmod_priv *priv, VCL_STRING str)
{
struct binlog_config *conf = priv->priv;
struct binlog_env *ep = binlog_env_get();
@@ -749,8 +761,8 @@ vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str)
ep->state = state_pack;
}
-void
-vmod_commit(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_commit(MOD_CTX ctx, struct vmod_priv *priv)
{
struct binlog_config *conf = priv->priv;
struct binlog_env *ep = binlog_env_get();
@@ -789,8 +801,8 @@ vmod_commit(struct sess *sp, struct vmod_priv *priv)
ep->state = state_init;
}
-void
-vmod_sync(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_sync(MOD_CTX ctx, struct vmod_priv *priv)
{
struct binlog_config *conf = priv->priv;
@@ -803,8 +815,8 @@ vmod_sync(struct sess *sp, struct vmod_priv *priv)
AZ(pthread_mutex_unlock(&conf->mutex));
}
-void
-vmod_close(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_close(MOD_CTX ctx, struct vmod_priv *priv)
{
struct binlog_config *conf = priv->priv;
@@ -813,7 +825,7 @@ vmod_close(struct sess *sp, struct vmod_priv *priv)
mutex = conf->mutex;
AZ(pthread_mutex_lock(&mutex));
- closefile(sp, conf);
+ closefile(ctx, conf);
close(conf->dd);
free(conf->dir);
free(conf->pattern);

Return to:

Send suggestions and report system problems to the System administrator.