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