|
Packit |
979a56 |
/*
|
|
Packit |
979a56 |
* Copyright (C) 2012 Red Hat, Inc.
|
|
Packit |
979a56 |
*
|
|
Packit |
979a56 |
* Author: Angus Salkeld <asalkeld@redhat.com>
|
|
Packit |
979a56 |
*
|
|
Packit |
979a56 |
* libqb is free software: you can redistribute it and/or modify
|
|
Packit |
979a56 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
Packit |
979a56 |
* the Free Software Foundation, either version 2.1 of the License, or
|
|
Packit |
979a56 |
* (at your option) any later version.
|
|
Packit |
979a56 |
*
|
|
Packit |
979a56 |
* libqb is distributed in the hope that it will be useful,
|
|
Packit |
979a56 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
979a56 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
979a56 |
* GNU Lesser General Public License for more details.
|
|
Packit |
979a56 |
*
|
|
Packit |
979a56 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
979a56 |
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
979a56 |
*/
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
#include <stdlib.h>
|
|
Packit |
979a56 |
#include <stdio.h>
|
|
Packit |
979a56 |
#include <string.h>
|
|
Packit |
979a56 |
#include <unistd.h>
|
|
Packit |
979a56 |
#include <signal.h>
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
#include <qb/qbdefs.h>
|
|
Packit |
979a56 |
#include <qb/qbrb.h>
|
|
Packit |
979a56 |
#include <qb/qbutil.h>
|
|
Packit |
979a56 |
#include <qb/qblog.h>
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
#define ONE_MEG 1048576
|
|
Packit |
979a56 |
static qb_ringbuffer_t *rb = NULL;
|
|
Packit |
979a56 |
static int keep_reading = QB_TRUE;
|
|
Packit |
979a56 |
int8_t buffer[ONE_MEG];
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
static void sigterm_handler(int32_t num)
|
|
Packit |
979a56 |
{
|
|
Packit |
979a56 |
qb_log(LOG_INFO, "signal %d", num);
|
|
Packit |
979a56 |
keep_reading = QB_FALSE;
|
|
Packit |
979a56 |
}
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
int32_t main(int32_t argc, char *argv[])
|
|
Packit |
979a56 |
{
|
|
Packit |
979a56 |
ssize_t num_read;
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
signal(SIGINT, sigterm_handler);
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
qb_log_init("rbreader", LOG_USER, LOG_EMERG);
|
|
Packit |
979a56 |
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
|
Packit |
979a56 |
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
|
|
Packit |
979a56 |
QB_LOG_FILTER_FILE, "*", LOG_TRACE);
|
|
Packit |
979a56 |
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
rb = qb_rb_open("tester", ONE_MEG * 3,
|
|
Packit |
979a56 |
QB_RB_FLAG_SHARED_PROCESS |
|
|
Packit |
979a56 |
QB_RB_FLAG_CREATE, 0);
|
|
Packit |
979a56 |
|
|
Packit |
979a56 |
if (rb == NULL) {
|
|
Packit |
979a56 |
qb_perror(LOG_ERR, "failed to create ringbuffer");
|
|
Packit |
979a56 |
return -1;
|
|
Packit |
979a56 |
}
|
|
Packit |
979a56 |
while (keep_reading) {
|
|
Packit |
979a56 |
num_read = qb_rb_chunk_read(rb, buffer,
|
|
Packit |
979a56 |
ONE_MEG, 0);
|
|
Packit |
979a56 |
if (num_read == -ETIMEDOUT) {
|
|
Packit |
979a56 |
usleep(100000);
|
|
Packit |
979a56 |
} else if (num_read < 0) {
|
|
Packit |
979a56 |
errno = -num_read;
|
|
Packit |
979a56 |
qb_perror(LOG_ERR, "nothing to read");
|
|
Packit |
979a56 |
}
|
|
Packit |
979a56 |
}
|
|
Packit |
979a56 |
qb_rb_close(rb);
|
|
Packit |
979a56 |
qb_log_fini();
|
|
Packit |
979a56 |
return 0;
|
|
Packit |
979a56 |
}
|