journal-remote-parse.c revision a83f403760cb63b1bf7787e9ff325ffb6d891d39
/*-*- 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;
}
}
char *c = NULL;
while (true) {
if (c != NULL)
break;
return -E2BIG;
}
/* we have to wait for some data to come to us */
return -EWOULDBLOCK;
return log_oom();
// FIXME: the buffer probably needs to be bigger than DATA_SIZE_MAX
// to accomodate such big fields.
if (n < 0) {
return -errno;
} else if (n == 0)
return 0;
}
/* Check if something remains */
if (remain) {
if (!newbuf)
return log_oom();
}
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;
/* 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;
}
/* Check if something remains */
if (remain) {
if (!newbuf)
return log_oom();
}
return 1;
}
int r;
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;
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_debug("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_debug("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;
return r;
}