/***
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 "alloc-util.h"
#include "fd-util.h"
#include "journal-remote-parse.h"
#include "journald-native.h"
#include "parse-util.h"
#include "string-util.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;
for (;;) {
if (c != NULL)
break;
}
return -E2BIG;
}
if (source->passive_fd)
/* we have to wait for some data to come to us */
return -EAGAIN;
/* We know that source->filled is at most DATA_SIZE_MAX, so if
we reallocate it, we'll increase the size at least a bit. */
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 -EAGAIN;
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 = 0;
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--;
if (r < 0)
return r;
} else {
/* replace \n with = */
/* we cannot put the field in iovec until we have all data */
}
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;
char *field;
// log_debug("get_data_data() -> %d", r);
if (r < 0)
return r;
if (r == 0) {
return 0;
}
if (r < 0)
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 full event from source@%p fd:%d (%s)",
log_warning("Entry with no payload, skipping");
goto freeing;
}
if (r < 0)
log_error_errno(r, "Failed to write entry of %zu bytes: %m",
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;
}