summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-12 14:29:05 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-10-12 14:29:05 (GMT)
commit66f3521c257d2777cbf9697716a9f2288254376c (patch) (side-by-side diff)
treebe3b4993d1b4bb515f67227bd0647dac4dbc08ff
parent60a356d55ed0aca4283ddc3134298936e45ad18b (diff)
downloadvmod-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 (more/less context) (ignore whitespace changes)
-rw-r--r--src/binlog.c44
-rw-r--r--src/pack.c24
-rw-r--r--src/pack.h1
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 {
};
struct binlog_config {
- size_t size; /* maximum file size */
- unsigned interval; /* file rotation interval */
- char *pattern; /* file name pattern */
- int umask; /* umask for new files and directories */
- char *dir; /* root storage directory */
- int dd; /* directory descriptor */
- char *fname; /* current file name */
- int fd; /* current file descriptor */
+ size_t size; /* maximum file size */
+ unsigned interval; /* file rotation interval */
+ char *pattern; /* file name pattern */
+ int umask; /* umask for new files and directories */
+ char *dir; /* root storage directory */
+ int dd; /* directory descriptor */
+ char *fname; /* current file name */
+ int fd; /* current file descriptor */
struct binlog_file_header *base; /* mmap base */
- char *recbase; /* record base */
- size_t recnum; /* number of records in recbase */
- size_t recsize; /* record size */
- time_t stoptime; /* when to rotate the current file */
+ char *recbase; /* record base */
+ size_t recnum; /* number of records in recbase */
+ size_t recsize; /* record size */
+ time_t stoptime; /* when to rotate the current file */
pthread_mutex_t mutex;
- int debug;
- int flags;
-
- char *dataspec;
- struct packinst *inst_head;
- struct packinst *inst_cur;
- struct packenv *env;
- enum binlog_state state;
- time_t timestamp;
+ int debug; /* debug level */
+ int flags; /* flags (see BLF_* defines above) */
+
+ char *dataspec; /* data format specification */
+ struct packinst *inst_head; /* compiled dataspec */
+ struct packinst *inst_cur; /* current instruction */
+ struct packenv *env; /* pack environment */
+ enum binlog_state state; /* binlog machine state */
+ time_t timestamp; /* timestamp for the entry being built */
};
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -496,7 +496,7 @@ vmod_start(struct sess *sp, struct vmod_priv *priv)
packenv_init(conf->env);
conf->state = state_start;
- conf->inst_cur = conf->inst_head;
+ conf->inst_cur = packinit(conf->inst_head);
conf->timestamp = ts;
}
diff --git a/src/pack.c b/src/pack.c
index 12dc19d..2e7e7a6 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -69,6 +69,7 @@ struct packinst {
struct packinst *next;
struct packspec *spec;
int rep;
+ int cur;
};
static char *
@@ -509,10 +510,12 @@ packinnext(struct packinst *pi, struct packenv *env)
return NULL;
if (pi->spec->flags & F_REP)
pi->spec->packer(env, pi->spec, pi->rep);
- else
- for (i = 0; i < pi->rep; i++)
- pi->spec->packer(env, pi->spec, 1);
- return pi->next;
+ else {
+ pi->spec->packer(env, pi->spec, 1);
+ if (++pi->cur < pi->rep)
+ return pi;
+ }
+ return packinit(pi->next);
}
void
@@ -524,8 +527,11 @@ packout(struct packinst *pi, struct packenv *env)
if (pi->spec->flags & F_REP)
pi->spec->unpacker(env, pi->spec, pi->rep);
else
- for (i = 0; i < pi->rep; i++)
+ for (i = 0; i < pi->rep; i++) {
+ if (i > 0)
+ fputc(' ', env->fp);
pi->spec->unpacker(env, pi->spec, 1);
+ }
if (pi->next)
fputc(' ', env->fp);
}
@@ -541,6 +547,14 @@ packsize(struct packinst *pi)
return env.buf_pos;
}
+struct packinst *
+packinit(struct packinst *inst)
+{
+ if (inst)
+ inst->cur = 0;
+ return inst;
+}
+
struct packenv *
packenv_create(size_t size)
{
diff --git a/src/pack.h b/src/pack.h
index 70a2488..36e20ec 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -30,6 +30,7 @@ struct packinst;
struct packinst *packcomp(const char *s, char **endp);
void packfree(struct packinst *pi);
+struct packinst *packinit(struct packinst *pi);
void packin(struct packinst *pi, struct packenv *env);
void packout(struct packinst *pi, struct packenv *env);
struct packinst *packinnext(struct packinst *pi, struct packenv *env);

Return to:

Send suggestions and report system problems to the System administrator.