f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt/*
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * Copyright (C) 2011 - 2015 Nominum, Inc.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt *
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * Permission to use, copy, modify, and distribute this software and its
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * documentation for any purpose with or without fee is hereby granted,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * provided that the above copyright notice and this permission notice
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * appear in all copies.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt *
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <fcntl.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <stdlib.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <string.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <unistd.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <sys/stat.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#define ISC_BUFFER_USEINLINE
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <isc/buffer.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include <isc/mem.h>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include "datafile.h"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include "log.h"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include "os.h"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#include "util.h"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#define BUFFER_SIZE (64 * 1024)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntstruct perf_datafile {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_mem_t *mctx;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt pthread_mutex_t lock;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt int pipe_fd;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt int fd;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_boolean_t is_file;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt size_t size;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_boolean_t cached;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt char databuf[BUFFER_SIZE + 1];
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_t data;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt unsigned int maxruns;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt unsigned int nruns;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_boolean_t read_any;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt};
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntstatic inline void
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntnul_terminate(perf_datafile_t *dfile)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt unsigned char *data;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt data = isc_buffer_used(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt *data = '\0';
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_t *
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_open(isc_mem_t *mctx, const char *filename)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt perf_datafile_t *dfile;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt struct stat buf;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile = isc_mem_get(mctx, sizeof(*dfile));
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile == NULL)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt perf_log_fatal("out of memory");
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->mctx = mctx;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt MUTEX_INIT(&dfile->lock);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->pipe_fd = -1;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->is_file = ISC_FALSE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->size = 0;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->cached = ISC_FALSE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->maxruns = 1;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->nruns = 0;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->read_any = ISC_FALSE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_init(&dfile->data, dfile->databuf, BUFFER_SIZE);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (filename == NULL) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->fd = STDIN_FILENO;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt } else {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->fd = open(filename, O_RDONLY);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile->fd < 0)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt perf_log_fatal("unable to open file: %s", filename);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (fstat(dfile->fd, &buf) == 0 && S_ISREG(buf.st_mode)) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->is_file = ISC_TRUE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->size = buf.st_size;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt nul_terminate(dfile);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return dfile;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntvoid
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_close(perf_datafile_t **dfilep)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt perf_datafile_t *dfile;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt ISC_INSIST(dfilep != NULL && *dfilep != NULL);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile = *dfilep;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt *dfilep = NULL;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile->fd >= 0 && dfile->fd != STDIN_FILENO)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt close(dfile->fd);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt MUTEX_DESTROY(&dfile->lock);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_mem_put(dfile->mctx, dfile, sizeof(*dfile));
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntvoid
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_setpipefd(perf_datafile_t *dfile, int pipe_fd)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->pipe_fd = pipe_fd;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntvoid
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_setmaxruns(perf_datafile_t *dfile, unsigned int maxruns)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->maxruns = maxruns;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntstatic void
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntreopen_file(perf_datafile_t *dfile)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile->cached) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_first(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt } else {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (lseek(dfile->fd, 0L, SEEK_SET) < 0)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt perf_log_fatal("cannot reread input");
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_clear(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt nul_terminate(dfile);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntstatic isc_result_t
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntread_more(perf_datafile_t *dfile)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt unsigned char *data;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt size_t size;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt ssize_t n;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_result_t result;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (!dfile->is_file && dfile->pipe_fd >= 0) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = perf_os_waituntilreadable(dfile->fd, dfile->pipe_fd,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt -1);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (result != ISC_R_SUCCESS)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (result);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_compact(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt data = isc_buffer_used(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt size = isc_buffer_availablelength(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt n = read(dfile->fd, data, size);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (n < 0)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (ISC_R_FAILURE);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_add(&dfile->data, n);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt nul_terminate(dfile);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile->is_file &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_usedlength(&dfile->data) == dfile->size)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->cached = ISC_TRUE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (ISC_R_SUCCESS);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntstatic isc_result_t
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntread_one_line(perf_datafile_t *dfile, isc_buffer_t *lines)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt const char *cur;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt unsigned int length, curlen, nrem;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_result_t result;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt while (ISC_TRUE) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /* Get the current line */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt cur = isc_buffer_current(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt curlen = strcspn(cur, "\n");
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /*
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * If the current line contains the rest of the buffer,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * we need to read more (unless the full file is cached).
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt nrem = isc_buffer_remaininglength(&dfile->data);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (curlen == nrem) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (! dfile->cached) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = read_more(dfile);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (result != ISC_R_SUCCESS)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (result);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (isc_buffer_remaininglength(&dfile->data) == 0) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->nruns++;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (ISC_R_EOF);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (isc_buffer_remaininglength(&dfile->data) > nrem)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt continue;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /* We now have a line. Advance the buffer past it. */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_forward(&dfile->data, curlen);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (isc_buffer_remaininglength(&dfile->data) > 0)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_forward(&dfile->data, 1);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /* If the line is empty or a comment, we need to try again. */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (curlen > 0 && cur[0] != ';')
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt break;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt length = isc_buffer_availablelength(lines);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (curlen > length - 1)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt curlen = length - 1;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_putmem(lines, cur, curlen);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_putuint8(lines, 0);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (ISC_R_SUCCESS);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntisc_result_t
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_next(perf_datafile_t *dfile, isc_buffer_t *lines,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_boolean_t is_update)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt const char *current;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_result_t result;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt LOCK(&dfile->lock);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile->maxruns > 0 && dfile->maxruns == dfile->nruns) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = ISC_R_EOF;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt goto done;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = read_one_line(dfile, lines);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (result == ISC_R_EOF) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (!dfile->read_any) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = ISC_R_INVALIDFILE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt goto done;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (dfile->maxruns != dfile->nruns) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt reopen_file(dfile);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = read_one_line(dfile, lines);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (result != ISC_R_SUCCESS) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt goto done;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->read_any = ISC_TRUE;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (is_update) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt while (ISC_TRUE) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt current = isc_buffer_used(lines);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = read_one_line(dfile, lines);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (result == ISC_R_EOF &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt dfile->maxruns != dfile->nruns) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt reopen_file(dfile);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (result != ISC_R_SUCCESS ||
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt strcasecmp(current, "send") == 0)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt break;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt };
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = ISC_R_SUCCESS;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt done:
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt UNLOCK(&dfile->lock);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return (result);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntunsigned int
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_nruns(const perf_datafile_t *dfile)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt{
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt return dfile->nruns;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt}