|
|
87ca29 |
From 199c328686aac174b0535619e5cea8450016e827 Mon Sep 17 00:00:00 2001
|
|
|
87ca29 |
From: Karel Zak <kzak@redhat.com>
|
|
|
87ca29 |
Date: Thu, 21 Oct 2021 18:47:40 +0200
|
|
|
87ca29 |
Subject: logger: fix --size use for stdin
|
|
|
87ca29 |
MIME-Version: 1.0
|
|
|
87ca29 |
Content-Type: text/plain; charset=UTF-8
|
|
|
87ca29 |
Content-Transfer-Encoding: 8bit
|
|
|
87ca29 |
|
|
|
87ca29 |
The stdin version counts log header into the message size, but
|
|
|
87ca29 |
for example when it reads message from argv[] it counts only message
|
|
|
87ca29 |
itself.
|
|
|
87ca29 |
|
|
|
87ca29 |
$ logger --stderr --size 3 "abcd"
|
|
|
87ca29 |
<13>Oct 21 18:48:29 kzak: abc
|
|
|
87ca29 |
|
|
|
87ca29 |
$ echo "abcd" | logger --stderr --size 3
|
|
|
87ca29 |
logger: cannot allocate 18446744073709551597 bytes: Cannot allocate memory
|
|
|
87ca29 |
|
|
|
87ca29 |
Upstream: http://github.com/util-linux/util-linux/commit/58e4ee082bca100034791a4a74481f263bb30a25
|
|
|
87ca29 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2033622
|
|
|
87ca29 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
87ca29 |
---
|
|
|
87ca29 |
misc-utils/logger.c | 9 +++------
|
|
|
87ca29 |
1 file changed, 3 insertions(+), 6 deletions(-)
|
|
|
87ca29 |
|
|
|
87ca29 |
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
|
|
|
87ca29 |
index 5b122de79..43284caeb 100644
|
|
|
87ca29 |
--- a/misc-utils/logger.c
|
|
|
87ca29 |
+++ b/misc-utils/logger.c
|
|
|
87ca29 |
@@ -976,8 +976,7 @@ static void logger_stdin(struct logger_ctl *ctl)
|
|
|
87ca29 |
int has_header = 1;
|
|
|
87ca29 |
int default_priority = ctl->pri;
|
|
|
87ca29 |
int last_pri = default_priority;
|
|
|
87ca29 |
- size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
|
|
|
87ca29 |
- char *const buf = xmalloc(max_usrmsg_size + 2 + 2);
|
|
|
87ca29 |
+ char *buf = xmalloc(ctl->max_message_size + 2 + 2);
|
|
|
87ca29 |
int pri;
|
|
|
87ca29 |
int c;
|
|
|
87ca29 |
size_t i;
|
|
|
87ca29 |
@@ -1004,16 +1003,14 @@ static void logger_stdin(struct logger_ctl *ctl)
|
|
|
87ca29 |
ctl->pri = default_priority;
|
|
|
87ca29 |
|
|
|
87ca29 |
if (ctl->pri != last_pri) {
|
|
|
87ca29 |
- has_header = 0;
|
|
|
87ca29 |
- max_usrmsg_size =
|
|
|
87ca29 |
- ctl->max_message_size - strlen(ctl->hdr);
|
|
|
87ca29 |
+ generate_syslog_header(ctl);
|
|
|
87ca29 |
last_pri = ctl->pri;
|
|
|
87ca29 |
}
|
|
|
87ca29 |
if (c != EOF && c != '\n')
|
|
|
87ca29 |
c = getchar();
|
|
|
87ca29 |
}
|
|
|
87ca29 |
|
|
|
87ca29 |
- while (c != EOF && c != '\n' && i < max_usrmsg_size) {
|
|
|
87ca29 |
+ while (c != EOF && c != '\n' && i < ctl->max_message_size) {
|
|
|
87ca29 |
buf[i++] = c;
|
|
|
87ca29 |
c = getchar();
|
|
|
87ca29 |
}
|
|
|
87ca29 |
--
|
|
|
87ca29 |
2.34.1
|
|
|
87ca29 |
|