journal-remote-parse.c revision cb41ff2922b8a555c01d52e1038ac26360253c15
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Zbigniew Jędrzejewski-Szmek
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.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "journal-remote-parse.h"
#include "journald-native.h"
if (!source)
return;
}
}
/**
* Initialize zero-filled source with given values. On success, takes
* ownerhship of fd and writer, otherwise does not touch them.
*/
log_debug("Creating source for %sfd:%d (%s)",
if (!source)
return NULL;
return source;
}
if (!b)
return NULL;
return b;
}
ssize_t n;
char *c = NULL;
while (true) {
if (c != NULL)
break;
}
return -E2BIG;
}
if (source->passive_fd)
/* we have to wait for some data to come to us */
return -EWOULDBLOCK;
return log_oom();
if (n < 0) {
return -errno;
} else if (n == 0)
return 0;
}
return 1;
}
log_error("Failed to store received data of size %zu "
"(in addition to existing %zu bytes with %zu filled): %s",
return -ENOMEM;
}
return 0;
}
int n;
if (source->passive_fd)
/* we have to wait for some data to come to us */
return -EWOULDBLOCK;
return log_oom();
if (n < 0) {
return -errno;
} else if (n == 0)
return 0;
}
return 1;
}
int r;
void *data;
if (r <= 0)
return r;
log_error("Stream declares field with size %zu > DATA_SIZE_MAX = %u",
return -EINVAL;
}
log_warning("Binary field with zero length");
return 1;
}
int r;
if (r <= 0)
return r;
return 1;
}
int r;
char *data;
if (r <= 0)
return r;
if (*data != '\n') {
return -EINVAL;
}
return 1;
}
const char *timestamp;
int r;
assert(n > 0);
/* XXX: is it worth to support timestamps in extended format?
* We don't produce them, but who knows... */
if (timestamp)
/* ignore __CURSOR */
return 1;
if (timestamp) {
long long unsigned x;
r = safe_atollu(timestamp, &x);
if (r < 0)
else
return r < 0 ? r : 1;
}
if (timestamp) {
long long unsigned x;
r = safe_atollu(timestamp, &x);
if (r < 0)
else
return r < 0 ? r : 1;
}
if (timestamp) {
return 1;
}
/* no dunder */
return 0;
}
int r;
case STATE_LINE: {
size_t n;
if (r < 0)
return r;
if (r == 0) {
return r;
}
assert(n > 0);
if (n == 1) {
log_trace("Received empty line, event is ready");
return 1;
}
if (r != 0)
return r < 0 ? r : 0;
/* MESSAGE=xxx\n
or
COREDUMP\n
LLLLLLLL0011223344...\n
*/
if (sep)
/* chomp newline */
n--;
else
/* replace \n with = */
if (r < 0) {
log_error("Failed to put line in iovect");
return r;
}
if (!sep)
return 0; /* continue */
}
case STATE_DATA_START:
r = get_data_size(source);
// log_debug("get_data_size() -> %d", r);
if (r < 0)
return r;
if (r == 0) {
return 0;
}
return 0; /* continue */
case STATE_DATA: {
void *data;
// log_debug("get_data_data() -> %d", r);
if (r < 0)
return r;
if (r == 0) {
return 0;
}
if (r < 0) {
log_error("failed to put binary buffer in iovect");
return r;
}
return 0; /* continue */
}
case STATE_DATA_FINISH:
r = get_data_newline(source);
// log_debug("get_data_newline() -> %d", r);
if (r < 0)
return r;
if (r == 0) {
return 0;
}
return 0; /* continue */
default:
assert_not_reached("wtf?");
}
}
int r;
r = process_data(source);
if (r <= 0)
return r;
/* We have a full event */
log_trace("Received a full event from source@%p fd:%d (%s)",
log_warning("Entry with no payload, skipping");
goto freeing;
}
if (r < 0)
log_error("Failed to write entry of %zu bytes: %s",
else
r = 1;
/* possibly reset buffer position */
if (remain == 0) /* no brainer */
}
target /= 2;
char *tmp;
if (!tmp)
log_warning("Failed to reallocate buffer to (smaller) size %zu",
target);
else {
log_debug("Reallocated buffer from %zu to %zu bytes",
}
}
return r;
}