journal-upload-journal.c revision da927ba997d68401563b927f92e6e40e021a8e5c
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering * Write up to size bytes to buf. Return negative on error, and number of
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering * bytes written otherwise. The last case is a kind of an error too.
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poetteringstatic ssize_t write_entry(char *buf, size_t size, Uploader *u) {
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering while (true) {
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering r = sd_journal_get_cursor(u->journal, &u->current_cursor);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error_errno(r, "Failed to get cursor: %m");
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* not enough space */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* exactly one character short, but we don't need it */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering } /* fall through */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering r = sd_journal_get_realtime_usec(u->journal, &realtime);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error_errno(r, "Failed to get realtime timestamp: %m");
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "__REALTIME_TIMESTAMP="USEC_FMT"\n", realtime);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* not enough space */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* exactly one character short, but we don't need it */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering } /* fall through */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering r = sd_journal_get_monotonic_usec(u->journal, &monotonic, &boot_id);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error_errno(r, "Failed to get monotonic timestamp: %m");
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "__MONOTONIC_TIMESTAMP="USEC_FMT"\n", monotonic);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* not enough space */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* exactly one character short, but we don't need it */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering } /* fall through */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering r = sd_journal_get_monotonic_usec(u->journal, NULL, &boot_id);
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error_errno(r, "Failed to get monotonic timestamp: %m");
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering "_BOOT_ID=%s\n", sd_id128_to_string(boot_id, sid));
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* not enough space */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering /* exactly one character short, but we don't need it */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering } /* fall through */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering r = sd_journal_enumerate_data(u->journal,
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering log_error("Failed to move to next field in entry: %s",
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering } else if (r == 0) {
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering if (!utf8_is_printable_newline(u->field_data,
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering u->entry_state = ENTRY_BINARY_FIELD_START;
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering } /* fall through */
bd3fa1d2434aa28564251ac4da34d01537de8c4bLennart Poettering done = size - pos > u->field_length - u->field_pos;
case ENTRY_BINARY_FIELD_START: {
if (!c || c == u->field_data) {
return -EINVAL;
return pos;
u->entry_state ++;
case ENTRY_BINARY_FIELD_SIZE: {
return pos;
u->entry_state ++;
case ENTRY_OUTRO:
return pos;
u->entry_state ++;
u->entries_sent ++;
return pos;
sd_journal *j;
ssize_t w;
assert(u);
j = u->journal;
r = sd_journal_next(j);
strerror(-r));
return CURL_READFUNC_ABORT;
if (u->input_event)
u->uploading = false;
return CURL_READFUNC_ABORT;
filled += w;
if (filled == 0) {
return CURL_READFUNC_ABORT;
return filled;
assert(u);
if (u->journal) {
u->timeout = 0;
} else if (r < skip)
if (u->input_event) {
if (r == SD_JOURNAL_NOP)
int fd,
void *userp) {
assert(u);
if (u->uploading) {
return check_journal_input(u);
sd_journal *j,
const char *cursor,
bool after_cursor,
bool follow) {
u->journal = j;
if (follow) {
if (fd < 0) {
return fd;
r = sd_journal_reliable_fd(j);
assert(r >= 0);
if (cursor) {