2008-03-09 19:14:36 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2005-2008 Poul-Henning Kamp
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2011-02-28 09:11:46 +00:00
|
|
|
#include <stdint.h>
|
2008-03-09 19:14:36 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
|
|
|
#include "fifolog.h"
|
|
|
|
#include "libfifolog_int.h"
|
|
|
|
#include "fifolog_write.h"
|
|
|
|
#include "miniobj.h"
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
static int fifolog_write_gzip(struct fifolog_writer *f, time_t now);
|
|
|
|
|
2008-03-09 19:14:36 +00:00
|
|
|
#define ALLOC(ptr, size) do { \
|
|
|
|
(*(ptr)) = calloc(size, 1); \
|
|
|
|
assert(*(ptr) != NULL); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
const char *fifolog_write_statnames[] = {
|
2011-02-25 09:40:17 +00:00
|
|
|
[FIFOLOG_PT_BYTES_PRE] = "Bytes before compression",
|
|
|
|
[FIFOLOG_PT_BYTES_POST] = "Bytes after compression",
|
|
|
|
[FIFOLOG_PT_WRITES] = "Writes",
|
|
|
|
[FIFOLOG_PT_FLUSH] = "Flushes",
|
|
|
|
[FIFOLOG_PT_SYNC] = "Syncs",
|
|
|
|
[FIFOLOG_PT_RUNTIME] = "Runtime"
|
2008-03-09 19:14:36 +00:00
|
|
|
};
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
2008-03-09 19:14:36 +00:00
|
|
|
* Check that everything is all right
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fifolog_write_assert(const struct fifolog_writer *f)
|
|
|
|
{
|
|
|
|
|
|
|
|
CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC);
|
|
|
|
assert(f->ff->zs->next_out + f->ff->zs->avail_out == \
|
2010-12-07 16:30:52 +00:00
|
|
|
f->obuf + f->obufsize);
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Allocate/Destroy a new fifolog writer instance
|
|
|
|
*/
|
|
|
|
|
2008-03-09 19:14:36 +00:00
|
|
|
struct fifolog_writer *
|
|
|
|
fifolog_write_new(void)
|
|
|
|
{
|
|
|
|
struct fifolog_writer *f;
|
|
|
|
|
2010-12-07 16:30:52 +00:00
|
|
|
ALLOC_OBJ(f, FIFOLOG_WRITER_MAGIC);
|
|
|
|
assert(f != NULL);
|
2008-03-09 19:14:36 +00:00
|
|
|
return (f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fifolog_write_destroy(struct fifolog_writer *f)
|
|
|
|
{
|
2011-02-28 09:11:46 +00:00
|
|
|
|
|
|
|
free(f->obuf);
|
|
|
|
free(f->ibuf);
|
|
|
|
FREE_OBJ(f);
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Open/Close the fifolog
|
|
|
|
*/
|
|
|
|
|
2008-03-09 19:14:36 +00:00
|
|
|
void
|
|
|
|
fifolog_write_close(struct fifolog_writer *f)
|
|
|
|
{
|
2011-02-28 09:11:46 +00:00
|
|
|
time_t now;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
|
|
|
CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC);
|
2011-02-28 09:11:46 +00:00
|
|
|
fifolog_write_assert(f);
|
|
|
|
|
|
|
|
f->cleanup = 1;
|
|
|
|
time(&now);
|
|
|
|
fifolog_write_gzip(f, now);
|
|
|
|
fifolog_write_assert(f);
|
2008-03-09 19:14:36 +00:00
|
|
|
fifolog_int_close(&f->ff);
|
2008-03-19 10:56:51 +00:00
|
|
|
free(f->ff);
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2011-02-28 09:11:46 +00:00
|
|
|
fifolog_write_open(struct fifolog_writer *f, const char *fn,
|
|
|
|
unsigned writerate, unsigned syncrate, unsigned compression)
|
2008-03-09 19:14:36 +00:00
|
|
|
{
|
|
|
|
const char *es;
|
|
|
|
int i;
|
|
|
|
time_t now;
|
|
|
|
off_t o;
|
|
|
|
|
|
|
|
CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC);
|
|
|
|
|
|
|
|
/* Check for legal compression value */
|
2011-02-28 09:11:46 +00:00
|
|
|
if (compression > Z_BEST_COMPRESSION)
|
2008-03-09 19:14:36 +00:00
|
|
|
return ("Illegal compression value");
|
|
|
|
|
|
|
|
f->writerate = writerate;
|
|
|
|
f->syncrate = syncrate;
|
|
|
|
f->compression = compression;
|
|
|
|
|
|
|
|
/* Reset statistics */
|
|
|
|
memset(f->cnt, 0, sizeof f->cnt);
|
|
|
|
|
|
|
|
es = fifolog_int_open(&f->ff, fn, 1);
|
|
|
|
if (es != NULL)
|
|
|
|
return (es);
|
|
|
|
es = fifolog_int_findend(f->ff, &o);
|
|
|
|
if (es != NULL)
|
|
|
|
return (es);
|
2009-02-02 14:29:15 +00:00
|
|
|
i = fifolog_int_read(f->ff, o);
|
|
|
|
if (i)
|
|
|
|
return ("Read error, looking for seq");
|
|
|
|
f->seq = be32dec(f->ff->recbuf);
|
|
|
|
if (f->seq == 0) {
|
|
|
|
/* Empty fifolog */
|
|
|
|
f->seq = random();
|
2008-03-09 19:14:36 +00:00
|
|
|
} else {
|
|
|
|
f->recno = o + 1;
|
2009-02-02 14:29:15 +00:00
|
|
|
f->seq++;
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 16:30:52 +00:00
|
|
|
f->obufsize = f->ff->recsize;
|
|
|
|
ALLOC(&f->obuf, f->obufsize);
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
f->ibufsize = f->obufsize * 10;
|
|
|
|
ALLOC(&f->ibuf, f->ibufsize);
|
|
|
|
f->ibufptr = 0;
|
|
|
|
|
2008-03-09 19:14:36 +00:00
|
|
|
i = deflateInit(f->ff->zs, (int)f->compression);
|
|
|
|
assert(i == Z_OK);
|
|
|
|
|
|
|
|
f->flag |= FIFOLOG_FLG_RESTART;
|
2010-12-07 16:30:52 +00:00
|
|
|
f->flag |= FIFOLOG_FLG_SYNC;
|
|
|
|
f->ff->zs->next_out = f->obuf + 9;
|
|
|
|
f->ff->zs->avail_out = f->obufsize - 9;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
|
|
|
time(&now);
|
|
|
|
f->starttime = now;
|
2010-12-07 16:30:52 +00:00
|
|
|
f->lastsync = now;
|
|
|
|
f->lastwrite = now;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
|
|
|
fifolog_write_assert(f);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Write an output record
|
|
|
|
* Returns -1 if there are trouble writing data
|
|
|
|
*/
|
|
|
|
|
2010-12-07 16:30:52 +00:00
|
|
|
static int
|
|
|
|
fifolog_write_output(struct fifolog_writer *f, int fl, time_t now)
|
2008-03-09 19:14:36 +00:00
|
|
|
{
|
2010-12-07 16:30:52 +00:00
|
|
|
long h, l = f->ff->zs->next_out - f->obuf;
|
2011-02-28 09:11:46 +00:00
|
|
|
ssize_t i, w;
|
|
|
|
int retval = 0;
|
2010-12-07 16:30:52 +00:00
|
|
|
|
|
|
|
h = 4; /* seq */
|
|
|
|
be32enc(f->obuf, f->seq);
|
|
|
|
f->obuf[h] = f->flag;
|
|
|
|
h += 1; /* flag */
|
|
|
|
if (f->flag & FIFOLOG_FLG_SYNC) {
|
|
|
|
be32enc(f->obuf + h, now);
|
|
|
|
h += 4; /* timestamp */
|
|
|
|
}
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
assert(l <= (long)f->ff->recsize); /* NB: l includes h */
|
2010-12-07 16:30:52 +00:00
|
|
|
assert(l >= h);
|
2011-02-28 09:11:46 +00:00
|
|
|
|
|
|
|
/* We will never write an entirely empty buffer */
|
2010-12-07 16:30:52 +00:00
|
|
|
if (l == h)
|
|
|
|
return (0);
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
if (l < (long)f->ff->recsize && fl == Z_NO_FLUSH)
|
2010-12-07 16:30:52 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
w = f->ff->recsize - l;
|
|
|
|
if (w > 255) {
|
|
|
|
be32enc(f->obuf + f->ff->recsize - 4, w);
|
|
|
|
f->obuf[4] |= FIFOLOG_FLG_4BYTE;
|
|
|
|
} else if (w > 0) {
|
2011-02-28 09:11:46 +00:00
|
|
|
f->obuf[f->ff->recsize - 1] = (uint8_t)w;
|
2010-12-07 16:30:52 +00:00
|
|
|
f->obuf[4] |= FIFOLOG_FLG_1BYTE;
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
2010-12-07 16:30:52 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
f->cnt[FIFOLOG_PT_BYTES_POST] += l - h;
|
2010-12-07 16:30:52 +00:00
|
|
|
|
|
|
|
i = pwrite(f->ff->fd, f->obuf, f->ff->recsize,
|
|
|
|
(f->recno + 1) * f->ff->recsize);
|
2011-02-28 09:11:46 +00:00
|
|
|
if (i != f->ff->recsize)
|
|
|
|
retval = -1;
|
|
|
|
else
|
|
|
|
retval = 1;
|
2010-12-07 16:30:52 +00:00
|
|
|
|
2008-03-09 19:14:36 +00:00
|
|
|
f->cnt[FIFOLOG_PT_WRITES]++;
|
2011-02-28 09:11:46 +00:00
|
|
|
f->cnt[FIFOLOG_PT_RUNTIME] = now - f->starttime;
|
2010-12-07 16:30:52 +00:00
|
|
|
|
|
|
|
f->lastwrite = now;
|
2011-02-28 09:11:46 +00:00
|
|
|
/*
|
|
|
|
* We increment these even on error, so as to properly skip bad,
|
|
|
|
* sectors or other light trouble.
|
|
|
|
*/
|
2010-12-07 16:30:52 +00:00
|
|
|
f->seq++;
|
|
|
|
f->recno++;
|
|
|
|
f->flag = 0;
|
|
|
|
|
|
|
|
memset(f->obuf, 0, f->obufsize);
|
|
|
|
f->ff->zs->next_out = f->obuf + 5;
|
|
|
|
f->ff->zs->avail_out = f->obufsize - 5;
|
2011-02-28 09:11:46 +00:00
|
|
|
return (retval);
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Run the compression engine
|
|
|
|
* Returns -1 if there are trouble writing data
|
|
|
|
*/
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
static int
|
|
|
|
fifolog_write_gzip(struct fifolog_writer *f, time_t now)
|
|
|
|
{
|
|
|
|
int i, fl, retval = 0;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
assert(now != 0);
|
|
|
|
if (f->cleanup || now >= (int)(f->lastsync + f->syncrate)) {
|
2008-03-09 19:14:36 +00:00
|
|
|
f->cleanup = 0;
|
|
|
|
fl = Z_FINISH;
|
|
|
|
f->cnt[FIFOLOG_PT_SYNC]++;
|
2010-12-07 16:30:52 +00:00
|
|
|
} else if (now >= (int)(f->lastwrite + f->writerate)) {
|
2008-03-09 19:14:36 +00:00
|
|
|
fl = Z_SYNC_FLUSH;
|
|
|
|
f->cnt[FIFOLOG_PT_FLUSH]++;
|
2011-02-28 09:11:46 +00:00
|
|
|
} else if (f->ibufptr == 0)
|
|
|
|
return (0);
|
2008-03-09 19:14:36 +00:00
|
|
|
else
|
|
|
|
fl = Z_NO_FLUSH;
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
f->ff->zs->avail_in = f->ibufptr;
|
|
|
|
f->ff->zs->next_in = f->ibuf;
|
2010-12-07 16:30:52 +00:00
|
|
|
|
|
|
|
while (1) {
|
2008-03-09 19:14:36 +00:00
|
|
|
i = deflate(f->ff->zs, fl);
|
2010-12-07 16:30:52 +00:00
|
|
|
assert(i == Z_OK || i == Z_BUF_ERROR || i == Z_STREAM_END);
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
i = fifolog_write_output(f, fl, now);
|
|
|
|
if (i == 0)
|
2010-12-07 16:30:52 +00:00
|
|
|
break;
|
2011-02-28 09:11:46 +00:00
|
|
|
if (i < 0)
|
|
|
|
retval = -1;
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
2010-12-07 16:30:52 +00:00
|
|
|
assert(f->ff->zs->avail_in == 0);
|
2011-02-28 09:11:46 +00:00
|
|
|
f->ibufptr = 0;
|
2010-12-07 16:30:52 +00:00
|
|
|
if (fl == Z_FINISH) {
|
|
|
|
f->flag |= FIFOLOG_FLG_SYNC;
|
|
|
|
f->ff->zs->next_out = f->obuf + 9;
|
|
|
|
f->ff->zs->avail_out = f->obufsize - 9;
|
|
|
|
f->lastsync = now;
|
|
|
|
assert(Z_OK == deflateReset(f->ff->zs));
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
2011-02-28 09:11:46 +00:00
|
|
|
return (retval);
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Poll to see if we need to flush out a record
|
|
|
|
* Returns -1 if there are trouble writing data
|
|
|
|
*/
|
|
|
|
|
2010-12-07 16:30:52 +00:00
|
|
|
int
|
|
|
|
fifolog_write_poll(struct fifolog_writer *f, time_t now)
|
2008-03-09 19:14:36 +00:00
|
|
|
{
|
2011-02-28 09:11:46 +00:00
|
|
|
|
2010-12-07 16:30:52 +00:00
|
|
|
if (now == 0)
|
|
|
|
time(&now);
|
2011-02-28 09:11:46 +00:00
|
|
|
return (fifolog_write_gzip(f, now));
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Attempt to write an entry into the ibuf.
|
2008-03-09 19:14:36 +00:00
|
|
|
* Return zero if there is no space, one otherwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2011-02-28 09:11:46 +00:00
|
|
|
fifolog_write_record(struct fifolog_writer *f, uint32_t id, time_t now,
|
|
|
|
const void *ptr, ssize_t len)
|
2008-03-09 19:14:36 +00:00
|
|
|
{
|
|
|
|
const unsigned char *p;
|
2011-02-28 09:11:46 +00:00
|
|
|
uint8_t buf[9];
|
2011-03-01 08:52:10 +00:00
|
|
|
ssize_t bufl;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
|
|
|
fifolog_write_assert(f);
|
|
|
|
assert(!(id & (FIFOLOG_TIMESTAMP|FIFOLOG_LENGTH)));
|
|
|
|
assert(ptr != NULL);
|
|
|
|
|
2008-03-19 10:56:51 +00:00
|
|
|
p = ptr;
|
2008-03-09 19:14:36 +00:00
|
|
|
if (len == 0) {
|
2011-02-28 09:11:46 +00:00
|
|
|
len = strlen(ptr);
|
|
|
|
len++;
|
2008-03-09 19:14:36 +00:00
|
|
|
} else {
|
|
|
|
assert(len <= 255);
|
|
|
|
id |= FIFOLOG_LENGTH;
|
|
|
|
}
|
2011-02-28 09:11:46 +00:00
|
|
|
assert (len > 0);
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/* Do a timestamp, if needed */
|
2008-03-09 19:14:36 +00:00
|
|
|
if (now == 0)
|
|
|
|
time(&now);
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
if (now != f->last)
|
2008-03-09 19:14:36 +00:00
|
|
|
id |= FIFOLOG_TIMESTAMP;
|
|
|
|
|
2010-12-07 16:30:52 +00:00
|
|
|
/* Emit instance+flag */
|
|
|
|
be32enc(buf, id);
|
2011-02-28 09:11:46 +00:00
|
|
|
bufl = 4;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
|
|
|
if (id & FIFOLOG_TIMESTAMP) {
|
2011-02-28 09:11:46 +00:00
|
|
|
be32enc(buf + bufl, (uint32_t)now);
|
|
|
|
bufl += 4;
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
2011-02-28 09:11:46 +00:00
|
|
|
if (id & FIFOLOG_LENGTH)
|
|
|
|
buf[bufl++] = (u_char)len;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
if (bufl + len + f->ibufptr > f->ibufsize)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
memcpy(f->ibuf + f->ibufptr, buf, bufl);
|
|
|
|
f->ibufptr += bufl;
|
|
|
|
memcpy(f->ibuf + f->ibufptr, p, len);
|
|
|
|
f->ibufptr += len;
|
|
|
|
f->cnt[FIFOLOG_PT_BYTES_PRE] += bufl + len;
|
|
|
|
|
|
|
|
if (id & FIFOLOG_TIMESTAMP)
|
|
|
|
f->last = now;
|
2008-03-09 19:14:36 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Write an entry, polling the gzip/writer until success.
|
2008-03-09 19:14:36 +00:00
|
|
|
* Long binary entries are broken into 255 byte chunks.
|
2011-02-28 09:11:46 +00:00
|
|
|
* Returns -1 if there are problems writing data
|
2008-03-09 19:14:36 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
int
|
|
|
|
fifolog_write_record_poll(struct fifolog_writer *f, uint32_t id, time_t now,
|
|
|
|
const void *ptr, ssize_t len)
|
2008-03-09 19:14:36 +00:00
|
|
|
{
|
|
|
|
u_int l;
|
|
|
|
const unsigned char *p;
|
2011-02-28 09:11:46 +00:00
|
|
|
int retval = 0;
|
2008-03-09 19:14:36 +00:00
|
|
|
|
2011-02-28 09:11:46 +00:00
|
|
|
if (now == 0)
|
|
|
|
time(&now);
|
2008-03-09 19:14:36 +00:00
|
|
|
fifolog_write_assert(f);
|
|
|
|
|
|
|
|
assert(!(id & (FIFOLOG_TIMESTAMP|FIFOLOG_LENGTH)));
|
|
|
|
assert(ptr != NULL);
|
|
|
|
|
|
|
|
if (len == 0) {
|
2011-02-28 09:11:46 +00:00
|
|
|
if (!fifolog_write_record(f, id, now, ptr, len)) {
|
|
|
|
if (fifolog_write_gzip(f, now) < 0)
|
|
|
|
retval = -1;
|
|
|
|
/* The string could be too long for the ibuf, so... */
|
|
|
|
if (!fifolog_write_record(f, id, now, ptr, len))
|
|
|
|
retval = -1;
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (p = ptr; len > 0; len -= l, p += l) {
|
|
|
|
l = len;
|
|
|
|
if (l > 255)
|
|
|
|
l = 255;
|
2011-02-28 09:11:46 +00:00
|
|
|
while (!fifolog_write_record(f, id, now, p, l))
|
|
|
|
if (fifolog_write_gzip(f, now) < 0)
|
|
|
|
retval = -1;
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-28 09:11:46 +00:00
|
|
|
if (fifolog_write_gzip(f, now) < 0)
|
|
|
|
retval = -1;
|
2008-03-09 19:14:36 +00:00
|
|
|
fifolog_write_assert(f);
|
2011-02-28 09:11:46 +00:00
|
|
|
return (retval);
|
2008-03-09 19:14:36 +00:00
|
|
|
}
|