|
|
17b0f1 |
From 608259be892c532d0afaeb81de3a5ee578d7658a Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
17b0f1 |
Date: Mon, 2 Mar 2015 10:34:51 -0500
|
|
|
17b0f1 |
Subject: [PATCH] journal-remote: fix saving of binary fields
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Binary fields were not processed properly, and resulting journal files
|
|
|
17b0f1 |
were non-conforming, resulting in an error ("Invalid field.") when reading.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
https://bugs.freedesktop.org/show_bug.cgi?id=89391
|
|
|
17b0f1 |
(cherry picked from commit 09d801a82a46df518dd752e40bf13ac404daa2ce)
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
src/journal-remote/journal-remote-parse.c | 31 +++++++++++++----------
|
|
|
17b0f1 |
src/journal-remote/journal-remote-parse.h | 4 ++-
|
|
|
17b0f1 |
2 files changed, 21 insertions(+), 14 deletions(-)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
|
|
|
17b0f1 |
index d9dea8deb0..afded7e380 100644
|
|
|
17b0f1 |
--- a/src/journal-remote/journal-remote-parse.c
|
|
|
17b0f1 |
+++ b/src/journal-remote/journal-remote-parse.c
|
|
|
17b0f1 |
@@ -344,22 +344,25 @@ int process_data(RemoteSource *source) {
|
|
|
17b0f1 |
LLLLLLLL0011223344...\n
|
|
|
17b0f1 |
*/
|
|
|
17b0f1 |
sep = memchr(line, '=', n);
|
|
|
17b0f1 |
- if (sep)
|
|
|
17b0f1 |
+ if (sep) {
|
|
|
17b0f1 |
/* chomp newline */
|
|
|
17b0f1 |
n--;
|
|
|
17b0f1 |
- else
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ r = iovw_put(&source->iovw, line, n);
|
|
|
17b0f1 |
+ if (r < 0)
|
|
|
17b0f1 |
+ return r;
|
|
|
17b0f1 |
+ } else {
|
|
|
17b0f1 |
/* replace \n with = */
|
|
|
17b0f1 |
line[n-1] = '=';
|
|
|
17b0f1 |
- log_trace("Received: %.*s", (int) n, line);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = iovw_put(&source->iovw, line, n);
|
|
|
17b0f1 |
- if (r < 0) {
|
|
|
17b0f1 |
- log_error("Failed to put line in iovect");
|
|
|
17b0f1 |
- return r;
|
|
|
17b0f1 |
+ source->field_len = n;
|
|
|
17b0f1 |
+ source->state = STATE_DATA_START;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ /* we cannot put the field in iovec until we have all data */
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- if (!sep)
|
|
|
17b0f1 |
- source->state = STATE_DATA_START;
|
|
|
17b0f1 |
+ log_trace("Received: %.*s (%s)", (int) n, line, sep ? "text" : "binary");
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
return 0; /* continue */
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -382,6 +385,7 @@ int process_data(RemoteSource *source) {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
case STATE_DATA: {
|
|
|
17b0f1 |
void *data;
|
|
|
17b0f1 |
+ char *field;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
assert(source->data_size > 0);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -396,11 +400,12 @@ int process_data(RemoteSource *source) {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
assert(data);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = iovw_put(&source->iovw, data, source->data_size);
|
|
|
17b0f1 |
- if (r < 0) {
|
|
|
17b0f1 |
- log_error("failed to put binary buffer in iovect");
|
|
|
17b0f1 |
+ field = (char*) data - sizeof(uint64_t) - source->field_len;
|
|
|
17b0f1 |
+ memmove(field + sizeof(uint64_t), field, source->field_len);
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ r = iovw_put(&source->iovw, field + sizeof(uint64_t), source->field_len + source->data_size);
|
|
|
17b0f1 |
+ if (r < 0)
|
|
|
17b0f1 |
return r;
|
|
|
17b0f1 |
- }
|
|
|
17b0f1 |
|
|
|
17b0f1 |
source->state = STATE_DATA_FINISH;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/journal-remote/journal-remote-parse.h b/src/journal-remote/journal-remote-parse.h
|
|
|
17b0f1 |
index 8499f4eb82..22db550913 100644
|
|
|
17b0f1 |
--- a/src/journal-remote/journal-remote-parse.h
|
|
|
17b0f1 |
+++ b/src/journal-remote/journal-remote-parse.h
|
|
|
17b0f1 |
@@ -42,7 +42,9 @@ typedef struct RemoteSource {
|
|
|
17b0f1 |
size_t offset; /* offset to the beginning of live data in the buffer */
|
|
|
17b0f1 |
size_t scanned; /* number of bytes since the beginning of data without a newline */
|
|
|
17b0f1 |
size_t filled; /* total number of bytes in the buffer */
|
|
|
17b0f1 |
- size_t data_size; /* size of the binary data chunk being processed */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ size_t field_len; /* used for binary fields: the field name length */
|
|
|
17b0f1 |
+ size_t data_size; /* and the size of the binary data chunk being processed */
|
|
|
17b0f1 |
|
|
|
17b0f1 |
struct iovec_wrapper iovw;
|
|
|
17b0f1 |
|