diff options
Diffstat (limited to 'src/binlog.c')
-rw-r--r-- | src/binlog.c | 64 |
1 files changed, 38 insertions, 26 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 @@ | |||
29 | #include <time.h> | 29 | #include <time.h> |
30 | #include "vrt.h" | 30 | #include "vrt.h" |
31 | #include "vcc_if.h" | 31 | #include "vcc_if.h" |
32 | #if VARNISHVERSION == 3 | ||
32 | # include "bin/varnishd/cache.h" | 33 | # include "bin/varnishd/cache.h" |
34 | # define VCL_VOID void | ||
35 | # define VCL_STRING const char * | ||
36 | # define MOD_CTX struct sess * | ||
37 | # define WSPTR(s) ((s)->wrk->ws) | ||
38 | #else | ||
39 | # include "bin/varnishd/cache/cache.h" | ||
40 | # define MOD_CTX const struct vrt_ctx * | ||
41 | # define WSPTR(s) ((s)->ws) | ||
42 | #endif | ||
33 | #include "vmod-binlog.h" | 43 | #include "vmod-binlog.h" |
34 | #include "pack.h" | 44 | #include "pack.h" |
45 | #include "pthread.h" | ||
35 | 46 | ||
36 | #ifndef O_SEARCH | 47 | #ifndef O_SEARCH |
37 | # define O_SEARCH 0 | 48 | # define O_SEARCH 0 |
@@ -262,7 +273,7 @@ make_key() | |||
262 | } | 273 | } |
263 | 274 | ||
264 | void | 275 | void |
265 | vmod_init(struct sess *sp, struct vmod_priv *priv, | 276 | vmod_init(MOD_CTX ctx, struct vmod_priv *priv, |
266 | const char *dir, const char *format, const char *param) | 277 | const char *dir, const char *format, const char *param) |
267 | { | 278 | { |
268 | struct binlog_config *conf = priv->priv; | 279 | struct binlog_config *conf = priv->priv; |
@@ -352,7 +363,6 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, | |||
352 | binlog_error("invalid size value"); | 363 | binlog_error("invalid size value"); |
353 | abort(); | 364 | abort(); |
354 | } | 365 | } |
355 | free(p); | ||
356 | switch (*q) { | 366 | switch (*q) { |
357 | case 'g': | 367 | case 'g': |
358 | case 'G': | 368 | case 'G': |
@@ -369,6 +379,7 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, | |||
369 | abort(); | 379 | abort(); |
370 | } | 380 | } |
371 | conf->size = u; | 381 | conf->size = u; |
382 | free(p); | ||
372 | } else | 383 | } else |
373 | conf->size = BINLOG_SIZE; | 384 | conf->size = BINLOG_SIZE; |
374 | 385 | ||
@@ -426,7 +437,7 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, | |||
426 | } | 437 | } |
427 | 438 | ||
428 | static char * | 439 | static char * |
429 | mkfilename(struct sess *sp, struct binlog_config *conf) | 440 | mkfilename(MOD_CTX ctx, struct binlog_config *conf) |
430 | { | 441 | { |
431 | time_t ts = time(NULL); | 442 | time_t ts = time(NULL); |
432 | size_t u, n; | 443 | size_t u, n; |
@@ -434,16 +445,16 @@ mkfilename(struct sess *sp, struct binlog_config *conf) | |||
434 | 445 | ||
435 | if (conf->flags & BLF_ROUNDTS) | 446 | if (conf->flags & BLF_ROUNDTS) |
436 | ts -= ts % conf->interval; | 447 | ts -= ts % conf->interval; |
437 | u = WS_Reserve(sp->wrk->ws, 0); | 448 | u = WS_Reserve(WSPTR(ctx), 0); |
438 | p = sp->wrk->ws->f; | 449 | p = WSPTR(ctx)->f; |
439 | n = strftime(p, u, conf->pattern, gmtime(&ts)); | 450 | n = strftime(p, u, conf->pattern, gmtime(&ts)); |
440 | if (n == 0) { | 451 | if (n == 0) { |
441 | WS_Release(sp->wrk->ws, 0); | 452 | WS_Release(WSPTR(ctx), 0); |
442 | return NULL; | 453 | return NULL; |
443 | } | 454 | } |
444 | q = strdup(p); | 455 | q = strdup(p); |
445 | AN(q); | 456 | AN(q); |
446 | WS_Release(sp->wrk->ws, 0); | 457 | WS_Release(WSPTR(ctx), 0); |
447 | return q; | 458 | return q; |
448 | } | 459 | } |
449 | 460 | ||
@@ -481,7 +492,7 @@ mkdir_p(struct binlog_config *conf, char *dir) | |||
481 | } | 492 | } |
482 | 493 | ||
483 | static int | 494 | static int |
484 | createfile(struct sess *sp, struct binlog_config *conf) | 495 | createfile(MOD_CTX ctx, struct binlog_config *conf) |
485 | { | 496 | { |
486 | char *fname; | 497 | char *fname; |
487 | int fd; | 498 | int fd; |
@@ -489,7 +500,7 @@ createfile(struct sess *sp, struct binlog_config *conf) | |||
489 | conf->fname = NULL; | 500 | conf->fname = NULL; |
490 | conf->fd = -1; | 501 | conf->fd = -1; |
491 | 502 | ||
492 | fname = mkfilename(sp, conf); | 503 | fname = mkfilename(ctx, conf); |
493 | if (!fname) | 504 | if (!fname) |
494 | return -1; | 505 | return -1; |
495 | if (mkdir_p(conf, fname)) { | 506 | if (mkdir_p(conf, fname)) { |
@@ -591,7 +602,7 @@ checkheader(struct binlog_config *conf, size_t hdrsize) | |||
591 | } | 602 | } |
592 | 603 | ||
593 | static int | 604 | static int |
594 | newfile(struct sess *sp, struct binlog_config *conf) | 605 | newfile(MOD_CTX ctx, struct binlog_config *conf) |
595 | { | 606 | { |
596 | int c; | 607 | int c; |
597 | void *base; | 608 | void *base; |
@@ -601,7 +612,7 @@ newfile(struct sess *sp, struct binlog_config *conf) | |||
601 | 612 | ||
602 | setstoptime(conf); | 613 | setstoptime(conf); |
603 | 614 | ||
604 | if (createfile(sp, conf)) | 615 | if (createfile(ctx, conf)) |
605 | return -1; | 616 | return -1; |
606 | 617 | ||
607 | hdrsize = ((sizeof(struct binlog_file_header) + | 618 | hdrsize = ((sizeof(struct binlog_file_header) + |
@@ -657,7 +668,8 @@ newfile(struct sess *sp, struct binlog_config *conf) | |||
657 | debug(conf,1,("reusing log file %s, recnum=%lu", | 668 | debug(conf,1,("reusing log file %s, recnum=%lu", |
658 | conf->fname, (unsigned long)conf->base->recnum)); | 669 | conf->fname, (unsigned long)conf->base->recnum)); |
659 | } else { | 670 | } else { |
660 | debug(conf,1,("created new log file %s",conf->fname)); | 671 | debug(conf,1,("created new log file %s, size %lu",conf->fname, |
672 | (unsigned long)conf->size)); | ||
661 | memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN); | 673 | memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN); |
662 | conf->base->version = BINLOG_VERSION; | 674 | conf->base->version = BINLOG_VERSION; |
663 | conf->base->recsize = conf->recsize; | 675 | conf->base->recsize = conf->recsize; |
@@ -674,7 +686,7 @@ newfile(struct sess *sp, struct binlog_config *conf) | |||
674 | } | 686 | } |
675 | 687 | ||
676 | static void | 688 | static void |
677 | closefile(struct sess *sp, struct binlog_config *conf) | 689 | closefile(MOD_CTX ctx, struct binlog_config *conf) |
678 | { | 690 | { |
679 | size_t size; | 691 | size_t size; |
680 | 692 | ||
@@ -691,8 +703,8 @@ closefile(struct sess *sp, struct binlog_config *conf) | |||
691 | reset(conf); | 703 | reset(conf); |
692 | } | 704 | } |
693 | 705 | ||
694 | void | 706 | VCL_VOID |
695 | vmod_start(struct sess *sp, struct vmod_priv *priv) | 707 | vmod_start(MOD_CTX ctx, struct vmod_priv *priv) |
696 | { | 708 | { |
697 | struct binlog_config *conf = priv->priv; | 709 | struct binlog_config *conf = priv->priv; |
698 | time_t ts; | 710 | time_t ts; |
@@ -705,8 +717,8 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) | |||
705 | 717 | ||
706 | if (ts >= conf->stoptime) { | 718 | if (ts >= conf->stoptime) { |
707 | AZ(pthread_mutex_lock(&conf->mutex)); | 719 | AZ(pthread_mutex_lock(&conf->mutex)); |
708 | closefile(sp, conf); | 720 | closefile(ctx, conf); |
709 | newfile(sp, conf); | 721 | newfile(ctx, conf); |
710 | AZ(pthread_mutex_unlock(&conf->mutex)); | 722 | AZ(pthread_mutex_unlock(&conf->mutex)); |
711 | } | 723 | } |
712 | 724 | ||
@@ -714,8 +726,8 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) | |||
714 | binlog_env_init(ep, conf, ts); | 726 | binlog_env_init(ep, conf, ts); |
715 | } | 727 | } |
716 | 728 | ||
717 | void | 729 | VCL_VOID |
718 | vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str) | 730 | vmod_pack(MOD_CTX ctx, struct vmod_priv *priv, VCL_STRING str) |
719 | { | 731 | { |
720 | struct binlog_config *conf = priv->priv; | 732 | struct binlog_config *conf = priv->priv; |
721 | struct binlog_env *ep = binlog_env_get(); | 733 | struct binlog_env *ep = binlog_env_get(); |
@@ -749,8 +761,8 @@ vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str) | |||
749 | ep->state = state_pack; | 761 | ep->state = state_pack; |
750 | } | 762 | } |
751 | 763 | ||
752 | void | 764 | VCL_VOID |
753 | vmod_commit(struct sess *sp, struct vmod_priv *priv) | 765 | vmod_commit(MOD_CTX ctx, struct vmod_priv *priv) |
754 | { | 766 | { |
755 | struct binlog_config *conf = priv->priv; | 767 | struct binlog_config *conf = priv->priv; |
756 | struct binlog_env *ep = binlog_env_get(); | 768 | struct binlog_env *ep = binlog_env_get(); |
@@ -789,8 +801,8 @@ vmod_commit(struct sess *sp, struct vmod_priv *priv) | |||
789 | ep->state = state_init; | 801 | ep->state = state_init; |
790 | } | 802 | } |
791 | 803 | ||
792 | void | 804 | VCL_VOID |
793 | vmod_sync(struct sess *sp, struct vmod_priv *priv) | 805 | vmod_sync(MOD_CTX ctx, struct vmod_priv *priv) |
794 | { | 806 | { |
795 | struct binlog_config *conf = priv->priv; | 807 | struct binlog_config *conf = priv->priv; |
796 | 808 | ||
@@ -803,8 +815,8 @@ vmod_sync(struct sess *sp, struct vmod_priv *priv) | |||
803 | AZ(pthread_mutex_unlock(&conf->mutex)); | 815 | AZ(pthread_mutex_unlock(&conf->mutex)); |
804 | } | 816 | } |
805 | 817 | ||
806 | void | 818 | VCL_VOID |
807 | vmod_close(struct sess *sp, struct vmod_priv *priv) | 819 | vmod_close(MOD_CTX ctx, struct vmod_priv *priv) |
808 | { | 820 | { |
809 | struct binlog_config *conf = priv->priv; | 821 | struct binlog_config *conf = priv->priv; |
810 | 822 | ||
@@ -813,7 +825,7 @@ vmod_close(struct sess *sp, struct vmod_priv *priv) | |||
813 |