journal-remote-parse.c revision 9ff48d0982fcb97923955685fe9fa4e0e67cb238
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering This file is part of systemd.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering Copyright 2014 Zbigniew Jędrzejewski-Szmek
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering (at your option) any later version.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering systemd is distributed in the hope that it will be useful, but
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering Lesser General Public License for more details.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersenvoid source_free(RemoteSource *source) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering if (source->fd >= 0 && !source->passive_fd) {
c7f1808add4d971229ba5311cf66e659122aa338Lennart Poettering log_debug("Closing fd:%d (%s)", source->fd, source->name);
28cb17ef0281efc3a46e5d0e702b0b0ddeaafaa4Filipe Brandenburger log_debug("Writer ref count %u", source->writer->n_ref);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * Initialize zero-filled source with given values. On success, takes
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * ownerhship of fd and writer, otherwise does not touch them.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart PoetteringRemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering log_debug("Creating source for %sfd:%d (%s)",
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic int get_line(RemoteSource *source, char **line, size_t *size) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert(source->buf == NULL || source->size > 0);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering while (true) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering c = memchr(source->buf + source->scanned, '\n',
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering log_error("Entry is bigger than %u bytes.", DATA_SIZE_MAX);
return -EWOULDBLOCK;
return log_oom();
return -errno;
if (remain) {
if (!newbuf)
return log_oom();
return -ENOMEM;
return -EWOULDBLOCK;
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;