systemd/0001-journal-fix-export-of-messages-containing-newlines.patch

81 lines
3.0 KiB
Diff
Raw Normal View History

From 0ade5ffe2778e7b238bba8d979ca4d53dee1e702 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Mon, 31 Mar 2014 08:57:28 -0400
Subject: [PATCH] journal: fix export of messages containing newlines
In "export" format, newlines are significant, and messages containing
newlines must be exported as "binary".
---
src/shared/logs-show.c | 7 ++++---
src/shared/utf8.c | 5 +++--
src/shared/utf8.h | 5 ++++-
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git src/shared/logs-show.c src/shared/logs-show.c
index 9d14933..b0b66f6 100644
--- src/shared/logs-show.c
+++ src/shared/logs-show.c
@@ -547,7 +547,9 @@ static int output_export(
startswith(data, "_BOOT_ID="))
continue;
- if (!utf8_is_printable(data, length)) {
+ if (utf8_is_printable_newline(data, length, false))
+ fwrite(data, length, 1, f);
+ else {
const char *c;
uint64_t le64;
@@ -562,8 +564,7 @@ static int output_export(
le64 = htole64(length - (c - (const char*) data) - 1);
fwrite(&le64, sizeof(le64), 1, f);
fwrite(c + 1, length - (c - (const char*) data) - 1, 1, f);
- } else
- fwrite(data, length, 1, f);
+ }
fputc('\n', f);
}
diff --git src/shared/utf8.c src/shared/utf8.c
index 0b524d8..c559c13 100644
--- src/shared/utf8.c
+++ src/shared/utf8.c
@@ -136,7 +136,7 @@ int utf8_encoded_to_unichar(const char *str) {
return unichar;
}
-bool utf8_is_printable(const char* str, size_t length) {
+bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
const uint8_t *p;
assert(str);
@@ -145,7 +145,8 @@ bool utf8_is_printable(const char* str, size_t length) {
int encoded_len = utf8_encoded_valid_unichar((const char *)p);
int val = utf8_encoded_to_unichar((const char*)p);
- if (encoded_len < 0 || val < 0 || is_unicode_control(val))
+ if (encoded_len < 0 || val < 0 || is_unicode_control(val) ||
+ (!newline && val == '\n'))
return false;
length -= encoded_len;
diff --git src/shared/utf8.h src/shared/utf8.h
index c0eb73a..c087995 100644
--- src/shared/utf8.h
+++ src/shared/utf8.h
@@ -31,7 +31,10 @@ const char *utf8_is_valid(const char *s) _pure_;
char *ascii_is_valid(const char *s) _pure_;
char *utf8_escape_invalid(const char *s);
-bool utf8_is_printable(const char* str, size_t length) _pure_;
+bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_;
+_pure_ static inline bool utf8_is_printable(const char* str, size_t length) {
+ return utf8_is_printable_newline(str, length, true);
+}
char *utf16_to_utf8(const void *s, size_t length);
--
1.7.9.2