journal-remote-parse.c revision 8201af08fa09c2bd0f005fbe262f27e2c5bd2d86
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering This file is part of systemd.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering Copyright 2014 Zbigniew Jędrzejewski-Szmek
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering systemd is free software; you can redistribute it and/or modify it
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering under the terms of the GNU Lesser General Public License as published by
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering (at your option) any later version.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering systemd is distributed in the hope that it will be useful, but
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering Lesser General Public License for more details.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering You should have received a copy of the GNU Lesser General Public License
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering log_debug("Closing fd:%d (%s)", source->fd, source->name);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringstatic int get_line(RemoteSource *source, char **line, size_t *size) {
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering assert(source->buf == NULL || source->size > 0);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering while (true) {
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering c = memchr(source->buf + source->scanned, '\n',
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering log_error("Entry is bigger than %u bytes.", DATA_SIZE_MAX);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering /* we have to wait for some data to come to us */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering if (source->size - source->filled < LINE_CHUNK &&
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering !GREEDY_REALLOC(source->buf, source->size,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering MAX(source->filled + LINE_CHUNK, DATA_SIZE_MAX)))
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering assert(source->size - source->filled >= LINE_CHUNK);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering n = read(source->fd, source->buf + source->filled,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering MAX(source->size, DATA_SIZE_MAX) - source->filled);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering if (errno != EAGAIN && errno != EWOULDBLOCK)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering log_error("read(%d, ..., %zd): %m", source->fd,
b8bde11658366290521e3d03316378b482600323Jan Engelhardt } else if (n == 0)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering /* Check if something remains */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering remain = source->buf + source->filled - c - 1;
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringint push_data(RemoteSource *source, const char *data, size_t size) {
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering if (!GREEDY_REALLOC(source->buf, source->size,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering log_error("Failed to store received data of size %zu "
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering "(in addition to existing %zu bytes with %zu filled): %s",
b8bde11658366290521e3d03316378b482600323Jan Engelhardt size, source->size, source->filled, strerror(ENOMEM));
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering memcpy(source->buf + source->filled, data, size);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringstatic int fill_fixed_size(RemoteSource *source, void **data, size_t size) {
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering assert(source->state == STATE_DATA_START ||
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering assert(source->scanned <= source->filled);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering assert(source->buf != NULL || source->size == 0);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering assert(source->buf == NULL || source->size > 0);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering /* we have to wait for some data to come to us */
return log_oom();
return -errno;
if (remain) {
if (!newbuf)
return log_oom();
return -EINVAL;
return -EINVAL;
const char *timestamp;
assert(n > 0);
if (timestamp)
if (timestamp) {
if (timestamp) {
if (timestamp) {
case STATE_LINE: {
size_t n;
assert(n > 0);
if (sep)
if (!sep)
case STATE_DATA_START:
case STATE_DATA: {
void *data;
case STATE_DATA_FINISH:
goto freeing;