diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-12 17:29:05 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-12 17:29:05 +0300 |
commit | 66f3521c257d2777cbf9697716a9f2288254376c (patch) | |
tree | be3b4993d1b4bb515f67227bd0647dac4dbc08ff /src | |
parent | 60a356d55ed0aca4283ddc3134298936e45ad18b (diff) | |
download | vmod-binlog-66f3521c257d2777cbf9697716a9f2288254376c.tar.gz vmod-binlog-66f3521c257d2777cbf9697716a9f2288254376c.tar.bz2 |
Fix processing repeat counts in packinnext.
* src/binlog.c (vmod_start): call packinit.
* src/pack.c (packinst) <cur>: New member.
(packinnext): Correctly process repeat counts.
(packout): Likewise.
(packinit): New function.
* src/pack.h (packinit): New proto.
Diffstat (limited to 'src')
-rw-r--r-- | src/binlog.c | 44 | ||||
-rw-r--r-- | src/pack.c | 24 | ||||
-rw-r--r-- | src/pack.h | 1 |
3 files changed, 42 insertions, 27 deletions
diff --git a/src/binlog.c b/src/binlog.c index b2d9f87..325f337 100644 --- a/src/binlog.c +++ b/src/binlog.c | |||
@@ -45,29 +45,29 @@ enum binlog_state { | |||
45 | }; | 45 | }; |
46 | 46 | ||
47 | struct binlog_config { | 47 | struct binlog_config { |
48 | size_t size; /* maximum file size */ | 48 | size_t size; /* maximum file size */ |
49 | unsigned interval; /* file rotation interval */ | 49 | unsigned interval; /* file rotation interval */ |
50 | char *pattern; /* file name pattern */ | 50 | char *pattern; /* file name pattern */ |
51 | int umask; /* umask for new files and directories */ | 51 | int umask; /* umask for new files and directories */ |
52 | char *dir; /* root storage directory */ | 52 | char *dir; /* root storage directory */ |
53 | int dd; /* directory descriptor */ | 53 | int dd; /* directory descriptor */ |
54 | char *fname; /* current file name */ | 54 | char *fname; /* current file name */ |
55 | int fd; /* current file descriptor */ | 55 | int fd; /* current file descriptor */ |
56 | struct binlog_file_header *base; /* mmap base */ | 56 | struct binlog_file_header *base; /* mmap base */ |
57 | char *recbase; /* record base */ | 57 | char *recbase; /* record base */ |
58 | size_t recnum; /* number of records in recbase */ | 58 | size_t recnum; /* number of records in recbase */ |
59 | size_t recsize; /* record size */ | 59 | size_t recsize; /* record size */ |
60 | time_t stoptime; /* when to rotate the current file */ | 60 | time_t stoptime; /* when to rotate the current file */ |
61 | pthread_mutex_t mutex; | 61 | pthread_mutex_t mutex; |
62 | int debug; | 62 | int debug; /* debug level */ |
63 | int flags; | 63 | int flags; /* flags (see BLF_* defines above) */ |
64 | 64 | ||
65 | char *dataspec; | 65 | char *dataspec; /* data format specification */ |
66 | struct packinst *inst_head; | 66 | struct packinst *inst_head; /* compiled dataspec */ |
67 | struct packinst *inst_cur; | 67 | struct packinst *inst_cur; /* current instruction */ |
68 | struct packenv *env; | 68 | struct packenv *env; /* pack environment */ |
69 | enum binlog_state state; | 69 | enum binlog_state state; /* binlog machine state */ |
70 | time_t timestamp; | 70 | time_t timestamp; /* timestamp for the entry being built */ |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | 73 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
@@ -496,7 +496,7 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) | |||
496 | 496 | ||
497 | packenv_init(conf->env); | 497 | packenv_init(conf->env); |
498 | conf->state = state_start; | 498 | conf->state = state_start; |
499 | conf->inst_cur = conf->inst_head; | 499 | conf->inst_cur = packinit(conf->inst_head); |
500 | conf->timestamp = ts; | 500 | conf->timestamp = ts; |
501 | } | 501 | } |
502 | 502 | ||
@@ -69,6 +69,7 @@ struct packinst { | |||
69 | struct packinst *next; | 69 | struct packinst *next; |
70 | struct packspec *spec; | 70 | struct packspec *spec; |
71 | int rep; | 71 | int rep; |
72 | int cur; | ||
72 | }; | 73 | }; |
73 | 74 | ||
74 | static char * | 75 | static char * |
@@ -509,10 +510,12 @@ packinnext(struct packinst *pi, struct packenv *env) | |||
509 | return NULL; | 510 | return NULL; |
510 | if (pi->spec->flags & F_REP) | 511 | if (pi->spec->flags & F_REP) |
511 | pi->spec->packer(env, pi->spec, pi->rep); | 512 | pi->spec->packer(env, pi->spec, pi->rep); |
512 | else | 513 | else { |
513 | for (i = 0; i < pi->rep; i++) | 514 | pi->spec->packer(env, pi->spec, 1); |
514 | pi->spec->packer(env, pi->spec, 1); | 515 | if (++pi->cur < pi->rep) |
515 | return pi->next; | 516 | return pi; |
517 | } | ||
518 | return packinit(pi->next); | ||
516 | } | 519 | } |
517 | 520 | ||
518 | void | 521 | void |
@@ -524,8 +527,11 @@ packout(struct packinst *pi, struct packenv *env) | |||
524 | if (pi->spec->flags & F_REP) | 527 | if (pi->spec->flags & F_REP) |
525 | pi->spec->unpacker(env, pi->spec, pi->rep); | 528 | pi->spec->unpacker(env, pi->spec, pi->rep); |
526 | else | 529 | else |
527 | for (i = 0; i < pi->rep; i++) | 530 | for (i = 0; i < pi->rep; i++) { |
531 | if (i > 0) | ||
532 | fputc(' ', env->fp); | ||
528 | pi->spec->unpacker(env, pi->spec, 1); | 533 | pi->spec->unpacker(env, pi->spec, 1); |
534 | } | ||
529 | if (pi->next) | 535 | if (pi->next) |
530 | fputc(' ', env->fp); | 536 | fputc(' ', env->fp); |
531 | } | 537 | } |
@@ -541,6 +547,14 @@ packsize(struct packinst *pi) | |||
541 | return env.buf_pos; | 547 | return env.buf_pos; |
542 | } | 548 | } |
543 | 549 | ||
550 | struct packinst * | ||
551 | packinit(struct packinst *inst) | ||
552 | { | ||
553 | if (inst) | ||
554 | inst->cur = 0; | ||
555 | return inst; | ||
556 | } | ||
557 | |||
544 | struct packenv * | 558 | struct packenv * |
545 | packenv_create(size_t size) | 559 | packenv_create(size_t size) |
546 | { | 560 | { |
@@ -30,6 +30,7 @@ struct packinst; | |||
30 | 30 | ||
31 | struct packinst *packcomp(const char *s, char **endp); | 31 | struct packinst *packcomp(const char *s, char **endp); |
32 | void packfree(struct packinst *pi); | 32 | void packfree(struct packinst *pi); |
33 | struct packinst *packinit(struct packinst *pi); | ||
33 | void packin(struct packinst *pi, struct packenv *env); | 34 | void packin(struct packinst *pi, struct packenv *env); |
34 | void packout(struct packinst *pi, struct packenv *env); | 35 | void packout(struct packinst *pi, struct packenv *env); |
35 | struct packinst *packinnext(struct packinst *pi, struct packenv *env); | 36 | struct packinst *packinnext(struct packinst *pi, struct packenv *env); |