summaryrefslogtreecommitdiffstats
path: root/misc-utils
diff options
context:
space:
mode:
authorKarel Zak2019-01-23 11:41:43 +0100
committerKarel Zak2019-01-23 11:41:43 +0100
commit1c4a2600cc5dc44e6d517ca9fa6f3d7b1ef9d481 (patch)
tree42b27b3fed6f9933b8a2bb721acaed14eef59d1b /misc-utils
parentlibblkid: remove dependence on libuuid (diff)
downloadkernel-qcow2-util-linux-1c4a2600cc5dc44e6d517ca9fa6f3d7b1ef9d481.tar.gz
kernel-qcow2-util-linux-1c4a2600cc5dc44e6d517ca9fa6f3d7b1ef9d481.tar.xz
kernel-qcow2-util-linux-1c4a2600cc5dc44e6d517ca9fa6f3d7b1ef9d481.zip
logger: concatenate multiple lines of MESSAGE into a single field.
this is deemed a useful special case since journalctl will only show either the first or last element of the message array if the field appears multiple times. Based on patch from: Kjetil Torgrim Homme <kjetil.homme@redpill-linpro.com> https://github.com/karelzak/util-linux/pull/743 Addresses: https://github.com/karelzak/util-linux/issues/742 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/logger.14
-rw-r--r--misc-utils/logger.c24
2 files changed, 26 insertions, 2 deletions
diff --git a/misc-utils/logger.1 b/misc-utils/logger.1
index bf11c411b..37a87e5c9 100644
--- a/misc-utils/logger.1
+++ b/misc-utils/logger.1
@@ -108,6 +108,10 @@ execution of
will display MESSAGE field. Use
.B journalctl \-\-output json-pretty
to see rest of the fields.
+.sp
+To include newlines in MESSAGE, specify MESSAGE several times. This is
+handled as a special case, other fields will be stored as an array in
+the journal if they appear multiple times.
.TP
.BR \-\-msgid " \fImsgid
Sets the RFC5424 MSGID field. Note that the space character is not permitted
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index ebdc56ec2..10b307ef9 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -336,11 +336,11 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
struct iovec *iovec;
char *buf = NULL;
ssize_t sz;
- int n, lines, vectors = 8, ret = 0;
+ int n, lines = 0, vectors = 8, ret = 0, msgline = -1;
size_t dummy = 0;
iovec = xmalloc(vectors * sizeof(struct iovec));
- for (lines = 0; /* nothing */ ; lines++) {
+ while (1) {
buf = NULL;
sz = getline(&buf, &dummy, fp);
if (sz == -1 ||
@@ -348,6 +348,25 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
free(buf);
break;
}
+
+ if (strncmp(buf, "MESSAGE=", 8) == 0) {
+ if (msgline == -1)
+ msgline = lines; /* remember the first message */
+ else {
+ char *p = xrealloc(iovec[msgline].iov_base,
+ iovec[msgline].iov_len + sz - 8 + 2);
+
+ iovec[msgline].iov_base = p;
+ p += iovec[msgline].iov_len;
+ *p++ = '\n';
+ memcpy(p, buf + 8, sz - 8);
+ free(buf);
+
+ iovec[msgline].iov_len += sz - 8 + 1;
+ continue;
+ }
+ }
+
if (lines == vectors) {
vectors *= 2;
if (IOV_MAX < vectors)
@@ -356,6 +375,7 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
}
iovec[lines].iov_base = buf;
iovec[lines].iov_len = sz;
+ ++lines;
}
if (!ctl->noact)